This is an automated email from the ASF dual-hosted git repository.
yiguolei 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 1f2c06dd6e [enhancement](rewrite) Remove unused wide common factors to
improve scan performance in ExtractCommonFactorsRule (#14381)
1f2c06dd6e is described below
commit 1f2c06dd6e81c6e12ec73b4030288a3d236bfead
Author: caiconghui <[email protected]>
AuthorDate: Sat Nov 19 13:23:49 2022 +0800
[enhancement](rewrite) Remove unused wide common factors to improve scan
performance in ExtractCommonFactorsRule (#14381)
* [enhancemeng](sql) Remove unused wide common factors to improve scan
performance in ExtractCommonFactorsRule
* fix regression test
Co-authored-by: caiconghui1 <[email protected]>
---
.../org/apache/doris/rewrite/ExtractCommonFactorsRule.java | 12 ++++++++----
.../doris/rewrite/ExtractCommonFactorsRuleFunctionTest.java | 8 ++++++++
.../suites/tpch_sf1_p1/tpch_sf1/explain/test_q12.groovy | 4 ++--
3 files changed, 18 insertions(+), 6 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/rewrite/ExtractCommonFactorsRule.java
b/fe/fe-core/src/main/java/org/apache/doris/rewrite/ExtractCommonFactorsRule.java
index 0ec42b7c59..6ff72d858b 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/rewrite/ExtractCommonFactorsRule.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/rewrite/ExtractCommonFactorsRule.java
@@ -20,12 +20,14 @@ package org.apache.doris.rewrite;
import org.apache.doris.analysis.Analyzer;
import org.apache.doris.analysis.BinaryPredicate;
import org.apache.doris.analysis.CompoundPredicate;
+import org.apache.doris.analysis.CompoundPredicate.Operator;
import org.apache.doris.analysis.Expr;
import org.apache.doris.analysis.InPredicate;
import org.apache.doris.analysis.LiteralExpr;
import org.apache.doris.analysis.SlotRef;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.planner.PlanNode;
+import org.apache.doris.rewrite.ExprRewriter.ClauseType;
import com.google.common.base.Preconditions;
import com.google.common.collect.BoundType;
@@ -70,7 +72,7 @@ public class ExtractCommonFactorsRule implements
ExprRewriteRule {
return null;
} else if (expr instanceof CompoundPredicate
&& ((CompoundPredicate) expr).getOp() ==
CompoundPredicate.Operator.OR) {
- Expr rewrittenExpr =
extractCommonFactors(exprFormatting((CompoundPredicate) expr), analyzer);
+ Expr rewrittenExpr =
extractCommonFactors(exprFormatting((CompoundPredicate) expr), analyzer,
clauseType);
if (rewrittenExpr != null) {
return rewrittenExpr;
}
@@ -101,7 +103,7 @@ public class ExtractCommonFactorsRule implements
ExprRewriteRule {
* 4. Construct new expr:
* @return: a and b' and (b or (e and f))
*/
- private Expr extractCommonFactors(List<List<Expr>> exprs, Analyzer
analyzer) {
+ private Expr extractCommonFactors(List<List<Expr>> exprs, Analyzer
analyzer, ExprRewriter.ClauseType clauseType) {
if (exprs.size() < 2) {
return null;
}
@@ -156,9 +158,11 @@ public class ExtractCommonFactorsRule implements
ExprRewriteRule {
}
// 3. find merge cross the clause
- if (analyzer.getContext() != null &&
analyzer.getContext().getSessionVariable().isExtractWideRangeExpr()) {
+ if (analyzer.getContext() != null && clauseType ==
ClauseType.WHERE_CLAUSE
+ &&
analyzer.getContext().getSessionVariable().isExtractWideRangeExpr()) {
Expr wideCommonExpr = findWideRangeExpr(clearExprs);
- if (wideCommonExpr != null) {
+ if (wideCommonExpr != null && !(wideCommonExpr instanceof
CompoundPredicate
+ && ((CompoundPredicate) wideCommonExpr).getOp() ==
Operator.OR)) {
commonFactorList.add(wideCommonExpr);
}
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/rewrite/ExtractCommonFactorsRuleFunctionTest.java
b/fe/fe-core/src/test/java/org/apache/doris/rewrite/ExtractCommonFactorsRuleFunctionTest.java
index 802e4f7f9e..bb6807abee 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/rewrite/ExtractCommonFactorsRuleFunctionTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/rewrite/ExtractCommonFactorsRuleFunctionTest.java
@@ -83,6 +83,14 @@ public class ExtractCommonFactorsRuleFunctionTest {
Assert.assertEquals(1, StringUtils.countMatches(planString,
"`tb1`.`k1` = `tb2`.`k1`"));
}
+
+ @Test
+ public void testWideCommonFactorsWithOrPredicate() throws Exception {
+ String query = "select * from tb1 where tb1.k1 > 1000 or tb1.k1 < 200
or tb1.k1 = 300";
+ String planString = dorisAssert.query(query).explainQuery();
+ Assert.assertTrue(planString.contains("PREDICATES: (`tb1`.`k1` > 1000
OR `tb1`.`k1` < 200 OR `tb1`.`k1` = 300)"));
+ }
+
@Test
public void testWideCommonFactorsWithEqualPredicate() throws Exception {
String query = "select * from tb1, tb2 where (tb1.k1=1 and tb2.k1=1)
or (tb1.k1 =2 and tb2.k1=2)";
diff --git
a/regression-test/suites/tpch_sf1_p1/tpch_sf1/explain/test_q12.groovy
b/regression-test/suites/tpch_sf1_p1/tpch_sf1/explain/test_q12.groovy
index f2ef14e5ba..7b42b5e413 100644
--- a/regression-test/suites/tpch_sf1_p1/tpch_sf1/explain/test_q12.groovy
+++ b/regression-test/suites/tpch_sf1_p1/tpch_sf1/explain/test_q12.groovy
@@ -59,11 +59,11 @@ suite("test_explain_tpch_sf_1_q12") {
explainStr.contains("VTOP-N\n" +
" | order by: <slot 10> <slot 7> `l_shipmode`
ASC") &&
explainStr.contains("VAGGREGATE (merge finalize)\n" +
- " | output: sum(<slot 8> sum(CASE WHEN
((<slot 18> = '1-URGENT' OR <slot 18> = '2-HIGH') AND (<slot 18> = '1-URGENT'
OR <slot 18> = '2-HIGH')) THEN 1 ELSE 0 END)), sum(<slot 9> sum(CASE WHEN <slot
18> != '1-URGENT' AND <slot 18> != '2-HIGH' THEN 1 ELSE 0 END))\n" +
+ " | output: sum(<slot 8> sum(CASE WHEN (<slot
18> = '1-URGENT' OR <slot 18> = '2-HIGH') THEN 1 ELSE 0 END)), sum(<slot 9>
sum(CASE WHEN <slot 18> != '1-URGENT' AND <slot 18> != '2-HIGH' THEN 1 ELSE 0
END))\n" +
" | group by: <slot 7> `l_shipmode`") &&
explainStr.contains("VAGGREGATE (update serialize)\n" +
" | STREAMING\n" +
- " | output: sum(CASE WHEN ((<slot 18> =
'1-URGENT' OR <slot 18> = '2-HIGH') AND (<slot 18> = '1-URGENT' OR <slot 18> =
'2-HIGH')) THEN 1 ELSE 0 END), sum(CASE WHEN <slot 18> != '1-URGENT' AND <slot
18> != '2-HIGH' THEN 1 ELSE 0 END)\n" +
+ " | output: sum(CASE WHEN (<slot 18> =
'1-URGENT' OR <slot 18> = '2-HIGH') THEN 1 ELSE 0 END), sum(CASE WHEN <slot 18>
!= '1-URGENT' AND <slot 18> != '2-HIGH' THEN 1 ELSE 0 END)\n" +
" | group by: <slot 13>") &&
explainStr.contains("join op: INNER JOIN(BROADCAST)[Tables are
not in the same group]\n" +
" | equal join conjunct: `l_orderkey` =
`o_orderkey`\n" +
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]