From 2f529c1c7b671daf88490853746644de808e15bb Mon Sep 17 00:00:00 2001 From: jakevin Date: Wed, 15 Nov 2023 15:58:33 +0800 Subject: [PATCH] [feature](Nereids): remove True in Join condition (#26951) Remove `True` in Join Condition like `SELECT * FROM t1 JOIN t2 on True`; --- .../doris/nereids/jobs/executor/Rewriter.java | 2 + .../apache/doris/nereids/rules/RuleType.java | 2 + .../rules/rewrite/EliminateJoinCondition.java | 49 ++ .../expressions/literal/BooleanLiteral.java | 2 +- .../rewrite/EliminateJoinConditionTest.java | 51 ++ .../eliminate_join_condition.out | 513 ++++++++++++++++++ .../eliminate_join_condition.groovy | 114 ++++ 7 files changed, 732 insertions(+), 1 deletion(-) create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateJoinCondition.java create mode 100644 fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/EliminateJoinConditionTest.java create mode 100644 regression-test/data/nereids_rules_p0/eliminate_join_condition/eliminate_join_condition.out create mode 100644 regression-test/suites/nereids_rules_p0/eliminate_join_condition/eliminate_join_condition.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java index 802ddaa6c0..1f314ce565 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java @@ -56,6 +56,7 @@ import org.apache.doris.nereids.rules.rewrite.EliminateAssertNumRows; import org.apache.doris.nereids.rules.rewrite.EliminateDedupJoinCondition; import org.apache.doris.nereids.rules.rewrite.EliminateEmptyRelation; import org.apache.doris.nereids.rules.rewrite.EliminateFilter; +import org.apache.doris.nereids.rules.rewrite.EliminateJoinCondition; import org.apache.doris.nereids.rules.rewrite.EliminateLimit; import org.apache.doris.nereids.rules.rewrite.EliminateNotNull; import org.apache.doris.nereids.rules.rewrite.EliminateNullAwareLeftAntiJoin; @@ -173,6 +174,7 @@ public class Rewriter extends AbstractBatchJobExecutor { new EliminateLimit(), new EliminateFilter(), new EliminateAggregate(), + new EliminateJoinCondition(), new EliminateAssertNumRows() ) ), diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java index 94ccef528f..f8760ada9e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java @@ -201,6 +201,8 @@ public enum RuleType { ELIMINATE_LIMIT_ON_ONE_ROW_RELATION(RuleTypeClass.REWRITE), ELIMINATE_LIMIT_ON_EMPTY_RELATION(RuleTypeClass.REWRITE), ELIMINATE_FILTER(RuleTypeClass.REWRITE), + ELIMINATE_JOIN(RuleTypeClass.REWRITE), + ELIMINATE_JOIN_CONDITION(RuleTypeClass.REWRITE), ELIMINATE_FILTER_ON_ONE_RELATION(RuleTypeClass.REWRITE), ELIMINATE_NOT_NULL(RuleTypeClass.REWRITE), ELIMINATE_UNNECESSARY_PROJECT(RuleTypeClass.REWRITE), diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateJoinCondition.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateJoinCondition.java new file mode 100644 index 0000000000..37e4cb85ce --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateJoinCondition.java @@ -0,0 +1,49 @@ +// 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. + +package org.apache.doris.nereids.rules.rewrite; + +import org.apache.doris.nereids.rules.Rule; +import org.apache.doris.nereids.rules.RuleType; +import org.apache.doris.nereids.trees.expressions.Expression; +import org.apache.doris.nereids.trees.expressions.literal.BooleanLiteral; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * Eliminate true Condition in Join Condition. + */ +public class EliminateJoinCondition extends OneRewriteRuleFactory { + + @Override + public Rule build() { + return logicalJoin().then(join -> { + List hashJoinConjuncts = join.getHashJoinConjuncts().stream() + .filter(expression -> !expression.equals(BooleanLiteral.TRUE)) + .collect(Collectors.toList()); + List otherJoinConjuncts = join.getOtherJoinConjuncts().stream() + .filter(expression -> !expression.equals(BooleanLiteral.TRUE)) + .collect(Collectors.toList()); + if (hashJoinConjuncts.size() == join.getHashJoinConjuncts().size() + && otherJoinConjuncts.size() == join.getOtherJoinConjuncts().size()) { + return null; + } + return join.withJoinConjuncts(hashJoinConjuncts, otherJoinConjuncts); + }).toRule(RuleType.ELIMINATE_JOIN_CONDITION); + } +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/BooleanLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/BooleanLiteral.java index d3dc5ef9af..f3b884dc15 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/BooleanLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/BooleanLiteral.java @@ -61,7 +61,7 @@ public class BooleanLiteral extends Literal { @Override public String toString() { - return Boolean.valueOf(value).toString().toUpperCase(); + return Boolean.toString(value).toUpperCase(); } @Override diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/EliminateJoinConditionTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/EliminateJoinConditionTest.java new file mode 100644 index 0000000000..37acd78e02 --- /dev/null +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/EliminateJoinConditionTest.java @@ -0,0 +1,51 @@ +// 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. + +package org.apache.doris.nereids.rules.rewrite; + +import org.apache.doris.nereids.trees.expressions.literal.BooleanLiteral; +import org.apache.doris.nereids.trees.plans.JoinType; +import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan; +import org.apache.doris.nereids.trees.plans.logical.LogicalPlan; +import org.apache.doris.nereids.util.LogicalPlanBuilder; +import org.apache.doris.nereids.util.MemoPatternMatchSupported; +import org.apache.doris.nereids.util.MemoTestUtils; +import org.apache.doris.nereids.util.PlanChecker; +import org.apache.doris.nereids.util.PlanConstructor; + +import com.google.common.collect.ImmutableList; +import org.junit.jupiter.api.Test; + +class EliminateJoinConditionTest implements MemoPatternMatchSupported { + private final LogicalOlapScan scan1 = PlanConstructor.newLogicalOlapScan(0, "t1", 0); + private final LogicalOlapScan scan2 = PlanConstructor.newLogicalOlapScan(1, "t2", 0); + + @Test + void basicCase() { + LogicalPlan filterFalse = new LogicalPlanBuilder(scan1) + .join(scan2, JoinType.INNER_JOIN, ImmutableList.of(BooleanLiteral.TRUE), + ImmutableList.of(BooleanLiteral.TRUE)) + .build(); + + PlanChecker.from(MemoTestUtils.createConnectContext(), filterFalse) + .applyTopDown(new EliminateJoinCondition()) + .matches( + logicalJoin().when(join -> join.getHashJoinConjuncts().size() == 0 + && join.getOtherJoinConjuncts().size() == 0) + ); + } +} diff --git a/regression-test/data/nereids_rules_p0/eliminate_join_condition/eliminate_join_condition.out b/regression-test/data/nereids_rules_p0/eliminate_join_condition/eliminate_join_condition.out new file mode 100644 index 0000000000..fad36fee64 --- /dev/null +++ b/regression-test/data/nereids_rules_p0/eliminate_join_condition/eliminate_join_condition.out @@ -0,0 +1,513 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !inner_join -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------NestedLoopJoin[CROSS_JOIN] +--------PhysicalOlapScan[t] +--------PhysicalDistribute +----------PhysicalOlapScan[t] + +-- !left_outer_join -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------NestedLoopJoin[LEFT_OUTER_JOIN] +--------PhysicalOlapScan[t] +--------PhysicalDistribute +----------PhysicalOlapScan[t] + +-- !right_outer_join -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------NestedLoopJoin[LEFT_OUTER_JOIN] +--------PhysicalOlapScan[t] +--------PhysicalDistribute +----------PhysicalOlapScan[t] + +-- !full_outer_join -- +PhysicalResultSink +--PhysicalProject +----NestedLoopJoin[FULL_OUTER_JOIN] +------PhysicalDistribute +--------PhysicalOlapScan[t] +------PhysicalDistribute +--------PhysicalOlapScan[t] + +-- !left_semi_join -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------NestedLoopJoin[LEFT_SEMI_JOIN] +--------PhysicalOlapScan[t] +--------PhysicalDistribute +----------PhysicalProject +------------PhysicalOlapScan[t] + +-- !left_anti_join -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------NestedLoopJoin[LEFT_ANTI_JOIN] +--------PhysicalOlapScan[t] +--------PhysicalDistribute +----------PhysicalProject +------------PhysicalOlapScan[t] + +-- !right_semi_join -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------NestedLoopJoin[LEFT_SEMI_JOIN] +--------PhysicalOlapScan[t] +--------PhysicalDistribute +----------PhysicalProject +------------PhysicalOlapScan[t] + +-- !right_anti_join -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------NestedLoopJoin[LEFT_ANTI_JOIN] +--------PhysicalOlapScan[t] +--------PhysicalDistribute +----------PhysicalProject +------------PhysicalOlapScan[t] + +-- !inner_join -- +1 1 a 1 1 a +1 1 a 10 \N \N +1 1 a 2 \N a +1 1 a 3 1 \N +1 1 a 4 2 b +1 1 a 5 \N b +1 1 a 6 2 \N +1 1 a 7 3 c +1 1 a 8 \N c +1 1 a 9 3 \N +10 \N \N 1 1 a +10 \N \N 10 \N \N +10 \N \N 2 \N a +10 \N \N 3 1 \N +10 \N \N 4 2 b +10 \N \N 5 \N b +10 \N \N 6 2 \N +10 \N \N 7 3 c +10 \N \N 8 \N c +10 \N \N 9 3 \N +2 \N a 1 1 a +2 \N a 10 \N \N +2 \N a 2 \N a +2 \N a 3 1 \N +2 \N a 4 2 b +2 \N a 5 \N b +2 \N a 6 2 \N +2 \N a 7 3 c +2 \N a 8 \N c +2 \N a 9 3 \N +3 1 \N 1 1 a +3 1 \N 10 \N \N +3 1 \N 2 \N a +3 1 \N 3 1 \N +3 1 \N 4 2 b +3 1 \N 5 \N b +3 1 \N 6 2 \N +3 1 \N 7 3 c +3 1 \N 8 \N c +3 1 \N 9 3 \N +4 2 b 1 1 a +4 2 b 10 \N \N +4 2 b 2 \N a +4 2 b 3 1 \N +4 2 b 4 2 b +4 2 b 5 \N b +4 2 b 6 2 \N +4 2 b 7 3 c +4 2 b 8 \N c +4 2 b 9 3 \N +5 \N b 1 1 a +5 \N b 10 \N \N +5 \N b 2 \N a +5 \N b 3 1 \N +5 \N b 4 2 b +5 \N b 5 \N b +5 \N b 6 2 \N +5 \N b 7 3 c +5 \N b 8 \N c +5 \N b 9 3 \N +6 2 \N 1 1 a +6 2 \N 10 \N \N +6 2 \N 2 \N a +6 2 \N 3 1 \N +6 2 \N 4 2 b +6 2 \N 5 \N b +6 2 \N 6 2 \N +6 2 \N 7 3 c +6 2 \N 8 \N c +6 2 \N 9 3 \N +7 3 c 1 1 a +7 3 c 10 \N \N +7 3 c 2 \N a +7 3 c 3 1 \N +7 3 c 4 2 b +7 3 c 5 \N b +7 3 c 6 2 \N +7 3 c 7 3 c +7 3 c 8 \N c +7 3 c 9 3 \N +8 \N c 1 1 a +8 \N c 10 \N \N +8 \N c 2 \N a +8 \N c 3 1 \N +8 \N c 4 2 b +8 \N c 5 \N b +8 \N c 6 2 \N +8 \N c 7 3 c +8 \N c 8 \N c +8 \N c 9 3 \N +9 3 \N 1 1 a +9 3 \N 10 \N \N +9 3 \N 2 \N a +9 3 \N 3 1 \N +9 3 \N 4 2 b +9 3 \N 5 \N b +9 3 \N 6 2 \N +9 3 \N 7 3 c +9 3 \N 8 \N c +9 3 \N 9 3 \N + +-- !left_outer_join -- +1 1 a 1 1 a +1 1 a 10 \N \N +1 1 a 2 \N a +1 1 a 3 1 \N +1 1 a 4 2 b +1 1 a 5 \N b +1 1 a 6 2 \N +1 1 a 7 3 c +1 1 a 8 \N c +1 1 a 9 3 \N +10 \N \N 1 1 a +10 \N \N 10 \N \N +10 \N \N 2 \N a +10 \N \N 3 1 \N +10 \N \N 4 2 b +10 \N \N 5 \N b +10 \N \N 6 2 \N +10 \N \N 7 3 c +10 \N \N 8 \N c +10 \N \N 9 3 \N +2 \N a 1 1 a +2 \N a 10 \N \N +2 \N a 2 \N a +2 \N a 3 1 \N +2 \N a 4 2 b +2 \N a 5 \N b +2 \N a 6 2 \N +2 \N a 7 3 c +2 \N a 8 \N c +2 \N a 9 3 \N +3 1 \N 1 1 a +3 1 \N 10 \N \N +3 1 \N 2 \N a +3 1 \N 3 1 \N +3 1 \N 4 2 b +3 1 \N 5 \N b +3 1 \N 6 2 \N +3 1 \N 7 3 c +3 1 \N 8 \N c +3 1 \N 9 3 \N +4 2 b 1 1 a +4 2 b 10 \N \N +4 2 b 2 \N a +4 2 b 3 1 \N +4 2 b 4 2 b +4 2 b 5 \N b +4 2 b 6 2 \N +4 2 b 7 3 c +4 2 b 8 \N c +4 2 b 9 3 \N +5 \N b 1 1 a +5 \N b 10 \N \N +5 \N b 2 \N a +5 \N b 3 1 \N +5 \N b 4 2 b +5 \N b 5 \N b +5 \N b 6 2 \N +5 \N b 7 3 c +5 \N b 8 \N c +5 \N b 9 3 \N +6 2 \N 1 1 a +6 2 \N 10 \N \N +6 2 \N 2 \N a +6 2 \N 3 1 \N +6 2 \N 4 2 b +6 2 \N 5 \N b +6 2 \N 6 2 \N +6 2 \N 7 3 c +6 2 \N 8 \N c +6 2 \N 9 3 \N +7 3 c 1 1 a +7 3 c 10 \N \N +7 3 c 2 \N a +7 3 c 3 1 \N +7 3 c 4 2 b +7 3 c 5 \N b +7 3 c 6 2 \N +7 3 c 7 3 c +7 3 c 8 \N c +7 3 c 9 3 \N +8 \N c 1 1 a +8 \N c 10 \N \N +8 \N c 2 \N a +8 \N c 3 1 \N +8 \N c 4 2 b +8 \N c 5 \N b +8 \N c 6 2 \N +8 \N c 7 3 c +8 \N c 8 \N c +8 \N c 9 3 \N +9 3 \N 1 1 a +9 3 \N 10 \N \N +9 3 \N 2 \N a +9 3 \N 3 1 \N +9 3 \N 4 2 b +9 3 \N 5 \N b +9 3 \N 6 2 \N +9 3 \N 7 3 c +9 3 \N 8 \N c +9 3 \N 9 3 \N + +-- !right_outer_join -- +1 1 a 1 1 a +1 1 a 10 \N \N +1 1 a 2 \N a +1 1 a 3 1 \N +1 1 a 4 2 b +1 1 a 5 \N b +1 1 a 6 2 \N +1 1 a 7 3 c +1 1 a 8 \N c +1 1 a 9 3 \N +10 \N \N 1 1 a +10 \N \N 10 \N \N +10 \N \N 2 \N a +10 \N \N 3 1 \N +10 \N \N 4 2 b +10 \N \N 5 \N b +10 \N \N 6 2 \N +10 \N \N 7 3 c +10 \N \N 8 \N c +10 \N \N 9 3 \N +2 \N a 1 1 a +2 \N a 10 \N \N +2 \N a 2 \N a +2 \N a 3 1 \N +2 \N a 4 2 b +2 \N a 5 \N b +2 \N a 6 2 \N +2 \N a 7 3 c +2 \N a 8 \N c +2 \N a 9 3 \N +3 1 \N 1 1 a +3 1 \N 10 \N \N +3 1 \N 2 \N a +3 1 \N 3 1 \N +3 1 \N 4 2 b +3 1 \N 5 \N b +3 1 \N 6 2 \N +3 1 \N 7 3 c +3 1 \N 8 \N c +3 1 \N 9 3 \N +4 2 b 1 1 a +4 2 b 10 \N \N +4 2 b 2 \N a +4 2 b 3 1 \N +4 2 b 4 2 b +4 2 b 5 \N b +4 2 b 6 2 \N +4 2 b 7 3 c +4 2 b 8 \N c +4 2 b 9 3 \N +5 \N b 1 1 a +5 \N b 10 \N \N +5 \N b 2 \N a +5 \N b 3 1 \N +5 \N b 4 2 b +5 \N b 5 \N b +5 \N b 6 2 \N +5 \N b 7 3 c +5 \N b 8 \N c +5 \N b 9 3 \N +6 2 \N 1 1 a +6 2 \N 10 \N \N +6 2 \N 2 \N a +6 2 \N 3 1 \N +6 2 \N 4 2 b +6 2 \N 5 \N b +6 2 \N 6 2 \N +6 2 \N 7 3 c +6 2 \N 8 \N c +6 2 \N 9 3 \N +7 3 c 1 1 a +7 3 c 10 \N \N +7 3 c 2 \N a +7 3 c 3 1 \N +7 3 c 4 2 b +7 3 c 5 \N b +7 3 c 6 2 \N +7 3 c 7 3 c +7 3 c 8 \N c +7 3 c 9 3 \N +8 \N c 1 1 a +8 \N c 10 \N \N +8 \N c 2 \N a +8 \N c 3 1 \N +8 \N c 4 2 b +8 \N c 5 \N b +8 \N c 6 2 \N +8 \N c 7 3 c +8 \N c 8 \N c +8 \N c 9 3 \N +9 3 \N 1 1 a +9 3 \N 10 \N \N +9 3 \N 2 \N a +9 3 \N 3 1 \N +9 3 \N 4 2 b +9 3 \N 5 \N b +9 3 \N 6 2 \N +9 3 \N 7 3 c +9 3 \N 8 \N c +9 3 \N 9 3 \N + +-- !full_outer_join -- +1 1 a 1 1 a +1 1 a 10 \N \N +1 1 a 2 \N a +1 1 a 3 1 \N +1 1 a 4 2 b +1 1 a 5 \N b +1 1 a 6 2 \N +1 1 a 7 3 c +1 1 a 8 \N c +1 1 a 9 3 \N +10 \N \N 1 1 a +10 \N \N 10 \N \N +10 \N \N 2 \N a +10 \N \N 3 1 \N +10 \N \N 4 2 b +10 \N \N 5 \N b +10 \N \N 6 2 \N +10 \N \N 7 3 c +10 \N \N 8 \N c +10 \N \N 9 3 \N +2 \N a 1 1 a +2 \N a 10 \N \N +2 \N a 2 \N a +2 \N a 3 1 \N +2 \N a 4 2 b +2 \N a 5 \N b +2 \N a 6 2 \N +2 \N a 7 3 c +2 \N a 8 \N c +2 \N a 9 3 \N +3 1 \N 1 1 a +3 1 \N 10 \N \N +3 1 \N 2 \N a +3 1 \N 3 1 \N +3 1 \N 4 2 b +3 1 \N 5 \N b +3 1 \N 6 2 \N +3 1 \N 7 3 c +3 1 \N 8 \N c +3 1 \N 9 3 \N +4 2 b 1 1 a +4 2 b 10 \N \N +4 2 b 2 \N a +4 2 b 3 1 \N +4 2 b 4 2 b +4 2 b 5 \N b +4 2 b 6 2 \N +4 2 b 7 3 c +4 2 b 8 \N c +4 2 b 9 3 \N +5 \N b 1 1 a +5 \N b 10 \N \N +5 \N b 2 \N a +5 \N b 3 1 \N +5 \N b 4 2 b +5 \N b 5 \N b +5 \N b 6 2 \N +5 \N b 7 3 c +5 \N b 8 \N c +5 \N b 9 3 \N +6 2 \N 1 1 a +6 2 \N 10 \N \N +6 2 \N 2 \N a +6 2 \N 3 1 \N +6 2 \N 4 2 b +6 2 \N 5 \N b +6 2 \N 6 2 \N +6 2 \N 7 3 c +6 2 \N 8 \N c +6 2 \N 9 3 \N +7 3 c 1 1 a +7 3 c 10 \N \N +7 3 c 2 \N a +7 3 c 3 1 \N +7 3 c 4 2 b +7 3 c 5 \N b +7 3 c 6 2 \N +7 3 c 7 3 c +7 3 c 8 \N c +7 3 c 9 3 \N +8 \N c 1 1 a +8 \N c 10 \N \N +8 \N c 2 \N a +8 \N c 3 1 \N +8 \N c 4 2 b +8 \N c 5 \N b +8 \N c 6 2 \N +8 \N c 7 3 c +8 \N c 8 \N c +8 \N c 9 3 \N +9 3 \N 1 1 a +9 3 \N 10 \N \N +9 3 \N 2 \N a +9 3 \N 3 1 \N +9 3 \N 4 2 b +9 3 \N 5 \N b +9 3 \N 6 2 \N +9 3 \N 7 3 c +9 3 \N 8 \N c +9 3 \N 9 3 \N + +-- !left_semi_join -- +1 1 a +10 \N \N +2 \N a +3 1 \N +4 2 b +5 \N b +6 2 \N +7 3 c +8 \N c +9 3 \N + +-- !left_anti_join -- + +-- !right_semi_join -- +1 1 a +10 \N \N +2 \N a +3 1 \N +4 2 b +5 \N b +6 2 \N +7 3 c +8 \N c +9 3 \N + +-- !right_anti_join -- + diff --git a/regression-test/suites/nereids_rules_p0/eliminate_join_condition/eliminate_join_condition.groovy b/regression-test/suites/nereids_rules_p0/eliminate_join_condition/eliminate_join_condition.groovy new file mode 100644 index 0000000000..09f2c9a2d3 --- /dev/null +++ b/regression-test/suites/nereids_rules_p0/eliminate_join_condition/eliminate_join_condition.groovy @@ -0,0 +1,114 @@ +// 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("eliminate_join_condition") { + sql "SET enable_nereids_planner=true" + sql "SET enable_fallback_to_original_planner=false" + + sql """ + DROP TABLE IF EXISTS t; + """ + + sql """ + CREATE TABLE IF NOT EXISTS t( + `id` int(32), + `score` int(64) NULL, + `name` varchar(64) NULL + ) ENGINE = OLAP + DISTRIBUTED BY HASH(id) BUCKETS 4 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + sql "insert into t values (1, 1, 'a')" + sql "insert into t values (2, null, 'a')" + sql "insert into t values (3, 1, null)" + sql "insert into t values (4, 2, 'b')" + sql "insert into t values (5, null, 'b')" + sql "insert into t values (6, 2, null)" + sql "insert into t values (7, 3, 'c')" + sql "insert into t values (8, null, 'c')" + sql "insert into t values (9, 3, null)" + sql "insert into t values (10, null, null)" + + qt_inner_join """ + explain shape plan select * from t t1 inner join t t2 on true; + """ + + qt_left_outer_join """ + explain shape plan select * from t t1 left outer join t t2 on true; + """ + + qt_right_outer_join """ + explain shape plan select * from t t1 right outer join t t2 on true; + """ + + qt_full_outer_join """ + explain shape plan select * from t t1 full outer join t t2 on true; + """ + + qt_left_semi_join """ + explain shape plan select * from t t1 left semi join t t2 on true; + """ + + qt_left_anti_join """ + explain shape plan select * from t t1 left anti join t t2 on true; + """ + + qt_right_semi_join """ + explain shape plan select * from t t1 right semi join t t2 on true; + """ + + qt_right_anti_join """ + explain shape plan select * from t t1 right anti join t t2 on true; + """ + + /* ******** Output ******** */ + + order_qt_inner_join """ + select * from t t1 inner join t t2 on true; + """ + + order_qt_left_outer_join """ + select * from t t1 left outer join t t2 on true; + """ + + order_qt_right_outer_join """ + select * from t t1 right outer join t t2 on true; + """ + + order_qt_full_outer_join """ + select * from t t1 full outer join t t2 on true; + """ + + order_qt_left_semi_join """ + select * from t t1 left semi join t t2 on true; + """ + + order_qt_left_anti_join """ + select * from t t1 left anti join t t2 on true; + """ + + order_qt_right_semi_join """ + select * from t t1 right semi join t t2 on true; + """ + + order_qt_right_anti_join """ + select * from t t1 right anti join t t2 on true; + """ +} \ No newline at end of file