You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by ja...@apache.org on 2024/01/18 07:55:43 UTC
(doris) branch master updated: [fix](Nereids): eliminate redundant join condition after inferring condition (#30093)
This is an automated email from the ASF dual-hosted git repository.
jakevin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 0c4e83f5fd3 [fix](Nereids): eliminate redundant join condition after inferring condition (#30093)
0c4e83f5fd3 is described below
commit 0c4e83f5fd36144aeb4475ea8ffe63b92c40016c
Author: 谢健 <ji...@gmail.com>
AuthorDate: Thu Jan 18 15:55:34 2024 +0800
[fix](Nereids): eliminate redundant join condition after inferring condition (#30093)
eliminate redundant join when find hashing join condition
such as for plan:
```
T1 join T2 on T1.id = T2.id join T3 on T1.id = T3.id and T2.id = T3.id
```
we infer a new predicate T1.id = T2.id which is redundant. Therefore we need to eliminate it when find hash condition
---
.../doris/nereids/rules/rewrite/FindHashConditionForJoin.java | 9 +++++----
.../nereids/jobs/joinorder/hypergraph/CompareOuterJoinTest.java | 5 ++++-
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/FindHashConditionForJoin.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/FindHashConditionForJoin.java
index fe51a7d830b..aeeeefb593b 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/FindHashConditionForJoin.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/FindHashConditionForJoin.java
@@ -28,6 +28,7 @@ import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
import org.apache.doris.nereids.util.JoinUtils;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Streams;
import java.util.List;
@@ -61,10 +62,10 @@ public class FindHashConditionForJoin extends OneRewriteRuleFactory {
return join;
}
- List<Expression> combinedHashJoinConjuncts = new ImmutableList.Builder<Expression>()
- .addAll(join.getHashJoinConjuncts())
- .addAll(extractedHashJoinConjuncts)
- .build();
+ List<Expression> combinedHashJoinConjuncts = Streams
+ .concat(join.getHashJoinConjuncts().stream(), extractedHashJoinConjuncts.stream())
+ .distinct()
+ .collect(ImmutableList.toImmutableList());
JoinType joinType = join.getJoinType();
if (joinType == JoinType.CROSS_JOIN && !combinedHashJoinConjuncts.isEmpty()) {
joinType = JoinType.INNER_JOIN;
diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/jobs/joinorder/hypergraph/CompareOuterJoinTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/jobs/joinorder/hypergraph/CompareOuterJoinTest.java
index f73d8a2923e..bbf7746ec6a 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/nereids/jobs/joinorder/hypergraph/CompareOuterJoinTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/jobs/joinorder/hypergraph/CompareOuterJoinTest.java
@@ -28,10 +28,12 @@ import org.apache.doris.nereids.rules.exploration.mv.mapping.RelationMapping;
import org.apache.doris.nereids.rules.exploration.mv.mapping.SlotMapping;
import org.apache.doris.nereids.sqltest.SqlTestBase;
import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.plans.JoinType;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.util.HyperGraphBuilder;
import org.apache.doris.nereids.util.PlanChecker;
+import com.google.common.collect.Sets;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -69,7 +71,8 @@ class CompareOuterJoinTest extends SqlTestBase {
@Test
void testRandomQuery() {
- Plan p1 = new HyperGraphBuilder().randomBuildPlanWith(3, 3);
+ Plan p1 = new HyperGraphBuilder(Sets.newHashSet(JoinType.INNER_JOIN))
+ .randomBuildPlanWith(3, 3);
p1 = PlanChecker.from(connectContext, p1)
.analyze()
.rewrite()
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org