[fix](Planner): don't push down isNull predicate into view (#26288)

We can't push down `isNull` predicate into view
This commit is contained in:
谢健
2023-11-03 16:30:12 +08:00
committed by GitHub
parent f92b572a97
commit 265c83d912
10 changed files with 32 additions and 16 deletions

View File

@ -799,8 +799,8 @@ public class BinaryPredicate extends Predicate implements Writable {
}
@Override
public Expr getResultValue(boolean inView) throws AnalysisException {
recursiveResetChildrenResult(inView);
public Expr getResultValue(boolean forPushDownPredicatesToView) throws AnalysisException {
recursiveResetChildrenResult(forPushDownPredicatesToView);
final Expr leftChildValue = getChild(0);
final Expr rightChildValue = getChild(1);
if (!(leftChildValue instanceof LiteralExpr)

View File

@ -399,8 +399,8 @@ public class CastExpr extends Expr {
}
@Override
public Expr getResultValue(boolean inView) throws AnalysisException {
recursiveResetChildrenResult(inView);
public Expr getResultValue(boolean forPushDownPredicatesToView) throws AnalysisException {
recursiveResetChildrenResult(forPushDownPredicatesToView);
final Expr value = children.get(0);
if (!(value instanceof LiteralExpr)) {
return this;

View File

@ -230,8 +230,8 @@ public class CompoundPredicate extends Predicate {
}
@Override
public Expr getResultValue(boolean inView) throws AnalysisException {
recursiveResetChildrenResult(inView);
public Expr getResultValue(boolean forPushDownPredicatesToView) throws AnalysisException {
recursiveResetChildrenResult(forPushDownPredicatesToView);
boolean compoundResult = false;
if (op == Operator.NOT) {
final Expr childValue = getChild(0);

View File

@ -2190,10 +2190,10 @@ public abstract class Expr extends TreeNode<Expr> implements ParseNode, Cloneabl
}
protected void recursiveResetChildrenResult(boolean inView) throws AnalysisException {
protected void recursiveResetChildrenResult(boolean forPushDownPredicatesToView) throws AnalysisException {
for (int i = 0; i < children.size(); i++) {
final Expr child = children.get(i);
final Expr newChild = child.getResultValue(inView);
final Expr newChild = child.getResultValue(forPushDownPredicatesToView);
if (newChild != child) {
setChild(i, newChild);
}

View File

@ -308,8 +308,8 @@ public class InPredicate extends Predicate {
}
@Override
public Expr getResultValue(boolean inView) throws AnalysisException {
recursiveResetChildrenResult(inView);
public Expr getResultValue(boolean forPushDownPredicatesToView) throws AnalysisException {
recursiveResetChildrenResult(forPushDownPredicatesToView);
final Expr leftChildValue = getChild(0);
if (!(leftChildValue instanceof LiteralExpr) || !isLiteralChildren()) {
return this;

View File

@ -155,8 +155,10 @@ public class IsNullPredicate extends Predicate {
* fix issue 6390
*/
@Override
public Expr getResultValue(boolean inView) throws AnalysisException {
recursiveResetChildrenResult(inView);
public Expr getResultValue(boolean forPushDownPredicatesToView) throws AnalysisException {
// Don't push down predicate to view for is null predicate because the value can contain null
// after outer join
recursiveResetChildrenResult(!forPushDownPredicatesToView);
final Expr childValue = getChild(0);
if (!(childValue instanceof LiteralExpr)) {
return this;

View File

@ -613,8 +613,8 @@ public class SlotRef extends Expr {
}
@Override
public Expr getResultValue(boolean foldSlot) throws AnalysisException {
if (!foldSlot) {
public Expr getResultValue(boolean forPushDownPredicatesToView) throws AnalysisException {
if (!forPushDownPredicatesToView) {
return this;
}
if (!isConstant() || desc == null) {
@ -626,7 +626,7 @@ public class SlotRef extends Expr {
}
Expr expr = exprs.get(0);
if (expr instanceof SlotRef) {
return expr.getResultValue(foldSlot);
return expr.getResultValue(forPushDownPredicatesToView);
}
if (expr.isConstant()) {
return expr;

View File

@ -137,7 +137,7 @@ public class VariableExpr extends Expr {
}
@Override
public Expr getResultValue(boolean inView) throws AnalysisException {
public Expr getResultValue(boolean forPushDownPredicatesToView) throws AnalysisException {
if (!Strings.isNullOrEmpty(name) && VariableVarConverters.hasConverter(name)) {
// Return the string type here so that it can correctly match the subsequent function signature.
// And we also set `beConverted` to session variable name in StringLiteral, so that it can be cast back

View File

@ -1,5 +1,10 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
-- !left --
1 doris 10 \N
2 spark 2 \N
3 flink 20 \N
-- !sql1 --

View File

@ -106,6 +106,15 @@ suite("literal_view_test") {
insert into test_insert values (1,'doris',10),(2,'spark',2),(3,'flink',20);
"""
sql "set enable_nereids_planner=false"
order_qt_left """select *
from test_insert
left join (select 1 as v1) t1
on false
where t1.v1 is null
"""
sql "set enable_nereids_planner=true"
qt_sql1 """
select id, name
from (