Fix pathological scan memory for NULLs trailing an overflow string (#24897) by mdlavin · Pull Request #24918 · duckdb/duckdb · GitHub
Skip to content

Fix pathological scan memory for NULLs trailing an overflow string (#24897) - #24918

Merged
Mytherin merged 1 commit into
duckdb:v1.5-variegatafrom
mdlavin:v1.5-fix-string-oome
Aug 25, 2026
Merged

Mytherin merged 1 commit into
duckdb:v1.5-variegatafrom
mdlavin:v1.5-fix-string-oome

Conversation

@mdlavin

@mdlavin mdlavin commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

This is a a backport of #24898. The testcase needed to avoid the use of include_segment_info which does not exist in 1.5.x

Uncompressed VARCHAR overflow strings are stored with a negative dictionary offset, and a NULL copies the previous row's offset verbatim to make its delta-computed length 0. This copies the sign too, so a NULL following an overflow string inherits its negative offset and FetchStringFromDict routes it to ReadOverflowString, allocating a full pinned copy of the big string per trailing NULL (~STANDARD_VECTOR_SIZE copies per vector, tag OVERFLOW_STRINGS).

A NULL that copied a marker has a negative offset but a computed length of 0, whereas a real overflow string always has length BIG_STRING_MARKER_SIZE. Short- circuit the negative branch when the length is 0 and return an empty string. This is a scan-side fix at the single choke point, so it also repairs already- written databases with no storage-format change.

…uckdb#24897)

Uncompressed VARCHAR overflow strings are stored with a negative dictionary
offset, and a NULL copies the previous row's offset verbatim to make its
delta-computed length 0. This copies the sign too, so a NULL following an
overflow string inherits its negative offset and FetchStringFromDict routes it
to ReadOverflowString, allocating a full pinned copy of the big string per
trailing NULL (~STANDARD_VECTOR_SIZE copies per vector, tag OVERFLOW_STRINGS).

A NULL that copied a marker has a negative offset but a computed length of 0,
whereas a real overflow string always has length BIG_STRING_MARKER_SIZE. Short-
circuit the negative branch when the length is 0 and return an empty string.
This is a scan-side fix at the single choke point, so it also repairs already-
written databases with no storage-format change.
@Mytherin
Mytherin merged commit e577113 into duckdb:v1.5-variegata Aug 25, 2026
115 of 148 checks passed
@Mytherin

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants