Skip to content

branch-4.1:[fix](fe) Fix redundant aggregation in agg-union query plan #62231#63577

Merged
yiguolei merged 2 commits into
apache:branch-4.1from
feiniaofeiafei:pick-agg-union
May 25, 2026
Merged

branch-4.1:[fix](fe) Fix redundant aggregation in agg-union query plan #62231#63577
yiguolei merged 2 commits into
apache:branch-4.1from
feiniaofeiafei:pick-agg-union

Conversation

@feiniaofeiafei
Copy link
Copy Markdown
Contributor

picked from #62231

…2231)

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.

Modified the `banAggUnionAll` method to only forbid one-phase
aggregation when the union inputs actually have PhysicalDistribute
operators:

1. Checks each group in the union
2. Examines all physical expressions in each group
3. Only forbids one-phase agg if any input has PhysicalDistribute
4. Allows one-phase agg if no inputs have PhysicalDistribute

Added regression test `agg_union_group_by.groovy` to verify correct
behavior

Improved query optimization: Eliminated redundant aggregation layers in
UNION ALL queries with GROUP BY on randomly distributed tables.
@feiniaofeiafei feiniaofeiafei requested a review from yiguolei as a code owner May 25, 2026 03:48
@feiniaofeiafei
Copy link
Copy Markdown
Contributor Author

run buildall

@hello-stephen
Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 9.38% (12/128) 🎉
Increment coverage report
Complete coverage report

@yiguolei yiguolei merged commit 93af55d into apache:branch-4.1 May 25, 2026
28 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants