Repository navigation
Conversation
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-3:20260707-093400 |
|
cc @Michicosun @CurtizJ for review (mutations / MergeTree part write). Fixes a data-integrity regression where a full-part-rewrite mutation drops hardlinked skip-index checksums from checksums.txt. |
There was a problem hiding this comment.
@groeneai add another select query after this statement
There was a problem hiding this comment.
Done in 3dfc278 (on the current head): after the CHECK TABLE there is now an EXPLAIN indexes = 1 assertion that the preserved index still prunes granules, plus a data SELECT:
SELECT count() > 0 FROM (EXPLAIN indexes = 1 SELECT count() FROM t_skip_idx_checksums WHERE k = 42) WHERE explain ILIKE '%mm_k%';
SELECT count() FROM t_skip_idx_checksums WHERE k = 42;Same pair follows the CHECK TABLE for the long-named-index case.
There was a problem hiding this comment.
The current EXPLAIN checks in tests/queries/0_stateless/04401_mutate_all_columns_preserve_skip_index_checksums.sql and tests/queries/0_stateless/04401_mutate_all_columns_preserve_skip_index_checksums.sql only assert that the index name appears somewhere in EXPLAIN indexes = 1. They still pass on Granules: 20/20, so they do not prove the preserved index is actually pruning after the mutation.
If you want this thread closed on the current head, the assertion needs to match a reduced granule count (as the later legacy-format tests already do), not just the presence of the index name.
There was a problem hiding this comment.
Fixed in ca9c8cc. Both EXPLAIN checks now assert Granules: 1/20 instead of index-name presence. The minmax is on the monotonic non-primary-key column v with index_granularity = 100 (20 granules), so only the skip index can eliminate granules; the assertion returns 0 on 20/20. Verified WITHOUT the fix the preserved-index checks now fail (index shows 20/20), WITH the fix they pass (1/20).
|
Workflow [PR], commit [357601d] Summary: ✅
AI ReviewSummaryThis PR fixes a real family of skip-index corruption bugs around mutation rewrites and adds good targeted coverage, but two suffix-collision cases are still wrong on the current head. In both cases the new legacy Findings❌ Blockers
Tests
Final VerdictChanges required. |
|
Done in 3dfc278. Added two queries after the CHECK TABLE: an |
|
Good catch, confirmed and fixed in 353bd9e. The preserved-index hardlink loop scanned It now resolves each substream's exact data/mark filename via Verified with a long-named minmax index (name > max_file_name_length, replace_long_file_name_to_hash=1): before the change |
CI finish ledger — 353bd9eEvery failure below has an owner. Fast test (incl. arm_darwin, our test
Session id: cron:our-pr-ci-monitor:20260707-183000 |
CI finish ledger — 353bd9eCI fully finished (Finish Workflow pass). One red check; every failure has an owner.
The Upgrade-check error-log scanner flags a pre-existing DatabasePostgreSQL background-connection error unrelated to this skip-index-checksum fix; our PR #109350 allowlists exactly these two code-path signatures ( Session id: cron:our-pr-ci-monitor:20260707-190000 |
|
Follow-up commit Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-5:20260707-184200 |
|
Fixed the `Fast test (arm_darwin)` failure on 04402 (commit 3801a41). The test does local-disk part-file surgery (renames the on-disk minmax index file in the detached part dir). The Fast test macOS environment does not reliably expose that layout, so `mv` wrote to stderr and failed the check. Tagged the test `no-fasttest`, matching the convention of other fixture-surgery tests (e.g. 02864_restore_table_with_broken_part). The bug is disk-layer independent and stays fully covered by the sanitizer stateless jobs (amd_asan_ubsan, amd_msan), which pass. Verified locally: normal stateless mode runs OK (fix validated), fast-tests-only mode SKIPs. |
|
Confirmed and fixed in e5d6795. The packed-archive preservation loop ( Both sites now probe the substreams actually present in the source part via Regression test A/B (debug, same-binary via patch file, MergeTree over local disk):
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260707-230500 |
|
Rebased onto master (resolved the conflict in Merge notes:
Re-validated on the merged tree (same-binary A/B): master baseline drops the legacy minmax member (04402 |
|
Addressed the rebuild-path gap in commit f386b3e.
Regression: |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-8:20260708-123000 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-7:20260708-134400 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-7:20260708-151500 |
Pre-PR validation gate (click to expand)
Verification: 04401 = 20/20 OK under randomization; the 04402/04403/04404/04425 legacy/mixed family = 40/40 OK (no regression). Guarded diff: 2 files (.sql +16/-11-ish, .reference 1 line), no submodule/contrib drift. Pushed 92e98c8..ca9c8cc (fast-forward). Session id: cron:clickhouse-worker-slot-0:20260708-164600 |
CI finish ledger — fc4ed57Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260729-140000 |
`Stateless tests (amd_asan_ubsan, flaky check)` failed 04428 five times out of
five with `Test runs too long (> 180s)`. The cost was client process spawns,
not query work: the test issued 82 sequential ${CLICKHOUSE_CLIENT} calls, and
on this build 82 bare spawns take 4.55s of the test's 5.9s wall clock (55ms
each) while the same 82 statements in one call take 0.17s. Under ASAN on a
loaded flaky-check host running 50 repeats, that constant is what crosses the
limit.
Group the fixture DDL, the mutation and the following assertions into single
calls, and let `make_corrupted_part` and the mutation statements return the
part path they just produced instead of having `orphan_on_disk` and
`side_streams_on_disk` re-query `system.parts` for it. A mutation with
`mutations_sync = 2` completes inside the batch, so a `SELECT path FROM
system.parts` in the same call already observes the post-mutation part.
82 spawns become 24, and the test goes from 5.59-6.14s to 2.69-2.89s. No
assertion, oracle, setting, row count or index count changes: the .reference
file is byte-identical, and reverting each of the three guards under test
(the substream walk, the checksums-membership check and the multi-substream
presence probe) still reddens exactly the paths it did before.
`SELECT count() FROM t_some WHERE hasToken(s, 'hello10')` was meant to show the surviving text index is still usable, but it proves nothing. The token sits in all five granules, so the count is 10 whether the index is read or not, and with an `ngrams` tokenizer `hasToken` does not consult a text index at all: the plan reports `Granules: 5/5` both with and without `use_skip_indexes`. Nor can the assertion be repaired into a pruning check. Any query that makes this table's text index prune opens `skp_idx_a.pos.cmrk2`, which the minmax index `a.pos` and the text `.pos` substream both write under `escape_index_filenames` = 0, so `hasPhrase` and a `LIKE` substring both throw `CANNOT_READ_ALL_DATA` on a pristine part, before any of this test's surgery. Renaming the sibling to `b` makes the same queries prune `Granules: 1/5`, which confirms the collision is the cause and is the pre-existing write-time issue `text_streams_on_disk` already documents. Assert instead that the index is still registered with readable substream sizes in `system.data_skipping_indices`, which is what a hardlinked-forward orphan loses, and record in the comment why a query-level oracle is not available here.
| MergeTreeIndexSubstreams substreams; | ||
| if (indexFileExistsInChecksums(checksums, relative_path_prefix, ".idx2", storage)) | ||
| substreams.push_back({MergeTreeIndexSubstream::Type::Regular, "", ".idx2"}); | ||
| if (indexFileExistsInChecksums(checksums, relative_path_prefix, ".idx", storage)) |
There was a problem hiding this comment.
This still misattributes colliding text substreams as legacy minmax data when escape_index_filenames = 0.
A healthy table with text index a and minmax index a.pst has both skp_idx_a.pst.idx (the text index's .pst data) and skp_idx_a.pst.idx2 (the minmax payload). This helper now reports both as substreams of a.pst, so a rebuild of a.pst (ALTER TABLE ... UPDATE w = w + 1 WHERE 1) makes collectFilesToSkip / remove_per_substream_checksums treat the text .pst.idx as stale minmax state: it is not hardlinked into the new part and its checksum is stripped even though the text index survives. The same false .idx also gets counted into secondary_indices_*_bytes for a.pst.
getAllSubstreamsInPart needs an ownership check here, not a raw "filename exists" union.
There was a problem hiding this comment.
Both confirmed by measurement, and I am declining them for this PR on scope rather than on
substance. Follow-up filed; details below.
The fixture is constructible: a text index a plus a minmax index named a.pst under
escape_index_filenames = 0 produces both skp_idx_a.pst.idx (the text .pst payload) and
skp_idx_a.pst.idx2 (the minmax payload). I A/B'd every case against the pristine master
snapshot, whose MergeTreeIndexMinMax.{cpp,h}, MergeTreeIndices.cpp and
IMergeTreeDataPart.cpp are md5-identical to this branch's merge base, so it is a valid control.
Build ids of both binaries verified against readelf -n before every run.
| action | sibling | build | skp_idx_a.pst.idx |
CHECK | system.data_skipping_indices |
|---|---|---|---|---|---|
ALTER UPDATE w |
a.pst |
this PR | DELETED | 1 | a=150/113442, a.pst=61/72 |
ALTER UPDATE w |
a.pst |
master | PRESENT | 1 | a=211/115783, a.pst=61/72 |
ALTER UPDATE w |
b.pst |
this PR | PRESENT | 1 | a=200/115783, b.pst=61/72 |
ALTER UPDATE w |
b.pst |
master | PRESENT | 1 | a=200/115783, b.pst=61/72 |
DROP INDEX a |
a.pst |
this PR | PRESENT | 1 | a.pst=61/2412 |
DROP INDEX a |
a.pst |
master | DELETED | 1 | a.pst=0/0 |
DROP INDEX a |
b.pst |
this PR | DELETED | 1 | b.pst=61/71 |
DROP INDEX a |
b.pst |
master | DELETED | 1 | b.pst=61/71 |
Both of your claims reproduce (rows 1 and 5). The two non-colliding b.pst rows are
byte-identical between this branch and master, so neither behaviour touches a table without a
suffix collision.
Two measurements bound how much this matters, and one of them changes the shape of the answer.
First, on a colliding table the text index is unreadable from birth, on unmodified master, with
no mutation and no part surgery: hasPhrase(s, 'alpha beta') returns
Code: 33 CANNOT_READ_ALL_DATA: Too many marks in file skp_idx_a.pst.cmrk2, marks expected 1.
With the sibling renamed b.pst the same fixture answers 500. The cause is at write time, not in
cleanup: minmax a.pst and the text index's .pst substream both write
skp_idx_a.pst.cmrk2. After the rebuild that query throws the same Code 33 on this branch and on
master. So the file dropped in row 1 was never readable, and the user-visible delta is the
reported index size, not query results. CHECK TABLE is 1 in all eight cells.
Second, on your DROP INDEX point, this branch and master fail in opposite directions and this
branch is the better one. EXPLAIN indexes = 1 on the surviving minmax after DROP INDEX a:
this branch keeps Granules: 1/5 with survivor a.pst at 61/1098, master reports Granules: 5/5
with survivor a.pst at 0/0, because master deletes the survivor's own .idx2 and .cmrk2 and
leaves only skp_idx_a.pos.*. Destroying the surviving index is the bug 04429 covers. The
retained file you identified is the price of not destroying it, and I would rather keep one
unreadable file of a dropped index than delete a healthy index the user still has.
On the proposed remedy: an ownership check cannot go where you point it.
getAllSubstreamsInPart(checksums, relative_path_prefix, storage) receives no metadata snapshot
and no sibling list, so ownership is not derivable there. It needs
metadata_snapshot->getSecondaryIndices(), which only the callers have, and this PR already has
that primitive in isIndexResolvableFromOwnFiles. For DROP INDEX it is harder than moving code:
metadata_snapshot in collectFilesForRenames is already post-drop, so the dropped index is
absent and "does the dropped text index declare skp_idx_a.pst.idx" cannot be answered from
metadata at all without threading pre-drop metadata through. That is a change to the
substream-ownership model across seven call sites, with its own fixtures.
I also cannot simply narrow the union walk, which is the other obvious shape: the override exists
for the legitimate mixed-format part where one minmax index carries both a legacy .idx and a
modern .idx2, and 04425 fabricates exactly that and asserts the reported size sums both files.
So I am keeping this PR to the bug it fixes and tracking the ownership model separately. Note that
none of this is reachable at shipped defaults: escape_index_filenames defaults to true, which
escapes the sibling to skp_idx_a%2Epst.*; measured at the default there is no collision and both
indexes answer correctly.
One process note: this is the seventh round on this collision family. Each round has been a
narrower spelling of one seam, which is that the filename namespace is ambiguous under
escape_index_filenames = 0, so ownership cannot be recovered from a filename suffix after the
fact by any number of per-site guards. I do not think another cleanup-side guard is the answer, and
I would rather a maintainer weigh whether colliding index names should be disambiguated or rejected
at write time. I am stopping the automated loop here and leaving that question open.
| /// minmax changed `.idx` (v1) -> `.idx2` (v2), so an upgraded part may still carry | ||
| /// the legacy file for a substream that now declares `.idx2`. | ||
| if (substream.extension == ".idx2") | ||
| protect(".idx"); |
There was a problem hiding this comment.
The legacy .idx protection here can still keep part of a dropped text index alive.
With escape_index_filenames = 0, a healthy text index a and a surviving minmax a.pst collide on skp_idx_a.pst.idx (text .pst data vs the minmax legacy probe). protect(".idx") adds that text file to surviving_index_owned_files, so DROP INDEX a skips deleting it and the new part keeps one substream of the dropped index in both the filesystem and checksums.txt.
This needs the same ownership check as the minmax legacy handling above; otherwise DROP INDEX is still incomplete on suffix-collision tables.
There was a problem hiding this comment.
Confirmed, and answered together with the MergeTreeIndexMinMax.cpp comment in
#109616 (comment) since both are the
same underlying issue.
Short version for this thread: your claim reproduces, but on a colliding table this branch and
master fail in opposite directions and this branch is the better one. Measured with
EXPLAIN indexes = 1 after DROP INDEX a, this branch keeps Granules: 1/5 with the surviving
minmax at 61/1098, while master reports Granules: 5/5 with the survivor at 0/0 because it deletes
the survivor's own .idx2 and .cmrk2. Destroying the surviving index is the bug 04429 covers; the
retained file is the price of not destroying it, and the retained file was never readable anyway
because the collision is at write time (hasPhrase throws Code: 33 CANNOT_READ_ALL_DATA on a
pristine part on unmodified master).
The ownership check cannot go at the site you point to either:
metadata_snapshot in collectFilesForRenames is already post-drop, so the dropped index is absent
and its declared substreams cannot be looked up from metadata at all without threading pre-drop
metadata through. Tracked separately rather than folded in here.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 179/182 (98.35%) · Uncovered code |
CI finish ledger - 357601dNo failures to own on this head. All 174 check-runs are complete: 156 success, 18 skipped, 0 failure, 0 incomplete.
Both reds on the previous head (
Session id: cron:our-pr-ci-monitor:20260730-013000 |
|
📊 Cloud Performance Report ✅ AI verdict: This PR fixes on-disk skip-index file cleanup during mutations and DROP INDEX (handling stale legacy substreams and orphaned files); it does not touch the query-execution hot path. One query was flagged on clickbench (Q4) with an apparent -19.6% improvement, but it was correctly left as no change: Q4's plain SELECT does not exercise the mutation-cleanup code this PR changes, and its median (232.0 ms) falls squarely inside master's current variance band of 201-297 ms, so the delta is run-to-run noise rather than a real PR effect. The deterministic suppression here is sound and no directional verdict is warranted. clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
Reconcile with master: the root-cause skip-index-checksum fix in MutateAllPartColumnsTask landed via #109616. Keep the source_part storage discriminators, and add two regression tests not covered by #109616: - 04416_mutate_all_columns_projection_hardlink (untouched projection hardlinked on an all-columns rewrite) - 04416_mutate_all_columns_packed_prefix_collision (idx_a/idx_a6 prefix collision on packed part storage)
Resolves the semantic overlap with the now-merged ClickHouse#109616, which introduced IMergeTreeIndex::getAllSubstreamsInPart. That accessor answers the physical question independently (its own getSubstreams + indexFileExistsInChecksums walk, with an explicit comment that it is deliberately not routed through getDeserializedFormat), so it needs no redirection onto this branch's new getPhysicalFormat: the union-of-on-disk-versions property that mutation cleanup and size accounting depend on holds by construction after the merge. The only textual conflict was the MergeTreeIndexMinMax declaration block, where this branch renames the virtual to getPhysicalFormat and master adds a getAllSubstreamsInPart override. Both are kept. Master adds no new getDeserializedFormat call site (13 before, 13 after), so the usability-versus-physical audit of this branch still covers every caller.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix skip indices being dropped from a data part (or
CHECK TABLEfailing withUNEXPECTED_FILE_IN_DATA_PART) after a full-part-rewrite mutation, such asALTER TABLE ... DROP COLUMNof aMATERIALIZEDcolumn, on aWidepart.Description
Closes: #109595
A mutation that rewrites a
Widepart throughMutateAllPartColumnsTask(for exampleDROP COLUMNof aMATERIALIZEDcolumn) hardlinks the skip-index files that are not being recalculated into the new part, but their checksums were no longer written into the new part'schecksums.txt.Regression from
70a1315cd92("remove support of writing statistics in old format", first released in 26.3): it removedMutationContext::existing_indices_stats_checksums, which carried the hardlinked index files' checksums intofinalizePart, while leaving the hardlink loop inMutateAllPartColumnsTask::preparein place. Since thenfinalizecallsfinalizePart(..., all_gathered_data)whosechecksumsis assembled solely from writer output plus projections, so the hardlinkedskp_idx_*entries are missing.secondary_indices_compressed_bytes-> 0).checksums.txt, soCHECK TABLEfails withUNEXPECTED_FILE_IN_DATA_PART.Compact parts are unaffected because
need_recalculateforces an index rebuild there.Primary fix: in the hardlink branch of
MutateAllPartColumnsTask::prepare, add each preserved index file's source checksum toall_gathered_data.checksumsso it reachesfinalizePart.The following related defects were found and fixed while reviewing this change:
checksums.filesby the rawskp_idx_<name>prefix, so a substream stored under its hash byreplace_long_file_name_to_hashwas never reached. Resolution now goes per substream throughIMergeTreeDataPart::getStreamNameOrHash.getDeserializedFormatreports only the preferred read layout, so a part carrying both the v1.idxand the v2.idx2payload had one of them omitted. AddedIMergeTreeIndex::getAllSubstreamsInPart, which answers what is physically present rather than what is preferred for reading, and moved the mutation and size-accounting callers onto it.skp_idx_*on disk, entries missing fromchecksums.txt) were not repairable: the full-rewrite path dropped the surviving files, and the some-columns andDROP INDEXpaths hardlinked them forward unchanged. Such an index is now rebuilt on a full rewrite, and removed on the other two paths, leaving the part consistent either way..dct,.pstand, with phrase search enabled,.possubstreams; the cleanup enumerated only the base.idx/.idx2plus one mark, so the side streams leaked.escape_index_filenames = 0a stream name is the index name verbatim, soDROP INDEX aaddressedskp_idx_a.pos.*, the on-disk name of a surviving index nameda.pos, and the reverse direction reached the.possubstream of a text index nameda. Ownership is now taken from each surviving index's owngetSubstreamsand only for the extension that substream declares, so neither direction deletes a file it does not own. The same collision also worked in reverse: a file belonging to another index made a corrupted index look intact, so neither repair path ran, and inside a packed skip-index archive a surviving index that is never packed protected a dropped index's mark. An index's health is now decided only by files no other index declares, and a mark inside a packed archive is protected only when the surviving index is itself packed.Regression tests:
04401-04404,04425-04429,04431.Deliberately out of scope: with
escape_index_filenames = 0, two skip indices can resolve to thesame on-disk filename at WRITE time - for instance a text index
aand an index nameda.pos,where the sibling's substream extension is also
.idx. The part is then already inconsistentbefore any mutation runs, and with a
setsiblingOPTIMIZEaborts inMergedPartOffsets. That is a pre-existing defect reproducible onmasterwithout any change fromthis pull request, it needs a fix at DDL or write time rather than in mutation bookkeeping, and it
is tracked separately.
Version info
26.8.1.446(included in26.8and later)