morrySnow commented on code in PR #51928:
URL: https://github.com/apache/doris/pull/51928#discussion_r2158920315


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/SubqueryToApply.java:
##########
@@ -404,7 +404,13 @@ private Pair<LogicalPlan, Optional<Expression>> 
addApply(SubqueryExpr subquery,
         // we use needRuntimeAnyValue to indicate if any_value() is needed
         // if needRuntimeAnyValue is true, we will add it to the project list
         boolean needRuntimeAnyValue = false;
-        NamedExpression oldSubqueryOutput = 
subquery.getQueryPlan().getOutput().get(0);
+        // For the unCorrelate case:
+        // 1. `t1.a = (select t2.x from t2 limit 1)`, subquery output t2.x 
maybe null if subquery output 0 rows;
+        // 2. `t1.a = (select count(t2.x) from t2)`, subquery output 
count(t2.x) is always not nullable;
+        // When given a slot reference S, we don't know S is t2.x or 
count(t2.x),
+        // For safety reason, we treat S as nullable. even S is count(t2.x),
+        // we may have performance downgrade, but the execute result still be 
right.
+        NamedExpression oldSubqueryOutput = 
subquery.getQueryPlan().getOutput().get(0).withNullable(true);

Review Comment:
   could we use `subquery.getSubqueryOutput()` here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to