Repository navigation
Fix wrong column type in part after compound RENAME COLUMN swap - #107064
alexey-milovidov merged 2 commits into
Conversation
A compound ALTER that reuses a freed column name across columns of
different types, e.g.
RENAME COLUMN ip TO ip_v4, RENAME COLUMN ip_v6 TO ip
wrote the wrong type into the materialized part's columns.txt. In
getColumnsForNewDataPart (MutateTask.cpp), the new column "ip" (target
of "ip_v6 TO ip") found a same-named source column "ip" - the old one
being renamed away to "ip_v4" - and took its type (UInt32) instead of
the renamed-from column "ip_v6" type (IPv6). The data files were
renamed correctly, so the part ended up with the IPv6 column declared
as UInt32.
At read time this produces CAST UInt32 -> IPv6 (Code 48, "Conversion
between numeric types and IPv6 is not supported") on release builds, or
an assertion on part load in debug builds ("Column `ip` has rows count
8 ... but data part has 2 rows", because 32 IPv6 bytes are interpreted
as 8 UInt32 values).
The kept-column branch only special-cased DROP xxx + RENAME yyy TO xxx
(was_removed). Generalize it to any column renamed into this name
(renamed_columns_to_from), which also covers the swap, so the type and
substreams come from the renamed-from source column.
Closes: ClickHouse#103247
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-5:20260610-191053 |
|
cc @CurtizJ @alesapin could you review this? It fixes a data-corruption bug in mutation part writing: a compound RENAME that swaps a column name between columns of different types (RENAME a TO b, RENAME c TO a) made getColumnsForNewDataPart record the renamed-away column's type for the new column, so the part's columns.txt ended up with the wrong type (IPv6 declared as UInt32), failing SELECT with Code 48 / aborting on part load. Closes #103247. |
|
Workflow [PR], commit [fb9bbc7] Summary: ✅
AI ReviewSummaryThis PR fixes Final VerdictStatus: ✅ Approve |
Adds regression coverage for the case raised in code review: ADD COLUMN ip_v6 (never materialized in existing parts) followed by the compound swap RENAME ip TO ip_v4, RENAME ip_v6 TO ip. Covered both as a metadata-only rename and with a non-key UPDATE in the same ALTER that forces the part to be rewritten by the mutation, so getColumnsForNewDataPart actually processes the part while the renamed-from column has no data. In every case the new ip is correctly dropped from the part (the reader default-fills it) and the old ip becomes ip_v4. These pass on the current fix, confirming the unmaterialized swap does not regress. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (updated for fb9bbc7)This update is test-only (extends
Session id: cron:clickhouse-worker-slot-16:20260611-001100 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 4/4 (100.00%) | Lost baseline coverage: none · Uncovered code |
|
Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment. TL;DRFix wrong column type in part after compound RENAME COLUMN swap ClickGap verified: reproduced it with the script below on ReproductionBisect
Affects
Suggested next stepThe fix has landed on master; the affected release branches above still need the backport. Component: cc fix PR author: @groeneai ClickGap · Finding: Triage metadata
|
Backport #107064 to 26.3: Fix wrong column type in part after compound RENAME COLUMN swap
…er compound RENAME COLUMN swap
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a compound
ALTER TABLE ... RENAME COLUMN a TO b, RENAME COLUMN c TO athat reuses a freed column name (a "swap") between columns of different types. The materialized part recorded the wrong column type, so a laterSELECTfailed withConversion between numeric types and IPv6 is not supported(or aborted on part load in debug builds).Description
Reported in #103247 (cc @ den-crane). Reproducer:
Root cause is in
getColumnsForNewDataPart(src/Storages/MergeTree/MutateTask.cpp). When building the new part's column list, the target columnip(fromRENAME ip_v6 TO ip) still finds a same-named source columnip(the old one being renamed away toip_v4) and took its type (UInt32) instead of the renamed-from columnip_v6type (IPv6). The.bindata files are renamed correctly, so the part ends up with the IPv6 column declared asUInt32.On read this produces
_CAST(UInt32, 'IPv6')(Code 48) on release builds, or an assertion on part load in debug builds (Column ip has rows count 8 ... but data part has 2 rows, because the 16-byte IPv6 values are read as 4-byte UInt32).The kept-column branch previously special-cased only
DROP a, RENAME c TO a(was_removed). The fix generalizes it to any column renamed into this name (renamed_columns_to_from), which also covers the swap, so both the type and the substreams come from the renamed-from source column. The table metadata was already correct; only the part'scolumns.txttype was wrong.Added regression test
03990_alter_rename_column_swap_different_typescovering the swap on both compact and wide parts, plus the existingDROP + RENAME intocase to guard against regressing it. The existing01278_alter_rename_combinationtest exercises the swap pattern but with all-Int32columns, so the wrong type was coincidentally identical and the bug was invisible.Version info
26.6.1.953-master(included in26.6and later)26.3.33.146