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
[dbolympics] Support correlated scalar subquery without aggregation #16137
"Correlated scalar subquery must be aggregated to return at most one row"
)
}
}
}?;
DataFusion tries to predict maximum rows possible instead of actually checking the number of rows.
DuckDB used to fix this by limiting the number of rows to one, now they have changed the behaviour to pass error by using something like case when rows> 0 then error(err_msg) into the projection itself .
┌──────────────┬────────────┐
│ PROJECTION │
│ ──────────────────── │
│ CASE WHEN ((#1 > 1)) THEN│
│ (error('More than one row│
│ returned by a subquery │
│ used as an expression - │
│ scalar subqueries can │
│ only return a single row.│
│ Use "SET │
│ scalar_subquery_error_on_m│
│ ultiple_rows=false" to │
│ revert to previous │
│ behavior of returning a │
│ random row.')) ELSE #0 END│
│ │
│ ~1 Rows │
└─────────────┬─────────────┘
> WITH src AS (
SELECT*FROM (VALUES
(1, NULL, 'Europe'),
(2, 1, 'Warsaw'),
(3, 1, 'Paris')
) t(id, parent_id, name)
)
SELECT
id,
name,
(SELECTp.nameFROM src p WHEREp.id=s.parent_idlimit1) AS parent_name
FROM src s;
This feature is not implemented: Physical plan does not support logical expression ScalarSubquery(<subquery>)
which is weird to say the least. I do not understand why just adding a limit will make it different.
changed the title [-]Support correlated scalar subquery without aggregation[/-][+][dbolympics] Support correlated scalar subquery without aggregation[/+]on Oct 24, 2026
in my opinion WE SHOULD NOT try and extend the existing subquery rewrites to support this type of query as that risks introducing many more wrong results, see #5492 (comment)
Activity
logan-keede commentedon May 25, 2025
datafusion/datafusion/expr/src/logical_plan/invariants.rs
Lines 174 to 201 in 34f250a
DataFusion tries to predict maximum rows possible instead of actually checking the number of rows.
DuckDB used to fix this by limiting the number of rows to one, now they have changed the behaviour to pass error by using something like
case when rows> 0 then error(err_msg)into the projection itself .Reference PR
I tried using limit and got
which is weird to say the least. I do not understand why just adding a limit will make it different.
[-]Support correlated scalar subquery without aggregation[/-][+][dbolympics] Support correlated scalar subquery without aggregation[/+]alamb commentedon Oct 24, 2026
Affects DB Olympics, see: #26661
alamb commentedon Oct 28, 2026
I think we should implement support support for this feature as part of the more general subquery decorrelation project described here
in my opinion WE SHOULD NOT try and extend the existing subquery rewrites to support this type of query as that risks introducing many more wrong results, see #5492 (comment)