Skip to content

Do not remove another column's stream with a column dropped from a merged part - #118246

Merged
alexey-milovidov merged 7 commits into
masterfrom
merge-drops-shadowed-column-stream
Sep 25, 2026
Merged

alexey-milovidov merged 7 commits into
masterfrom
merge-drops-shadowed-column-stream

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 5, 2026 •

Copy link
Copy Markdown
Member

A column that no source part holds and that has no default expression is dropped from the merged part, and its files are looked up through the part's serialization of that name. Once the column itself is gone from the part, that name resolves to the serialization of a same-named subcolumn of another column - a column named like a subcolumn, a.size0 next to an Array column a - so the streams enumerated from it are the other column's. The removal then took the array's offsets file with it, and every read of the table failed:

CREATE TABLE t (a Array(UInt64)) ENGINE = MergeTree ORDER BY tuple()
SETTINGS min_bytes_for_wide_part = 0;
INSERT INTO t VALUES ([10, 20, 30]);
ALTER TABLE t ADD COLUMN `a.size0` UInt64;
OPTIMIZE TABLE t FINAL;

SELECT a FROM t;
-- Code: 49. DB::Exception: Stream a.size0 for column a with type Array(UInt64) is not found.

The merged part is left without the offsets file it claims in columns_substreams.txt, so the data of the array column becomes unreadable - CHECK TABLE cannot repair it either.

The removal now takes the serialization from the column entry of the part's column list, and skips a column the list does not hold at all - such a column has no files in the part to remove.

Found while fixing #114588, and reproduces without that change.

The mutation side has the same shape: the wide-part DROP_COLUMN branch of collectFilesForRenames in MutateTask.cpp also resolved the dropped name through IMergeTreeDataPart::tryGetSerialization, so dropping a column the part holds only as a missing-column marker (skip_empty_columns_on_insert with serialization_info_version = 'with_missing_columns') removed the array's offsets stream from the mutated part. The same rule is applied there, and to the RENAME COLUMN fallback for parts without columns_substreams.txt.

Closes: #118255
Related: #114588
Related: #113420
Related: #92453

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 to CHANGELOG.md):

Fixed a merge or a mutation making a table unreadable (Stream ... is not found) when a column that a part does not hold is dropped and its name is also the name of a subcolumn of another column, for example a.size0 next to an Array column a.


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

Version info

  • Merged into: 26.10.1.647-master (included in 26.10 and later)

…rged part

A column that no source part holds and that has no default expression is
dropped from the merged part, and its files are looked up through the part's
serialization of that name. Once the column itself is gone from the part, that
name resolves to the serialization of a same-named subcolumn of another column -
a column named like a subcolumn, `a.size0` next to an `Array` column `a` - so
the streams enumerated from it are the *other* column's. The removal then took
the array's offsets file with it, and every read of the table failed:

    CREATE TABLE t (a Array(UInt64)) ENGINE = MergeTree ORDER BY tuple()
    SETTINGS min_bytes_for_wide_part = 0;
    INSERT INTO t VALUES ([10, 20, 30]);
    ALTER TABLE t ADD COLUMN `a.size0` UInt64;
    OPTIMIZE TABLE t FINAL;

    SELECT a FROM t;
    Code: 49. Stream a.size0 for column a with type Array(UInt64) is not found.

The removal now takes the serialization from the column entry of the part's
column list, and skips a column the list does not hold at all - such a column
has no files in the part to remove.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [80a88d4]

Summary: ✅


AI Review

Summary

This PR fixes the merge-side and mutation-side stream-accounting bug behind shadowing names like a.size0, so merges and mutations stop deleting another column's offsets stream when the shadowing column is absent from the part. I did not find a remaining correctness bug in the new guards, but one current mutation entrypoint they protect still lacks focused regression coverage.

Tests
  • ⚠️ [src/Storages/MergeTree/MutateTask.cpp:1227-1245] The new getStreamCounts guard is also what keeps marker-only READ_COLUMN mutations such as ALTER TABLE ... MODIFY COLUMN from resolving a.size0 to the array offsets stream. splitAndModifyMutationCommands still routes missing-column markers into READ_COLUMN, and collectFilesToSkip counts updated_header.getNames() through this helper. The added tests cover DROP COLUMN, RENAME COLUMN, and CLEAR COLUMN, but they do not exercise this reachable READ_COLUMN path. Please add a focused stateless regression with skip_empty_columns_on_insert = 1, a marker-only shadowing a.size0, and a READ_COLUMN mutation (for example ALTER TABLE ... MODIFY COLUMN \a.size0` Nullable(UInt64) SETTINGS mutations_sync = 2), then assert both SELECT aandCHECK TABLE`.
Final Verdict
  • Status: ⚠️ Request changes
  • Add one focused regression test for the marker-only READ_COLUMN / ALTER MODIFY COLUMN path that this guard now protects.

LLVM Coverage Report

Measured on commit 80a88d4.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.40% 79.40% +0.00%

Changed lines: Changed C/C++ lines covered: 30/31 (96.77%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 5, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Sep 5, 2026
@zlareb1

zlareb1 commented Sep 5, 2026

Copy link
Copy Markdown
Member

The fix looks complete for the merge side: both callers of removeEmptyColumnsFromPart (MergedBlockOutputStream.cpp horizontal finalize and MergedColumnOnlyOutputStream.cpp vertical gather) go through the fixed chokepoint, the fallback formula matches what buildSerializationGroup uses for real-column entries, and dropping a physically present a.size0 still removes exactly its own files.

One sibling of the same shape stays open after this PR and #118242: the wide-part DROP_COLUMN branch of collectFilesForRenames in MutateTask.cpp also resolves the dropped name via source_part->tryGetSerialization and deletes the enumerated streams. When the dropped column exists in the part only as a missing-column marker (skip_empty_columns_on_insert = 1 with serialization_info_version = 'with_missing_columns'), the lookup answers with the array's a.size0 subcolumn serialization and the mutation removes the array's offsets file from the new part, after which every read of a fails with a LOGICAL_ERROR exception. Reproduced on 26.9.1.767 and filed as #118255 with fault and control runs.

@clickhouse-gh

clickhouse-gh Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 80a88d4085c82a2c29b638000e12df6d717f6876 was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception).

See the job log for details.

alexey-milovidov and others added 2 commits September 10, 2026 22:09
…column

`collectFilesForRenames` resolved the dropped or renamed column name through
`IMergeTreeDataPart::tryGetSerialization` and enumerated the resulting streams to
decide which files of a wide part to remove or rename. A column the part holds
only as a missing-column marker (`skip_empty_columns_on_insert` with
`serialization_info_version = 'with_missing_columns'`) has no serialization of its
own, so a name like `a.size0` next to an `Array` column `a` resolved to that
array's subcolumn serialization: `ALTER TABLE ... DROP COLUMN` then removed the
array's offsets stream from the mutated part and every read of the array failed
with a `LOGICAL_ERROR` exception.

Apply the same rule as `removeEmptyColumnsFromPart` on the merge side: look the
serialization up only for a column the source part physically holds, and skip the
stream enumeration otherwise. The `RENAME COLUMN` fallback path (for parts without
`columns_substreams.txt`) enumerates the streams the same way and is guarded too.

Closes: #118255

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pushed c3a043c: master merged in, plus the mutation-side half of this bug that the review asked for (collectFilesForRenames in MutateTask.cpp, #118255) with a new test 05175_mutation_drops_shadowed_column_stream. The DROP COLUMN case was verified against a control binary with only that hunk reverted: it fails there with Stream a.size0 for column a with type Array(UInt64) is not found and passes with the fix.

@groeneai, the reds on the previous commit look unrelated to this change and need a separate look:

Comment thread src/Storages/MergeTree/MutateTask.cpp Resolved
@groeneai

Copy link
Copy Markdown
Collaborator

Tracked, and already fixed on master: #118489 (yours), merged 2026-09-10T14:42:04Z as 6d69b30d. The run you linked started 2026-09-05, five days before that merge; c3a043c has 6d69b30d as an ancestor, so nothing needs filing here.

All 15 CIDB rows for this test in the last 30 days (10 pull requests plus 5 true-master runs) carry the same signature, so that one fix closes the whole class: Code: 906, reference approx_top_k(v) against metamorphic approx_top_kMerge(approx_top_kState(v)) across the oracle's UNION ALL partition split. It is a false mismatch rather than a defect: approx_top_k keeps a bounded Filtered-Space-Saving counter table, so which elements survive and the counts reported for them depend on the order values arrive in and on how the partial states are merged, and the partitioned State/Merge rewrite is not required to equal the whole-table evaluation. non_deterministic_functions in QueryOracleChecker.cpp blocked topK/topKWeighted but not the identically-implemented approx_top_* family; #118489 adds approx_top_k and approx_top_sum and resolves aggregate aliases through AggregateFunctionFactory::getAliasToOrName, so the approx_top_count spelling is covered without its own entry.

alexey-milovidov and others added 3 commits September 18, 2026 07:13
…holds

`getStreamCounts` in `MutateTask.cpp` decides which files of the source part a mutation
rewrites instead of hardlinking. For a column name that is not recorded in
`columns_substreams.txt` it fell back to `tryGetSerialization`, which resolves the name in
the part's serializations including the generated subcolumns of other columns. For a column
the part does not hold (a missing-column marker written with `skip_empty_columns_on_insert`
and `serialization_info_version = 'with_missing_columns'`) named like a subcolumn of another
column (`a.size0` next to an `Array` column `a`), that lookup answers with the array's offsets
serialization, and the offsets stream would be marked as rewritten and not hardlinked.

The same guard the previous commit added to `collectFilesForRenames` is applied here: only a
column present in the part's column list has streams to count. The dependent-column paths of
`ALTER TABLE ... CLEAR COLUMN` (a recomputed skip index and a recomputed `MATERIALIZED`
column) are pinned by the new test `05227_mutation_clears_shadowed_column_stream`.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pushed 15109b4: master merged in (the branch was 3839 commits behind), plus the getStreamCounts guard the AI review asked for and a new test 05227_mutation_clears_shadowed_column_stream covering CLEAR COLUMN of a marker-only shadowing column with a dependent skip index, a dependent MATERIALIZED column, and no dependencies. Details and the correction to the review's premise are on the thread.

The two reds on c3a043c were job-level timeouts rather than test failures: Integration tests (amd_asan_ubsan, db disk, old analyzer, 3/6) ended with session-timeout occurred during test execution and no failed test, and Stateless tests (amd_llvm_coverage, AsyncInsert, s3 storage, parallel) ran out of the job's time budget at test 13234 of 13874 with every test OK. The new run on the merged branch will show whether either recurs.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pushed 80a88d4: merged master (the branch was 3899 commits behind; the merge was clean, and both changed translation units compile). The only red on 15109b4 was the coverage job Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) with 01414_push_predicate_when_contains_with_clause, 03262_filter_push_down_view and 03174_exact_rows_before_aggregation. These failed across the whole fleet on 2026-09-17 and 2026-09-18, on master and in about 130 PRs, and stopped by 2026-09-19. The fix is already on master, so the merge pulls it in.

/// subcolumn's serialization, and the streams enumerated from it are the other column's.
/// Counting them here would mark the array's offsets as rewritten by the mutation and
/// skip hardlinking them, leaving the new part without them.
if (!data_part->getColumns().contains(column_name))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getStreamCounts is also the protection for current marker-only READ_COLUMN mutations, not only the CLEAR COLUMN cases added in the new regressions. splitAndModifyMutationCommands still routes a missing-column marker through READ_COLUMN for ALTER MODIFY COLUMN / MATERIALIZE COLUMN, and collectFilesToSkip calls getStreamCounts on updated_header.getNames(). The added tests cover DROP COLUMN, RENAME COLUMN, and CLEAR COLUMN, but they do not exercise that reachable READ_COLUMN path.

Please add a focused stateless regression with skip_empty_columns_on_insert = 1, a marker-only shadowing a.size0, and a READ_COLUMN mutation such as ALTER TABLE ... MODIFY COLUMN \a.size0` Nullable(UInt64) SETTINGS mutations_sync = 2; then verify both SELECT aandCHECK TABLE`.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Sep 25, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 25, 2026
Merged via the queue into master with commit 6279fe1 Sep 25, 2026
173 checks passed
@alexey-milovidov
alexey-milovidov deleted the merge-drops-shadowed-column-stream branch September 25, 2026 02:13
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 25, 2026
@clickhouse-gh clickhouse-gh Bot added comp-mutations ALTER UPDATE/DELETE and mutation execution over parts (including lightweight updates/deletes). and removed comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-mutations ALTER UPDATE/DELETE and mutation execution over parts (including lightweight updates/deletes). 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

4 participants