diff options
Diffstat (limited to 'src/backend/optimizer/plan/planagg.c')
-rw-r--r-- | src/backend/optimizer/plan/planagg.c | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/backend/optimizer/plan/planagg.c b/src/backend/optimizer/plan/planagg.c index 4007ac45588..5bbfd2377eb 100644 --- a/src/backend/optimizer/plan/planagg.c +++ b/src/backend/optimizer/plan/planagg.c @@ -48,6 +48,7 @@ static bool find_minmax_aggs_walker(Node *node, List **context); static bool build_minmax_path(PlannerInfo *root, MinMaxAggInfo *mminfo, Oid eqop, Oid sortop, bool nulls_first); +static void minmax_qp_callback(PlannerInfo *root, void *extra); static void make_agg_subplan(PlannerInfo *root, MinMaxAggInfo *mminfo); static Node *replace_aggs_with_params_mutator(Node *node, PlannerInfo *root); static Oid fetch_agg_sort_op(Oid aggfnoid); @@ -446,25 +447,11 @@ build_minmax_path(PlannerInfo *root, MinMaxAggInfo *mminfo, FLOAT8PASSBYVAL); /* - * Set up requested pathkeys. - */ - subroot->group_pathkeys = NIL; - subroot->window_pathkeys = NIL; - subroot->distinct_pathkeys = NIL; - - subroot->sort_pathkeys = - make_pathkeys_for_sortclauses(subroot, - parse->sortClause, - parse->targetList, - false); - - subroot->query_pathkeys = subroot->sort_pathkeys; - - /* * Generate the best paths for this query, telling query_planner that we * have LIMIT 1. */ query_planner(subroot, parse->targetList, 1.0, 1.0, + minmax_qp_callback, NULL, &cheapest_path, &sorted_path, &dNumGroups); /* @@ -506,6 +493,24 @@ build_minmax_path(PlannerInfo *root, MinMaxAggInfo *mminfo, } /* + * Compute query_pathkeys and other pathkeys during plan generation + */ +static void +minmax_qp_callback(PlannerInfo *root, void *extra) +{ + root->group_pathkeys = NIL; + root->window_pathkeys = NIL; + root->distinct_pathkeys = NIL; + + root->sort_pathkeys = + make_pathkeys_for_sortclauses(root, + root->parse->sortClause, + root->parse->targetList); + + root->query_pathkeys = root->sort_pathkeys; +} + +/* * Construct a suitable plan for a converted aggregate query */ static void |