Repository navigation
Fix TOO_LARGE_STRING_SIZE when reading a valid part with a large Array(FixedString) span - #117385
Conversation
…sing it `SerializationFixedString::deserializeBinaryBulk` refused any bulk read whose `limit * n` exceeded `MAX_STRINGS_SIZE` (1 GiB). For a nested column `limit` is an element count, not a row count: `SerializationArray` derives it from the `.size0` offsets stream and bounds it only at `MAX_ARRAYS_SIZE` (1 << 40 elements). A granule that legitimately held 1024 x 81920 x 16 = 1342177280 bytes of `Array(FixedString(16))` was therefore rejected before a byte was read, so an `INSERT` could write a part that no later `SELECT` could read back. The same refusal reached `MergeTreeSequentialSource`, so `OPTIMIZE TABLE ... FINAL` could not rewrite the part either. `MAX_STRINGS_SIZE` was added in e3dafdb to bound the speculative `data.resize` performed before the data is known to exist. It is not an on-disk format bound and not a per-value `FixedString` bound, and `serializeBinaryBulk` has no matching cap, so the writer could always produce spans the reader rejected. Growing the column in steps of at most `MAX_STRINGS_SIZE` bytes, and allocating the next step only after the previous one has been filled from the stream, keeps that bound while removing the false rejection. A read of `MAX_STRINGS_SIZE` or less runs exactly one iteration, whose `resize`, `readBig` and checks are the previous calls in the previous order. Working in elements also removes the need for the `limit * n` multiplication-overflow branch. The bound still has to exist, which is why it is kept rather than raised: `SerializationLowCardinality` reads a dictionary size off the stream and passes it straight in as `limit`, and the `Native` format passes a declared row count. On a `Native` block declaring 999999999 rows of `FixedString(16)`, that is 14.9 GiB, backed by 32 bytes of payload, the previous code threw `TOO_LARGE_STRING_SIZE` and this code throws `CANNOT_READ_ALL_DATA` after allocating a single step, with a peak RSS 14 MB above the refusing build. `SerializationArray`'s `nested_column.size() == last_offset` check is what turns a short read into that error. `Array(String)` and `Array(UInt128)` read a byte-identical span without error, so the rejection was specific to `Array(FixedString)`. Closes: ClickHouse#116772 Related: ClickHouse#115698 Co-Authored-By: Claude Opus 5 <[email protected]>
… order
The previous test could not fail for either property it was supposed to cover.
Every element was `toFixedString('a', 1048576)`, so a step written at the wrong
offset lands inside identical bytes. Measured on a build that assembles the span
in the wrong order while preserving its total size and full coverage: the old
assertion returns 1, the new one returns 0 for all three positions. Giving every
element a distinct value and asserting both sides of the boundary at
1073741824 / 1048576 = 1024 elements (`arr[1024]` and `arr[1025]`) is what makes
the ordering observable.
Deleting the bound outright, rather than stepping within it, also passed. The
`Native` case added here declares 999999999 rows of `FixedString(16)`, which is
14.9 GiB, behind 32 bytes of payload, and reads it under `max_memory_usage` of
4G. Stepping allocates 2 GiB once and reports `CANNOT_READ_ALL_DATA`; a single
`resize` of the declared size is tracked before it is allocated
(`Allocator.cpp`), so the naive form reports `MEMORY_LIMIT_EXCEEDED` instead.
`TOO_LARGE_STRING_SIZE` on the unchanged reader distinguishes it from both. Only
the error name is asserted, and the declared row count stays below
`DEFAULT_NATIVE_BINARY_MAX_NUM_ROWS`, or `NativeReader` refuses it first and the
case asserts nothing.
The structure is passed to `format` explicitly because schema inference wraps the
error in `CANNOT_EXTRACT_TABLE_STRUCTURE`.
Both cases live in one `.sh` file, replacing the `.sql`, so the suite gains a
file rather than a directory of them.
Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 findings; bounded: 1 full pass + 1 fix round + 1 delta recheck).
Severity: ❌ blocker / Correcting my own commit message: the Session id: cron:clickhouse-review-slot-8:20260831-150800 |
|
Workflow [PR], commit [9e56041] Summary: ❌
AI ReviewSummaryThis PR changes Final Verdict✅ Approve. LLVM Coverage ReportMeasured on commit 9e56041.
Changed lines: Changed C/C++ lines covered: 15/18 (83.33%) · Uncovered code |
|
cc @Avogar @CurtizJ, could you review this? For a nested column the |
Build profile diff (arm_release)Comparing commit See the job log for details. |
CI finish ledger - 22b7cb3Every failure below has an owner: a fixing PR, or a full-effort fix task whose fixing-PR link will be
None of the rows above is caused by this pull request. On the Session id: |
…ray-fixedstring-large-read-span
…ray-fixedstring-large-read-span
5a80639
Closes: #116772
Related: #115698
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
TOO_LARGE_STRING_SIZE(Too large sizes of FixedString to deserialize) when reading a correctly written part whoseArray(FixedString(N))column holds more than 1 GiB of elements in one read span. Such a span is now read in bounded steps instead of being rejected, so the affected parts can be read and merged again without being rewritten. Closes #116772Description
An
INSERTwrites a valid part; a laterSELECTfails:Code: 131. Too large sizes of FixedString to deserialize: 1342177280.SerializationFixedString::deserializeBinaryBulkrefused any bulk read whoselimit * nexceeded a 1 GiB constant. For a nested columnlimitis an element count from theArrayoffsets stream, not a row count, so a granule of1024 * 81920 * 16bytes was rejected unread. The constant bounds aresizedone before the data is known to exist; it is not a format bound, andserializeBinaryBulkhas no cap.The span is now read in steps of at most that same bound, each allocated only after the previous was filled. A read of 1 GiB or less runs one iteration.
The bound must stay:
SerializationLowCardinalitypasses a stream-read dictionary size aslimit,Nativea declared row count. ANativeblock declaring 999999999FixedString(16)rows backed by 32 bytes now fails withCANNOT_READ_ALL_DATAafter one step, 14 MB peak RSS above the refusing build.The test fails on master; a part written by an unpatched binary now reads;
OPTIMIZE TABLE t FINALsucceeds; 50/50 randomized runs pass.On #115698's concern that looping
readBigstill assembles a block over 1 GiB: it does, because the data is that large and this layer cannot return fewer elements than asked; bounding it ismax_block_size's and the memory tracker's job.The write side is unchanged:
DelayedStreammerges consecutive marks into one request, and #115698 measured the fixture still failing atindex_granularity = 512, so it fixes neither this read nor existing parts.Workflow [PR]
Sync PR [sync-upstream/pr/117385]
Version info
26.10.1.24(included in26.10and later)