diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 1999-08-22 20:15:04 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 1999-08-22 20:15:04 +0000 |
commit | 78114cd4d4fd99feb0c753de34d358b16d1ff0ee (patch) | |
tree | 58838858badf427beddaafe425a9def510741d37 /src/backend/optimizer/plan/planner.c | |
parent | db436adf761bd5cb7990745ceba2959ac4bfca7c (diff) | |
download | postgresql-78114cd4d4fd99feb0c753de34d358b16d1ff0ee.tar.gz postgresql-78114cd4d4fd99feb0c753de34d358b16d1ff0ee.zip |
Further planner/optimizer cleanups. Move all set_tlist_references
and fix_opids processing to a single recursive pass over the plan tree
executed at the very tail end of planning, rather than haphazardly here
and there at different places. Now that tlist Vars do not get modified
until the very end, it's possible to get rid of the klugy var_equal and
match_varid partial-matching routines, and just use plain equal()
throughout the optimizer. This is a step towards allowing merge and
hash joins to be done on expressions instead of only Vars ...
Diffstat (limited to 'src/backend/optimizer/plan/planner.c')
-rw-r--r-- | src/backend/optimizer/plan/planner.c | 52 |
1 files changed, 21 insertions, 31 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index b328c40f226..0003262a454 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.63 1999/08/21 03:49:03 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.64 1999/08/22 20:14:48 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -70,6 +70,8 @@ planner(Query *parse) } result_plan->nParamExec = length(PlannerParamVar); + set_plan_references(result_plan); + return result_plan; } @@ -173,8 +175,7 @@ union_planner(Query *parse) 0, true); - var = makeVar(rowmark->rti, -1, TIDOID, - -1, 0, rowmark->rti, -1); + var = makeVar(rowmark->rti, -1, TIDOID, -1, 0); ctid = makeTargetEntry(resdom, (Node *) var); tlist = lappend(tlist, ctid); @@ -279,6 +280,8 @@ union_planner(Query *parse) */ if (parse->havingQual) { + List *ql; + /* convert the havingQual to conjunctive normal form (cnf) */ parse->havingQual = (Node *) cnfify((Expr *) parse->havingQual, true); @@ -295,13 +298,21 @@ union_planner(Query *parse) * Check for ungrouped variables passed to subplans. (Probably * this should be done for the targetlist as well???) */ - check_having_for_ungrouped_vars(parse->havingQual, - parse->groupClause, - parse->targetList); + if (check_subplans_for_ungrouped_vars(parse->havingQual, + parse->groupClause, + parse->targetList)) + elog(ERROR, "Sub-SELECT in HAVING clause must use only GROUPed attributes from outer SELECT"); } - /* Calculate the opfids from the opnos */ - parse->havingQual = (Node *) fix_opids((List *) parse->havingQual); + /* + * Require an aggregate function to appear in each clause of the + * havingQual (else it could have been done as a WHERE constraint). + */ + foreach(ql, (List *) parse->havingQual) + { + if (pull_agg_clause(lfirst(ql)) == NIL) + elog(ERROR, "SELECT/HAVING requires aggregates to be valid"); + } } /* @@ -315,13 +326,6 @@ union_planner(Query *parse) result_plan->qual = (List *) parse->havingQual; /* - * Update vars to refer to subplan result tuples, and - * make sure there is an Aggref in every HAVING clause. - */ - if (!set_agg_tlist_references((Agg *) result_plan)) - elog(ERROR, "SELECT/HAVING requires aggregates to be valid"); - - /* * Assume result is not ordered suitably for ORDER BY. * XXX it might be; improve this! */ @@ -474,7 +478,6 @@ make_groupplan(List *group_tlist, Plan *subplan) { int numCols = length(groupClause); - Group *grpplan; if (! is_sorted) { @@ -515,21 +518,8 @@ make_groupplan(List *group_tlist, keyno); } - /* - * Fix variables in tlist (should be done somewhere else?) - */ - group_tlist = copyObject(group_tlist); /* necessary?? */ - replace_tlist_with_subplan_refs(group_tlist, - (Index) 0, - subplan->targetlist); - - /* - * Make the Group node - */ - grpplan = make_group(group_tlist, tuplePerGroup, numCols, - grpColIdx, subplan); - - return (Plan *) grpplan; + return (Plan *) make_group(group_tlist, tuplePerGroup, numCols, + grpColIdx, subplan); } /* |