starocean999 opened a new pull request, #65095: URL: https://github.com/apache/doris/pull/65095
Related PR: https://github.com/apache/doris/pull/48502 Problem Summary: The SetPreAggStatus rule uses a bottom-up traversal to determine whether pre-aggregation can be enabled for OlapScan nodes. The original implementation used a `Stack<PreAggInfoContext>` as the traversal context, which had a fundamental flaw: multiple scan nodes under sibling subtrees (e.g., both sides of a Join) incorrectly shared the same stack-level context. This caused two problems: 1. A scan could inherit filter/join/project information from unrelated branches of the plan tree. 2. To work around this, `visitLogicalAggregate` used `retainAll()` to filter out scan nodes that were not actually children of the current aggregate — an inelegant patch that partially masked the underlying issue. Root cause: The stack-based context could not guarantee a one-to-one correspondence between a scan node and its nearest aggregate ancestor. Fix: Replace the `Stack<PreAggInfoContext>` with a `Map<RelationId, PreAggInfoContext>`, where each scan node gets its own dedicated context entry. Each visitor method uses a snapshot-diff pattern: 1. Snapshot the current map keys before visiting children 2. Visit children (they add scan contexts to the map) 3. Diff to identify which scans were added by this subtree 4. Apply node-specific info only to those scans At `LogicalAggregate`, child scan contexts are consumed (removed from the map) and their results are stored — no more `retainAll()` filtering needed. None ### 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]
