aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/planner.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/optimizer/plan/planner.c')
-rw-r--r--src/backend/optimizer/plan/planner.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 3c7a665563c..b5c8d7d3de8 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.65 1999/08/22 23:56:45 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.66 1999/08/26 05:07:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -296,26 +296,27 @@ union_planner(Query *parse)
/*
* If we have a HAVING clause, do the necessary things with it.
+ * This code should parallel query_planner()'s initial processing
+ * of the WHERE clause.
*/
if (parse->havingQual)
{
List *ql;
- /* convert the havingQual to conjunctive normal form (cnf) */
- parse->havingQual = (Node *) cnfify((Expr *) parse->havingQual, true);
+ /* Replace uplevel Vars with Params */
+ if (PlannerQueryLevel > 1)
+ parse->havingQual = SS_replace_correlation_vars(parse->havingQual);
if (parse->hasSubLinks)
{
- /*
- * There may be a subselect in the havingQual, so we have to
- * process it using the same function as for a subselect in
- * 'where'
- */
+ /* Expand SubLinks to SubPlans */
parse->havingQual = SS_process_sublinks(parse->havingQual);
/*
* Check for ungrouped variables passed to subplans. (Probably
- * this should be done for the targetlist as well???)
+ * this should be done for the targetlist as well??? But we
+ * should NOT do it for the WHERE qual, since WHERE is
+ * evaluated pre-GROUP.)
*/
if (check_subplans_for_ungrouped_vars(parse->havingQual,
parse->groupClause,
@@ -323,6 +324,9 @@ union_planner(Query *parse)
elog(ERROR, "Sub-SELECT in HAVING clause must use only GROUPed attributes from outer SELECT");
}
+ /* convert the havingQual to conjunctive normal form (cnf) */
+ parse->havingQual = (Node *) cnfify((Expr *) parse->havingQual, true);
+
/*
* Require an aggregate function to appear in each clause of the
* havingQual (else it could have been done as a WHERE constraint).
@@ -428,10 +432,11 @@ make_subplanTargetList(Query *parse,
/*
* Otherwise, start with a "flattened" tlist (having just the vars
- * mentioned in the targetlist and HAVING qual).
+ * mentioned in the targetlist and HAVING qual --- but not upper-
+ * level Vars; they will be replaced by Params later on).
*/
sub_tlist = flatten_tlist(tlist);
- extravars = pull_var_clause(parse->havingQual);
+ extravars = pull_var_clause(parse->havingQual, false);
sub_tlist = add_to_flat_tlist(sub_tlist, extravars);
freeList(extravars);