From ee280c260030c703000bc78ee9b02f1bde74abee Mon Sep 17 00:00:00 2001 From: Tomas Vondra Date: Fri, 13 Jan 2017 05:19:12 +0100 Subject: [PATCH] rework grouping_distribution_match() to accept list of clauses Accepting (Query*) is not sufficient, because we need to know which of the clause lists to inspect (DISTINCT, GROUP BY, ...). Note: Perhaps we should use PathKeys instead of those clause lists? --- src/backend/optimizer/plan/planner.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index 2f038ef65e..c8a60f7d58 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -160,8 +160,8 @@ static PathTarget *make_sort_input_target(PlannerInfo *root, bool *have_postponed_srfs); static bool equal_distributions(PlannerInfo *root, Distribution *dst1, Distribution *dst2); -static bool grouping_distribution_match(PlannerInfo *root, Path *path, - Query *parse); +static bool grouping_distribution_match(PlannerInfo *root, Query *parse, + Path *path, List *clauses); /***************************************************************************** @@ -4477,7 +4477,7 @@ create_distinct_paths(PlannerInfo *root, -1.0); /* In case of grouping / distribution mismatch, inject remote scan. */ - if (! grouping_distribution_match(root, path, parse)) + if (!grouping_distribution_match(root, parse, path, parse->distinctClause)) path = create_remotesubplan_path(root, path, NULL); /* XXX Maybe we need another sort here? */ @@ -4525,7 +4525,7 @@ create_distinct_paths(PlannerInfo *root, Path *input_path = cheapest_input_path; /* If needed, inject RemoteSubplan redistributing the data. */ - if (!grouping_distribution_match(root, input_path, parse)) + if (!grouping_distribution_match(root, parse, input_path, parse->distinctClause)) input_path = create_remotesubplan_path(root, input_path, NULL); /* XXX Maybe we can make this a 2-phase aggregate too? */ @@ -5631,14 +5631,15 @@ plan_cluster_use_sort(Oid tableOid, Oid indexOid) * other paths, relying on grouping infrastructure (DISTINCT ON, UNIQUE). */ static bool -grouping_distribution_match(PlannerInfo *root, Path *path, Query *parse) +grouping_distribution_match(PlannerInfo *root, Query *parse, Path *path, + List *clauses) { int i; bool matches_key = false; Distribution *distribution = path->distribution; - int numGroupCols = list_length(parse->distinctClause); - AttrNumber *groupColIdx = extract_grouping_cols(parse->distinctClause, + int numGroupCols = list_length(clauses); + AttrNumber *groupColIdx = extract_grouping_cols(clauses, parse->targetList); /* -- 2.39.5