Repository navigation
Fix mutations failing with CANNOT_READ_ALL_DATA when they read a column and its LowCardinality subcolumn - #123160
Conversation
…subcolumn `SerializationLowCardinality::deserializeBinaryBulkStatePrefix` asks the Wide reader's `has_uniform_marks_callback` whether the part may have a single dictionary. The callback looked the stream up with `streams.find()` and answered `false` when the reader had not opened it yet. Map bucket and Dynamic variant streams are opened lazily by the prefix getter, which runs after the callback, so the answer depended on which column sharing the stream was deserialized first: `m.keys` was treated as multi-dictionary, `m` as single dictionary, and `m`'s prefix read the shared dictionary stream to EOF. Mutations read without seeking to marks, so the data read of `m.keys` then called `read_dictionary()` on the EOF stream and failed with `CANNOT_READ_ALL_DATA` on every attempt. Open the stream in the callback, as the neighbouring callbacks already do. Regression from ClickHouse#103662 (first released in 26.6). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (1 nit).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261001-000014 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20260930-225800 |
|
Workflow [PR], commit [75dcc35] Summary: ✅
AI ReviewSummaryThis PR fixes Missing context / blind spots
Final Verdict
LLVM Coverage ReportMeasured on commit 75dcc35.
Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline. |
| return false; | ||
|
|
||
| /// Bucket and dynamic streams are opened lazily; the verdict must not depend on which column opened them first. | ||
| auto * stream = getOrAddStream(substream_path, *stream_name); |
There was a problem hiding this comment.
@groeneai are you sure it won't ever return a null pointer? Maybe you should add that defensive check
There was a problem hiding this comment.
Yes, it cannot return null. FileStreams::getOrCreate returns either the existing map entry or the one it has just inserted, it is the only place that inserts into the map, and the factory in getOrAddStream always returns a std::make_unique<...> result (it throws on failure, never returns null). A part without a file for this substream is handled just above by if (!stream_name) return false;, before getOrAddStream is reached. The other two callers in deserializePrefix (getStream at L424 and seek_to_start_callback at L473) already dereference its result unchecked.
I'd rather not bring back return false here: false for a stream whose file exists is exactly the order-dependent verdict this PR removes. If you still want an explicit guard, I can add chassert(stream).
There was a problem hiding this comment.
We prefer references over pointers. So if a pointer can't be non-null, it should be a reference.
Wait for this PR to be merged, then send a follow-up.
There was a problem hiding this comment.
Acknowledged. After this PR is merged I will send a follow-up that makes getOrAddStream return a reference instead of a never-null pointer, and link it here.
`FileStreams::getOrCreate` returns either the existing map entry or the one it just inserted, and the only factory (`getOrAddStream`'s lambda) always returns `std::make_unique` (throws on failure, never null); `release` moves the entry out and erases it under the same lock, so the map never holds a null stream. Every caller either dereferenced the pointer unchecked or discarded it, so return `MergeTreeReaderStream &` from both functions instead. `FileStreams::find` stays a pointer because it returns null for a missing stream, and `getAll` stays a vector of pointers. Follow-up to ClickHouse#123160, requested in ClickHouse#123160 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed mutations such as
ALTER TABLE ... UPDATEfailing withCANNOT_READ_ALL_DATAon every attempt, and never completing, when they read a column together with itsLowCardinalitysubcolumn in a Wide part: aDynamiccolumn and itsLowCardinality(String)subcolumn, or aMapwithmap_serialization_version = 'with_buckets'and itskeysorvaluessubcolumn. The problem appeared in 26.6.Description
On 26.9, an
ALTER TABLE ... UPDATEthat reads aDynamiccolumn together with itsLowCardinality(String)subcolumn (or a bucketedMaptogether withm.keys/m.values) fails withCANNOT_READ_ALL_DATAon every attempt and never completes:Measured on the official 26.6, 26.7, 26.8 and 26.9 images; 26.3 and 26.5 complete the mutation. It came with the single-dictionary optimization of #103662.
SerializationLowCardinalityasks the Wide reader'shas_uniform_marks_callbackwhether the part has a single dictionary. The callback answeredfalsefor a stream the reader had not opened yet, and Map bucket and Dynamic variant streams are opened lazily. So the subcolumn was treated as multi-dictionary while the full column, deserialized next, read the shared dictionary stream to EOF. Mutations read without seeking to marks, so the subcolumn's first dictionary read then hit EOF.The callback now opens the stream, like the neighbouring callbacks, so both columns get the same answer.
The new test fails on master (4 errors) and passes with the change (50 randomized runs).
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123160]
Version info
26.10.1.1474-master(included in26.10and later)