Repository navigation
Fix a stuck mutation after MODIFY COLUMN from Nullable with a DEFAULT that reads another column - #124561
Fix a stuck mutation after MODIFY COLUMN from Nullable with a DEFAULT that reads another column#124561groeneai wants to merge 7 commits into
MODIFY COLUMN from Nullable with a DEFAULT that reads another column#124561Conversation
…he row Converting a column from `Nullable` to a non-`Nullable` type replaces NULLs with the column's DEFAULT (ClickHouse#84770). The reader evaluated that expression on a block holding only the converted columns, and did not read the columns the DEFAULT refers to, so `MODIFY COLUMN a Int64 DEFAULT c0 + 100` was accepted, its mutation failed forever with UNKNOWN_IDENTIFIER `c0`, and every read of `a` failed until the ALTER was undone. Mirror what the reader already does for the DEFAULT of a missing column: - `injectRequiredColumns` also reads the columns the DEFAULT of such a column refers to; - `performRequiredConversions` gets the other columns of the same rows (this read step and the previous steps of the chain) as extra inputs; - the conversion is resolved with `prefer_column_name_to_alias = 0`, so a DEFAULT reading another column that is converted too reads the converted value whatever the server profile says. A DEFAULT reading a column the old part does not store (added later and not materialized) still fails as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ALTER A previous read step can hold a value written after the pending `ALTER MODIFY COLUMN`: a patch part newer than the ALTER is applied after conversions in the step that reads its column, and an on-fly mutation newer than the ALTER overwrites its target columns. Feeding such a value to the NULL->DEFAULT conversion of a later step made the result depend on PREWHERE placement: after `UPDATE t SET c0 = c0 + 10`, `SELECT c0, a` returned `(11, 101)` while `SELECT a ... PREWHERE c0 > 0` returned `111`. Pass the previous steps' columns to the conversion only when the chain has no patch part and no on-fly mutation newer than the ALTER. Otherwise a DEFAULT dependency read by an earlier step fails with UNKNOWN_IDENTIFIER, as before, until the mutation finishes; dependencies read by the same step, and the mutation itself, are unaffected. The test also asserts that the lazy materialization case is really lazy. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop three comments that restate the name they sit above, and restore an unchanged master comment line. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (2 rounds, 6 findings; click to expand)Pre-publication review by an independent model (engine: codex) plus my own review of the code.
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261008-065200 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261008-061100 |
|
Workflow [PR], commit [31af886] Summary: ✅
AI ReviewSummaryThe PR supplies other row columns to the Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block Preserve mutation order during |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes19 object files changed (+56.80 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units160 translation units recompiled, 1521 s compile time in total, 160 of them have a recent master baseline. |
…default-reads-other-columns Co-Authored-By: Claude Opus 5.5 <[email protected]>
The master merge brought the `MergeTreeReadersChain::previous_steps_columns` field (`std::vector<NameSet>`), which the `Block` local of the same name in `executeActionsBeforePrewhere` now shadows, failing `-Wshadow` in Fast test and `Build (arm_tidy)`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…default-reads-other-columns Resolve the conflict in `MergeTreeReadersChain::evaluateMissingDefaults`: keep master's `mayEvaluateMissingDefaults` assertion and the shared `getPreviousStepsColumns` helper. A reader that replaces NULLs with a DEFAULT requests a column with a DEFAULT, so `mayEvaluateMissingDefaults` holds for it and the earlier steps still keep the columns they project out. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…default-reads-other-columns # Conflicts: # src/Storages/MergeTree/MergeTreeReadersChain.cpp # src/Storages/MergeTree/MergeTreeReadersChain.h
Related: #84770
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
ALTER TABLE ... MODIFY COLUMNfrom aNullabletype to a non-Nullabletype with aDEFAULTthat reads another column, for exampleMODIFY COLUMN a Int64 DEFAULT c0 + 100: the mutation never finished (UNKNOWN_IDENTIFIER) and every read of the column failed, even afterKILL MUTATION.Description
On 26.8.18.2 and 26.3.42.3,
ALTER TABLE t MODIFY COLUMN a Int64 DEFAULT c0 + 100of aNullable(Int64)column is accepted, but its mutation never finishes (Code: 47 Unknown expression or function identifier c0) and everySELECTofafails the same way.KILL MUTATIONdoes not help.Since #84770 the reader converts such a column with
if(isNull(a), <DEFAULT>, assumeNotNull(a)), but it evaluates that on a block holding only the converted columns and never reads the columns theDEFAULTrefers to. TheALTER-time check uses the full old header and passes.The reader now does for this conversion what it already does for the
DEFAULTof a missing column:injectRequiredColumnsalso reads the columns theDEFAULTof such a column refers to;performRequiredConversionsgets the row's other columns as extra inputs, only when a step converts NULLs through aDEFAULT: those of this read step, and those of earlier steps only when no patch part or on-fly mutation newer than theALTERexists (they may hold values written after it);prefer_column_name_to_alias = 0, so aDEFAULTreading a column that is converted too reads its converted value under any profile (with1it read the old one).Known limitations: a
DEFAULTreading a column the old part does not store (added later and not materialized) still fails as before (MATERIALIZE COLUMNfirst works around it); after a lightweightUPDATEissued while the mutation is pending, a read whosePREWHEREreads the dependency fails as before until the mutation finishes.The new test fails on master and covers Compact and Wide parts, reads before the mutation (with
PREWHEREand lazy materialization),MATERIALIZEDand converted dependencies, patch parts before and after theALTERandLowCardinality(Nullable(String)); 50 randomized runs pass.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/124561]