[fix](fe) Fix redundant aggregation in agg-union query plan#62231
Merged
924060929 merged 3 commits intoapache:masterfrom Apr 10, 2026
Merged
[fix](fe) Fix redundant aggregation in agg-union query plan#62231924060929 merged 3 commits intoapache:masterfrom
924060929 merged 3 commits intoapache:masterfrom
Conversation
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
### What problem does this PR solve?
Issue Number: close #N/A
Problem Summary: When multiple grouped queries are combined via UNION ALL on randomly distributed tables without PhysicalDistribute operators, Doris was generating redundant local aggregation and global aggregation layers without a distribute operator between them.
The issue was in the `banAggUnionAll` method in ChildrenPropertiesRegulator, which was too aggressively forbidding one-phase aggregation for all agg-union patterns, regardless of whether the union inputs had PhysicalDistribute operators.
### Release note
Improved query optimization: Eliminated redundant aggregation layers in UNION ALL queries with GROUP BY on randomly distributed tables.
### Check List (For Author)
- Test: FE UT and Regression test added
- FE UT: Added AggregateUnionPlanTest to verify correct behavior
- Regression test: Added agg_union_group_by test case to verify execution
- Behavior changed: Yes - query plans are now more optimal with fewer redundant aggregation layers
- Does this need documentation: No
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
7664792 to
8eb3f8a
Compare
Contributor
Author
|
run buildall |
Contributor
FE UT Coverage ReportIncrement line coverage |
Contributor
Author
|
run buildall |
Contributor
FE UT Coverage ReportIncrement line coverage |
Contributor
Author
|
run feut |
924060929
approved these changes
Apr 10, 2026
Contributor
|
PR approved by at least one committer and no changes requested. |
Contributor
|
PR approved by anyone and no changes requested. |
englefly
approved these changes
Apr 10, 2026
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.
Problem
When multiple grouped queries are combined via UNION ALL on randomly distributed tables without PhysicalDistribute operators, Doris was generating redundant local aggregation and global aggregation layers without a distribute operator between them.
The issue was in the
banAggUnionAllmethod in ChildrenPropertiesRegulator, which was too aggressively forbidding one-phase aggregation for all agg-union patterns, regardless of whether the union inputs had PhysicalDistribute operators.Solution
Modified the
banAggUnionAllmethod to only forbid one-phase aggregation when the union inputs actually have PhysicalDistribute operators:Test
Added regression test
agg_union_group_by.groovyto verify correct behaviorImpact
Improved query optimization: Eliminated redundant aggregation layers in UNION ALL queries with GROUP BY on randomly distributed tables.