Skip to content

branch-4.1: [refactor](fe) Create PreAggInfoContext top-down from aggregate instead of bottom-up from scan in SetPreAggStatus #65237#65372

Open
github-actions[bot] wants to merge 1 commit into
branch-4.1from
auto-pick-65237-branch-4.1
Open

branch-4.1: [refactor](fe) Create PreAggInfoContext top-down from aggregate instead of bottom-up from scan in SetPreAggStatus #65237#65372
github-actions[bot] wants to merge 1 commit into
branch-4.1from
auto-pick-65237-branch-4.1

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Cherry-picked from #65237

…ad of bottom-up from scan in SetPreAggStatus (#65237)

related pr: #48502

Problem Summary:
The `SetPreAggStatus` rule previously created `PreAggInfoContext` at
`LogicalOlapScan` nodes (bottom-up): the first encountered AGG_KEYS scan
pushed a new context onto the stack, subsequent scans and intermediate
nodes
(filter/join/project) filled in information, and `LogicalAggregate`
popped
and consumed the context. This bottom-up approach had two issues:

1. **Nested aggregate information loss**: When a query contains nested
aggregates (e.g., an outer aggregate over an inner aggregate), the inner
   aggregate's `visitLogicalAggregate` would pop the only context on the
   stack, leaving the outer aggregate with no context for scans directly
   under it.

2. **Unclear context ownership**: Context lifecycle was split across
scan
   (creation) and aggregate (consumption), making the ownership boundary
implicit and fragile — intermediate plan nodes that call
`context.clear()`
via the base `visit()` method could inadvertently destroy the context.

This PR refactors the context propagation to a **top-down** model:

- `visitLogicalAggregate` now creates a fresh `PreAggInfoContext`,
pushes it
  onto the stack, visits children, then pops and stores it.
- `visitLogicalOlapScan` only fills relation IDs into an existing
context;
  it no longer creates contexts.
- The `retainAll` filtering is no longer needed since each aggregate
creates
  its own isolated context with only the scan IDs from its subtree.
- Nested aggregates each get their own independent context, correctly
  isolating preagg information per aggregate level.
@github-actions github-actions Bot requested a review from yiguolei as a code owner July 8, 2026 09:23
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@hello-stephen

Copy link
Copy Markdown
Contributor

run buildall

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.

2 participants