feiniaofeiafei opened a new pull request, #71034:
URL: https://github.com/apache/doris/pull/71034

   ### Background
   
   When multiple consumers read a materialized CTE, their `ExchangeNode`s share 
the producer's plan root. The FE follows these links when it checks for a 
null-aware left anti join before choosing how to execute a fragment.
   
   ### What problem does this PR solve?
   
   Issue Number: None  
   Related PR: #31690 (introduced the recursive join check), #51053 (switched 
the check to `anyMatch`)  
   PR Type: Bugfix
   
   Problem Summary:
   
   Planning can stall when nested CTEs reuse producers. In the regression test, 
two levels of reuse made the FE evaluate the join-search predicate 13 times on 
a plan with seven nodes. The fix evaluates it seven times and can still find a 
join across an exchange.
   
   ### Details
   
   - **Frequency:** Always when a search reaches the same producer by multiple 
paths before finding a match. Each additional level of reuse can multiply the 
visits.
   - **Root cause:** `PlanFragment.hasNullAwareLeftAntiJoin()` used a tree 
search. Each incoming exchange caused it to search the producer's inputs again.
   - **Why existing tests missed it:** `PlanNodeTest` covered projection and 
`test_cte_multicast_complex` checked SQL results. Both could pass with repeated 
visits.
   - **Fix:** Use an explicit stack and a per-search identity set for 
`PlanNode`. Pushing children in reverse order preserves left-to-right 
depth-first order and early return. A search from one root takes O(V + E) time 
for a constant-time predicate.
   - **Other paths and branches:** The traversal covers `anyMatch`, both 
instance `contains` overloads, `containsSubclass` and `findFirstOf`. The 
recursive join check was also present in the inspected 3.1, 4.0, 4.1 and 4.2 
release refs.
   
   ### Testing
   
   - `PlanNodeTest.testSearchSharedExchangeInputs` failed on the parent commit 
with `expected: <7> but was: <13>`. It passed with the fix. A separate test 
verified that an exchange still exposes a null-aware left anti join in its 
input.
   - All 51 local FE tests across `PlanNodeTest`, 
`LocalShuffleNodeCoverageTest`, `ExprToConnectorExpressionConverterTest` and 
`RemoteDorisScanNodeTest` passed. Checkstyle reported zero violations in 
`fe-common` and `fe-core`.
   
   ### Release note
   
   Queries that reuse nested materialized CTEs can spend less time in FE 
planning when checking for null-aware left anti joins.
   
   ### Check List (For Author)
   
   - Behavior changed: No
   - Does this need documentation: No
   - Pre-submission status: Ready
   
   ### AI Disclosure
   
   - Tool: OpenAI Codex (GPT-6)
   - Generated: Implementation, tests and PR description
   - Human review: Not stated
   


-- 
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]

Reply via email to