Skip to content

Cherry pick #107562 to 26.3: Fix missing variant_discr stream for Dynamic columns after mutation - #112064

Merged
robot-ch-test-poll2 merged 13 commits into
backport/26.3/107562from
cherrypick/26.3/107562
Jul 27, 2026
Merged

robot-ch-test-poll2 merged 13 commits into
backport/26.3/107562from
cherrypick/26.3/107562

Conversation

@robot-ch-test-poll3

Copy link
Copy Markdown
Contributor

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-pick locally.
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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

alexey-milovidov and others added 11 commits June 15, 2026 19:45
… 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]>
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
@robot-ch-test-poll3 robot-ch-test-poll3 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Jul 27, 2026
…rypick/26.3/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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants