From fbdef19dd03426aa991059948fd00111946be75c Mon Sep 17 00:00:00 2001 From: starocean999 <12095047@qq.com> Date: Tue, 14 May 2024 17:11:57 +0800 Subject: [PATCH] [fix](planner)correlated predicate should include isnull predicate --- .../apache/doris/analysis/StmtRewriter.java | 3 +- .../test_subquery_with_agg.groovy | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/StmtRewriter.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/StmtRewriter.java index 62737131b62d72..93823cf398c2dc 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/StmtRewriter.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/StmtRewriter.java @@ -957,7 +957,8 @@ private static boolean containsCorrelatedPredicate(Expr root, List tupl * query block (i.e. is not bound by the given 'tupleIds'). */ private static boolean isCorrelatedPredicate(Expr expr, List tupleIds) { - return (expr instanceof BinaryPredicate || expr instanceof SlotRef) && !expr.isBoundByTupleIds(tupleIds); + return (expr instanceof BinaryPredicate || expr instanceof SlotRef + || expr instanceof IsNullPredicate) && !expr.isBoundByTupleIds(tupleIds); } /** diff --git a/regression-test/suites/correctness_p0/test_subquery_with_agg.groovy b/regression-test/suites/correctness_p0/test_subquery_with_agg.groovy index e0592830ffe921..a962d64dcbc637 100644 --- a/regression-test/suites/correctness_p0/test_subquery_with_agg.groovy +++ b/regression-test/suites/correctness_p0/test_subquery_with_agg.groovy @@ -82,4 +82,45 @@ suite("test_subquery_with_agg") { drop table if exists agg_subquery_table; """ + sql """drop table if exists subquery_table_xyz;""" + sql """CREATE TABLE `subquery_table_xyz` ( + `phone`bigint(20) NULL + ) ENGINE=OLAP + DUPLICATE KEY(`phone`) + COMMENT 'OLAP' + DISTRIBUTED BY HASH(`phone`) BUCKETS 3 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + );""" + sql """WITH tmp1 AS + (SELECT DISTINCT phone + FROM subquery_table_xyz oua + WHERE (NOT EXISTS + (SELECT 1 + FROM subquery_table_xyz o1 + WHERE oua.phone = o1.phone + AND phone IS NOT NULL))), + tmp2 AS + (SELECT DISTINCT phone + FROM subquery_table_xyz oua + WHERE (NOT EXISTS + (SELECT 1 + FROM subquery_table_xyz o1 + WHERE oua.phone = o1.phone + and phone IS NOT NULL))), + tmp3 AS + (SELECT DISTINCT phone + FROM subquery_table_xyz oua + WHERE (NOT EXISTS + (SELECT 1 + FROM subquery_table_xyz o1 + WHERE oua.phone = o1.phone and + phone IS NOT NULL))) + SELECT COUNT(DISTINCT tmp1.phone) + FROM tmp1 + JOIN tmp2 + ON tmp1.phone = tmp2.phone + JOIN tmp3 + ON tmp2.phone = tmp3.phone;""" + }