From 2053bb51bdde5c20bb8dc29caa41183ad345ac3a Mon Sep 17 00:00:00 2001 From: starocean999 <12095047@qq.com> Date: Mon, 6 Nov 2023 17:01:15 +0800 Subject: [PATCH 1/2] [fix](planner)isnull predicate can't be safely constant folded in inlineview --- .../java/org/apache/doris/analysis/IsNullPredicate.java | 2 +- .../java/org/apache/doris/rewrite/FoldConstantsRule.java | 5 ++++- .../suites/query_p0/literal_view/lietral_test.groovy | 6 ++++++ 3 files changed, 11 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 bf81cb48100d02..c67ca1b06029db 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 Expr getResultValue(boolean forPushDownPredicatesToView) throws AnalysisE // 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 509e78ffb8b641..006266dd716cca 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 @@ -124,7 +124,10 @@ public Expr apply(Expr expr, Analyzer analyzer, ExprRewriter.ClauseType clauseTy 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(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 905ed6696dd31f..b19f33e2939685 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") + } } From 1feb7c59a37cb06d1c2bdb7f5cc670bb10cab807 Mon Sep 17 00:00:00 2001 From: starocean999 <12095047@qq.com> Date: Mon, 6 Nov 2023 20:07:23 +0800 Subject: [PATCH 2/2] fix failed ut --- .../main/java/org/apache/doris/rewrite/FoldConstantsRule.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 006266dd716cca..e28feabbf4d430 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.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; @@ -127,7 +128,7 @@ public Expr apply(Expr expr, Analyzer analyzer, ExprRewriter.ClauseType clauseTy // 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(analyzer.isInlineViewAnalyzer()); + return expr.getResultValue(expr instanceof SlotRef ? false : analyzer.isInlineViewAnalyzer()); } /**