Skip to content

Commit

Permalink
[fix](Planner): don't push down isNull predicate into view (apache#26288
Browse files Browse the repository at this point in the history
)

We can't push down `isNull` predicate into view
  • Loading branch information
keanji-x authored and seawinde committed Nov 8, 2023
1 parent cda092a commit f4dffb8
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,8 @@ public static BinaryPredicate read(DataInput in) throws IOException {
}

@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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ public boolean canHashPartition() {
}

@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ public static boolean isOr(Expr expr) {
}

@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);
Expand Down
4 changes: 2 additions & 2 deletions fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
Original file line number Diff line number Diff line change
Expand Up @@ -2194,10 +2194,10 @@ public boolean supportSerializable() {
}


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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ public String toString() {
}

@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ public boolean isNullable() {
* 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,8 @@ public boolean matchExprs(List<Expr> exprs, SelectStmt stmt, boolean ignoreAlias
}

@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) {
Expand All @@ -630,7 +630,7 @@ public Expr getResultValue(boolean foldSlot) throws AnalysisException {
}
Expr expr = exprs.get(0);
if (expr instanceof SlotRef) {
return expr.getResultValue(foldSlot);
return expr.getResultValue(forPushDownPredicatesToView);
}
if (expr.isConstant()) {
return expr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public Expr getLiteralExpr() {
}

@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
Expand Down
5 changes: 5 additions & 0 deletions regression-test/data/query_p0/literal_view/lietral_test.out
Original file line number Diff line number Diff line change
@@ -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 --

Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit f4dffb8

Please sign in to comment.