You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Wrong results: EXISTS over unnest of a correlated count(*) without GROUP BY drops outer rows with no match #27829
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
CREATETABLEt (a INT) ASVALUES (1), (2), (4);
CREATETABLEi (a INT) ASVALUES (1), (2), (2), (3);
SELECTo.aFROM t o WHERE EXISTS (
SELECT unnest(make_array(c, c))
FROM (SELECTcount(*) c FROM i WHERE a =o.a) e
) ORDER BYo.a;
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 #27783 . That PR keeps this behavior unchanged for Unnest.
Related: this is the same class of bug as #24960 and #27690 (an outer row with no match is treated as if a count(*) without GROUP BY gave no row). The plain EXISTS repro in #24960 returns the correct rows on main, but this shape with an Unnest between the aggregate and the EXISTS still drops them.
Activity
Faizaanp commentedon Nov 29, 2026
take