feat: rewrite count(non-nullable column) to count(1) - #25990
Open
wudidapaopao wants to merge 1 commit into
Open
wudidapaopao wants to merge 1 commit into
wudidapaopao wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #25990 +/- ##
==========================================
- Coverage 82.62% 82.62% -0.01%
==========================================
Files 1147 1147
Lines 445272 445397 +125
Branches 445272 445397 +125
==========================================
+ Hits 367913 368013 +100
- Misses 55016 55028 +12
- Partials 22343 22356 +13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Author
|
@neilconway Thanks for the suggestion! I split the COUNT(non-nullable column) -> COUNT(1) rewrite out of #25849 into this PR. |
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
COUNT(non_nullable_column)counts every input row, but evaluating it still reads and materializes the column unnecessarily.What changes are included in this PR?
DISTINCTcounts over non-nullable columns toCOUNT(1)during expression simplification while preserving output names and schemas.SingleDistinctToGroupByrewrites working when name preservation adds an alias around the rewritten count.What is the testing strategy for this PR?
Covered by unit, optimizer, column-pruning, and sqllogictest cases.
Are there any user-facing changes?
Query results and output schemas are unchanged. Optimized plans can show
count(1) AS count(column), and scans can prune non-nullable columns used only byCOUNT.