refactor: Simplify LimitedDistinctAggregation optimizer rule - #26069
Open
2010YOUY01 wants to merge 3 commits into
Open
2010YOUY01 wants to merge 3 commits into
2010YOUY01 wants to merge 3 commits into
Conversation
2010YOUY01
commented
Oct 6, 2026
| if let Some(aggr) = plan.downcast_ref::<AggregateExec>() { | ||
| if found_match_aggr | ||
| && let Some(parent_aggr) = match_aggr.downcast_ref::<AggregateExec>() | ||
| && !parent_aggr.group_expr().eq(aggr.group_expr()) |
Contributor
Author
There was a problem hiding this comment.
bug fix: missing a as_final to adapt projection difference
| ( | ||
| AggregateMode::Final | AggregateMode::FinalPartitioned, | ||
| AggregateMode::Partial, | ||
| ) if final_agg.group_expr() == &partial_agg.group_expr().as_final() => {} |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #26069 +/- ##
==========================================
+ Coverage 82.66% 82.69% +0.02%
==========================================
Files 1147 1147
Lines 446357 447312 +955
Branches 446357 447312 +955
==========================================
+ Hits 368971 369892 +921
- Misses 54997 55008 +11
- Partials 22389 22412 +23 ☔ 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?
This is primarily a simplifying refactor, with an optimizer regression fix piggy-backed on top (an inefficient plan shape, not a correctness issue):
The optimizer fix itself is only a one-line change. If this simplification is not desirable, I'll open a replacement PR containing just the direct fix.
Rationale for this change
Part 1: Optimizer fix
See sqllogictest diff for the reproducer
I'll mark the fix in comments
Part 2: Optimizer simplification
During different stages in physical optimization, a logical aggregation can be either
So the existing implementation is using a nested dfs (the closure has another dfs inside, to match non-consecutive aggregates) try to match all of the 3 cases.
However, after looking at related optimizer rules:
We can find only case 1 is possible, so the implementation can be simplified into a naive pattern matching
What changes are included in this PR?
What is the testing strategy for this PR?
sltAre there any user-facing changes?