Repository navigation
Take referential dependencies into account in DROP DATABASE table order - #114952
Conversation
`InterpreterDropQuery::executeToDatabaseImpl` sorted the tables of a database being dropped in reverse topological order of loading dependencies only (see #97057). Now referential dependencies are taken into account as well, so a dependent is always dropped before the tables it depends on, and if the server crashes mid-drop, the remaining tables keep their dependencies intact. Implements the TODO from #114917 Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [2bb5dc5] Summary: ✅
AI ReviewSummaryThis PR updates Final VerdictStatus: ✅ Approve LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 15/16 (93.75%) · Uncovered code |
…ential-deps-order # Conflicts: # src/Interpreters/DatabaseCatalog.cpp
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units9 translation units recompiled, 35 s compile time in total, 8 of them have a recent master baseline. |
…ing DROP DATABASE `DROP DATABASE` and `DETACH DATABASE` build a local dependency graph from the union of each table's loading and referential dependencies (ClickHouse#114952). The two global graphs can disagree on the UUID of the same name: the referential node of a view gets its UUID from `ALTER`, and it survives `DROP TABLE` + `CREATE TABLE` of that name while a dictionary still depends on it. A dictionary reading that name then has the dependencies `[db.x, db.x (stale uuid)]`. In the local graph the first entry resolves to the node of the real table, and the second one takes the name-conflict branch of `addOrUpdateNode`, which removes that node. The vector overload of `addDependencies` had already stored its raw pointer, and then inserted into the freed node's `dependents`. Keep every node collected by `addDependencies` alive until the end of the call, replace `table_node` by the node that took its name (the rule the single-dependency overload already uses since ClickHouse#126292), and drop the removed nodes from the new dependency set: each of them gave its name to the node of a later dependency, which is in the set. When no node is removed, the resulting graph is the same as before. Found by La Casa Del Dolor (arm_asan_ubsan), STID 4010-5179, on PR ClickHouse#129186. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #114917
Related: #97057
InterpreterDropQuery::executeToDatabaseImplsorts the tables of a database being dropped in reverse topological order, so that a dependent is always dropped before the tables it depends on, and if the server crashes mid-drop, the remaining tables keep their dependencies intact and can be loaded on restart. Previously the ordering took only loading dependencies into account (#97057); now it takes the union of loading and referential dependencies (loading dependencies are mostly a subset of referential ones, but that is not enforced anywhere, so we merge both). This implements the TODO added in #114917, and the comment inDatabaseCatalog::checkTableCanBeRemovedOrRenamedUnlockednow simply documents the invariant.Like #97057, this comes without a functional test: within a single
DROP DATABASE, dependents from the same database are deliberately ignored by the dependency check, so the drop order is not observable without crash injection in the middle ofDROP DATABASE.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
DROP DATABASEnow drops tables in reverse topological order of both loading and referential dependencies (previously only loading dependencies), so a crash in the middle ofDROP DATABASEcannot leave a table whose dependencies were already dropped.Version info
26.8.1.1488(included in26.8and later)