From cadf94af6e10999d28a71839c3830e28b1f980ed Mon Sep 17 00:00:00 2001 From: englefly Date: Wed, 11 Nov 2026 16:48:20 +0800 Subject: [PATCH 1/2] [improvement](nereids) Support OR expansion for right joins ### What problem does this PR solve? Issue Number: None Related PR: #67067 Problem Summary: OR expansion excludes RIGHT OUTER and RIGHT ANTI joins even when each disjunct is an eligible hash equality. Consequently, equivalent queries can miss hash join expansion depending on their join direction or earlier join swaps. Extend the supported types and reuse the existing FULL OUTER right-preserving anti expansion path. RIGHT OUTER combines matching branches with unmatched right rows, while RIGHT ANTI emits only unmatched right rows. Preserve the original output slots, order and nullability, and add unit and regression coverage for both new types and the existing paths. ### 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) - Test: - Unit Test: MAVEN_ARGS='-Ddisable.obs=true' bash run-fe-ut.sh --run org.apache.doris.nereids.rules.rewrite.OrExpansionTest (14 passed) - Regression test: or_expansion_right_join, or_expansion and join_extract_or_from_case_when (3 suites passed using run-regression-test.sh) - Manual test: All 15 enabled/disabled result pairs match an independent bag-semantics oracle. - Build and style: bash build.sh --fe --exclude-obs-dependencies -j8 (passed, 0 FE core Checkstyle violations) - Behavior changed: Yes. Eligible right outer and right anti joins can now use OR expansion. - Does this need documentation: No --- .../nereids/rules/rewrite/OrExpansion.java | 16 +- .../rules/rewrite/OrExpansionTest.java | 73 +++++- .../union/or_expansion_right_join.out | 223 ++++++++++++++++++ .../union/or_expansion_right_join.groovy | 88 +++++++ 4 files changed, 391 insertions(+), 9 deletions(-) create mode 100644 regression-test/data/query_p0/union/or_expansion_right_join.out create mode 100644 regression-test/suites/query_p0/union/or_expansion_right_join.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/OrExpansion.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/OrExpansion.java index aed58ae002fc9f..450b09123561ee 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/OrExpansion.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/OrExpansion.java @@ -74,7 +74,9 @@ public class OrExpansion extends DefaultPlanRewriter implem .Builder() .add(JoinType.INNER_JOIN) .add(JoinType.LEFT_ANTI_JOIN) + .add(JoinType.RIGHT_ANTI_JOIN) .add(JoinType.LEFT_OUTER_JOIN) + .add(JoinType.RIGHT_OUTER_JOIN) .add(JoinType.FULL_OUTER_JOIN) .build(); @@ -160,19 +162,23 @@ public Plan visitLogicalJoin(LogicalJoin join, O joins.addAll(expandInnerJoin(ctx.cascadesContext, hashOtherConditions, join, leftProducer, rightProducer, leftCloneToLeft, rightCloneToRight)); } else if (join.getJoinType().isOuterJoin()) { - // left outer join = inner join union left anti join + // Outer join = matching rows union unmatched rows from each preserved side. joins.addAll(expandInnerJoin(ctx.cascadesContext, hashOtherConditions, join, leftProducer, rightProducer, leftCloneToLeft, rightCloneToRight)); - joins.add(expandLeftAntiJoin(ctx.cascadesContext, - hashOtherConditions, join, leftProducer, rightProducer, leftCloneToLeft, rightCloneToRight)); - if (join.getJoinType().equals(JoinType.FULL_OUTER_JOIN)) { - // full outer join = inner join union left anti join union right anti join + if (join.getJoinType().isLeftOuterJoin() || join.getJoinType().isFullOuterJoin()) { + joins.add(expandLeftAntiJoin(ctx.cascadesContext, + hashOtherConditions, join, leftProducer, rightProducer, leftCloneToLeft, rightCloneToRight)); + } + if (join.getJoinType().isRightOuterJoin() || join.getJoinType().isFullOuterJoin()) { joins.add(expandLeftAntiJoin(ctx.cascadesContext, hashOtherConditions, join, rightProducer, leftProducer, rightCloneToRight, leftCloneToLeft)); } } else if (join.getJoinType().equals(JoinType.LEFT_ANTI_JOIN)) { joins.add(expandLeftAntiJoin(ctx.cascadesContext, hashOtherConditions, join, leftProducer, rightProducer, leftCloneToLeft, rightCloneToRight)); + } else if (join.getJoinType().isRightAntiJoin()) { + joins.add(expandLeftAntiJoin(ctx.cascadesContext, hashOtherConditions, + join, rightProducer, leftProducer, rightCloneToRight, leftCloneToLeft)); } else { throw new RuntimeException("or-expansion is not supported for " + join); } diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/OrExpansionTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/OrExpansionTest.java index 9a1094079b8453..846409ba9d0367 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/OrExpansionTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/OrExpansionTest.java @@ -17,15 +17,25 @@ package org.apache.doris.nereids.rules.rewrite; +import org.apache.doris.nereids.trees.expressions.Slot; +import org.apache.doris.nereids.trees.plans.JoinType; import org.apache.doris.nereids.trees.plans.Plan; import org.apache.doris.nereids.trees.plans.logical.LogicalCTEAnchor; import org.apache.doris.nereids.trees.plans.logical.LogicalCTEConsumer; +import org.apache.doris.nereids.trees.plans.logical.LogicalCTEProducer; +import org.apache.doris.nereids.trees.plans.logical.LogicalJoin; +import org.apache.doris.nereids.trees.plans.logical.LogicalUnion; import org.apache.doris.nereids.util.MemoPatternMatchSupported; import org.apache.doris.nereids.util.PlanChecker; import org.apache.doris.utframe.TestWithFeService; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; + +import java.util.List; +import java.util.stream.Collectors; class OrExpansionTest extends TestWithFeService implements MemoPatternMatchSupported { @Override @@ -63,15 +73,16 @@ void testOrExpand() { Assertions.assertTrue(plan.child(1) instanceof LogicalCTEAnchor); } - @Test - void testOrExpandCTE() { + @ParameterizedTest + @EnumSource(value = JoinType.class, names = {"INNER_JOIN", "RIGHT_OUTER_JOIN", "RIGHT_ANTI_JOIN"}) + void testOrExpandCTE(JoinType joinType) { connectContext.getSessionVariable().setDisableNereidsRules("PRUNE_EMPTY_PARTITION"); connectContext.getSessionVariable().inlineCTEReferencedThreshold = 0; String sql = "with t3 as (select t1.id1 + 1 as id1, t1.id2 + 2 as id2 from t1), " + "t4 as (select t2.id1 + 1 as id1, t2.id2 + 2 as id2 from t2) " - + "select t3.id1 from " + + "select t4.id1 from " + "(select id1, id2 from t3 group by id1, id2) t3 " - + " join " + + " " + joinType.name().replace('_', ' ') + " " + "(select id1, id2 from t4 group by id1, id2) t4 " + "on t3.id1 = t4.id1 or t3.id2 = t4.id2"; Plan plan = PlanChecker.from(connectContext) @@ -87,4 +98,58 @@ void testOrExpandCTE() { Assertions.assertTrue(plan.child(1).child(1).child(1) .anyMatch(x -> x instanceof LogicalCTEConsumer)); } + + @ParameterizedTest + @EnumSource(value = JoinType.class, names = { + "INNER_JOIN", "LEFT_OUTER_JOIN", "RIGHT_OUTER_JOIN", "FULL_OUTER_JOIN", + "LEFT_ANTI_JOIN", "RIGHT_ANTI_JOIN"}) + void testExpansionPreservesOutput(JoinType joinType) { + String sql = "select * from t1 " + joinType.name().replace('_', ' ') + " t2" + + " on t1.id1 = t2.id1 or t1.id2 = t2.id2"; + PlanChecker checker = PlanChecker.from(connectContext).analyze(sql); + List output = checker.getPlan().getOutput(); + Plan plan = checker.applyCustom(OrExpansion.INSTANCE).getPlan(); + Assertions.assertEquals(output, plan.getOutput()); + Assertions.assertEquals(output.stream().map(Slot::nullable).collect(Collectors.toList()), + plan.getOutput().stream().map(Slot::nullable).collect(Collectors.toList())); + List unions = plan.collectToList(LogicalUnion.class::isInstance); + Assertions.assertEquals(1, unions.size(), plan.treeString()); + int innerBranches = joinType.isInnerJoin() || joinType.isOuterJoin() ? 2 : 0; + int antiBranches = joinType.isFullOuterJoin() ? 2 : (joinType.isInnerJoin() ? 0 : 1); + Assertions.assertEquals(innerBranches + antiBranches, unions.get(0).arity(), plan.treeString()); + } + + @ParameterizedTest + @EnumSource(value = JoinType.class, names = {"RIGHT_OUTER_JOIN", "RIGHT_ANTI_JOIN"}) + void testRightExpansionPreservesRightInput(JoinType joinType) { + String sql = "select * from t1 " + joinType.name().replace('_', ' ') + " t2" + + " on (t1.id1 + 1 = t2.id1 or t1.id2 = t2.id2 + 1 or t2.id1 + 2 = t1.id2)" + + " and t1.id1 < t2.id2"; + Plan plan = PlanChecker.from(connectContext).analyze(sql).applyCustom(OrExpansion.INSTANCE).getPlan(); + List producers = plan.collectToList(LogicalCTEProducer.class::isInstance); + LogicalUnion union = (LogicalUnion) plan.collectToList(LogicalUnion.class::isInstance).get(0); + Plan unmatched = union.child(union.arity() - 1); + List consumers = unmatched.collectToList(LogicalCTEConsumer.class::isInstance); + // The preserved right input is read once; each OR disjunct removes matches from it. + Assertions.assertEquals(1, consumers.stream() + .filter(c -> c.getCteId().equals(producers.get(1).getCteId())).count(), plan.treeString()); + Assertions.assertEquals(3, consumers.stream() + .filter(c -> c.getCteId().equals(producers.get(0).getCteId())).count(), plan.treeString()); + List antiJoins = unmatched.collectToList(LogicalJoin.class::isInstance); + Assertions.assertEquals(3, antiJoins.size(), plan.treeString()); + for (LogicalJoin antiJoin : antiJoins) { + Assertions.assertEquals(JoinType.LEFT_ANTI_JOIN, antiJoin.getJoinType()); + Assertions.assertEquals(1, antiJoin.getHashJoinConjuncts().size()); + Assertions.assertEquals(1, antiJoin.getOtherJoinConjuncts().size()); + } + } + + @ParameterizedTest + @EnumSource(value = JoinType.class, names = {"RIGHT_OUTER_JOIN", "RIGHT_ANTI_JOIN"}) + void testRightExpansionRequiresHashDisjuncts(JoinType joinType) { + String sql = "select * from t1 " + joinType.name().replace('_', ' ') + " t2" + + " on t1.id1 = t2.id1 or t1.id2 > t2.id2"; + Plan plan = PlanChecker.from(connectContext).analyze(sql).applyCustom(OrExpansion.INSTANCE).getPlan(); + Assertions.assertFalse(plan.anyMatch(LogicalUnion.class::isInstance), plan.treeString()); + } } diff --git a/regression-test/data/query_p0/union/or_expansion_right_join.out b/regression-test/data/query_p0/union/or_expansion_right_join.out new file mode 100644 index 00000000000000..76167bde330c7d --- /dev/null +++ b/regression-test/data/query_p0/union/or_expansion_right_join.out @@ -0,0 +1,223 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !enabled -- +\N \N \N 105 \N \N 5 +\N \N \N 106 7 70 6 +\N \N \N 106 7 70 6 +1 1 10 101 1 10 1 +2 2 20 102 9 20 2 +2 2 20 102 9 20 2 +3 \N 30 103 \N 30 3 +4 4 \N 104 4 \N 4 + +-- !disabled -- +\N \N \N 105 \N \N 5 +\N \N \N 106 7 70 6 +\N \N \N 106 7 70 6 +1 1 10 101 1 10 1 +2 2 20 102 9 20 2 +2 2 20 102 9 20 2 +3 \N 30 103 \N 30 3 +4 4 \N 104 4 \N 4 + +-- !enabled -- +\N \N \N 103 \N 30 3 +\N \N \N 104 4 \N 4 +\N \N \N 105 \N \N 5 +\N \N \N 106 7 70 6 +\N \N \N 106 7 70 6 +1 1 10 101 1 10 1 +2 2 20 102 9 20 2 +2 2 20 102 9 20 2 + +-- !disabled -- +\N \N \N 103 \N 30 3 +\N \N \N 104 4 \N 4 +\N \N \N 105 \N \N 5 +\N \N \N 106 7 70 6 +\N \N \N 106 7 70 6 +1 1 10 101 1 10 1 +2 2 20 102 9 20 2 +2 2 20 102 9 20 2 + +-- !enabled -- +\N \N \N 101 1 10 1 +\N \N \N 102 9 20 2 +\N \N \N 103 \N 30 3 +\N \N \N 104 4 \N 4 +\N \N \N 105 \N \N 5 +6 6 60 106 7 70 6 +6 6 60 106 7 70 6 + +-- !disabled -- +\N \N \N 101 1 10 1 +\N \N \N 102 9 20 2 +\N \N \N 103 \N 30 3 +\N \N \N 104 4 \N 4 +\N \N \N 105 \N \N 5 +6 6 60 106 7 70 6 +6 6 60 106 7 70 6 + +-- !enabled -- +\N \N \N 106 7 70 6 +\N \N \N 106 7 70 6 +1 1 10 101 1 10 1 +2 2 20 102 9 20 2 +2 2 20 102 9 20 2 +3 \N 30 103 \N 30 3 +3 \N 30 105 \N \N 5 +4 4 \N 104 4 \N 4 +5 \N \N 103 \N 30 3 +5 \N \N 105 \N \N 5 + +-- !disabled -- +\N \N \N 106 7 70 6 +\N \N \N 106 7 70 6 +1 1 10 101 1 10 1 +2 2 20 102 9 20 2 +2 2 20 102 9 20 2 +3 \N 30 103 \N 30 3 +3 \N 30 105 \N \N 5 +4 4 \N 104 4 \N 4 +5 \N \N 103 \N 30 3 +5 \N \N 105 \N \N 5 + +-- !case_enabled -- +\N \N \N 102 9 20 2 +\N \N \N 103 \N 30 3 +\N \N \N 104 4 \N 4 +\N \N \N 105 \N \N 5 +\N \N \N 106 7 70 6 +\N \N \N 106 7 70 6 +1 1 10 101 1 10 1 + +-- !case_disabled -- +\N \N \N 102 9 20 2 +\N \N \N 103 \N 30 3 +\N \N \N 104 4 \N 4 +\N \N \N 105 \N \N 5 +\N \N \N 106 7 70 6 +\N \N \N 106 7 70 6 +1 1 10 101 1 10 1 + +-- !enabled -- +105 \N \N 5 +106 7 70 6 +106 7 70 6 + +-- !disabled -- +105 \N \N 5 +106 7 70 6 +106 7 70 6 + +-- !enabled -- +103 \N 30 3 +104 4 \N 4 +105 \N \N 5 +106 7 70 6 +106 7 70 6 + +-- !disabled -- +103 \N 30 3 +104 4 \N 4 +105 \N \N 5 +106 7 70 6 +106 7 70 6 + +-- !enabled -- +101 1 10 1 +102 9 20 2 +103 \N 30 3 +104 4 \N 4 +105 \N \N 5 + +-- !disabled -- +101 1 10 1 +102 9 20 2 +103 \N 30 3 +104 4 \N 4 +105 \N \N 5 + +-- !enabled -- +106 7 70 6 +106 7 70 6 + +-- !disabled -- +106 7 70 6 +106 7 70 6 + +-- !case_enabled -- +102 9 20 2 +103 \N 30 3 +104 4 \N 4 +105 \N \N 5 +106 7 70 6 +106 7 70 6 + +-- !case_disabled -- +102 9 20 2 +103 \N 30 3 +104 4 \N 4 +105 \N \N 5 +106 7 70 6 +106 7 70 6 + +-- !aggregate -- +101 1 10 1 +102 2 40 4 +103 1 30 3 +104 1 \N 4 +105 0 \N 5 +106 0 \N 12 + +-- !aggregate_disabled -- +101 1 10 1 +102 2 40 4 +103 1 30 3 +104 1 \N 4 +105 0 \N 5 +106 0 \N 12 + +-- !empty_enabled -- +\N \N \N 101 1 10 1 +\N \N \N 102 9 20 2 +\N \N \N 103 \N 30 3 +\N \N \N 104 4 \N 4 +\N \N \N 105 \N \N 5 +\N \N \N 106 7 70 6 +\N \N \N 106 7 70 6 + +-- !empty_disabled -- +\N \N \N 101 1 10 1 +\N \N \N 102 9 20 2 +\N \N \N 103 \N 30 3 +\N \N \N 104 4 \N 4 +\N \N \N 105 \N \N 5 +\N \N \N 106 7 70 6 +\N \N \N 106 7 70 6 + +-- !empty_enabled -- + +-- !empty_disabled -- + +-- !empty_enabled -- +101 1 10 1 +102 9 20 2 +103 \N 30 3 +104 4 \N 4 +105 \N \N 5 +106 7 70 6 +106 7 70 6 + +-- !empty_disabled -- +101 1 10 1 +102 9 20 2 +103 \N 30 3 +104 4 \N 4 +105 \N \N 5 +106 7 70 6 +106 7 70 6 + +-- !empty_enabled -- + +-- !empty_disabled -- + diff --git a/regression-test/suites/query_p0/union/or_expansion_right_join.groovy b/regression-test/suites/query_p0/union/or_expansion_right_join.groovy new file mode 100644 index 00000000000000..130939e437c6f2 --- /dev/null +++ b/regression-test/suites/query_p0/union/or_expansion_right_join.groovy @@ -0,0 +1,88 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("or_expansion_right_join", "p0") { + sql "DROP TABLE IF EXISTS or_expansion_right_join_l" + sql "DROP TABLE IF EXISTS or_expansion_right_join_r" + sql """CREATE TABLE or_expansion_right_join_l (id INT NOT NULL, a INT, b INT) + DUPLICATE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES("replication_num" = "1")""" + sql """CREATE TABLE or_expansion_right_join_r (id BIGINT NOT NULL, a BIGINT, b BIGINT, v INT) + DUPLICATE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES("replication_num" = "1")""" + // Include duplicate matches, overlapping OR branches, UNKNOWN predicates and unmatched rows. + sql """INSERT INTO or_expansion_right_join_l VALUES + (1, 1, 10), (2, 2, 20), (2, 2, 20), (3, NULL, 30), + (4, 4, NULL), (5, NULL, NULL), (6, 6, 60)""" + sql """INSERT INTO or_expansion_right_join_r VALUES + (101, 1, 10, 1), (102, 9, 20, 2), (103, NULL, 30, 3), + (104, 4, NULL, 4), (105, NULL, NULL, 5), (106, 7, 70, 6), (106, 7, 70, 6)""" + + for (String joinType : ["RIGHT OUTER", "RIGHT ANTI"]) { + for (String condition : [ + "l.a = r.a OR l.b = r.b", + "(l.a = r.a OR l.b = r.b) AND l.id + r.v < 6", + "(l.a + 1 = r.a OR l.b = r.b + 1 OR r.a + 2 = l.b) AND l.id < r.id", + "l.a <=> r.a OR l.b = r.b"]) { + String query = """SELECT %s * FROM or_expansion_right_join_l l + ${joinType} JOIN or_expansion_right_join_r r ON ${condition}""" + explain { + sql String.format(query, "") + contains "VHASH JOIN" + notContains "VNESTED LOOP JOIN" + } + order_qt_enabled String.format(query, "") + order_qt_disabled String.format(query, "/*+ SET_VAR(disable_nereids_rules='OR_EXPANSION') */") + } + + // Enlarging OrExpansion's supported types also enables CASE extraction for right joins. + String caseQuery = """SELECT %s * FROM or_expansion_right_join_l l + ${joinType} JOIN or_expansion_right_join_r r + ON CASE WHEN r.v < 3 THEN l.a ELSE l.b END = r.a""" + explain { + sql String.format(caseQuery, "") + contains "VHASH JOIN" + notContains "VNESTED LOOP JOIN" + } + order_qt_case_enabled String.format(caseQuery, "") + order_qt_case_disabled String.format(caseQuery, + "/*+ SET_VAR(disable_nereids_rules='OR_EXPANSION,JOIN_EXTRACT_OR_FROM_CASE_WHEN') */") + } + + // Exercise the full rewrite pipeline with aggregation above the right join. + order_qt_aggregate """SELECT r.id, COUNT(l.id), SUM(l.b), SUM(r.v) + FROM or_expansion_right_join_l l RIGHT OUTER JOIN or_expansion_right_join_r r + ON l.a = r.a OR l.b = r.b GROUP BY r.id""" + order_qt_aggregate_disabled """SELECT /*+ SET_VAR(disable_nereids_rules='OR_EXPANSION') */ + r.id, COUNT(l.id), SUM(l.b), SUM(r.v) + FROM or_expansion_right_join_l l RIGHT OUTER JOIN or_expansion_right_join_r r + ON l.a = r.a OR l.b = r.b GROUP BY r.id""" + + // Test empty inputs on each side while keeping an equijoin OR predicate. + for (String joinType : ["RIGHT OUTER", "RIGHT ANTI"]) { + for (String emptySide : ["l", "r"]) { + String left = emptySide == "l" + ? "(SELECT * FROM or_expansion_right_join_l WHERE id < 0)" : "or_expansion_right_join_l" + String right = emptySide == "r" + ? "(SELECT * FROM or_expansion_right_join_r WHERE id < 0)" : "or_expansion_right_join_r" + String query = """SELECT %s * FROM ${left} l ${joinType} JOIN ${right} r + ON l.a = r.a OR l.b = r.b""" + order_qt_empty_enabled String.format(query, "") + order_qt_empty_disabled String.format(query, "/*+ SET_VAR(disable_nereids_rules='OR_EXPANSION') */") + } + } +} From ce8c493c6d696e78f98e7f44fb6cff5b758fe078 Mon Sep 17 00:00:00 2001 From: englefly Date: Wed, 11 Nov 2026 18:42:19 +0800 Subject: [PATCH 2/2] [test](regression) Preserve right joins when testing OR expansion ### What problem does this PR solve? Issue Number: None Related PR: #70471, #67067 Problem Summary: With join reordering enabled, SemiJoinCommute can normalize RIGHT OUTER and RIGHT ANTI joins to LEFT joins before OR expansion. The regression's hash-join assertions could therefore pass through existing left-join expansion without exercising the new right-join dispatch. Set disable_join_reorder=true in the suite and add negative-control EXPLAIN checks that retain the corresponding RIGHT nested loop join when OR expansion is disabled. Keep the existing enabled hash-join checks and result comparisons, including CASE extraction, aggregation and empty inputs. ### Release note None ### Check List (For Author) - Test: - Regression test: bash run-regression-test.sh --conf /tmp/or-expansion-regression-conf.groovy --run -d query_p0/union -s or_expansion_right_join (passed) - Manual test: All 30 actual output blocks match the committed generated expectations; all 15 enabled/disabled pairs match. - Style: git diff --check (passed) - Behavior changed: No. Test coverage only. - Does this need documentation: No --- .../query_p0/union/or_expansion_right_join.groovy | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/regression-test/suites/query_p0/union/or_expansion_right_join.groovy b/regression-test/suites/query_p0/union/or_expansion_right_join.groovy index 130939e437c6f2..5fdb1fa34bce4e 100644 --- a/regression-test/suites/query_p0/union/or_expansion_right_join.groovy +++ b/regression-test/suites/query_p0/union/or_expansion_right_join.groovy @@ -16,6 +16,8 @@ // under the License. suite("or_expansion_right_join", "p0") { + // Keep RIGHT joins through RBO: SemiJoinCommute would otherwise normalize them to LEFT joins. + sql "SET disable_join_reorder = true" sql "DROP TABLE IF EXISTS or_expansion_right_join_l" sql "DROP TABLE IF EXISTS or_expansion_right_join_r" sql """CREATE TABLE or_expansion_right_join_l (id INT NOT NULL, a INT, b INT) @@ -45,6 +47,12 @@ suite("or_expansion_right_join", "p0") { contains "VHASH JOIN" notContains "VNESTED LOOP JOIN" } + explain { + sql String.format(query, "/*+ SET_VAR(disable_nereids_rules='OR_EXPANSION') */") + contains "${joinType} JOIN" + contains "VNESTED LOOP JOIN" + notContains "VHASH JOIN" + } order_qt_enabled String.format(query, "") order_qt_disabled String.format(query, "/*+ SET_VAR(disable_nereids_rules='OR_EXPANSION') */") } @@ -58,6 +66,13 @@ suite("or_expansion_right_join", "p0") { contains "VHASH JOIN" notContains "VNESTED LOOP JOIN" } + explain { + sql String.format(caseQuery, + "/*+ SET_VAR(disable_nereids_rules='OR_EXPANSION,JOIN_EXTRACT_OR_FROM_CASE_WHEN') */") + contains "${joinType} JOIN" + contains "VNESTED LOOP JOIN" + notContains "VHASH JOIN" + } order_qt_case_enabled String.format(caseQuery, "") order_qt_case_disabled String.format(caseQuery, "/*+ SET_VAR(disable_nereids_rules='OR_EXPANSION,JOIN_EXTRACT_OR_FROM_CASE_WHEN') */")