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

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


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new 4cb192dc61a [fix](nereids)collect all correlated slots from subquery 
in correct way (#31340)
4cb192dc61a is described below

commit 4cb192dc61a3668f9ff8df7f316751f190ebda7b
Author: starocean999 <40539150+starocean...@users.noreply.github.com>
AuthorDate: Mon Feb 26 09:47:47 2024 +0800

    [fix](nereids)collect all correlated slots from subquery in correct way 
(#31340)
---
 .../java/org/apache/doris/nereids/util/Utils.java     | 19 ++-----------------
 .../data/nereids_p0/subquery/test_subquery.out        | 12 ++++++++++++
 .../suites/nereids_p0/subquery/test_subquery.groovy   | 13 +++++++++++++
 3 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java
index 6ac9ffd9513..d259e348042 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/Utils.java
@@ -17,10 +17,8 @@
 
 package org.apache.doris.nereids.util;
 
-import org.apache.doris.nereids.exceptions.AnalysisException;
 import org.apache.doris.nereids.trees.expressions.Cast;
 import org.apache.doris.nereids.trees.expressions.Expression;
-import org.apache.doris.nereids.trees.expressions.Not;
 import org.apache.doris.nereids.trees.expressions.SlotReference;
 import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
 
@@ -159,21 +157,8 @@ public class Utils {
      */
     public static List<Expression> getCorrelatedSlots(List<Expression> 
correlatedPredicates,
             List<Expression> correlatedSlots) {
-        List<Expression> slots = new ArrayList<>();
-        correlatedPredicates.forEach(predicate -> {
-            if (!(predicate instanceof BinaryExpression) && !(predicate 
instanceof Not)) {
-                throw new AnalysisException("UnSupported expr type: " + 
correlatedPredicates);
-            }
-
-            BinaryExpression binaryExpression;
-            if (predicate instanceof Not) {
-                binaryExpression = (BinaryExpression) ((Not) 
predicate).child();
-            } else {
-                binaryExpression = (BinaryExpression) predicate;
-            }
-            slots.addAll(collectCorrelatedSlotsFromChildren(binaryExpression, 
correlatedSlots));
-        });
-        return slots;
+        return ExpressionUtils.getInputSlotSet(correlatedPredicates).stream()
+                .filter(slot -> 
!correlatedSlots.contains(slot)).collect(Collectors.toList());
     }
 
     private static List<Expression> collectCorrelatedSlotsFromChildren(
diff --git a/regression-test/data/nereids_p0/subquery/test_subquery.out 
b/regression-test/data/nereids_p0/subquery/test_subquery.out
index 7e44c264f5b..ca61be79456 100644
--- a/regression-test/data/nereids_p0/subquery/test_subquery.out
+++ b/regression-test/data/nereids_p0/subquery/test_subquery.out
@@ -30,6 +30,18 @@ true 15      1992    3021    11011920        0.000   true    
9999-12-12      2015-04-02T00:00                3.141592653     2
 1      9
 2      \N
 
+-- !select60 --
+\N     1
+\N     2
+1      2
+1      3
+2      4
+3      3
+3      4
+20     2
+22     3
+24     4
+
 -- !select61 --
 
 -- !select62 --
diff --git a/regression-test/suites/nereids_p0/subquery/test_subquery.groovy 
b/regression-test/suites/nereids_p0/subquery/test_subquery.groovy
index 1c8078ebc6f..21dd257a274 100644
--- a/regression-test/suites/nereids_p0/subquery/test_subquery.groovy
+++ b/regression-test/suites/nereids_p0/subquery/test_subquery.groovy
@@ -244,6 +244,7 @@ suite("test_subquery") {
     sql """drop table if exists table_9_undef_undef"""
 
     sql "drop table if exists t1"
+    sql "drop table if exists t2"
     sql """create table t1
                     (k1 bigint, k2 bigint)
                     ENGINE=OLAP
@@ -253,8 +254,20 @@ suite("test_subquery") {
             PROPERTIES (
             "replication_num" = "1"
             );"""
+    sql """create table t2
+                    (k1 int, k2 varchar(128), k3 bigint, v1 bigint, v2 bigint)
+                    ENGINE=OLAP
+            DUPLICATE KEY(k1, k2)
+            COMMENT 'OLAP'
+            DISTRIBUTED BY HASH(k2) BUCKETS 1
+            PROPERTIES (
+            "replication_num" = "1"
+            );"""
     sql """insert into t1 values (1,null),(null,1),(1,2), (null,2),(1,3), 
(2,4), (2,5), (3,3), (3,4), (20,2), (22,3), (24,4),(null,null);"""
+    sql """insert into t2 values (1,'abc',2,3,4), (1,'abcd',3,3,4), 
(2,'xyz',2,4,2), (2,'uvw',3,4,2), (2,'uvw',3,4,2), (3,'abc',4,5,3), 
(3,'abc',4,5,3), (null,null,null,null,null);"""
+        qt_select60 """select * from t1 where exists(select distinct k1 from 
t2 where t1.k1 > t2.k3 or t1.k2 < t2.v1) order by t1.k1, t1.k2;"""
     qt_select61 """SELECT * FROM t1 AS t1 WHERE EXISTS (SELECT k1 FROM t1 AS 
t2 WHERE t1.k1 <> t2.k1 + 7 GROUP BY k1 HAVING k1 >= 100);"""
     qt_select62 """select * from t1 left semi join ( select * from t1 where 
t1.k1 < -1 ) l on true;"""
     sql "drop table if exists t1"
+    sql "drop table if exists t2"
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to