You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2022/05/07 12:41:16 UTC
[incubator-doris] branch master updated: [fix](rewrite) The where condition cannot be pushed down because there is no derivation (#8980)
This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push:
new e5a88dd0a4 [fix](rewrite) The where condition cannot be pushed down because there is no derivation (#8980)
e5a88dd0a4 is described below
commit e5a88dd0a4fefe56b846896a83003731b105cd6c
Author: zhengshiJ <32...@users.noreply.github.com>
AuthorDate: Sat May 7 20:41:11 2022 +0800
[fix](rewrite) The where condition cannot be pushed down because there is no derivation (#8980)
Fix a bug.
The where condition cannot be pushed down because there is no derivation
eg:
select * from tb1 left join tb2 on tb1.id = tb2.id where tb2.id = 1;
The correct case is that the condition of "=1" needs to be deduced to tb1.id,
but the current implementation does not do the deduction
---
.../java/org/apache/doris/qe/SessionVariable.java | 2 +-
.../org/apache/doris/rewrite/InferFiltersRule.java | 12 ++++--------
.../apache/doris/rewrite/InferFiltersRuleTest.java | 21 +++++++++++++++++++++
3 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
index 20fccab3fa..8bc47eac47 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
@@ -422,7 +422,7 @@ public class SessionVariable implements Serializable, Writable {
private boolean disableJoinReorder = false;
@VariableMgr.VarAttr(name = ENABLE_INFER_PREDICATE)
- private boolean enableInferPredicate = false;
+ private boolean enableInferPredicate = true;
@VariableMgr.VarAttr(name = SQL_QUOTE_SHOW_CREATE)
public boolean sqlQuoteShowCreate = true;
diff --git a/fe/fe-core/src/main/java/org/apache/doris/rewrite/InferFiltersRule.java b/fe/fe-core/src/main/java/org/apache/doris/rewrite/InferFiltersRule.java
index 6cfc4cac45..3ccd390144 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/rewrite/InferFiltersRule.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/rewrite/InferFiltersRule.java
@@ -70,16 +70,14 @@ public class InferFiltersRule implements ExprRewriteRule {
}
// slotEqSlotExpr: Record existing and infer equivalent connections
- List<Expr> slotEqSlotExpr =
- (clauseType == ExprRewriter.ClauseType.ON_CLAUSE) ? analyzer.getOnSlotEqSlotExpr() : new ArrayList<>();
+ List<Expr> slotEqSlotExpr = analyzer.getOnSlotEqSlotExpr();
// slotEqSlotDeDuplication: De-Duplication for slotEqSlotExpr
Set<Pair<Expr, Expr>> slotEqSlotDeDuplication =
(clauseType == ExprRewriter.ClauseType.ON_CLAUSE) ? analyzer.getOnSlotEqSlotDeDuplication() : Sets.newHashSet();
// slotToLiteralExpr: Record existing and infer expr which slot and literal are equal
- List<Expr> slotToLiteralExpr =
- (clauseType == ExprRewriter.ClauseType.ON_CLAUSE) ? analyzer.getOnSlotToLiteralExpr() : new ArrayList<>();
+ List<Expr> slotToLiteralExpr = analyzer.getOnSlotToLiteralExpr();
// slotToLiteralDeDuplication: De-Duplication for slotToLiteralExpr
Set<Pair<Expr, Expr>> slotToLiteralDeDuplication =
@@ -91,16 +89,14 @@ public class InferFiltersRule implements ExprRewriteRule {
List<Pair<Expr, Boolean>> newExprWithState = new ArrayList<>();
// isNullExpr: Record existing and infer not null predicate
- List<Expr> isNullExpr =
- (clauseType == ExprRewriter.ClauseType.ON_CLAUSE) ? analyzer.getOnIsNullExpr() : new ArrayList<>();
+ List<Expr> isNullExpr = analyzer.getOnIsNullExpr();
// isNullDeDuplication: De-Duplication for isNullExpr
Set<Expr> isNullDeDuplication =
(clauseType == ExprRewriter.ClauseType.ON_CLAUSE) ? analyzer.getOnIsNullDeDuplication() : Sets.newHashSet();
// inExpr: Record existing and infer in predicate
- List<Expr> inExpr =
- (clauseType == ExprRewriter.ClauseType.ON_CLAUSE) ? analyzer.getInExpr() : new ArrayList<>();
+ List<Expr> inExpr = analyzer.getInExpr();
// inDeDuplication: De-Duplication for inExpr
Set<Expr> inDeDuplication =
diff --git a/fe/fe-core/src/test/java/org/apache/doris/rewrite/InferFiltersRuleTest.java b/fe/fe-core/src/test/java/org/apache/doris/rewrite/InferFiltersRuleTest.java
index 15234fb5c3..c3c14f9ca5 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/rewrite/InferFiltersRuleTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/rewrite/InferFiltersRuleTest.java
@@ -299,4 +299,25 @@ public class InferFiltersRuleTest {
Assert.assertTrue(planString.contains("`tb2`.`k1` >= 1"));
Assert.assertTrue(planString.contains("`tb2`.`k1` <= 2"));
}
+
+ @Test
+ public void testOnAndWhere2TablesLeftJoin() throws Exception {
+ SessionVariable sessionVariable = dorisAssert.getSessionVariable();
+ sessionVariable.setEnableInferPredicate(true);
+ Assert.assertTrue(sessionVariable.isEnableInferPredicate());
+ String query = "select * from tb1 left join tb2 on tb1.k1 = tb2.k1 where tb2.k1 = 1";
+ String planString = dorisAssert.query(query).explainQuery();
+ Assert.assertTrue(planString.contains("`tb1`.`k1` = 1"));
+ }
+
+ @Test
+ public void testOnAndWhere2TablesInnerJoin() throws Exception {
+ SessionVariable sessionVariable = dorisAssert.getSessionVariable();
+ sessionVariable.setEnableInferPredicate(true);
+ Assert.assertTrue(sessionVariable.isEnableInferPredicate());
+ String query = "select * from tb1 inner join tb2 on tb1.k1 = tb2.k1 where tb2.k1 = 1";
+ String planString = dorisAssert.query(query).explainQuery();
+ Assert.assertTrue(planString.contains("`tb1`.`k1` = 1"));
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org