You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by st...@apache.org on 2023/11/08 12:46:36 UTC

(doris) branch master updated: [fix](planner)isnull predicate can't be safely constant folded in inlineview (#25377)

This is an automated email from the ASF dual-hosted git repository.

starocean999 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 0c1458f21f6 [fix](planner)isnull predicate can't be safely constant folded in inlineview (#25377)
0c1458f21f6 is described below

commit 0c1458f21f6142a707b59f3923aba4f0b578bf93
Author: starocean999 <40...@users.noreply.github.com>
AuthorDate: Wed Nov 8 20:46:29 2023 +0800

    [fix](planner)isnull predicate can't be safely constant folded in inlineview (#25377)
    
    disable is null predicate constant fold rule for inline view
    consider sql
    select c.*
    from (
    select a.*, b.x
    from test_insert a left join
    (select 'some_const_str' x from test_insert) b on true
    ) c
    where c.x is null;
    
    when push “c.x is null” into c, after folding constant rule, it will get empty result. Because x is 'some_const_str' and "x is null" will be evaluated to false. This is wrong.
---
 .../src/main/java/org/apache/doris/analysis/IsNullPredicate.java    | 2 +-
 .../src/main/java/org/apache/doris/rewrite/FoldConstantsRule.java   | 6 +++++-
 regression-test/suites/query_p0/literal_view/lietral_test.groovy    | 6 ++++++
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/IsNullPredicate.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/IsNullPredicate.java
index bf81cb48100..c67ca1b0602 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/IsNullPredicate.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/IsNullPredicate.java
@@ -160,7 +160,7 @@ public class IsNullPredicate extends Predicate {
         // after outer join
         recursiveResetChildrenResult(!forPushDownPredicatesToView);
         final Expr childValue = getChild(0);
-        if (!(childValue instanceof LiteralExpr)) {
+        if (forPushDownPredicatesToView || !(childValue instanceof LiteralExpr)) {
             return this;
         }
         return childValue instanceof NullLiteral ? new BoolLiteral(!isNotNull) : new BoolLiteral(isNotNull);
diff --git a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FoldConstantsRule.java b/fe/fe-core/src/main/java/org/apache/doris/rewrite/FoldConstantsRule.java
index 509e78ffb8b..e28feabbf4d 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FoldConstantsRule.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/rewrite/FoldConstantsRule.java
@@ -29,6 +29,7 @@ import org.apache.doris.analysis.Expr;
 import org.apache.doris.analysis.InformationFunction;
 import org.apache.doris.analysis.LiteralExpr;
 import org.apache.doris.analysis.NullLiteral;
+import org.apache.doris.analysis.SlotRef;
 import org.apache.doris.analysis.VariableExpr;
 import org.apache.doris.catalog.Env;
 import org.apache.doris.catalog.PrimitiveType;
@@ -124,7 +125,10 @@ public class FoldConstantsRule implements ExprRewriteRule {
                 return expr;
             }
         }
-        return expr.getResultValue(false);
+        // it may be wrong to fold constant value in inline view
+        // so pass the info to getResultValue method to let predicate itself
+        // to decide if it can fold constant value safely
+        return expr.getResultValue(expr instanceof SlotRef ? false : analyzer.isInlineViewAnalyzer());
     }
 
     /**
diff --git a/regression-test/suites/query_p0/literal_view/lietral_test.groovy b/regression-test/suites/query_p0/literal_view/lietral_test.groovy
index 905ed6696dd..b19f33e2939 100644
--- a/regression-test/suites/query_p0/literal_view/lietral_test.groovy
+++ b/regression-test/suites/query_p0/literal_view/lietral_test.groovy
@@ -140,4 +140,10 @@ suite("literal_view_test") {
         sql "select * from (select null as top) t where top = 5"
         result ([])
     }
+
+    sql """set enable_nereids_planner=false;"""
+    explain {
+        sql """ select c.* from ( select a.*, '' x from test_insert a left join test_insert b on true ) c where c.x is null; """
+        notContains("VEMPTYSET")
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org