Skip to content

Fix TOO_LARGE_STRING_SIZE when reading a valid part with a large Array(FixedString) span - #117385

Merged
Avogar merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-array-fixedstring-large-read-span
Sep 17, 2026
Merged

Avogar merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-array-fixedstring-large-read-span

Conversation

@groeneai

@groeneai groeneai commented Aug 31, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #116772
Related: #115698

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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 whose Array(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 #116772

Description

An INSERT writes a valid part; a later SELECT fails: Code: 131. Too large sizes of FixedString to deserialize: 1342177280.

SerializationFixedString::deserializeBinaryBulk refused any bulk read whose limit * n exceeded a 1 GiB constant. For a nested column limit is an element count from the Array offsets stream, not a row count, so a granule of 1024 * 81920 * 16 bytes was rejected unread. The constant bounds a resize done before the data is known to exist; it is not a format bound, and serializeBinaryBulk has 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: SerializationLowCardinality passes a stream-read dictionary size as limit, Native a declared row count. A Native block declaring 999999999 FixedString(16) rows backed by 32 bytes now fails with CANNOT_READ_ALL_DATA after one step, 14 MB peak RSS above the refusing build.

SET allow_suspicious_fixed_string_types = 1, max_memory_usage = '8G';
CREATE TABLE t (k UInt64, arr Array(FixedString(1048576))) ENGINE = MergeTree ORDER BY k;
INSERT INTO t SELECT 1, arrayMap(x -> toFixedString(toString(x), 1048576), range(1025));
SELECT arr[1024] = toFixedString('1023', 1048576),
       arr[1025] = toFixedString('1024', 1048576) FROM t;

The test fails on master; a part written by an unpatched binary now reads; OPTIMIZE TABLE t FINAL succeeds; 50/50 randomized runs pass.

On #115698's concern that looping readBig still 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 is max_block_size's and the memory tracker's job.

The write side is unchanged: DelayedStream merges consecutive marks into one request, and #115698 measured the fixture still failing at index_granularity = 512, so it fixes neither this read nor existing parts.


Workflow [PR]
Sync PR [sync-upstream/pr/117385]

Version info

  • Merged into: 26.10.1.24 (included in 26.10 and later)

groeneai and others added 2 commits August 31, 2026 13:40
…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]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Aug 31, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
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).

# Sev Finding Verdict Evidence / action
1 ⚠️ The changelog promises the span is read in bounded steps, but nothing tested that or the preserved allocation bound: every element held the same bytes, and a build with the bound simply deleted passed the test AGREE, fixed @ 22b7cb3 Distinct per-element values, and both sides of the 1024-element step boundary asserted. A build that assembles the span in the wrong order while preserving its size passes the old assertion and fails the new one. A second case reads a Native block declaring 999999999 FixedString(16) rows behind 32 bytes of payload under max_memory_usage of 4G, where stepping gives CANNOT_READ_ALL_DATA and the deleted-bound build gives MEMORY_LIMIT_EXCEEDED
2 ⚠️ The test is too heavy to be stable at flaky-check concurrency and should pin max_threads and memory settings DISAGREE allow_oversubscription returns False for flaky and targeted checks by design (ci/jobs/functional_tests.py:262-280), and long_test_runs_ratio defaults to 0.1, so a long test gets 5 copies there, not 50. The 0.7 server ratio is sanitizer-only and every sanitizer build is tagged out. The fixture is one row, so it is one granule and the settings named cannot affect it. 50 randomized runs, 50 OK

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding. The delta recheck of the second commit returned no findings.

Correcting my own commit message: the CANNOT_READ_ALL_DATA for that Native block comes from NativeReader's declared-row-count check, not from SerializationArray's offsets-versus-elements check as the first commit message states. The SerializationArray check is the one that applies on the Array read path.

Session id: cron:clickhouse-review-slot-8:20260831-150800

@clickhouse-gh clickhouse-gh Bot closed this Aug 31, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Aug 31, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9e56041]

Summary: ❌

job_name test_name status info comment
Build profile diff ERROR

AI Review

Summary

This PR changes SerializationFixedString::deserializeBinaryBulk to read large FixedString spans in bounded chunks instead of rejecting any request above 1 GiB, and adds a stateless test that covers both the cross-chunk ordering boundary and the large-declared-size Native failure mode. I did not find a correctness, compatibility, or coverage issue in the current diff after checking the affected callers and the prior review discussion.

Final Verdict

✅ Approve.

LLVM Coverage Report

Measured on commit 9e56041.

Metric Baseline Current Δ
Lines 88.40% 88.40% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 80.60% 80.60% +0.00%

Changed lines: Changed C/C++ lines covered: 15/18 (83.33%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 31, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @Avogar @CurtizJ, could you review this? For a nested column the limit that SerializationFixedString::deserializeBinaryBulk checks against its 1 GiB bound is an element count taken from the Array offsets stream, not a row count, so a correctly written Array(FixedString(N)) granule holding more than 1 GiB was rejected unread. I read the span in steps of at most that same bound instead, allocating each step only after the previous one has been filled, so the bound that SerializationLowCardinality and the Native format rely on is preserved.

@clickhouse-gh

clickhouse-gh Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing commit 9e56041615505c1703bee0bc1c1e07f181d3054b with master failed: RuntimeError: CI logs cluster query failed: SELECT count() AS c FROM binary_sizes W….

See the job log for details.

@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 22b7cb3

Every failure below has an owner: a fixing PR, or a full-effort fix task whose fixing-PR link will be
posted here when it opens.

Check / test Reason Owner / fixing PR
Bugfix validation (functional tests, amd64) ERRORs at ci/jobs/functional_tests.py:734 with AssertionError: Could not find master builds in S3 before any server starts, so the job measured no test. Trunk-wide, onset 19:00Z on 08-31 with zero errors in the six preceding hours, and still firing at 01:00Z #117433 (ours, open)
Bugfix validation (functional tests, aarch64) same Could not find master builds in S3 abort as the row above #117433 (ours, open)
Finish Workflow / Post Hooks cascade of the Bugfix validation rows: new_tests_check.py reds when no per-arch job reports OK or XFAIL, and its own log quotes that same functional_tests.py:734 traceback #117433 (ours, open)
Stateless tests (amd_llvm_coverage, old analyzer, s3 storage, DBReplicated, parallel, 1/3) / 03707_autopr_unsupported_cases trunk-wide rather than specific to this branch: 118 rows over 115 trees, 104 pull requests and 12 true-master commits in 24h. The test collects parallel-replicas statistics off the query plan, which only the analyzer builds #117364 (external, merged 2026-08-31 22:05Z), absent from this tree
Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6) / Container memory budget exceeded (/docker) job-level container-memory abort with no failing test assertion; 323 rows over 314 trees, 256 pull requests and 25 true-master commits in 24h a fix task holds it at P1, blocked on the integration-test capacity decision I put to the maintainers at #115963 (comment)
Stress test (amd_debug) / Unexpected return type from globalIn. Expected Nullable(UInt8). Got UInt8 (STID 3262-3243) pre-existing trunk defect on the GLOBAL IN shard-rewrite path, not reachable from this diff. The abort runs StorageDistributed.cpp:1024 -> InterpreterSelectQueryAnalyzer::getSampleBlock -> Planner.cpp:605 -> ExpressionStep.cpp:70 -> ActionsDAG.cpp:1545 -> :1711 -> :1420; 12 rows over 12 pull requests and 0 on master in 30d. It fired in one of the two concurrent PR runs on this head #116980 (external, open)

None of the rows above is caused by this pull request.

On the Stress test (amd_debug) row: #116980 rewrites the repeated-GLOBAL IN temporary-table handling in src/Storages/buildQueryTreeForShard.cpp, which is what builds the mistyped globalIn node whose declared type is then rejected while deriving the ExpressionStep header, and its own regression test asserts this exact message. On the 03707 row: #117364 merged at 22:05:00Z and this head predates it.

Session id: cron:our-pr-ci-monitor:20260901-013000

@clickhouse-gh clickhouse-gh Bot added the comp-data-types Type system & core datatypes used across query planning/execution. label Sep 4, 2026
@Avogar Avogar self-assigned this Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-data-types Type system & core datatypes used across query planning/execution. groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Correctly written part is no longer readable

3 participants