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

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new b5fad610d8b [fix](planner)isnull predicate can't be safely constant 
folded in inlineview #25377 (#26685)
b5fad610d8b is described below

commit b5fad610d8b099aa9aaba9c3b259928677097098
Author: starocean999 <[email protected]>
AuthorDate: Thu Nov 9 23:32:08 2023 +0800

    [fix](planner)isnull predicate can't be safely constant folded in 
inlineview #25377 (#26685)
---
 .../src/main/java/org/apache/doris/analysis/IsNullPredicate.java    | 4 ++--
 .../src/main/java/org/apache/doris/rewrite/FoldConstantsRule.java   | 6 +++++-
 regression-test/suites/query_p0/literal_view/lietral_test.groovy    | 6 ++++++
 3 files changed, 13 insertions(+), 3 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 087b4a7c399..3542160741d 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
@@ -156,9 +156,9 @@ public class IsNullPredicate extends Predicate {
      */
     @Override
     public Expr getResultValue(boolean inView) throws AnalysisException {
-        recursiveResetChildrenResult(inView);
+        recursiveResetChildrenResult(!inView);
         final Expr childValue = getChild(0);
-        if (!(childValue instanceof LiteralExpr)) {
+        if (inView || !(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 3bd22cdbf24..7418b615a40 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 0c5f8bcec00..d1a1b51fd69 100644
--- a/regression-test/suites/query_p0/literal_view/lietral_test.groovy
+++ b/regression-test/suites/query_p0/literal_view/lietral_test.groovy
@@ -131,4 +131,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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to