This is an automated email from the ASF dual-hosted git repository.

starocean999 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 8cf30aa0a17 [fix](fe) Prevent pushing other join conditions to right 
child of null-aware anti join (#64898)
8cf30aa0a17 is described below

commit 8cf30aa0a1708276054c939deb9f2025bff4b2f7
Author: starocean999 <[email protected]>
AuthorDate: Tue Jul 7 10:47:24 2026 +0800

    [fix](fe) Prevent pushing other join conditions to right child of 
null-aware anti join (#64898)
    
    When `PushDownJoinOtherCondition` processes a
    `NULL_AWARE_LEFT_ANTI_JOIN`
    with empty hash join conjuncts, it incorrectly pushes the other join
    conditions
    that reference only the right-side slots down to the right child. This
    changes
    the evaluation semantics of the NOT IN subquery, because filtering the
    right
    child before the null-aware anti join eliminates NULL values
    prematurely.
    
    For a `NULL_AWARE_LEFT_ANTI_JOIN`, the hash join conjuncts represent the
    correlation between the outer and inner tables. When there is no
    correlation
    (i.e., hash conjuncts are empty), the other join conditions must not be
    pushed
    to the right child, as doing so would filter rows from the subquery
    result
    before the NULL check, potentially producing incorrect results.
    
    Example affected query:
      SELECT COUNT(*) FROM (SELECT 1 AS x) t
      WHERE 1 NOT IN (SELECT CAST(NULL AS INT));
    
    The subquery returns NULL, so NOT IN should evaluate to UNKNOWN (NULL),
    meaning no rows match and COUNT returns 0. However, pushing the other
    condition
    to the right child changes this behavior and produces wrong results.
    
    Fix:
    Prevent pushing other join conditions to right child of null-aware anti
    join
    
    
    Related PR: https://github.com/apache/doris/pull/16774
---
 .../doris/nereids/rules/rewrite/PushDownJoinOtherCondition.java      | 1 -
 regression-test/data/query_p0/subquery/subquery_unnesting.out        | 3 +++
 regression-test/suites/query_p0/subquery/subquery_unnesting.groovy   | 5 +++++
 3 files changed, 8 insertions(+), 1 deletion(-)

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 994060da011..098175ff462 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
@@ -56,7 +56,6 @@ public class PushDownJoinOtherCondition extends 
OneRewriteRuleFactory {
             JoinType.INNER_JOIN,
             JoinType.LEFT_OUTER_JOIN,
             JoinType.LEFT_ANTI_JOIN,
-            JoinType.NULL_AWARE_LEFT_ANTI_JOIN,
             JoinType.LEFT_SEMI_JOIN,
             JoinType.RIGHT_SEMI_JOIN,
             JoinType.CROSS_JOIN
diff --git a/regression-test/data/query_p0/subquery/subquery_unnesting.out 
b/regression-test/data/query_p0/subquery/subquery_unnesting.out
index 535e10059ad..229c7a2069f 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 ea90e867f71..47873c04b0e 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));
+    """
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to