mirror of
https://github.com/postgres/postgres.git
synced 2025-07-15 19:21:59 +03:00
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.
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user