Fix incorrect planning of grouping sets
authorTomas Vondra <[email protected]>
Fri, 15 Sep 2017 00:13:37 +0000 (02:13 +0200)
committerTomas Vondra <[email protected]>
Fri, 15 Sep 2017 00:13:37 +0000 (02:13 +0200)
Commit 04f96689945462a4212047f03eb3281fb56bcf2f incorrectly allowed
distributed grouping paths for grouping sets, causing failures in
'groupingsets' regression test suite. So fix that by making sure
try_distributed_aggregation=false for plans with grouping sets.

src/backend/optimizer/plan/planner.c

index cc4b06a292b6b1f3d982b5c64c57b7fc4d5e855e..c2166808896d4fd9f56325fc430cbda86003a14c 100644 (file)
@@ -3930,8 +3930,14 @@ create_grouping_paths(PlannerInfo *root,
 
        /*
         * The distributed aggregation however works even if there are no partial
-        * paths, and for grouping sets (we need to be able to at least push them
-        * on top of remote subplan).
+        * paths (when the distribution key is included in the grouping keys, we
+        * may simply push down the whole aggregate).
+        *
+        * XXX We currently don't even try to push down grouping sets, although we
+        * might do that when all grouping sets include the distribution key. But
+        * that seems like a fairly rare case, as in most cases there will be
+        * empty grouping set () aggregating all the data. So let's look into this
+        * optimization later.
         */
        if (!grouped_rel->consider_parallel)
        {
@@ -3946,6 +3952,11 @@ create_grouping_paths(PlannerInfo *root,
                 */
                try_distributed_aggregation = false;
        }
+       else if (parse->groupingSets)
+       {
+               /* We don't know how to do grouping sets in parallel. */
+               try_distributed_aggregation = false;
+       }
        else if (agg_costs->hasNonPartial || agg_costs->hasNonSerial)
        {
                /* Insufficient support for partial mode. */