Fix constant GROUP BY on empty input - #2045
Open
krylosov-aa wants to merge 2 commits into
Open
krylosov-aa wants to merge 2 commits into
krylosov-aa wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The hash aggregation path still permits incorrect global-group behavior for constant GROUP BY queries.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
Fixes incorrect results for constant GROUP BY queries on empty input during multi-phase aggregation.
Changes:
- Adjusts aggregation strategy selection.
- Adds regression coverage across planners and execution modes.
- Updates affected expected outputs and schedules the test.
| File | Description |
|---|---|
src/test/regress/sql/gp_group_by_constant.sql |
Adds regression queries. |
src/test/regress/greenplum_schedule |
Schedules the regression test. |
src/test/regress/expected/gp_group_by_constant.out |
Adds expected results and plans. |
src/test/regress/expected/bfv_aggregate.out |
Updates affected plan output. |
src/backend/cdb/cdbgroupingpaths.c |
Adjusts aggregation path selection. |
contrib/pax_storage/src/test/regress/expected/bfv_aggregate.out |
Updates corresponding plan output. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Alena0704
reviewed
Sep 29, 2026
Collaborator
|
You should rebase your branch on the current version of main branch. |
Alena0704
approved these changes
Sep 29, 2026
Alena0704
self-requested a review
September 29, 2026 18:20
Collaborator
|
I think you should add at least two more tests with enabled enable_parallel parameter - there are none now: |
Contributor
Author
Alena0704
approved these changes
Sep 30, 2026
Collaborator
|
The fix looks correct, LGTM either |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #2025
What does this PR do?
With
optimizer=offandgp_enable_multiphase_agg=on, grouping by a constant can return a row when the input is empty. For example,SELECT count(*) FROM t GROUP BY 'x'::textreturns one row with zero instead of no rows.The planner removes constant grouping keys, then treats the final aggregation step as if the query had no GROUP BY.
This change checks the original GROUP BY clause when choosing the aggregation strategy. Empty input now returns no rows even when all grouping keys have been removed. It also fixes an assertion failure for constant GROUP BY without aggregate functions.
Type of Change
Test Plan
Added
gp_group_by_constant. It fails before the fix and passes after it. The test covers both planners, single-phase and multi-phase aggregation, and parallel execution.Tested on Linux ARM64 with assertions enabled and three primary segments.
aggregates,gp_aggregates,gp_dqa,aggregate_with_groupingsets, andcbdb_parallelalso passed.Checklist