summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/planner.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2003-02-15 20:12:41 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2003-02-15 20:12:41 +0000
commit056467ec6bcbd81a9d1480af8d641946a5ef1bff (patch)
tree9bcbdc5f6443cc045783a0e712fbab572eff0952 /src/backend/optimizer/plan/planner.c
parent50c4190e370a66bc8c52a0985cebf5560b28b058 (diff)
Teach planner how to propagate pathkeys from sub-SELECTs in FROM up to
the outer query. (The implementation is a bit klugy, but it would take nontrivial restructuring to make it nicer, which this is probably not worth.) This avoids unnecessary sort steps in examples like SELECT foo,count(*) FROM (SELECT ... ORDER BY foo,bar) sub GROUP BY foo which means there is now a reasonable technique for controlling the order of inputs to custom aggregates, even in the grouping case.
Diffstat (limited to 'src/backend/optimizer/plan/planner.c')
-rw-r--r--src/backend/optimizer/plan/planner.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 9a0df30613b..2b46b4b7401 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.146 2003/02/09 23:57:19 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.147 2003/02/15 20:12:40 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -469,6 +469,9 @@ inheritance_planner(Query *parse, List *inheritlist)
/* Save the target-relations list for the executor, too */
parse->resultRelations = inheritlist;
+ /* Mark result as unordered (probably unnecessary) */
+ parse->query_pathkeys = NIL;
+
return (Plan *) make_append(subplans, true, tlist);
}
@@ -491,7 +494,8 @@ inheritance_planner(Query *parse, List *inheritlist)
* The normal case is to pass -1, but some callers pass values >= 0 to
* override this routine's determination of the appropriate fraction.
*
- * Returns a query plan.
+ * Returns a query plan. Also, parse->query_pathkeys is returned as the
+ * actual output ordering of the plan (in pathkey format).
*--------------------
*/
static Plan *
@@ -1191,10 +1195,13 @@ grouping_planner(Query *parse, double tuple_fraction)
if (parse->sortClause)
{
if (!pathkeys_contained_in(sort_pathkeys, current_pathkeys))
+ {
result_plan = (Plan *) make_sort_from_sortclauses(parse,
tlist,
result_plan,
parse->sortClause);
+ current_pathkeys = sort_pathkeys;
+ }
}
/*
@@ -1232,6 +1239,12 @@ grouping_planner(Query *parse, double tuple_fraction)
parse->limitCount);
}
+ /*
+ * Return the actual output ordering in query_pathkeys for possible
+ * use by an outer query level.
+ */
+ parse->query_pathkeys = current_pathkeys;
+
return result_plan;
}