list_reduce can use column values from another row
Author: SvetufCreated Sep 16, 2026Updated Sep 17, 2026
Labelsreproduced
What happens?
Using list_reduce with a constant initial value and a column reference inside the lambda can return the wrong result when the lists have different lengths. The lambda can read the column value from another row. With a filtered input, it can also fail with an INTERNAL Error.
To Reproduce
SELECT v, list_reduce(l, lambda acc, x: acc + x + v, 0) AS result
FROM (VALUES ([1], 10), ([1, 2], 30)) t(l, v);Actual result:
v result
10 11
30 43The second result should be 63: (0 + 1 + 30) + 2 + 30. Instead, the last step uses 10 from the first row.
Adding a filter can also produce an INTERNAL Error:
SELECT v, list_reduce(l, lambda acc, x: acc + x + v, 0) AS result
FROM (VALUES ([], 0), ([1], 10), ([1, 2], 30)) t(l, v)
WHERE v > 0;INTERNAL Error: DataChunk::SetChildCardinality - vector has size 2 but expected size 1 - and cannot change vector size because it is not a flat or constant vectorOS:
Ubuntu 22.04.5 LTS, x86_64
DuckDB Version:
v2.1.0-dev84749 (2bbfe6f236)
DuckDB Client:
CLI
Hardware:
No response
Full Name:
Ilya Mishurov
Affiliation:
Postgres Professional
Did you include all relevant configuration (e.g., CPU architecture, Linux distribution) to reproduce the issue?
- Yes, I have
Did you include all code required to reproduce the issue?
- Yes, I have
Did you include all relevant data sets for reproducing the issue?
Yes
Source: duckdb/duckdb