Repository navigation
Conversation
…t while ALTER MODIFY COLUMN is pending A patch part written before a pending ALTER MODIFY COLUMN is read without conversions and applied with Order::BeforeConversions, into the read columns while they still have the data part's types. The header passed to applyPatches was the read sample block, i.e. the requested (post-ALTER) types, so createPatchSources / CombinedPatchBuilder::createPatchForColumn cast the patch to a type that neither the patch nor the data column has, and updateFrom then inserted e.g. a Nullable(UInt64) column into a ColumnLowCardinality: an assertTypeEquality abort in debug builds (STID 2508-2c9e, Stress test (amd_debug) on PR ClickHouse#110321), ILLEGAL_COLUMN, SIGSEGV or wrong values in release builds, and a mutation of such a part that never finishes. The types differ whenever the column's type changed between the data part and the patch without being materialized: KILL MUTATION of an earlier MODIFY COLUMN, or a heavy ALTER UPDATE executed under newer metadata. - The before-conversions application gets a header with the types the read columns have before performRequiredConversions (IMergeTreeReader::getColumnTypeBeforeConversions, now also used by performRequiredConversions itself). - A before-conversions patch whose column type (MergeTreePatchReader:: getColumnTypeInPatch) differs from the column's type in the part is applied after conversions instead, so it is cast from its own type straight to the requested type. Casting it into the part's type first is lossy ('abc' into Nullable(UInt64), 1000 into UInt8), while this gives the same values as a heavy ALTER UPDATE. Such a patch is not applied to a column that an on-the-fly mutation overwrites before reading it (its value is discarded, and casting it into the part's type can fail). Columns that are not converted keep the old order, for which both orders are the same. - createPatchSources / CombinedPatchBuilder::createPatchForColumn also cast a patch whose declared type differs from the result's when both have the same column class: an Int32 patch value was copied into a Date32 column as a raw day number instead of the value CAST gives (-1000000 is clamped to the lower bound of Date32, a unix timestamp is converted to its date). - applyPatchesToBlockLegacy (v1 patch parts) applies only the group's updated columns, as the v2 MergeOnKey path already does: one patch can now update its columns at different stages. This is the change of ClickHouse#126698, taken verbatim so that the two PRs merge in either order. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop comments that narrate the new code (left_unconverted, the equal-type early exit, the getColumnTypeBeforeConversions header doc), merge the before-conversions type note with the reclassification rule, shorten the dropped-column note. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (click to expand)
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261022-090300 |
|
cc @alesapin @Michicosun, could you review this and add the |
|
Workflow [PR], commit [64b6dbf] Summary: ❌
AI ReviewSummaryThe PR corrects patch column types and conversion ordering while Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block Preserve unchanged conversion dependencies and cover patch visibility between mutation stages; fix or explicitly track the pre-existing version-boundary defect. |
…sions A patch older than the pending ALTER whose column type differs from the data part was applied after all conversions, so a conversion that replaces the NULLs of another column by a DEFAULT reading the patched column read the unpatched value. With a part storing `a Int32`, a patch `a = toDate32(1000)` written after a killed `MODIFY COLUMN a Date32`, and a pending `MODIFY COLUMN b Int64 DEFAULT toInt64(a)` of `b Nullable(Int64)`, `b` was 1 instead of 1000 (master gives 1000: `Int32` and `Date32` share the column class, so it copies the patch before conversions), and a DEFAULT that throws on the old value (`intDiv(10, toInt64(a))` with an old `a = 0`) failed the read. Now such a column alone is converted to the requested type first, the patch is applied, and then the usual conversions run with it as an input. If its own conversion replaces NULLs, it is first converted to the Nullable requested type, so that DEFAULT is evaluated by the usual conversions too, and a NULL written by the patch is replaced like the NULLs of the part instead of failing with `CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN`. A requested type that cannot be inside Nullable (`Dynamic`, `Variant`) is the type of the first conversion itself, so the patch keeps its values (a cast into the type in the part could turn them into NULLs), and a NULL of such a patch stays NULL. A DEFAULT still reads the converted value of another column, as it does through the alias in a single conversion. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| } | ||
| } | ||
|
|
||
| DB::performRequiredConversions( |
There was a problem hiding this comment.
[P1] Preserve DEFAULT dependencies in the early conversion block
This block contains only columns selected for early conversion. When the destination cannot be wrapped in Nullable (for example Dynamic), performRequiredConversions evaluates its DEFAULT here, so a dependency outside that subset becomes an unknown identifier even when it was read successfully.
Reproduced with the current Fast test binary for both patch_parts_version = 'v1' and 'v2':
SET enable_lightweight_update = 1;
CREATE TABLE t (id UInt64, a Nullable(Int32), b Int32)
ENGINE = MergeTree ORDER BY id
SETTINGS enable_block_number_column = 1, enable_block_offset_column = 1;
INSERT INTO t VALUES (0, 1, 7), (1, NULL, 8);
SYSTEM STOP MERGES t;
ALTER TABLE t MODIFY COLUMN a Nullable(Int64), MODIFY COLUMN b Int64
SETTINGS alter_sync = 0, mutations_sync = 0;
KILL MUTATION WHERE database = currentDatabase() AND table = 't' SYNC FORMAT Null;
UPDATE t SET a = 1000 WHERE id = 0;
ALTER TABLE t MODIFY COLUMN a Dynamic DEFAULT b
SETTINGS alter_sync = 0, mutations_sync = 0;
SELECT a, b FROM t ORDER BY id;The final query throws UNKNOWN_IDENTIFIER for b while compiling the conversion of a. The previous PR head, 715cf84eb9cc, returns (1000, 7), (8, 8); removing the patch also makes the current head succeed. Please retain the inputs needed by conversion expressions, or defer their DEFAULT evaluation until those inputs are available, and cover this case in both patch formats.
There was a problem hiding this comment.
Fixed in fbb878c: the early conversion no longer evaluates a DEFAULT, so DEFAULT b is evaluated by the usual conversion with all columns (block J of the test).
There was a problem hiding this comment.
[Blocker] The DEFAULT b dependency is still missing on 64b6dbff4f45 when b does not itself change type. src/Storages/MergeTree/IMergeTreeReader.cpp:912-913 skips equal-typed columns, so moving evaluation to the usual conversion does not preserve this input.
Reproduced with the current Fast test binary for both patch_parts_version = 'v1' and 'v2':
SET enable_lightweight_update = 1;
CREATE TABLE t (id UInt64, a Nullable(Int32), b Int32)
ENGINE = MergeTree ORDER BY id
SETTINGS enable_block_number_column = 1, enable_block_offset_column = 1;
INSERT INTO t VALUES (0, 1, 7), (1, NULL, 8);
SYSTEM STOP MERGES t;
ALTER TABLE t MODIFY COLUMN a Nullable(Int64)
SETTINGS alter_sync = 0, mutations_sync = 0;
KILL MUTATION WHERE database = currentDatabase() AND table = 't' SYNC FORMAT Null;
UPDATE t SET a = 1000 WHERE id = 0;
ALTER TABLE t MODIFY COLUMN a Dynamic DEFAULT b
SETTINGS alter_sync = 0, mutations_sync = 0;
SELECT a, b FROM t ORDER BY id;The final query raises UNKNOWN_IDENTIFIER b. Adding MODIFY COLUMN b Int64 to the first alteration makes it return the expected (1000, 7), (8, 8). The conversion block needs the unchanged dependencies too.
There was a problem hiding this comment.
Not caused by the patch: on master 573bbb2a the same table without the UPDATE, even without the killed MODIFY, already throws UNKNOWN_IDENTIFIER b (also for MODIFY COLUMN a Int64 DEFAULT b), because a column whose type does not change is not passed to the conversion of the others. With the patch, 64b6dbff gives that same error instead of master's abort, so I am keeping this pre-existing case out of this PR.
…r type The early conversion of such a column evaluated the DEFAULT of a requested type that cannot be inside Nullable (Dynamic, Variant) in a block of only the early-converted columns: a DEFAULT reading another column threw UNKNOWN_IDENTIFIER, and one reading a patched column read the value from before its patch. The early conversion now runs without DEFAULTs, so Dynamic and Variant keep the NULLs, and the usual conversion replaces them with all columns at hand: performRequiredConversions gets the columns whose NULLs still await a DEFAULT. A NULL written by such a patch over a Nullable part now gets the DEFAULT too. Over a Nullable part, a requested type that holds no NULL and cannot be Nullable (Array) gets its patch after the conversions, as on 715cf84. Test blocks I and J: the two reproductions of the review of 01293f6, a DEFAULT that reads a patched Dynamic column, and a NULL patch into Dynamic. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes9 object files changed (+34.14 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 units163 translation units recompiled, 1446 s compile time in total, 163 of them have a recent master baseline. |
CI finish ledger - fbb878cEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261023-053005 |
…differs-from-part # Conflicts: # src/Storages/MergeTree/IMergeTreeReader.cpp
…differs-from-part # Conflicts: # src/Storages/MergeTree/MergeTreeReadersChain.cpp
| } | ||
| } | ||
|
|
||
| column_it->order = ColumnForPatch::Order::AfterColumnConversion; |
There was a problem hiding this comment.
[Blocker] Apply pre-ALTER patches when their mutation-version window opens
The new ordering is local to executeActionsBeforePrewhere. If an earlier on-the-fly mutation reads this column, patch_max_version excludes a newer patch here. When that patch becomes visible, applyPatchesAfterReader recomputes its order as BeforeConversions, but accepts only AfterConversions and AfterEvaluatingDefaults (MergeTreeReadersChain.cpp:1103-1107). The patch is consequently never applied to the already-read column.
Reproduced on 64b6dbff4f45 with the Fast test binary for both patch formats:
SET enable_lightweight_update = 1;
SET apply_mutations_on_fly = 1;
CREATE TABLE t (id UInt64, a UInt8, b UInt64)
ENGINE = MergeTree ORDER BY id
SETTINGS enable_block_number_column = 1, enable_block_offset_column = 1;
INSERT INTO t VALUES (0, 1, 0);
SYSTEM STOP MERGES t;
ALTER TABLE t MODIFY COLUMN a UInt64
SETTINGS alter_sync = 0, mutations_sync = 0;
KILL MUTATION WHERE database = currentDatabase() AND table = 't' SYNC FORMAT Null;
ALTER TABLE t UPDATE b = a WHERE 1 SETTINGS mutations_sync = 0;
UPDATE t SET a = 1000 WHERE id = 0;
ALTER TABLE t MODIFY COLUMN a UInt32
SETTINGS alter_sync = 0, mutations_sync = 0;
SELECT a, b FROM t;This returns (1, 1) instead of (1000, 1). Removing the final ALTER returns (1000, 1); putting the patch before the mutation returns (1000, 1000). The version-boundary problem also exists with matching part/patch types, and the mismatched-type input this PR supports reaches it. Please handle these patches between reader stages, or link a tracking issue for that remaining path, and add a focused regression case.
There was a problem hiding this comment.
Pre-existing and not specific to the type change: master 573bbb2a returns the same (1, 1), also with a UInt64 part and no killed MODIFY, which is the case #127372 fixes (its test cases t_read_v1/t_read_v2 have that shape). With #127372 (9c98b41f) alone, and with both heads merged locally, your query and the same-type variant return (1000, 1) in both patch formats, so there is nothing to add here.
CI finish ledger - 64b6dbfEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261121-170022 |
Related: #126698
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a server crash, an
ILLEGAL_COLUMNexception or wrong values when reading a column that has a lightweightUPDATEpatch and a pendingALTER MODIFY COLUMN, when the column's type in the data part differs from its type in the patch part (for example afterKILL MUTATIONof an earlierMODIFY COLUMNof that column). The pending mutation of such a part no longer fails forever.Description
On 26.9.16.11 and 26.8.18.2, after
KILL MUTATIONof aMODIFY COLUMN a Nullable(String)on a part that storesaasLowCardinality(Nullable(String)), anUPDATE t SET a = '42'followed by a pendingMODIFY COLUMN a Nullable(UInt64)makesSELECT a FROM tthrowILLEGAL_COLUMN; the mirrored types crash the server (SIGSEGV), and numeric widening returns wrong values. Debug builds abort (Logical error: '(isConst() || isSparse() || ..., STID 2508-2c9e) in the stress test: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=110321&sha=7f4ebf08f19cc79f40eef60ff855db08df1961bc&name_0=PR&name_1=Stress%20test%20%28amd_debug%29Root cause: a patch older than the pending
ALTERis applied before conversions, into columns of the data part's types, butexecuteActionsBeforePrewherepassed the requested types, so the patch was cast to a type neither side has.The change:
NULLs (Nullable,Dynamic,Variant) and before the other conversions, so theDEFAULTs replacingNULLs read patched values; it is cast even when both types are stored alike (Int32,Date32).ADD COLUMN#126698; this fix needs it).Still throwing: a data-part value the new type cannot take, even if such a patch replaces it, and such a patch's
NULLinto a non-Nullabletype over a non-Nullablepart (intoDynamic/Variantit staysNULL). Over aNullablepart, a type holding noNULL(Array) gets such a patch after all conversions.The new test covers the stress-test shape, a domain change, widening, types stored alike, an on-the-fly overwrite and
DEFAULTs reading patched columns, also intoDynamic; it aborts master and passes for bothpatch_parts_versionvalues.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/127367]