fix(physical-plan): count empty grouping sets in the aggregate row estimate for an empty input - #24039
Open
asolimando wants to merge 3 commits into
Open
Conversation
…timate for an empty input
… the folding rules
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #24039 +/- ##
========================================
Coverage 80.85% 80.86%
========================================
Files 1101 1101
Lines 374933 375633 +700
Branches 374933 375633 +700
========================================
+ Hits 303166 303746 +580
- Misses 53671 53775 +104
- Partials 18096 18112 +16 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Which issue does this PR close?
Rationale for this change
AggregateExecreported a row count ofExact(0)whenever its input had no rows, even when thegroup-by contained an empty grouping set.
GROUPING SETS(()),ROLLUPandCUBEeach emit agrand-total row for such an input, so the row count contradicted execution. The count was claimed
as
Exact, so rules that answer a query from statistics rather than by executing it returned avalue that no row of the result holds:
This is a correctness fix, not an estimation improvement.
What changes are included in this PR?
estimate_num_rowscounts the empty grouping sets instead of reusing the child's row count ofzero. Partial aggregation emits the grand-total row from every output partition, so the count
goes through the per-partition scaling already applied to aggregates without grouping
expressions, now factored into
scale_logical_rows.count of zero, and a null count equal to the row count.
Are these changes tested?
Yes.
grouping.sltfor both folds: an outerCOUNT(*)overROLLUP,CUBEandGROUPING SETS, and an outerMIN/MAXover the grand-total row.GROUP BY, one row forGROUPING SETS((a), ()), two rows forGROUPING SETS((a), (), ()), the partition scaling of apartial aggregate, and the NULL grouping-column statistics.
Each test was checked to fail without the corresponding change.
Are there any user-facing changes?
Yes. Queries such as the one above now return the correct result. There are no API changes.
Disclaimer: I used AI to assist in the code generation, I have manually reviewed the output and it matches my intention and understanding.