diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/SubqueryToApply.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/SubqueryToApply.java index d64c7f2baed6a4..cacd3d9cd6ce02 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/SubqueryToApply.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/SubqueryToApply.java @@ -381,7 +381,7 @@ private Pair> subqueryToApply( if (!ctx.subqueryIsAnalyzed(subqueryExpr)) { tmpPlan = addApply(subqueryExpr, tmpPlan.first, - subqueryToMarkJoinSlot, ctx, conjunct, + subqueryToMarkJoinSlot, ctx, tmpPlan.second, isProject, subqueryExprs.size() == 1, isMarkJoinSlotNotNull); } } diff --git a/regression-test/data/nereids_p0/subquery/subquery_unnesting.out b/regression-test/data/nereids_p0/subquery/subquery_unnesting.out index 5124b5f9700ed9..535e10059ad7ae 100644 --- a/regression-test/data/nereids_p0/subquery/subquery_unnesting.out +++ b/regression-test/data/nereids_p0/subquery/subquery_unnesting.out @@ -1519,3 +1519,19 @@ 20 2 22 3 24 4 + +-- !select64 -- +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +2 + diff --git a/regression-test/suites/nereids_p0/subquery/subquery_unnesting.groovy b/regression-test/suites/nereids_p0/subquery/subquery_unnesting.groovy index 397c5cfbf29bc7..8fa6524aefac68 100644 --- a/regression-test/suites/nereids_p0/subquery/subquery_unnesting.groovy +++ b/regression-test/suites/nereids_p0/subquery/subquery_unnesting.groovy @@ -133,4 +133,13 @@ suite ("subquery_unnesting") { 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;""" qt_select63 """SELECT * FROM t1 AS t1 WHERE EXISTS (SELECT k1 FROM t1 AS t2 WHERE t1.k1 <> t2.k1 + 7 GROUP BY k1 HAVING sum(k2) >= 1) order by t1.k1, t1.k2;""" + + qt_select64 """ + select case + when t1.k1=1 then (select count(*) from t2 where t1.k2=t2.k2) + when t1.k1=2 then (select count(*) from t3 where t1.k2=t3.k2) + else 0 end as kk + from t1 + order by kk + """ }