Repository navigation
Conversation
`SELECT length(y)` is answered from the `y.size` subcolumn, and that rewrite is
keyed on the metadata snapshot type. While an `ALTER TABLE ... MODIFY COLUMN y
String` is pending, the snapshot already says `String` so `y.size` is requested,
while the part on disk still holds `LowCardinality(String)`, a type that has no
`size` subcolumn.
`MergeTreeReaderCompact` refuses such a read and lets the existing
missing-subcolumn path derive the value from the converted parent.
`MergeTreeReaderWide` did not. `getSerializationInPart` fell back to the
requested type's default serialization, which is single stream, so
`SerializationStringSize` parsed the dictionary indexes stream as string lengths
into a `ColumnVector<UInt64>`. The substreams cache is shared per storage column,
so the subsequent full `y` read adopted that column, and the alter-conversion
`_CAST(y, 'LowCardinality(String)')` class-cast it in
`FunctionCast::prepareUnpackDictionaries`:
Logical error: 'Bad cast from type DB::ColumnVector<unsigned long>
to DB::ColumnLowCardinality'
`performRequiredConversions` is where it surfaces, not where it originates. The
query is rejected in every build; debug and sanitizer builds abort. Found by
`Stress test (arm_tsan)` on an unrelated pull request.
Move the presence check into `IMergeTreeReader::isSubcolumnMissingInPart` and use
it from both readers so they cannot diverge again. In the wide reader the decision
is made once in the constructor, before any stream name is resolved: for a
subcolumn absent from the part's type `getStreamNameForColumn` resolves an
existing stream of the parent, so a check made after resolution cannot distinguish
the two cases. Every per-column loop consults that one decision, including the
prefix loop and stream enumeration, so no loop opens or prefixes a stream that the
read loop skips.
The predicate resolves the part's column against the part's own columns list
rather than the Nested-collected view. With `share_nested_offsets`, asking the
synthesized `Nested(...)` group type about a member reports every member the part
lacks as a missing subcolumn, which would suppress a read that the offsets-sharing
path legitimately owns.
Read path only: on-disk data is unaffected and there is no format or setting
change, so existing parts read correctly and no migration is needed.
Internal second-model review (click to expand)An independent cold review plus a second-model pass ran against this diff before it was
Verified independently during the review rather than taken from the implementation notes: Session id: cron:clickhouse-review-slot-8:20260822-232500 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20260822-203800 |
|
Workflow [PR], commit [bfb7b8d] Summary: ❌
AI ReviewSummaryThis PR centralizes the missing-subcolumn check in Final Verdict
|
|
cc @rschu1ze @Avogar, could you review this? A wide-part reader was reading a subcolumn the part's own column type does not have ( Adjacent to #115670, which touches the same file at a different hunk. It is a distinct defect: the substreams cache key is unchanged here. |
Build profile diff (arm_release)Commit See the job log for details. |
… too The test reached the reader's subcolumn request through `length(y)`, which only becomes `y.size` via the FunctionToSubcolumns analyzer pass. That pass reads `optimize_functions_to_subcolumns` in src/Analyzer/Passes only, so with the old analyzer the rewrite never happens: the arming probe reported 0, the parent was read directly, and the reference no longer matched. The same two cells that the probe guards also flipped, which is what CI reported on the amd_llvm_coverage/old analyzer arm. Asking for `y.size` directly reaches the same request under both analyzers, so the pinned `optimize_functions_to_subcolumns = 1` is no longer needed either. Measured on the pre-fix master binary: the LOGICAL_ERROR reproduces with the old analyzer as well, so this widens coverage rather than skipping the arm.
|
Pushed 444cf70 to fix the The test reached the reader's subcolumn request through The test now asks for I checked that this widens coverage rather than skipping the arm, so no One residual, disclosed rather than fixed here: when the subcolumn's parent is a dotted |
|
@groeneai Sorry, I still have a backlog of fixes to check and will not find time to review this one soon. |
…ng-subcolumn-read Conflict in `MergeTreeReaderCompact::fillColumnPositions`: master added a metadata lookup of the requested regular subcolumn before the serialization-based `hasSubcolumn` check (e009889, performance), while this branch moved that check into `IMergeTreeReader::isSubcolumnMissingInPart` so the wide reader shares it. Kept the call to the shared helper and moved master's lookup into the helper, so the compact reader keeps the fast path and the wide reader gets it too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`05030` is now used by seven other tests on master. The note explained why the test requests `y.size` directly instead of `length(y)`; the old analyzer it referred to is removed, and the direct request stays because it does not depend on `optimize_functions_to_subcolumns`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With `share_nested_offsets` the wide reader remaps `n.y.size` to subcolumn `y.size` of the synthesized group `n`, which is not a column of the part, so the presence check found nothing and let the read through: with a pending `MODIFY COLUMN n.y Array(String)` over an `Array(LowCardinality(String))` member this hit the same logical error as the single-level case. The check now resolves such a request to the member the part stores and asks the member's type; a member the part lacks entirely is still left to the missing-column path, which owns offsets sharing (04770). The compact reader already reset the position for such subcolumns, but then handed the column to `findPositionForMissedNested`, which is meant for an array the part does not have at all, and read the present column's offsets with the requested type: `Code: 33 CANNOT_READ_ALL_DATA` for both a plain `Array(LowCardinality(String))` and a Nested member (26.3, 26.8, master), or wrong lengths in 26.3 when only the subcolumn is read. A present column whose type lacks the subcolumn is now derived from the converted parent, as for scalar types. Found by the second-model review; the dotted-member case was also raised by the AI reviewer on this PR. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
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):
Fix wrong results or an exception when reading a subcolumn that the column's type in a part does not have, which can happen while an
ALTER TABLE ... MODIFY COLUMNis not yet materialized. For example,SELECT length(y)over a part whereyis stillLowCardinality(String)while the table metadata already saysStringreturned wrong lengths in 26.3 and failed withExpected ColumnLowCardinality, got UInt64in 26.8, and the same insideArrayorNestedfailed as well.Description
Related: #115705, where it failed Stress test (arm_tsan); no related open issue found.
On 26.3.33.24, with a pending
MODIFY COLUMN y Stringover a wideLowCardinality(String)part holding'a'and'bb',SELECT length(y)returns0and5; on 26.8.10.6 it fails withCode: 44 ... Expected ColumnLowCardinality, got UInt64. Both return1and2once the mutation is materialized.length(y)reads they.sizesubcolumn because the metadata already saysString, while the part'sLowCardinality(String)has nosizesubcolumn.MergeTreeReaderWideread it anyway, parsing dictionary indexes as string lengths; whenywas read too, the substreams cache handed thatColumnVector<UInt64>to it.MergeTreeReaderCompactrefused scalar columns but passed an array one to the path meant for arrays the part lacks entirely, which then failed reading the present column's offsets.This moves the presence check into
IMergeTreeReaderand uses it in both readers. The wide reader decides it once in the constructor, before any stream name is resolved, and all five per-column loops consult it. A request thatshare_nested_offsetsremapped onto a synthesizedNestedgroup is checked against the member the part stores; a member the part lacks entirely still goes to offsets sharing. The compact reader no longer treats a present column as a missing array.Read-path only; no format or setting change.
The new test covers scalar,
ArrayandNestedcolumns in wide and compact parts; every case except the already handled compact scalar one fails before the fix. A control asserts via profile events that a subcolumn the part has is still read from its own stream.subcolumn,nested,lowcardinality,alter,tuple,array,quantizeand JSON tests were compared against a pre-fix build: every remaining failure fails identically on both.Workflow [PR]
Sync PR [sync-upstream/pr/115964]