Repository navigation
Description
Summary
A SELECT that subscripts an array-typed column multiple times crashes the server
with an internal assertion when all of the following hold:
- the array column is produced by a
CASE(orif) expression, - at least one
CASEbranch is a user-defined function returning an array, - the column is subscripted two or more times in the projection, and
- the query has an
ORDER BY.
Removing any one of these (no CASE, no ORDER BY, a single subscript, or only
literal-array branches) makes the same query run correctly. The process aborts hard
(the client connection is dropped), so it also takes down any other in-flight queries.
Environment
PostgreSQL 16.3 compatible CedarDB v2026-06-23, compiled on 2026-06-23, arm64 build- Official Docker image
cedardb/cedardb:latest
Minimal, self-contained reproduction
CREATE OR REPLACE FUNCTION arr3(x double precision) RETURNS double precision[]
LANGUAGE sql AS 'ARRAY[x, x + 1.0, x + 2.0]';
WITH s AS (
SELECT g AS idx,
CASE WHEN g > 2 THEN arr3(g::double precision)
ELSE ARRAY[0.1, 0.2, 0.3]::double precision[] END AS col
FROM generate_series(0, 5) g
)
SELECT idx, col[1], col[2]
FROM s
ORDER BY idx;Expected
Six rows, e.g.
0 | 0.1 | 0.2
1 | 0.1 | 0.2
2 | 0.1 | 0.2
3 | 3 | 4
4 | 4 | 5
5 | 5 | 6
Actual
ERROR: Assertion `data.size() >= getSize()` failed. /cedardb/runtime/types/ArrayRuntime.cpp:937: cedar::ArrayHeader::ArrayHeader(std::span<const std::byte>)
HINT: Internal database error. Please report it with reproduction steps at https://github.com/cedardb/issues
(The server process aborts; the connection is lost.)
What does and does not trigger it
Starting from the repro above, each of these variants runs correctly — so all four
ingredients are required together:
| Variant | Result |
|---|---|
repro as written (CASE + ORDER BY + 2 subscripts + function-array branch) |
crash |
drop the ORDER BY |
ok |
replace the CASE with the arr3(...) call directly (no CASE) |
ok |
subscript the column only once (SELECT idx, col[1]) |
ok |
make both CASE branches literal arrays (no function call) |
ok |
It looks like the array header produced through the CASE branch is mis-sized when the
value is materialized for the sort and then subscripted more than once.
Context
Found while porting a ClickHouse SQL ray tracer to CedarDB (CedarDB compiles and runs the
full multi-WITH RECURSIVE ray-march scene nicely, ~12x faster than the original here —
thank you!). The crash was the one rough edge; worked around by replacing the array CASE
with an arithmetic blend. Repro distilled out of that work.
Activity
benchmark: report CedarDB array bug upstream; correct the LATERAL mis…
ChrisWint commentedon Jun 29, 2026
Thanks for the issue and excellent reproducer, it indeed required all of the components you mentioned and could only trigger when a non-trivial
caseexpression combined a SQL-constant array and non-constant array (or long string, through table scan or function call) materialized below the case expression, which was triggered by using it more than once after the sort. Fix is live internally and will be included in the next release.While I have you here, would be great if someone on your end could get around to ClickHouse/ClickBench#897, that has been sitting dormant for 6 weeks now 😉