From: Tomas Vondra Date: Sat, 14 Jan 2017 16:24:19 +0000 (+0100) Subject: WIP: allow GROUPING SETS, ROLLUP and CUBE (without push-down) X-Git-Tag: XL_10_R1BETA1~465 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=44fd89e2134f8dd9bc49c5f9adc86048ec3b4dfd;p=postgres-xl.git WIP: allow GROUPING SETS, ROLLUP and CUBE (without push-down) This enables groupin sets path by removing the elog(ERROR, ...) from transformGroupClause(). The paths are currently considered as not eligible for push-down, irrespectedly of the distribution. This could be improved by enabling pushdown if all the grouping sets are compatible with the distribution (as if each grouping set was a separate GROUP BY clause). So for example assuming a table 't' distributed by column 'a', we could push down these grouping sets GROUP BY GROUPING SETS ((a), (a, b), (a, c)) but not GROUP BY GROUPING SETS ((b), (a, b), (a, c)) because the first grouping set does not contain the distribution key. The grouping sets require sorted paths, so we get paths like this: SELECT a, b, COUNT(c) FROM t GROUP BY GROUPING SETS ((a), (a, b)); QUERY PLAN --------------------------------------------- GroupAggregate Group Key: a, b Group Key: a -> Remote Subquery Scan on all (dn1,dn2) -> Sort Sort Key: a, b -> Seq Scan on t2 (7 rows) There's however a bug somewhere (likely in fix_upper_expr or elsewhere in setrefs.c), resulting in failures like this: SELECT a, b, COUNT(c) FROM t GROUP BY GROUPING SETS ((a), (b)); ERROR: variable not found in subplan target list The only difference between the queries is removal of the distribution key from the second grouping set. --- diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index 4941562d2e..f279e08e7d 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -6059,7 +6059,7 @@ can_push_down_grouping(PlannerInfo *root, Query *parse, Path *path) /* only called when constructing grouping paths */ Assert(parse->groupingSets || parse->hasAggs || parse->groupClause); - /* grouping sets are currently disabled */ + /* push-down of grouping sets is not supported yet */ if (parse->groupingSets) return false; diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c index 42513db4ef..751de4bddb 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -2274,9 +2274,6 @@ transformGroupClause(ParseState *pstate, List *grouplist, List **groupingSets, case GROUPING_SET_SETS: case GROUPING_SET_CUBE: case GROUPING_SET_ROLLUP: - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("GROUPING SETS, ROLLUP or CUBE is not yet supported"))); gsets = lappend(gsets, transformGroupingSet(&result, pstate, gset,