starocean999 opened a new pull request, #65682: URL: https://github.com/apache/doris/pull/65682
Related PR: https://github.com/apache/doris/pull/61146 #### Problem Summary: When enable_dphyp_optimizer=true, DPHyp join reorder can produce wrong results for queries where the nullable side of an outer join contains Alias/Project expressions with functions like COALESCE, IFNULL, or CAST(COALESCE(...)). #### Root Cause: HyperGraph.Builder.addAlias() unconditionally adds all aliases to aliasReplaceMap, including those defined on the nullable side of outer joins. This causes their defining expressions to be "unwrapped" and later reconstructed by PlanReceiver.proposeProject() ABOVE the outer join via finalProjects. The expression then operates on null-extended values, changing semantics — e.g., COALESCE(NULL, 0) = 0 instead of the correct NULL for non-matching outer join rows. #### Fix: Added an isNullableSide context flag that propagates through buildForDPhyper() and addAlias() during graph construction. When processing an outer join: LEFT OUTER JOIN → right child flagged as nullable RIGHT OUTER JOIN → left child flagged as nullable FULL OUTER JOIN → both children flagged as nullable The flag propagates through nested projects and inner joins Aliases on the nullable side are not added to aliasReplaceMap, preserving the original Project boundary below the outer join so that expressions execute before null-extension. 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]
