Repository navigation
Fix Memory table abort on ALTER commands with no per-row data effect (STID 2380-3043) - #106621
Conversation
Pre-PR validation gate
Session id: cron:clickhouse-ci-task-worker:20260606-032500 |
|
cc @alexey-milovidov @novikd — could you review this? It is the bundled PR @alexey-milovidov asked for on #106615: a broader fix for STID 2380-3043 that filters every mutation command kind with no per-row data effect on a |
|
Workflow [PR], commit [a2562ae] Summary: ✅
AI ReviewSummary
Final Verdict
|
…utate Address clickhouse-gh[bot] CR feedback on PR ClickHouse#106621 (ClickHouse#106621 (review)). The previous filter included `MATERIALIZE_TTL`, `DROP_INDEX`, `DROP_PROJECTION`, and `DROP_STATISTICS`. The bot correctly noted these never reach `StorageMemory::mutate`: - `DROP INDEX` / `DROP PROJECTION` / `DROP STATISTICS` are parsed into an `AlterCommands` segment and rejected by `StorageMemory::checkAlterIsPossible` (NOT_IMPLEMENTED) before any mutation segment runs. - `MATERIALIZE TTL` is rejected by `MutationsInterpreter::prepare` during pre-mutation validation (`InterpreterAlterQuery::runCommandSegments` builds a `MutationsInterpreter` with `validate_mutation_query = 1` before `StorageMemory::mutate` is called) with INCORRECT_QUERY when there is no TTL on the table. Listing those kinds in the filter advertised behavior the implementation does not provide. Narrow the filter to the actually-reachable set: `APPLY_PATCHES`, `APPLY_DELETED_MASK`, `MATERIALIZE_INDEX`, `MATERIALIZE_PROJECTION`, `MATERIALIZE_STATISTICS`, `REWRITE_PARTS`. This matches the CIDB-observed crash shapes for STID 2380-3043. Update `04322_memory_mutate_no_op_commands_2380_3043`: - Drop the implicit `nonex` warnings in `MATERIALIZE INDEX nonex` and `MATERIALIZE PROJECTION nonex` by adding query-level `SETTINGS send_logs_level = 'error'` (clickhouse-test treats any server warning forwarded to the client as a `having stderror` failure on Fast test, which broke the test on PR ClickHouse#106621 even though stdout matched the reference). - Add a `REWRITE PARTS` case to cover the retained set. - Reference file gets the corresponding `after rewrite parts:` row. Source code comment is updated to record exactly why the rejected kinds are not in the filter. Verified on the local debug build at port 29000: - Test passes against the fix (stdout matches reference, stderr empty). - Existing `01867_fix_storage_memory_mutation` and `04229_memory_mutation_timeout_break` continue to pass. Closes the bot's two Major findings and the test-coverage Tests note on PR ClickHouse#106621 review 4441649372. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Pushed
Pre-PR validation gate
Session id: cron:clickhouse-ci-task-worker:20260606-051000 |
CI ledger — covered SHA:
|
| job | classification | disposition |
|---|---|---|
Stress test (arm_debug) — Cannot start clickhouse-server |
NOT PR-caused — pre-existing trunk text-index marks bug | Server fails to start during metadata load: Too many marks in file .../skp_idx_idx.cmrk4, marks expected 0 (bytes size 0) for an INDEX ... TYPE text(tokenizer = array()) MergeTree part. PR #106621 only touches src/Storages/StorageMemory.cpp (Memory engine mutate() filter list) and a stateless test — wholly unrelated to MergeTree text-index mark loading. 30-day cross-PR check on test_context_raw LIKE '%Too many marks%text(tokenizer%' shows 3 hits on independent refs in ~17 hours: PR #103961 (2026-06-05 13:42), master (2026-06-05 23:57), PR #106621 (2026-06-06 06:40). Tracked in our task 2026-06-06-p1-stress-text-index-marks-corruption--. |
All other 134 checks pass on this SHA. The PR-caused Fast test failure on the previous SHA 41c17e17c9d2 (regression test had <Warning> stderr output) is fixed by the SETTINGS send_logs_level = 'error' change in this commit, plus the narrow-scope refactor addressing the bot's two Major findings on MATERIALIZE_TTL / DROP_* reachability.
🤖 Posted by our-pr-ci-monitor.
|
@groeneai, we have to fix the stress test failure first. Fix it and send a PR. You can include the fix for clang-tidy to that PR as well, so we can merge it. |
- src/.../MergingSortedAlgorithm.cpp: collapse the 6-line gate explanation next to `if (apply_virtual_row_conversions)` into a one-line invariant note. The full root-cause explanation (Union of read-in-order subtrees, per-source conversions, default-zero fallback in setVirtualRow) lives in the PR description and the original commit message of 28c0151. - tests/.../04323_virtual_row_two_shards_pk_alias.sql: collapse the 11-line header comment into a one-line "Regression test for STID 2651-3359 (debug assertion added in ClickHouse#106565)" - test name and the SET list make the purpose self-evident, full context lives in ClickHouse#106664. Also corrects the outdated test-file PR reference noted by clickhouse-gh inline (ClickHouse#106565 introduced the assertion; the test reproduces the assertion path covered by this PR, not ClickHouse#106654 which is unrelated). No code-behavior changes. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@alexey-milovidov filed the stress text-index marks corruption fix as separate PR #106675 ("Skip mark file read for parts with zero granules") per your directive. It was a generic CIDB cross-PR evidence (30 days) showed three independent hits on master / PR #103961 / PR #106621 within ~17 hours - trunk-side, not caused by this PR. The arm_tidy fix you mentioned is already in master via @ davenger's PR #106609 (commit 1c0b3c1), so there is nothing else to bundle. |
|
PR #106621 supersedes PR #105286 rather than duplicating it. #105286 narrows the Details and CIDB-backed reproduction are in the PR description and the pre-PR validation gate at #issuecomment-4637516079. Once this PR merges, #105286 can be closed. |
|
@groeneai, fix conflicts. |
|
@groeneai, also find out why the server couldn't start in the Stress test. |
…ect (STID 2380-3043) Fixes `STID: 2380-3043` (`Logical error: Mutation of \`Memory\` table produced incomplete output: block 0 has 0 rows, expected N`), reported by `@alexey-milovidov` on ClickHouse#106615 and seen on master and 8+ unrelated PRs. Reproducer (master HEAD, deterministic; aborts the server in debug builds): CREATE TABLE t (id UInt64, value String) ENGINE = Memory; INSERT INTO t VALUES (1, 'a'), (2, 'b'); ALTER TABLE t (APPLY PATCHES); -- or: ALTER TABLE t MATERIALIZE STATISTICS ALL; -- or: ALTER TABLE t MATERIALIZE INDEX nonex; Root cause: `MutationsInterpreter` short-circuits `APPLY_PATCHES` and `APPLY_DELETED_MASK` in its prepare loop without adding a stage. For `MATERIALIZE_INDEX`, `MATERIALIZE_PROJECTION`, `MATERIALIZE_STATISTICS`, and `MATERIALIZE_TTL`, the prepare loop also adds no column dependencies when the target structure does not exist on the storage (`Memory` has no indices, projections, statistics or TTL). The resulting pipeline pulls one output block per input block but with zero rows in each. `StorageMemory::mutate` then walks the partial-column path and fails the per-block row-count invariant. Fix: filter at the storage entry point. `Memory` tables hold raw column blocks in RAM and have no on-storage analog of indices, projections, statistics, TTL, patch parts, or a `_row_exists` deletion mask. Mutation commands that target those structures are semantic no-ops on `Memory` and are removed from the command set before constructing the pipeline. If all commands are filtered out, `mutate` returns immediately. A real `UPDATE` / `DELETE` / `MATERIALIZE_COLUMN` mixed into the same `ALTER` still executes. This supersedes ClickHouse#105286, which filtered only `APPLY_PATCHES` and `APPLY_DELETED_MASK`; CIDB shows the same `LOGICAL_ERROR` reaching the same code path via `MATERIALIZE STATISTICS ALL`, `MATERIALIZE INDEX <name>`, and `MATERIALIZE PROJECTION <name>` shapes that the narrower fix did not cover. Regression test `04322_memory_mutate_no_op_commands_2380_3043` exercises every no-op shape (`APPLY PATCHES` parens form and bare form, `APPLY DELETED MASK`, `MATERIALIZE STATISTICS ALL`, `MATERIALIZE INDEX nonex`, `MATERIALIZE PROJECTION nonex`) plus a mixed `UPDATE ... APPLY PATCHES SETTINGS mutations_sync = 1` to prove that real updates still execute. The existing `01867_fix_storage_memory_mutation` and `04229_memory_mutation_timeout_break` tests still pass. Caused by: ClickHouse#103706 Co-Authored-By: Claude Opus 4.8 <[email protected]>
…utate Address clickhouse-gh[bot] CR feedback on PR ClickHouse#106621 (ClickHouse#106621 (review)). The previous filter included `MATERIALIZE_TTL`, `DROP_INDEX`, `DROP_PROJECTION`, and `DROP_STATISTICS`. The bot correctly noted these never reach `StorageMemory::mutate`: - `DROP INDEX` / `DROP PROJECTION` / `DROP STATISTICS` are parsed into an `AlterCommands` segment and rejected by `StorageMemory::checkAlterIsPossible` (NOT_IMPLEMENTED) before any mutation segment runs. - `MATERIALIZE TTL` is rejected by `MutationsInterpreter::prepare` during pre-mutation validation (`InterpreterAlterQuery::runCommandSegments` builds a `MutationsInterpreter` with `validate_mutation_query = 1` before `StorageMemory::mutate` is called) with INCORRECT_QUERY when there is no TTL on the table. Listing those kinds in the filter advertised behavior the implementation does not provide. Narrow the filter to the actually-reachable set: `APPLY_PATCHES`, `APPLY_DELETED_MASK`, `MATERIALIZE_INDEX`, `MATERIALIZE_PROJECTION`, `MATERIALIZE_STATISTICS`, `REWRITE_PARTS`. This matches the CIDB-observed crash shapes for STID 2380-3043. Update `04322_memory_mutate_no_op_commands_2380_3043`: - Drop the implicit `nonex` warnings in `MATERIALIZE INDEX nonex` and `MATERIALIZE PROJECTION nonex` by adding query-level `SETTINGS send_logs_level = 'error'` (clickhouse-test treats any server warning forwarded to the client as a `having stderror` failure on Fast test, which broke the test on PR ClickHouse#106621 even though stdout matched the reference). - Add a `REWRITE PARTS` case to cover the retained set. - Reference file gets the corresponding `after rewrite parts:` row. Source code comment is updated to record exactly why the rejected kinds are not in the filter. Verified on the local debug build at port 29000: - Test passes against the fix (stdout matches reference, stderr empty). - Existing `01867_fix_storage_memory_mutation` and `04229_memory_mutation_timeout_break` continue to pass. Closes the bot's two Major findings and the test-coverage Tests note on PR ClickHouse#106621 review 4441649372. Co-Authored-By: Claude Opus 4.8 <[email protected]>
9f30253 to
a2562ae
Compare
|
@alexey-milovidov, both done. 1. Conflicts. Rebased onto current master ( 2. Stress server-start failure. Not caused by this PR. The Stress (arm_debug) job failed at server startup with: This is a pre-existing text-index marks-corruption bug on the MergeTree path (a zero-granule part whose Root cause and fix are in #106675 ("Skip mark file read for parts with zero granules": |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 16/16 (100.00%) | Lost baseline coverage: none · Uncovered code |
`MergeTreeMarksLoader::loadMarksImpl` opens the marks file unconditionally and verifies that the underlying reader is at EOF after the requested number of marks has been consumed. For a part with zero granules (`marks_count == 0`) the for-loop runs 0 iterations and the EOF check fires immediately. If the marks file on disk happens to contain any bytes, the check throws `Too many marks in file <path>, marks expected 0 (bytes size 0)` during table ATTACH or `SYSTEM PREWARM MARK CACHE`, which prevents the server from starting up. This shape was observed in stress tests where a `text(tokenizer = array())` skip-index part on a deeply-mutated empty result (`all_1_7_2_8` with zero rows) ended up with a non-empty `skp_idx_idx.cmrk4` file. Independent hits on master, PR ClickHouse#103961 and PR ClickHouse#106621 within ~17 hours pointed to a trunk-side issue rather than a PR regression. Return an empty marks structure when `marks_count == 0` without opening the file. The check is moved before the existing `file_size == 0` validation so the empty-marks-count path is fully decoupled from file content. The pre-existing `file_size == 0` check is preserved with the now-redundant `marks_count != 0` predicate dropped: the new early-return makes that branch unreachable when `marks_count` is zero. Adds a regression test that creates an empty part with a `text` skip-index and exercises `SYSTEM PREWARM MARK CACHE`. Tracked by ClickHouse#106621 (replied). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Fixes
STID: 2380-3043(Logical error: Mutation of \Memory` table produced incomplete output: block 0 has 0 rows, expected N), reported by @alexey-milovidov on https://github.com/ClickHouse/ClickHouse/pull/106615 as a chronicBuzzHouse` finding hitting master and 8+ unrelated PRs.Per @alexey-milovidov directive on #106615: "fix this logical error ... Send a new PR which does the fix, and also includes the fix for clang-tidy, so at least we will be able to merge that PR." The arm_tidy fix from #106615 already landed independently in master (commit
1c0b3c1b4071, PR #106609 by@davenger), so this PR carries only the Memory-mutate fix.Closes: #105286
Caused by: #103706
Related: #106615
Related: #99972
Reproducer (master HEAD, deterministic — aborts in debug builds)
Root cause
MutationsInterpreter::prepareshort-circuitsAPPLY_PATCHES/APPLY_DELETED_MASK/REWRITE_PARTS(MutationsInterpreter.cpp:1282-1287) without adding a stage. ForMATERIALIZE_INDEX/MATERIALIZE_PROJECTION/MATERIALIZE_STATISTICS, the prepare loop also adds no column dependencies when the target structure does not exist on the storage (Memoryhas no indices, projections, or statistics). Either way the resulting pipeline pulls one output block per input block but with zero rows in each.StorageMemory::mutatethen walks the partial-column path and fails the per-block row-count invariant atStorageMemory.cpp:329-331.Fix
Memorytables hold raw column blocks in RAM and have no on-storage analog of skip indices, projections, statistics, patch parts, the_row_existsdeletion mask, or rewritten parts. Mutation commands that target those structures are semantic no-ops onMemory: the post-state the user is asking for is already trivially satisfied. The fix filters them out at the storage entry point before constructing the mutation pipeline. If all commands are filtered out,mutatereturns immediately. A realUPDATE/DELETE/MATERIALIZE COLUMN/RENAME_COLUMNmixed into the sameALTERstill executes normally.The filter targets only the kinds that actually reach
StorageMemory::mutatefor aMemorytable:APPLY_PATCHES,APPLY_DELETED_MASK,MATERIALIZE_INDEX,MATERIALIZE_PROJECTION,MATERIALIZE_STATISTICS,REWRITE_PARTS.Two related kinds are intentionally not in the filter because they are rejected earlier and never reach
mutate:DROP INDEX/DROP PROJECTION/DROP STATISTICSare parsed into anAlterCommandssegment and rejected byStorageMemory::checkAlterIsPossiblewithNOT_IMPLEMENTEDbefore any mutation segment runs.MATERIALIZE TTLis rejected byMutationsInterpreter::prepareduring pre-mutation validation (called fromInterpreterAlterQuery::runCommandSegmentswithvalidate_mutation_query = 1) withINCORRECT_QUERY: Cannot MATERIALIZE TTL as there is no TTL set for tablewhen the table has no TTL.This supersedes #105286, which filtered only
APPLY_PATCHESandAPPLY_DELETED_MASK; CIDB shows the sameLOGICAL_ERRORreaching the same code path viaMATERIALIZE STATISTICS ALL,MATERIALIZE INDEX <name>, andMATERIALIZE PROJECTION <name>shapes that the narrower fix did not cover. Sample CIDB rows from the last 7 days:Regression test
04322_memory_mutate_no_op_commands_2380_3043exercises every no-op shape that reachesStorageMemory::mutate:APPLY PATCHES(parens form and bare form),APPLY DELETED MASK,MATERIALIZE STATISTICS ALL,MATERIALIZE INDEX nonex,MATERIALIZE PROJECTION nonex, andREWRITE PARTS. It also covers a mixedUPDATE ... APPLY PATCHES SETTINGS mutations_sync = 1case to prove real updates still execute. Verified locally against a debug build of master + this fix: each ALTER shape now succeeds, table contents are preserved, and the mixed-command case correctly applies theUPDATE. The existing01867_fix_storage_memory_mutationand04229_memory_mutation_timeout_breaktests continue to pass against the new code path.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix exception
Mutation of \Memory` table produced incomplete outputraised when runningALTER TABLE <memory_table>commands that have no per-row data effect on aMemoryengine, namelyAPPLY PATCHES,APPLY DELETED MASK,MATERIALIZE STATISTICS,MATERIALIZE INDEX,MATERIALIZE PROJECTION, andREWRITE PARTS.Memory` tables do not own those structures, so such commands are now treated as no-ops.Documentation entry for user-facing changes
Version info
26.6.1.773