Fix partial aggregation for the case of a degenerate GROUP BY clause.
authorTom Lane
Thu, 10 Nov 2016 16:31:56 +0000 (11:31 -0500)
committerTom Lane
Thu, 10 Nov 2016 16:31:56 +0000 (11:31 -0500)
The plan generated for sorted partial aggregation with "GROUP BY constant"
included a Sort node with no sort keys, which the executor does not like.

Per report from Steve Randall.  I'd add a regression test case if I could
think of a compact one, but it doesn't seem worth expending lots of cycles
on.

Report: 

src/backend/optimizer/plan/planner.c

index b265628325146d71d4e4e8f71ce84e37614d9f52..d84f1b7dd8d456382560ef16fbfd5ece31ead66b 100644 (file)
@@ -3714,11 +3714,11 @@ create_grouping_paths(PlannerInfo *root,
                                               &total_groups);
 
            /*
-            * Gather is always unsorted, so we'll need to sort, unless
-            * there's no GROUP BY clause, in which case there will only be a
-            * single group.
+            * Since Gather's output is always unsorted, we'll need to sort,
+            * unless there's no GROUP BY clause or a degenerate (constant)
+            * one, in which case there will only be a single group.
             */
-           if (parse->groupClause)
+           if (root->group_pathkeys)
                path = (Path *) create_sort_path(root,
                                                 grouped_rel,
                                                 path,