tlfua opened a new issue, #27829:
URL: https://github.com/apache/datafusion/issues/27829
### Describe the bug
An `EXISTS` subquery that unnests the result of a correlated `count(*)`
without `GROUP BY` drops the outer rows that have no match. The count of such a
row is `0`, so the unnest still gives rows and the `EXISTS` should be true.
### To Reproduce
```sql
CREATE TABLE t (a INT) AS VALUES (1), (2), (4);
CREATE TABLE i (a INT) AS VALUES (1), (2), (2), (3);
SELECT o.a FROM t o WHERE EXISTS (
SELECT unnest(make_array(c, c))
FROM (SELECT count(*) c FROM i WHERE a = o.a) e
) ORDER BY o.a;
```
DataFusion main (25da21b69703fad181f08f64568b90ebb963e0e0) returns:
```text
1
2
```
### Expected behavior
```text
1
2
4
```
DuckDB 2.0.1 returns `1, 2, 4` (with `list_value` in place of `make_array`).
### Additional context
It looks like `PullUpCorrelatedExpr` adds `i.a` to the `GROUP BY` of the
aggregate and pulls the filter up through the `Unnest`. After that the
aggregate gives no row for `a = 4`, where it gave one row with `0`. The
`EXISTS` path retries the pull up without count bug handling, so nothing
restores that row.
Found while reviewing https://github.com/apache/datafusion/pull/27783 . That
PR keeps this behavior unchanged for `Unnest`.
--
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]