From: Tomas Vondra Date: Sun, 22 Jan 2017 20:11:39 +0000 (+0100) Subject: properly redistribute WindowAgg input, fix plan change in window.out X-Git-Tag: XL_10_R1BETA1~405 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=f6da270dd887a7085eaa7d540746be0c959b2166;p=postgres-xl.git properly redistribute WindowAgg input, fix plan change in window.out We can't push down the whole WindowAgg (at least now for now), so we need to redistribute the input properly. Luckily thanks to the parallel aggregates, we get plans like this: QUERY PLAN ----------------------------------------------------------------- WindowAgg -> Finalize GroupAggregate Group Key: (tenk1.ten + tenk1.four) -> Remote Subquery Scan on all (datanode_1,datanode_2) -> Sort Sort Key: ((tenk1.ten + tenk1.four)) -> Partial HashAggregate Group Key: (tenk1.ten + tenk1.four) -> Seq Scan on tenk1 (9 rows) That however means mild breakage in window.out, due to the partial aggregates etc. --- diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index 4ea83f0b0d..fffcddd0ff 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -167,7 +167,7 @@ static bool groupingsets_distribution_match(PlannerInfo *root, Query *parse, static Path *adjust_path_distribution(PlannerInfo *root, Query *parse, Path *path); static bool can_push_down_grouping(PlannerInfo *root, Query *parse, Path *path); - +static bool can_push_down_window(PlannerInfo *root, Path *path); /***************************************************************************** * @@ -4820,6 +4820,10 @@ create_one_window_path(PlannerInfo *root, window_target = output_target; } + /* We can't really push down window functions for now. */ + if (!can_push_down_window(root, path)) + path = create_remotesubplan_path(root, path, NULL); + path = (Path *) create_windowagg_path(root, window_rel, path, window_target, wflists->windowFuncs[wc->winref], @@ -6340,3 +6344,13 @@ can_push_down_grouping(PlannerInfo *root, Query *parse, Path *path) return grouping_distribution_match(root, parse, path, parse->groupClause); } + +static bool +can_push_down_window(PlannerInfo *root, Path *path) +{ + /* */ + if (! path->distribution) + return true; + + return false; +} diff --git a/src/backend/optimizer/util/pathnode.c b/src/backend/optimizer/util/pathnode.c index 7bd7840786..3c7553051d 100644 --- a/src/backend/optimizer/util/pathnode.c +++ b/src/backend/optimizer/util/pathnode.c @@ -4189,6 +4189,8 @@ create_windowagg_path(PlannerInfo *root, pathnode->winclause = winclause; pathnode->winpathkeys = winpathkeys; + pathnode->path.distribution = copyObject(subpath->distribution); + /* * For costing purposes, assume that there are no redundant partitioning * or ordering columns; it's not worth the trouble to deal with that diff --git a/src/test/regress/expected/window.out b/src/test/regress/expected/window.out index a844fb357b..2d92a32e4f 100644 --- a/src/test/regress/expected/window.out +++ b/src/test/regress/expected/window.out @@ -598,13 +598,15 @@ select first_value(max(x)) over (), y QUERY PLAN ----------------------------------------------------------------- WindowAgg - -> HashAggregate + -> Finalize GroupAggregate Group Key: (tenk1.ten + tenk1.four) -> Remote Subquery Scan on all (datanode_1,datanode_2) - -> HashAggregate - Group Key: (tenk1.ten + tenk1.four) - -> Seq Scan on tenk1 -(7 rows) + -> Sort + Sort Key: ((tenk1.ten + tenk1.four)) + -> Partial HashAggregate + Group Key: (tenk1.ten + tenk1.four) + -> Seq Scan on tenk1 +(9 rows) -- test non-default frame specifications SELECT four, ten,