Repository navigation
Allow ALTER of column type when its key subcolumns are unchanged - #113862
Conversation
ALTER MODIFY COLUMN was forbidden for any column whose subcolumns are used in the primary or partition key, even when the ALTER did not change those subcolumns. Relax the check: allow the ALTER as long as every key subcolumn keeps an on-disk-compatible type (isSafeForKeyConversion) - the same rule already applied to top-level key columns - and reject it only when a used key subcolumn changes unsafely. Other subcolumns of the column may change freely. Closes: #92808 Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Workflow [PR], commit [5cfc428] Summary: ❌
AI ReviewSummaryThis PR relaxes Findings❌ Blockers
Tests
Final Verdict❌ Not ready. The key-subcolumn safety check is improved, but the new allowance still leaves persisted derived state inconsistent after valid LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 30/50 (60.00%) · Uncovered code |
…mn is unchanged The `my.tuple` ALTER only adds an unrelated element `b` while the key subcolumn `my.tuple.a` stays the same, which is now allowed. The JSON case above stays forbidden because its key subcolumn `my.json.b` changes type. Co-Authored-By: Claude Opus 4.8 <[email protected]>
In the key-subcolumn safety check, the new subcolumn could be absent when an ALTER removes it (e.g. drops a Tuple element). Relying on chassert made this undefined behavior in release builds. Replace it with an explicit runtime check that throws ALTER_OF_COLUMN_IS_FORBIDDEN, and add a regression test. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Looks good, but please check the AI Review |
They are not actionable in this PR. The mentioned code in mutations is fixed in #112717 |
Closes: #92808
Related: #112302
ALTER MODIFY COLUMN was forbidden for any column whose subcolumns are used in the primary or partition key, even when the ALTER did not change those subcolumns (e.g. adding an unrelated typed path to a
JSONcolumn, adjusting a parameter, orSKIP-ing a path, while the key subcolumn stays the same).This relaxes the check to mirror how top-level key columns are handled: the ALTER is allowed as long as every key subcolumn keeps an on-disk-compatible type (
isSafeForKeyConversion), and is rejected only when a used key subcolumn changes unsafely. Other subcolumns of the column may change freely. A mutation does not re-sort data, so a key subcolumn must convert the same order-preserving way a top-level key column does; the mutation then rebuildsprimary.idxfrom the new data.Similar subcolumn-level checks are added for the lazy
JSONtype-hint ALTER path in #112302; this PR does the same for the regular (mutation) ALTER path and should be merged after it.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Allow
ALTER TABLE ... MODIFY COLUMNof a column whose subcolumns are used in the primary or partition key, as long as the subcolumns used in the key keep an on-disk-compatible type. Previously any such ALTER was forbidden.