diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index b2656283251..d84f1b7dd8d 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -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,