Repository navigation
Cherry pick #107562 to 25.8: Fix missing variant_discr stream for Dynamic columns after mutation - #112063
Merged
robot-ch-test-poll2 merged 14 commits intoJul 27, 2026
Conversation
… mutation `getStreamCounts` in `MutateTask` enumerated each column's streams with a default `enumerateStreams` call (without a column or deserialization state). For columns with a dynamic structure (`Dynamic`, `JSON`, ...), `SerializationDynamic::enumerateStreams` stops after the `dynamic_structure` substream in that case and never reports the data-dependent substreams such as `variant_discr`. As a result the mutation file bookkeeping (`collectFilesToSkip` / `collectFilesForRenames`) was blind to those substreams, which could leave a `variant_discr` stream neither rewritten nor hardlinked into the new part — producing a part that later fails to read or merge with `Logical error: Stream <col>.variant_discr ... is not found` in `MergeTreeReaderWide`. Use the substreams recorded in `columns_substreams.txt` (the ground truth of what exists in the part) for dynamic-structure columns, mirroring the approach already used by `MergeTreeDataPartWide::checkConsistency`, and fall back to enumeration for old parts and not-yet-written columns. The change is gated on `hasDynamicSubcolumns`, so regular and `Nested` columns are unaffected. Note: the original failure was found by CI fuzzers and could not be reproduced in isolation, so this is a candidate fix that needs verification by the fuzzers and review by the serialization subsystem owners. Related: #107561 Co-Authored-By: Claude Opus 4.8 <[email protected]>
…p_signed_types from master Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…during mutation Address review on #107562: `getStreamCounts` resolved every recorded substream of a dynamic-structure column against the source part's checksums, including the placeholder substream that `getColumnsForNewDataPart` records for a column that the mutation will write but that is not yet present in the source part. If the table also contains an unrelated column literally named `dummy`, the placeholder resolved to that column's real `dummy.bin` stream, so the unchanged stream was marked as skipped and was neither rewritten nor hardlinked into the new part, producing a part whose checksums reference a missing `dummy.bin`/`dummy.cmrk2`. Introduce a named `NOT_YET_WRITTEN_COLUMN_SUBSTREAM_PLACEHOLDER` sentinel for the placeholder and skip it explicitly in `getStreamCounts`, falling back to stream enumeration as before. Add regression test `04342_dynamic_mutation_dummy_placeholder_stream` that materializes a newly added `Dynamic` column next to an existing column named `dummy` and validates the resulting part with `CHECK TABLE`. Verified that the test fails before this change (the mutated part is missing `dummy.cmrk2`) and passes after it. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…n_variant_discr # Conflicts: # src/Storages/MergeTree/MutateTask.cpp
…d substreams A partial mutation accounts for a column's streams via `getStreamCounts`, which for a column with a dynamic structure (`Dynamic`, `JSON`, ...) relies on the substreams recorded in `columns_substreams.txt`: state-less `serialization->enumerateStreams` stops after the `dynamic_structure` substream and never reports the data-dependent substreams (`variant_discr`, the variant element streams, ...). Wide parts written before `columns_substreams.txt` was introduced (in 25.8) can contain such a column with no recorded substreams (the file is also discarded when found corrupted). For those parts the stream accounting is incomplete again, so a partial mutation could leave a `variant_discr` stream neither rewritten nor hardlinked into the new part - the same write-side problem this PR addresses. Force a full part rewrite (`MutateAllPartColumnsTask`) for that case, mirroring the existing behaviour for direct mutations of dynamic columns. The new helper `hasDynamicColumnsWithoutRecordedSubstreams` is added to both full-vs-partial decision sites (`splitAndModifyMutationCommands` and the task selection in `MutateTask::prepare`) so they stay consistent. A full rewrite re-serializes the column, so no stream can be orphaned, and the resulting part has a `columns_substreams.txt` again, so later mutations can take the partial path. Add `04401_dynamic_mutation_old_part_no_substreams_file`, which simulates an old part by deleting `columns_substreams.txt`, runs a partial mutation that does not touch the `Dynamic` column, and validates the result with `CHECK TABLE`.
Address the code review on PR #107562: the new `hasDynamicColumnsWithoutRecordedSubstreams` guard (and the matching check in `getStreamCounts`) used `hasDynamicSubcolumns`, which also returns true for a plain `Map` (`DataTypeMap::hasDynamicSubcolumnsData` is unconditionally true) and a plain `Variant`. As a result an upgraded Wide part with a basic `Map` column but no `columns_substreams.txt` would force `MutateAllPartColumnsTask` for any unrelated partial mutation, turning a cheap single-column mutation into a full rewrite of all the `Map` data, with no correctness need. Only `Dynamic`/`JSON` have a data-dependent structure whose substreams (`variant_discr`, ...) cannot be enumerated without a deserialization state (`SerializationDynamic`/`SerializationObject::enumerateStreams` short-circuit without a column/state). That is exactly what `hasDynamicStructure` reports: plain `Map`/`Variant` return false, `Dynamic`/`JSON` and any composite that contains one return true. `SerializationVariant::enumerateStreams` enumerates all element streams from the type, so a plain `Variant` is correctly excluded. Use `hasDynamicStructure` at both decision sites. New test `04412_mutation_old_part_basic_map_partial` builds a Wide part with a basic `Map` column, deletes `columns_substreams.txt` to simulate a pre-25.8 part, runs a partial mutation that does not touch the `Map`, and asserts it stays on the partial path (the part does not regain `columns_substreams.txt`) while `CHECK TABLE` passes. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…utation_variant_discr
Use recorded substreams from `columns_substreams.txt` for all column types, not only for columns with dynamic structure. The file is the ground truth of what streams exist on disk. Fall back to `enumerateStreams` when no recorded substreams are available (old parts) or when the column carries the not-yet-written placeholder (to preserve shared-stream accounting for regular columns like Nested array sizes). Co-Authored-By: Claude Opus 4.6 <[email protected]>
…nt_discr Fix missing variant_discr stream for Dynamic columns after mutation
…rypick/25.8/107562 # Conflicts: # src/Storages/MergeTree/MutateTask.cpp
Same as the master fix: under the merge-tree settings randomizer the parts can become packed, where columns_substreams.txt lives inside data.packed and the on-disk assertions no longer hold.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #107562
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job