From 6f64f49eb8d64baf077f13ffc2e3fd3f49b730bb Mon Sep 17 00:00:00 2001 From: Tomas Vondra Date: Sat, 28 Jan 2017 23:43:01 +0100 Subject: [PATCH] redistribute Limit nodes nested in MinMaxAggPath Make sure min/max path are redistributed. Doing it in createplan.c is probably only a temporary solution, though. First, it breaks the costing model (the path cost does not include the redistribution), and it also probably breaks how distribution is propagated up the path tree. --- src/backend/optimizer/plan/createplan.c | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index 5adde29bc6..182c81f06e 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -1914,6 +1914,35 @@ create_minmaxagg_plan(PlannerInfo *root, MinMaxAggPath *best_path) plan->plan_width = mminfo->path->pathtarget->width; plan->parallel_aware = false; + /* + * XL: Add a remote subplan, splitting the LIMIT into a remote and + * local part LIMIT parts. + * + * XXX This should probably happen when constructing the path in + * create_minmaxagg_path(), not this late. + * + * XXX The costing in here is mostly bogus. Not that it'd matter + * this late, though. + */ + if (mminfo->path->distribution) + { + plan = (Plan *) make_remotesubplan(root, plan, + NULL, + mminfo->path->distribution, + mminfo->path->pathkeys); + + plan = (Plan *) make_limit(plan, + subparse->limitOffset, + subparse->limitCount, + 0, 1); + + plan->startup_cost = mminfo->path->startup_cost; + plan->total_cost = mminfo->pathcost; + plan->plan_rows = 1; + plan->plan_width = mminfo->path->pathtarget->width; + plan->parallel_aware = false; + } + /* Convert the plan into an InitPlan in the outer query. */ SS_make_initplan_from_plan(root, subroot, plan, mminfo->param); } -- 2.39.5