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 4fc008e89e2 [fix](nereids)show user friendly error message when meet 
unsupported subquery (#49319)
4fc008e89e2 is described below

commit 4fc008e89e276278fba73206e0f35a3add27241e
Author: starocean999 <[email protected]>
AuthorDate: Mon Apr 14 18:13:05 2025 +0800

    [fix](nereids)show user friendly error message when meet unsupported 
subquery (#49319)
    
    ```
    SELECT *
        FROM t1
        WHERE t1.k1 IN
            (SELECT t2.k2
                FROM t2 JOIN t3
                    ON t2.k2 = t3.k1
                        AND t1.k2 = t3.k3); -- access t1.k2 in join conjuncts 
is not suppported
    
    SELECT *
        FROM t1
        WHERE t1.c1 =
            (SELECT c2
                FROM t2
                   WHERE t1.c1 in (SELECT c1 FROM t3)-- access t1.c1 as compare 
expr of in-subquery is not supported
            );
    ```
---
 .../nereids/rules/analysis/ExpressionAnalyzer.java | 16 +++++++++++++
 .../subquery/correlated_scalar_subquery.groovy     |  9 +++++++-
 .../nereids_syntax_p0/sub_query_correlated.groovy  | 26 ++++++++++++++++++++++
 3 files changed, 50 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java
index 41dc4ac1476..485ba677ff4 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ExpressionAnalyzer.java
@@ -81,6 +81,7 @@ import 
org.apache.doris.nereids.trees.expressions.literal.StringLiteral;
 import 
org.apache.doris.nereids.trees.expressions.typecoercion.ImplicitCastInputTypes;
 import org.apache.doris.nereids.trees.plans.PlaceholderId;
 import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
 import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
 import org.apache.doris.nereids.types.ArrayType;
 import org.apache.doris.nereids.types.BigIntType;
@@ -299,6 +300,11 @@ public class ExpressionAnalyzer extends 
SubExprAnalyzer<ExpressionRewriteContext
                 Expression firstBound = bounded.get(0);
                 if (!foundInThisScope && firstBound instanceof Slot
                         && 
!outerScope.get().getCorrelatedSlots().contains(firstBound)) {
+                    if (currentPlan instanceof LogicalJoin) {
+                        throw new AnalysisException(
+                                "Unsupported correlated subquery with 
correlated slot in join conjuncts "
+                                        + currentPlan);
+                    }
                     outerScope.get().getCorrelatedSlots().add((Slot) 
firstBound);
                 }
                 return firstBound;
@@ -703,6 +709,16 @@ public class ExpressionAnalyzer extends 
SubExprAnalyzer<ExpressionRewriteContext
         } else {
             newCompareExpr = afterTypeCoercion.left();
         }
+        if (getScope().getOuterScope().isPresent()) {
+            Scope outerScope = getScope().getOuterScope().get();
+            for (Slot slot : newCompareExpr.getInputSlots()) {
+                if (outerScope.getCorrelatedSlots().contains(slot)) {
+                    throw new AnalysisException(
+                            String.format("access outer query column %s in 
expression %s is not supported",
+                                    slot, inSubquery));
+                }
+            }
+        }
         return new InSubquery(newCompareExpr, (ListQuery) 
afterTypeCoercion.right(),
                 inSubquery.getCorrelateSlots(), ((ListQuery) 
afterTypeCoercion.right()).getTypeCoercionExpr(),
                 inSubquery.isNot());
diff --git 
a/regression-test/suites/nereids_p0/subquery/correlated_scalar_subquery.groovy 
b/regression-test/suites/nereids_p0/subquery/correlated_scalar_subquery.groovy
index 80d9cdb4bb2..fb01fe62e1a 100644
--- 
a/regression-test/suites/nereids_p0/subquery/correlated_scalar_subquery.groovy
+++ 
b/regression-test/suites/nereids_p0/subquery/correlated_scalar_subquery.groovy
@@ -176,7 +176,7 @@ suite("correlated_scalar_subquery") {
         sql """
               select c1 from correlated_scalar_t1 where 
correlated_scalar_t1.c2 > (select correlated_scalar_t2.c1 from 
correlated_scalar_t2 join correlated_scalar_t3 on correlated_scalar_t1.c1 = 
correlated_scalar_t3.c2 );
         """
-        exception "access outer query's column in join is not supported"
+        exception "Unsupported correlated subquery with correlated slot in 
join conjuncts"
     }
 
     test {
@@ -220,4 +220,11 @@ suite("correlated_scalar_subquery") {
         """
         exception "access outer query's column before two agg nodes is not 
supported"
     }
+
+    test {
+        sql """
+              select * from correlated_scalar_t1 where correlated_scalar_t1.c1 
= (select c2 from correlated_scalar_t2 where correlated_scalar_t1.c1 in (select 
c1 from correlated_scalar_t3));
+        """
+        exception "access outer query column"
+    }
 }
\ No newline at end of file
diff --git 
a/regression-test/suites/nereids_syntax_p0/sub_query_correlated.groovy 
b/regression-test/suites/nereids_syntax_p0/sub_query_correlated.groovy
index 09ba6c31bec..80409c6b564 100644
--- a/regression-test/suites/nereids_syntax_p0/sub_query_correlated.groovy
+++ b/regression-test/suites/nereids_syntax_p0/sub_query_correlated.groovy
@@ -648,6 +648,32 @@ suite ("sub_query_correlated") {
         exception "Unsupported correlated subquery with grouping and/or 
aggregation";
     }
 
+    test {
+        sql """
+                SELECT *
+                    FROM sub_query_correlated_subquery1
+                    WHERE sub_query_correlated_subquery1.k1 IN 
+                        (SELECT sub_query_correlated_subquery2.k2
+                        FROM sub_query_correlated_subquery2
+                        JOIN sub_query_correlated_subquery3
+                            ON sub_query_correlated_subquery2.k2 = 
sub_query_correlated_subquery3.k1
+                                AND sub_query_correlated_subquery1.k2 = 
sub_query_correlated_subquery3.k3); """
+        exception "Unsupported correlated subquery with correlated slot in 
join conjuncts";
+    }
+
+    test {
+        sql """
+                SELECT *
+                    FROM sub_query_correlated_subquery1
+                    WHERE EXISTS 
+                        (SELECT sub_query_correlated_subquery2.k2
+                        FROM sub_query_correlated_subquery2
+                        JOIN sub_query_correlated_subquery3
+                            ON sub_query_correlated_subquery2.k2 = 
sub_query_correlated_subquery3.k1
+                                AND sub_query_correlated_subquery1.k2 = 
sub_query_correlated_subquery3.k3); """
+        exception "Unsupported correlated subquery with correlated slot in 
join conjuncts";
+    }
+
     qt_doris_7643 """
         SELECT sub_query_correlated_subquery6.*
         FROM sub_query_correlated_subquery6


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

Reply via email to