Repository navigation
Conversation
New setting `check_named_collection_dependencies` set to true by default. When enabled, dropping a named collection that is used by any table will fail with NAMED_COLLECTION_IS_USED error. This is similar to how `check_referential_table_dependencies` works for table dependencies. The implementation uses UUID-based tracking for Atomic databases (where UUIDs persist across renames) and database+table name tracking for Ordinary databases (which don't have UUIDs).
Contributor
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a new setting check_named_collection_dependencies (enabled by default) to prevent dropping named collections that are currently in use by tables. The implementation tracks dependencies between named collections and tables using UUID-based tracking for Atomic databases and database+table name tracking for Ordinary databases.
Changes:
- Adds dependency tracking for named collections with UUID-based tracking for Atomic databases and name-based tracking for Ordinary databases
- Introduces a new error code
NAMED_COLLECTION_IS_USEDand settingcheck_named_collection_dependencies - Updates all storage engine registration functions to register table dependencies with named collections
Reviewed changes
Copilot reviewed 34 out of 35 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/queries/0_stateless/03822_named_collection_drop_dependency_check.sh | Comprehensive test cases covering Atomic and Ordinary databases, rename operations, and exchange tables |
| src/Common/ErrorCodes.cpp | Adds new error code NAMED_COLLECTION_IS_USED |
| src/Core/Settings.cpp | Adds check_named_collection_dependencies setting |
| src/Core/SettingsChangesHistory.cpp | Records new setting in version history |
| src/Common/NamedCollections/NamedCollectionsFactory.h | Defines dependency tracking data structures using Boost.MultiIndex |
| src/Common/NamedCollections/NamedCollectionsFactory.cpp | Implements dependency management methods (add, remove, rename, getDependents) |
| src/Storages/NamedCollectionsHelpers.h | Updates function signature to accept optional table_id for dependency registration |
| src/Storages/NamedCollectionsHelpers.cpp | Registers dependencies when tables use named collections |
| src/Interpreters/InterpreterDropNamedCollectionQuery.cpp | Checks for dependent tables before allowing named collection drop |
| src/Interpreters/InterpreterRenameQuery.cpp | Updates dependency tracking during table rename and exchange operations |
| src/Interpreters/DatabaseCatalog.h | Adds is_rename parameter to removeDependencies |
| src/Interpreters/DatabaseCatalog.cpp | Removes named collection dependencies when tables are dropped (except during rename) |
| src/Storages/*.cpp | Updates all storage engines to pass table_id when using named collections |
pamarcos
marked this pull request as draft
February 10, 2026 22:10
1. Verify dependent tables exist via `DatabaseCatalog` before blocking `DROP NAMED COLLECTION`, cleaning up stale entries from failed `CREATE TABLE` automatically. 2. Add `no-replicated-database` tag to stateless test that uses Ordinary database.
pamarcos
marked this pull request as ready for review
February 11, 2026 15:51
vitlibar
reviewed
Feb 16, 2026
This comes from Vitaly's suggestion. It makes more sense and keeps the code cleaner.
vitlibar
approved these changes
Feb 16, 2026
pamarcos
deleted the
prevent-named-collection-drop-if-any-table-uses-it
branch
February 17, 2026 15:27
1 task
clickgapai
pushed a commit
to clickgapai/ClickHouse
that referenced
this pull request
Oct 4, 2026
`check_named_collection_dependencies` makes `DROP NAMED COLLECTION` throw `NAMED_COLLECTION_IS_USED` only for tables that registered a dependency, and a table engine registers by passing its `StorageID` to `tryGetNamedCollectionWithOverrides`. `StorageMongoDB`'s `getConfigurationImpl` had `table_id` in scope but did not pass it: ClickHouse#96181 added the argument in 2311e59, and its branch merge 468aaca with ClickHouse#89616 (which rewrote the function) kept master's line without it. Every other table engine passes its id. So the drop succeeded under a live MongoDB table, the table could not be attached on the next restart (669), its database became unusable, and with `async_load_databases = 0` the server did not start. The new line is identical to the hunk in ClickHouse#112805. `05315_mongodb_connection_options_secrets` (ClickHouse#123240) dropped its two collections while `e06`, `e07` and `e08` still used them. Stateless CI drops the test database, but Stress keeps it and restarts the server, so master Stress jobs failed with `Cannot start clickhouse-server`. The test now expects the drop to be refused while the tables exist, drops the tables first, and pins `ast_fuzzer_any_query = 0` on every statement that names a collection: the stress profile fuzzes DDL, and a fuzzed `DETACH` of such a table hides it from the catalog, so its dependency is pruned and the collection drop succeeds (the generic detached-table hole, ClickHouse#121519); `__fuzz_N` clones would otherwise also hold the collection and make the final drop fail. Not changed: table functions (`CREATE TABLE ... AS mongodb(nc)`) register no dependency for any engine except `bigquery`; the experimental `MaterializedPostgreSQL` engine has the same omission. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
New setting
check_named_collection_dependenciesset to true by default. When enabled, dropping a named collection that is used by any table will fail with NAMED_COLLECTION_IS_USED error.This is similar to how
check_referential_table_dependenciesworks for table dependencies.The implementation uses UUID-based tracking for Atomic databases (where UUIDs persist across renames) and database+table name tracking for Ordinary databases (which don't have UUIDs).
Closes #77366
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add new check enabled by default via setting
check_named_collection_dependenciesto avoid dropping named collections used by tables.Documentation entry for user-facing changes