Repository navigation
Conversation
…ructing it `validateStorage` checked the column names against the virtual columns of the engine only after `StorageFactory` had built the table, and undid a rejected `CREATE` with `IStorage::drop()` (DROP TABLE semantics). The MergeTree constructors have already taken the data path by then and, for `ReplicatedMergeTree`, registered the replica in Keeper. With `table_disk = 1` the data path is the disk root, which the constructor accepts while it holds only detached parts of another table (adopting them is the documented workflow), so `dropAllData()` deleted those parts. Reproduced on 26.3.33.24, 26.8.21.12 and master. The check needs nothing from the constructed table: its inputs (the final columns and `MergeTreeData::createVirtuals`) are known in the factory. Move the loop of `validateVirtualColumns` into `throwIfColumnsConflictWithVirtuals` in `StorageFactory` and call it from `registerStorageMergeTree` in `CREATE` mode before the constructors, like the factory's other CREATE-only checks and `throwIfUnreplicatedTableDataNotAllowed`. The reserved-name part uses the interpreter's predicate (`allow_reserved_column_names` of the same context, not for replayed definitions). The factory also runs `checkAllTypesAreAllowedInTable` on the final columns, since a columnless `ReplicatedMergeTree` takes them from Keeper after `StorageFactory::get` checked the empty list; that was the only other check `validateStorage` could reject a MergeTree table with. A rejected definition now constructs nothing, so there is nothing to roll back. `validateStorage` is unchanged and still covers the other engines and `ATTACH`; ATTACH, startup and `RESTART REPLICA` never reach the new call. Related: ClickHouse#115958 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Rewrite the factory check's comment as a one-line invariant without the reference to InterpreterCreateQuery. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review: my own cold review plus an independent model (engine: codex); 3 findings, all nits, no fix round needed.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-11:20261119-041501 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261119-021200 |
|
Workflow [PR], commit [b0e7229] Summary: ✅
AI ReviewSummaryMoves virtual-column and final-column-type validation before Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units189 translation units recompiled, 1352 s compile time in total, 189 of them have a recent master baseline. |
CI finish ledger - 765375dEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The other CIDB Session id: cron:our-pr-ci-monitor:20261119-080025 |
Related: #115958 (comment)
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A
CREATE TABLEof aMergeTreetable that is rejected for a column named like a virtual column (for example_row_exists) no longer deletes the data already stored at the root of a disk withtable_disk = 1, such as detached parts of another table: the definition is now refused before the table is constructed.Description
On 26.8.21.12 (and 26.3.33.24), a
CREATE TABLEwithtable_disk = 1that is rejected for a column named_row_existsdeletes the detached parts already stored at the root of its disk.A
table_diskroot may hold only detached parts of another table, and a new table may be created there to adopt them.validateStoragechecks the column names against the virtual columns only afterStorageFactoryhas built the table, and undoes a rejectedCREATEwithIStorage::drop(). For MergeTree that isdropAllData(), which removes every detached part under the root (and, forReplicatedMergeTree, the replica the constructor has just registered).The check needs nothing from the constructed table, so I moved it into
throwIfColumnsConflictWithVirtualsinStorageFactory(the code is unchanged) and call it from the MergeTree factory inCREATEmode, before the constructors, next to its otherCREATE-only checks. A rejected definition now constructs nothing, so there is nothing to roll back. The interpreter keeps calling the same function for the other engines and forATTACH; for thosevalidateStorageis unchanged. The factory also re-checks the column types there, because a columnlessReplicatedMergeTreetakes its columns from Keeper afterStorageFactorychecked them.The same statements are refused as before, only earlier;
ATTACH, server startup andRESTART REPLICAare not affected.Validation: the new test fails on master (the detached part and its 3 rows are gone after the rejected
CREATE, forMergeTreeandReplicatedMergeTree) and passes with the fix, 50/50 with randomized settings; removing the new call or limiting it toATTACHmakes it fail again.Workflow [PR]
Sync PR [sync-upstream/pr/132874]