Skip to content

Commit

Permalink
[fix](planner)isnull predicate can't be safely constant folded in inl…
Browse files Browse the repository at this point in the history
…ineview #25377 (#26685)
  • Loading branch information
starocean999 authored Nov 9, 2023
1 parent 8e3d09e commit b5fad61
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ public boolean isNullable() {
*/
@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -124,7 +125,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(expr instanceof SlotRef ? false : analyzer.isInlineViewAnalyzer());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit b5fad61

Please sign in to comment.