WIP: allow GROUPING SETS, ROLLUP and CUBE (without push-down)
authorTomas Vondra <[email protected]>
Sat, 14 Jan 2017 16:24:19 +0000 (17:24 +0100)
committerTomas Vondra <[email protected]>
Sat, 14 Jan 2017 16:24:19 +0000 (17:24 +0100)
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.

src/backend/optimizer/plan/planner.c
src/backend/parser/parse_clause.c

index 4941562d2e3dac8c9baeebec0512f6ae77541468..f279e08e7dbcc0f56b0081ef62498f086465d5ee 100644 (file)
@@ -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;
 
index 42513db4ef2b150b51bd8bfe3252d6da8c3bcd54..751de4bddb5e7f21b903fcf23f2bd330634cd27a 100644 (file)
@@ -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,