mohammadnaqvi04 commented on code in PR #25391:
URL: https://github.com/apache/datafusion/pull/25391#discussion_r4032166345


##########
datafusion/optimizer/src/decorrelate.rs:
##########
@@ -383,6 +454,7 @@ impl TreeNodeRewriter for PullUpCorrelatedExpr {
                     // Correlated exist subquery, remove the limit(so that 
correlated expressions can pull up)
                     (true, false) => Transformed::yes(match 
limit.get_fetch_type()? {
                         FetchType::Literal(Some(0)) => {
+                            self.forces_empty_result = true;

Review Comment:
   `LIMIT 0` on the subquery collapses it to an `EmptyRelation` before the 
count-bug join ever sees it, so without this flag, join-compensation has no way 
of knowing that the subquery is unconditionally empty and defaults every row to 
matched. For
   
   ```sql
   SELECT t1.t1_int FROM t1 WHERE EXISTS (
       SELECT count(*) FROM t2 WHERE t1.t1_int = t2.t2_int LIMIT 0
   );
   ```
   
   `t1_int` should never appear in the result, since `LIMIT 0` empties the 
subquery regardless of whether `t2` has a matching row. Setting 
`forces_empty_result` is what makes `build_join_with_count_bug` return `false` 
unconditionally instead of falling back to its usual "matched" default.



-- 
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