diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-01-20 20:45:41 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-01-20 20:45:41 +0000 |
| commit | f41803bb39bc2949db200116a609fd242d0ec221 (patch) | |
| tree | 2c81bcf712ab8b46133c2f50bbee34b2b3ea7129 /src/backend/optimizer/plan/planner.c | |
| parent | 2b7334d4877ba445003f96b0bb7eed4e7078a39b (diff) | |
Refactor planner's pathkeys data structure to create a separate, explicit
representation of equivalence classes of variables. This is an extensive
rewrite, but it brings a number of benefits:
* planner no longer fails in the presence of "incomplete" operator families
that don't offer operators for every possible combination of datatypes.
* avoid generating and then discarding redundant equality clauses.
* remove bogus assumption that derived equalities always use operators
named "=".
* mergejoins can work with a variety of sort orders (e.g., descending) now,
instead of tying each mergejoinable operator to exactly one sort order.
* better recognition of redundant sort columns.
* can make use of equalities appearing underneath an outer join.
Diffstat (limited to 'src/backend/optimizer/plan/planner.c')
| -rw-r--r-- | src/backend/optimizer/plan/planner.c | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index 5fcfc58bf9b..ae9c10fc6b6 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.211 2007/01/10 18:06:03 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.212 2007/01/20 20:45:39 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -206,6 +206,8 @@ subquery_planner(Query *parse, double tuple_fraction, /* Create a PlannerInfo data structure for this subquery */ root = makeNode(PlannerInfo); root->parse = parse; + root->planner_cxt = CurrentMemoryContext; + root->eq_classes = NIL; root->in_info_list = NIL; root->append_rel_list = NIL; @@ -715,9 +717,10 @@ grouping_planner(PlannerInfo *root, double tuple_fraction) * operation's result. We have to do this before overwriting the sort * key information... */ - current_pathkeys = make_pathkeys_for_sortclauses(set_sortclauses, - result_plan->targetlist); - current_pathkeys = canonicalize_pathkeys(root, current_pathkeys); + current_pathkeys = make_pathkeys_for_sortclauses(root, + set_sortclauses, + result_plan->targetlist, + true); /* * We should not need to call preprocess_targetlist, since we must be @@ -742,9 +745,10 @@ grouping_planner(PlannerInfo *root, double tuple_fraction) /* * Calculate pathkeys that represent result ordering requirements */ - sort_pathkeys = make_pathkeys_for_sortclauses(parse->sortClause, - tlist); - sort_pathkeys = canonicalize_pathkeys(root, sort_pathkeys); + sort_pathkeys = make_pathkeys_for_sortclauses(root, + parse->sortClause, + tlist, + true); } else { @@ -778,12 +782,18 @@ grouping_planner(PlannerInfo *root, double tuple_fraction) /* * Calculate pathkeys that represent grouping/ordering requirements. * Stash them in PlannerInfo so that query_planner can canonicalize - * them. + * them after EquivalenceClasses have been formed. */ root->group_pathkeys = - make_pathkeys_for_sortclauses(parse->groupClause, tlist); + make_pathkeys_for_sortclauses(root, + parse->groupClause, + tlist, + false); root->sort_pathkeys = - make_pathkeys_for_sortclauses(parse->sortClause, tlist); + make_pathkeys_for_sortclauses(root, + parse->sortClause, + tlist, + false); /* * Will need actual number of aggregates for estimating costs. @@ -1069,10 +1079,9 @@ grouping_planner(PlannerInfo *root, double tuple_fraction) { if (!pathkeys_contained_in(sort_pathkeys, current_pathkeys)) { - result_plan = (Plan *) - make_sort_from_sortclauses(root, - parse->sortClause, - result_plan); + result_plan = (Plan *) make_sort_from_pathkeys(root, + result_plan, + sort_pathkeys); current_pathkeys = sort_pathkeys; } } |
