Repository navigation
Conversation
…llable is pending After `ALTER TABLE ... MODIFY COLUMN c T DEFAULT expr` from `Nullable(T)` or `LowCardinality(Nullable(T))`, parts the mutation has not rewritten yet are converted on read: `convertRequiredExpressions` replaces NULL rows with the DEFAULT. A subcolumn that the part's older type also has (`x.a` of `Nullable(Tuple(a ...))`, `s.size` of `Nullable(String)`) was read from the part and converted on its own; the DEFAULT was looked up under the subcolumn's name, found nothing, and the former NULL rows got the type default. Elements whose type did not change were not converted at all. `length(s)`, `empty(s)` and `tupleElement` reach the same subcolumns through `optimize_functions_to_subcolumns`, and mutations use the same read path, so `ALTER DELETE WHERE x.a = 0` reaching an unconverted part deleted rows whose `x.a` is the DEFAULT's value. For `LowCardinality(Nullable(String))` the Wide reader read `.size` through the `String` serialization from the part's LC streams (an assertion in debug builds, `Expected ColumnLowCardinality` in release). The replacement is a property of the parent's conversion, so such a subcolumn is not read from the part: injection reads the parent instead (the branch added for a subcolumn the part's type lacks), Wide and Compact readers skip the subcolumn like a column dropped by a pending mutation, and `evaluateMissingDefaults` extracts it from the converted parent. One predicate, `conversionReplacesNullsWithDefault`, now defines the condition for the conversion, the injection and the readers. The readers evaluate it on the part's own type of the parent, because a subcolumn the part's type lacks is resolved with the storage type. A subcolumn whose DEFAULT reads another column now fails with UNKNOWN_IDENTIFIER, as the full column already does, instead of returning the type default. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…of a skipped subcolumn The readers now skip a subcolumn whose parent's pending conversion replaces NULLs with the DEFAULT. `fillMissingColumns` leaves such a subcolumn for `evaluateMissingDefaults` only if the parent has a DEFAULT or is available, and `executeActionsBeforePrewhere` built the set of columns from earlier steps from `previous_header` alone. A parent consumed by an explicit `PREWHERE` (or a row policy) is not an output of that step; it survives only in `ReadResult::additional_columns`. With the DEFAULT removed by a later `MODIFY COLUMN x REMOVE DEFAULT` while the first conversion is pending, the subcolumn was then filled with the type default for every row: `x.a` read `0` for `x = (10, 20)`, where master reads `10`. `additional_columns` is now part of that set, matching what `evaluateMissingDefaults` receives. The test gains a `PREWHERE` on the full column for Compact and Wide parts (the subcolumn read the type default on master) and the removed-DEFAULT case (correct on master, wrong with only the reader skip). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the narration of how the skipped subcolumn is produced elsewhere; keep the invariants. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; round 1: 1 finding, round 2 on the fix delta: 0 findings) plus the reviewer's own pass (round 1: 4 findings, round 2: none new).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261010-043000 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261010-035800 |
|
Workflow [PR], commit [48e0aaf] Summary: ❌
AI ReviewSummaryThe PR makes subcolumns follow the parent's Findings❌ Blockers
Missing context / blind spots
Tests
Final VerdictStatus: ❌ Block Preserve the parent default when extracting subcolumns from patches on parts missing the parent, and add regression coverage for that case. |
Build profile diff (arm_release)Comparing Binary sizes
The official master build is compiled with Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/Storages/System/CMakeFiles/clickhouse_storages_system.dir/StorageSystemChangelog.generated.cpp.o |
3.10 MiB | 4.00 MiB | +921.19 KiB (+29.02%) |
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.
Compile time of recompiled translation units
161 translation units recompiled, 1462 s compile time in total, 161 of them have a recent master baseline.
Symbol sizes
| Binary | Symbol | Master | PR | Δ |
|---|---|---|---|---|
programs/clickhouse |
DB::auto_changelog |
292.03 KiB | 371.81 KiB | +79.78 KiB (+27.32%) |
…Nullable The ALTER check for a column whose subcolumn is used in the sorting or partition key compares only the subcolumn types, so `Nullable(Tuple(a Nullable(UInt64)))` to `Tuple(a Nullable(UInt64)) DEFAULT tuple(7)` passed with `ORDER BY x.a`. The conversion replaces the column's NULLs, which changes the key subcolumn from NULL to 7 for those rows, and a mutation neither re-sorts nor repartitions the part. After it finished, `WHERE x.a = 7` returned no rows with the primary index (one without it), `ORDER BY x.a` returned the wrong order, and partition pruning dropped the row. Reject the conversion, as for a top-level key column, except when a Replicated database replays an ALTER an older version accepted. Such a conversion may still be pending from an older version. Its key subcolumns are read from the part, as before: extracting them from the converted parent made `x.a` disagree with the index, and MergeOnKey patch parts, whose key columns are read without the parent, filled the skipped `x.a` from the DEFAULT for every row, so lightweight updates were not applied and reading the parent with them hit a bad cast in evaluateMissingDefaults. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - bf86abeEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261010-140006 |
|
The The fuzzer added #115964 (mine, open) covers this case: with it the reader does not read a subcolumn that the part's column type does not have, and takes it from the converted parent instead. |
…m-converted-nullable-column # Conflicts: # src/Storages/MergeTree/MergeTreeBlockReadUtils.cpp # src/Storages/MergeTree/MergeTreeBlockReadUtils.h # src/Storages/MergeTree/MergeTreeReadersChain.cpp
…column The readers created for patch parts also skipped a subcolumn whose `Nullable` parent is converted with a `DEFAULT`, but nothing extracts it from the parent there, so the patch was not applied to the subcolumn. When the patched part lacks the column (added by `ALTER ADD COLUMN` after the part was written), the subcolumn of an updated row then read the `DEFAULT` instead of the updated value (`s.size` 3 for 'updated'). A patch part now provides such a subcolumn as stored. When the patched part extracts the subcolumn from its own column, the patch reads only that column, so its unconverted subcolumn does not overwrite the value extracted after the patch is applied to the column. With legacy (`v1`) patches, deferring the subcolumn to the last read stage makes the Merge and Join modes re-apply the column there, after its conversion, so a `NULL` the patch set throws `CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN` (master returns the type default). ClickHouse#126698 fixes that re-application by restricting each stage to its own columns; the new test pins `patch_parts_version = 'v2'`. Reported in ClickHouse#125037 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
`addPatchPartsColumns` does not read a subcolumn from a patch when the patched part extracts it from its converted column, but `getColumnsForPatches` still listed that subcolumn as updated by the patch at the `AfterEvaluatingDefaults` stage. `applyPatchesToBlockLegacy` builds the header of a v1 patch group from all columns of the patch block, so it re-applied the patch's `Nullable` column to the already converted column, and a NULL in the patch threw `CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN` where master returned the type default. Skip the columns the patch reader does not read. Adds a v1 arm to 05353. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - bfb3f50Every 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:20261024-223006 |
…m-converted-nullable-column # Conflicts: # src/Storages/MergeTree/IMergeTreeReader.cpp
…m-converted-nullable-column # Conflicts: # src/Storages/MergeTree/MergeTreeReaderWide.cpp # src/Storages/MergeTree/MergeTreeReaderWide.h
| auto column_in_part = data_part_info_for_reader.getColumns().tryGetByName(column_name_in_part); | ||
| return column_in_part && isSubcolumnReadFromConvertedColumn(storage_snapshot, column, column_in_part->type); |
There was a problem hiding this comment.
[Blocker] Read the patch's parent when the base part predates the column
This decision only examines the base part. When that part predates ADD COLUMN x, it returns false and the patch reader requests x.a directly. The new patch exemption in IMergeTreeReader.cpp:102 then reads the stored subcolumn without replacing the parent's NULL with its DEFAULT.
For example, consider this case, derived by tracing the current code:
SET enable_nullable_tuple_type = 1;
SET enable_lightweight_update = 1;
CREATE TABLE t (id UInt64) ENGINE = MergeTree ORDER BY id
SETTINGS enable_block_number_column = 1, enable_block_offset_column = 1,
min_bytes_for_wide_part = 0, patch_parts_version = 'v2';
INSERT INTO t VALUES (1);
SYSTEM STOP MERGES t;
ALTER TABLE t ADD COLUMN x Nullable(Tuple(a Nullable(UInt64))) DEFAULT tuple(1);
UPDATE t SET x = NULL WHERE id = 1;
ALTER TABLE t MODIFY COLUMN x Tuple(a Nullable(UInt64)) DEFAULT tuple(7)
SETTINGS mutations_sync = 0, alter_sync = 0;
SELECT id, x.a FROM t; -- expected: 1, 7The patch's x.a is NULL and has the same Nullable(UInt64) type as the requested element. It therefore overwrites the default-derived 7 with NULL after evaluateMissingDefaults, giving an incorrect result and causing predicates on x.a = 7 to discard the row. The same path exists for v1 patches. The current test patches a missing parent only to a non-null value; its NULL patch targets a part that already contains the parent.
Please reconstruct subcolumns from the converted patched parent based on the patch's own type even when the base part lacks it, and cover a NULL patch on a part predating ADD COLUMN.
There was a problem hiding this comment.
Measured on this PR's head and on master: both return NULL for x.a here, and on both SELECT x throws CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN and the MODIFY mutation fails with it on every retry, so there is no converted parent to extract x.a from. Applying a patch's NULL to a column the part lacks once that column becomes non-Nullable is a separate bug in the patch application, so I am not changing it in this PR.
CI finish ledger - 48e0aafEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The 63 jobs reported as DROPPED were skipped behind the targeted failure and carry no outcome of their own. Session id: cron:our-pr-ci-monitor:20261124-050027 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed subcolumns (and functions optimized to read them, such as
length,emptyortupleElement) of a column converted fromNullableto a non-Nullabletype byALTER TABLE ... MODIFY COLUMN ... DEFAULTreturning the type default instead of theDEFAULTfor the formerNULLrows until the mutation finished. Mutations reading such subcolumns, for exampleALTER TABLE ... DELETE WHERE x.a = 0, could delete or update the wrong rows. The conversion is now rejected for a column with a subcolumn in the sorting or partition key, where it changed key values without re-sorting the data.Description
On 26.8.22.13, while
ALTER TABLE t MODIFY COLUMN s String DEFAULT 'abc'fromNullable(String)has not rewritten a part,SELECT length(s)returns0for the formerNULLrows whileSELECT sreturnsabc, andWHERE length(s) = 3drops them. Tuple elements behave the same, and a pendingALTER DELETE WHERE x.a = 0deletes rows that hold theDEFAULT.LowCardinality(Nullable(String))reads fail.Root cause: the
NULLtoDEFAULTreplacement (#84770) converts the whole column, but a subcolumn the part has was converted alone, without theDEFAULT.Change: such a subcolumn is extracted from the converted parent instead, as #110584 does for a subcolumn the part lacks. A lightweight-update patch,
v1orv2, provides that parent, or the stored subcolumn if the part lacks the column.ALTERnow rejects the conversion for a column with a key subcolumn, whose values it would change without re-sorting; one an older version accepted keeps its stored value.Without #124561, such a subcolumn whose
DEFAULTreads another column fails like the full column.A part that omits the column (
skip_empty_columns_on_insert) still returns the type default for such a subcolumn; this PR does not cover it.Test
05353_modify_nullable_to_non_nullable_subcolumn_defaultcovers tuple elements,String,LowCardinality(Nullable(String)), both part formats,PREWHERE, lazy materialization, on-the-fly mutations,v1andv2lightweight-update patches, a persistedDELETE/UPDATEand the rejectedALTER. It fails on master and passes 50/50 randomized.Workflow [PR]
Sync PR [sync-upstream/pr/125037]