feiniaofeiafei opened a new pull request, #67165:
URL: https://github.com/apache/doris/pull/67165
### What problem does this PR solve?
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
The eager aggregation rewrite previously returned immediately when the child
of a `LogicalAggregate` was rewritten. As a result, although eager aggregation
could be pushed down for an inner aggregate, the current outer aggregate would
skip its own pushdown attempt, missing additional optimization opportunities.
The rewrite also performed recursive subtree checks before invoking
`EagerAggRewriter`:
1. It searched for a non-Mark Join in the aggregate subtree.
2. It required every node in the subtree to belong to `acceptNodeType`.
These checks were both restrictive and redundant. A Join hidden behind a
rewrite boundary could incorrectly satisfy the first check, while an
unsupported node in one branch could reject the entire rewrite even when
aggregation could still be pushed down through another branch. Repeatedly
scanning the complete subtree for nested aggregates could also introduce
quadratic traversal overhead in deeply nested plans.
In addition, `PushDownAggContext` validity checks were distributed across
child visitors. A derived context could first be passed to a child and only
then be rejected by the child visitor, making the context lifecycle harder to
reason about and causing duplicated checks.
This PR improves eager aggregation rewriting as follows:
1. Continue processing the current aggregate after its child has been
rewritten. The rewritten child is attached to the current aggregate, and eager
aggregation pushdown is then attempted for the current aggregate as well.
2. Remove the recursive subtree pattern and `acceptNodeType` checks.
`EagerAggRewriter` now determines the actual rewrite boundary during traversal,
avoiding redundant full-subtree scans and allowing each branch to be handled
independently.
3. Centralize context validity checking in `PushDownAggContext#isValid`.
Every newly created or derived context is validated immediately before it is
passed to a child, including contexts created for Join, Union, Project, and
Filter nodes.
4. Relax eager aggregation placement restrictions:
- Allow an eager aggregate to be generated above an existing aggregate.
- Remove the explicit aggregate traversal barrier.
- For plan nodes without a specialized visitor, attempt to generate an
eager aggregate above the node instead of unconditionally stopping without a
rewrite.
- Allow unsupported nodes to act as aggregation placement boundaries
without preventing optimization in other branches.
These changes expand eager aggregation pushdown coverage while reducing
redundant optimizer traversal and keeping context validation close to context
construction.
### Release note
Improve eager aggregation pushdown coverage and reduce optimizer overhead
for plans containing nested aggregates or previously unsupported rewrite
boundaries.
### Check List (For Author)
- Test <!-- At least one of them must be included. -->
- [ ] Regression test
- [ ] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason <!-- Add your reason? -->
- Behavior changed:
- [ ] No.
- [ ] Yes. <!-- Explain the behavior change -->
- Does this need documentation?
- [ ] No.
- [ ] Yes. <!-- Add document PR link here. eg:
https://github.com/apache/doris-website/pull/1214 -->
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR should
merge into -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]