diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownJoinOtherCondition.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownJoinOtherCondition.java index 994060da011972..7c884261587981 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownJoinOtherCondition.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownJoinOtherCondition.java @@ -86,7 +86,16 @@ && allCoveredBy(otherConjunct, join.left().getOutputSet())) { leftConjuncts.add(otherConjunct); } else if (PUSH_DOWN_RIGHT_VALID_TYPE.contains(join.getJoinType()) && allCoveredBy(otherConjunct, join.right().getOutputSet())) { - rightConjuncts.add(otherConjunct); + // For NULL_AWARE_LEFT_ANTI_JOIN (NOT IN subquery), when hash join + // conjuncts are empty (no correlation), pushing other conditions to + // the right child would filter rows before the null-aware check, + // changing the NOT IN semantics. Keep them as remaining other + // conjuncts instead. + if (join.getJoinType().isNullAwareLeftAntiJoin() && join.getHashJoinConjuncts().isEmpty()) { + remainingOther.add(otherConjunct); + } else { + rightConjuncts.add(otherConjunct); + } } else { remainingOther.add(otherConjunct); } diff --git a/regression-test/data/query_p0/subquery/subquery_unnesting.out b/regression-test/data/query_p0/subquery/subquery_unnesting.out index 535e10059ad7ae..229c7a2069faed 100644 --- a/regression-test/data/query_p0/subquery/subquery_unnesting.out +++ b/regression-test/data/query_p0/subquery/subquery_unnesting.out @@ -1535,3 +1535,6 @@ 0 2 +-- !select65 -- +0 + diff --git a/regression-test/suites/query_p0/subquery/subquery_unnesting.groovy b/regression-test/suites/query_p0/subquery/subquery_unnesting.groovy index ea90e867f71a81..47873c04b0ee99 100644 --- a/regression-test/suites/query_p0/subquery/subquery_unnesting.groovy +++ b/regression-test/suites/query_p0/subquery/subquery_unnesting.groovy @@ -140,4 +140,9 @@ suite ("subquery_unnesting") { from t1 order by kk """ + qt_select65 """ + SELECT COUNT(*) AS c + FROM (SELECT 1 AS x) t + WHERE 1 NOT IN (SELECT CAST(NULL AS INT)); + """ }