Repository navigation
Fix stale subcolumns left behind by ALTER TABLE ... RENAME COLUMN - #122527
Conversation
ColumnsDescription::rename re-keyed the column in `columns` but left its
subcolumns registered in `subcolumns` under the old storage name. After
ALTER TABLE ... RENAME COLUMN c0 TO c1, `c0.null` stayed registered without
a parent, and hasSubcolumn, tryGetColumn and tryGetColumnDescription then
dereference columns.find("c0") == end(). MemorySanitizer reports that as
use-of-uninitialized-value (STID 3520-32eb, BuzzHouse amd_msan, reached from
StorageBuffer::read); a Merge table over the renamed table and
OPTIMIZE ... DEDUPLICATE BY reach the same lookups. When a column with the
old name is added again, the stale entries become phantom subcolumns of it:
on 26.3, SELECT c0.null returns 1 for a non-NULL UInt64 c0.
Remove the subcolumns before modify_key (column_from may refer to the
element's own name, as in the DeltaLake caller) and register them again under
the new name when the column had any, so ALIAS columns and descriptions built
with add_subcolumns = false stay unchanged. If modify_key fails, the element
is erased together with its subcolumns.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
ALTER TABLE ... RENAME COLUMN re-adds every column's subcolumns after the rename, so SQL cannot observe that rename itself moves them. Check that the old subcolumns are gone, the renamed column has its own, and an ALIAS column gains none, with the element's own name as column_from. 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; 1 finding in the full pass, 0 in the delta recheck of the fix).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20260927-115400 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20260927-092800 |
|
Workflow [PR], commit [ea391a5] Summary: ✅
AI ReviewSummaryThis PR keeps Final Verdict
LLVM Coverage ReportMeasured on commit ea391a5.
Changed lines: Changed C/C++ lines covered: 8/9 (88.89%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 13 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - 0d1bc6eEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All 172 check runs completed (130 pass, 39 not selected, 3 red: the row above and its two rollups), Session id: cron:our-pr-ci-monitor:20260927-173207 |
| } | ||
| } | ||
|
|
||
| TEST_F(ColumnsDescriptionTest, RenameMovesSubcolumns) |
There was a problem hiding this comment.
Removed in 04995668e17b. The SQL test 05265_rename_column_subcolumns stays, and I dropped the unit-test sentence from the description.
The stateless test 05265_rename_column_subcolumns covers the fix, as requested in review. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 6b916d6Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
None of these touches Session id: cron:our-pr-ci-monitor:20261004-013156 |
CI finish ledger - 3f385b8Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The Session id: cron:our-pr-ci-monitor:20261004-063241 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
After
ALTER TABLE ... RENAME COLUMN, the subcolumns of the renamed column (for examplec0.nullora.size0) stayed resolvable under the old name. Reading them through aBufferorMergetable, or using them inOPTIMIZE ... DEDUPLICATE BY, read uninitialized memory, and once a new column reused the old name they returned wrong values instead of throwingUNKNOWN_IDENTIFIER.Description
On 26.3.33.24, after
ALTER TABLE t RENAME COLUMN c0 TO c1andALTER TABLE t ADD COLUMN c0 UInt64,SELECT c0.null FROM treturns1for a row withc0 = 42(Memory and MergeTree) instead ofUNKNOWN_IDENTIFIER.CI failure:
BuzzHouse (amd_msan), STID 3520-32eb,MemorySanitizer: use-of-uninitialized-valueinColumnsDescription::tryGetColumn(ColumnsDescription.cpp:877) called fromStorageBuffer::read(job, report).Root cause:
ColumnsDescription::renamere-keyed the column but left its subcolumns registered under the old storage name.hasSubcolumn,tryGetColumnandtryGetColumnDescriptionfind such a name and dereference the parent lookup, which isend(). When a new column reuses the old name, the stale entries (with the old types) become phantom subcolumns of it.Fix:
renameremoves the column's subcolumns before re-keying it and registers them again under the new name. It is the only mutator that left the subcolumn index out of sync with the columns, so no lookup site needs a guard.Validation: the new stateless test fails on master (both
serverErrorlines, and MSan aborts at:877) and passes with the fix. Same-tree MSan builds are clean with the fix for theBuffer,MergeandOPTIMIZE ... DEDUPLICATE BYshapes. 50/50 randomized runs pass, and 118 otherRENAME COLUMNtests plus 37 DeltaLake tests give identical results with and without the fix.Not addressed here: the
Memoryengine does not rename the columns of blocks stored before aRENAME COLUMN.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/122527]
Version info
26.10.1.1536-master(included in26.10and later)