mohammadnaqvi04 commented on code in PR #25391:
URL: https://github.com/apache/datafusion/pull/25391#discussion_r4032117255
##########
datafusion/optimizer/src/decorrelate_predicate_subquery.rs:
##########
@@ -616,6 +659,118 @@ fn build_join(
Ok(Some(new_plan))
}
+/// Builds the join for a correlated `EXISTS` subquery whose groupless
+/// aggregate requires count-bug compensation.
Review Comment:
This decorrelates a groupless-aggregate subquery to a `LEFT JOIN`, grouped
by the correlated column, with the unmatched-row `NULL` replaced by the
aggregate's empty-input default (e.g. `count(*)` → `0`, `sum(x)` -> `NULL`).
For
```sql
SELECT t1.t1_int FROM t1 WHERE EXISTS (
SELECT count(*) FROM t2 WHERE t1.t1_int = t2.t2_int
);
```
this is equivalent to
```sql
SELECT t1.t1_int
FROM t1
LEFT JOIN (SELECT t2_int, count(*) AS cnt FROM t2 GROUP BY t2_int) AS sq
ON t1.t1_int = sq.t2_int;
```
--
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]