englefly opened a new pull request, #70471: URL: https://github.com/apache/doris/pull/70471
### Background OR expansion replaces a nested loop join with hash joins over individual disjuncts and combines their results through CTEs and UNION ALL. Outer and anti joins also need anti join branches to preserve unmatched rows. ### What problem does this PR solve? Issue Number: None Related PR: #67067 (replaced InitJoinOrder; expansion should not depend on earlier join-direction swaps) PR Type: Enhancement Problem Summary: RIGHT OUTER and RIGHT ANTI joins are excluded from OR expansion even when their OR disjuncts are eligible hash equalities. Equivalent queries can therefore miss the optimization depending on the SQL join direction or an earlier join swap. Extend both types using the right-preserving anti expansion already used by FULL OUTER JOIN, keeping original output slots and ordering. Most of the diff adds tests and generated expected results. ### Details - **Change map:** 16 changed production lines in OrExpansion.java; 161 changed test lines across OrExpansionTest.java and the new regression suite; 223 generated expected-result lines. - **Before and after:** RIGHT OUTER now combines the existing matching branches with unmatched right rows, null-padding the left output. RIGHT ANTI returns unmatched right rows through the existing left anti helper with producers and slot maps swapped together. Previously both types were skipped. - **Configs and defaults:** No new settings. The existing OR_EXPANSION rule switch controls expansion; the existing mark join and hash-disjunct eligibility restrictions still apply. - **Impact on existing users:** Eligible right joins can use hash joins rather than nested loop joins. INNER, LEFT OUTER, FULL OUTER and LEFT ANTI branch construction remains covered by unit tests and the existing regression suite. JoinExtractOrFromCaseWhen shares the eligibility check, so CASE extraction for right joins is also covered. - **Behavior change:** Query plans for eligible right joins can change; SQL result semantics remain the same. No BE operator, protocol or storage change is needed. ### Testing Run locally with the newly built FE and an existing ASAN BE: - `MAVEN_ARGS='-Ddisable.obs=true' bash run-fe-ut.sh --run org.apache.doris.nereids.rules.rewrite.OrExpansionTest`: 14 tests passed, covering output ExprIds/order/nullability, CTE nesting, right-side preservation, expression hash keys, residual predicates and non-hash rejection. - `bash build.sh --fe --exclude-obs-dependencies -j8`: passed, including FE core Checkstyle with 0 violations. - `bash run-regression-test.sh --conf /tmp/or-expansion-regression-conf.groovy --run -d query_p0/union -s or_expansion_right_join -genOut`: generated the new expected results. - `bash run-regression-test.sh --conf /tmp/or-expansion-regression-conf.groovy --run -d query_p0/union,nereids_rules_p0/join_extract_or_from_case_when -s or_expansion_right_join,or_expansion,join_extract_or_from_case_when`: all 3 suites passed. The temporary config only points to the isolated local cluster. - All 15 rule-enabled/disabled result pairs match; independently checked their bag semantics for duplicates, NULLs, null-safe equality, residual predicates, CASE extraction, aggregation and empty inputs. EXPLAIN checks confirm hash joins are actually used. ### Release note Support OR expansion for RIGHT OUTER and RIGHT ANTI joins with eligible disjunctive equality predicates, allowing these queries to use hash joins. ### Check List (For Author) - Behavior changed: Yes (see Details). - Does this need documentation: No. - Pre-submission status: Ready. ### AI Disclosure - Tool: Codex (GPT-6). - Generated: Implementation, tests and this PR description. - Human review: Pending author review. -- 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]
