diff --git a/src/Interpreters/InterpreterDropQuery.cpp b/src/Interpreters/InterpreterDropQuery.cpp index c70431e5238..5cc14f93530 100644 --- a/src/Interpreters/InterpreterDropQuery.cpp +++ b/src/Interpreters/InterpreterDropQuery.cpp @@ -52,7 +52,7 @@ BlockIO InterpreterDropQuery::execute() return executeToDictionary(drop.database, drop.table, drop.kind, drop.if_exists, drop.temporary, drop.no_ddl_lock); } else if (!drop.database.empty()) - return executeToDatabase(drop.database, drop.kind, drop.if_exists); + return executeToDatabase(drop.database, drop.kind, drop.if_exists, drop.no_delay); else throw Exception("Nothing to drop, both names are empty", ErrorCodes::LOGICAL_ERROR); } @@ -223,7 +223,7 @@ BlockIO InterpreterDropQuery::executeToTemporaryTable(const String & table_name, } -BlockIO InterpreterDropQuery::executeToDatabase(const String & database_name, ASTDropQuery::Kind kind, bool if_exists) +BlockIO InterpreterDropQuery::executeToDatabase(const String & database_name, ASTDropQuery::Kind kind, bool if_exists, bool no_delay) { auto ddl_guard = DatabaseCatalog::instance().getDDLGuard(database_name, ""); @@ -252,8 +252,12 @@ BlockIO InterpreterDropQuery::executeToDatabase(const String & database_name, AS ASTDropQuery query; query.kind = kind; query.database = database_name; + query.no_delay = no_delay; + for (auto iterator = database->getTablesIterator(context); iterator->isValid(); iterator->next()) { + /// Reset reference counter of the StoragePtr to allow synchronous drop. + iterator->reset(); query.table = iterator->name(); executeToTable({query.database, query.table}, query); } diff --git a/src/Interpreters/InterpreterDropQuery.h b/src/Interpreters/InterpreterDropQuery.h index b54736b5c21..1e0118c49d8 100644 --- a/src/Interpreters/InterpreterDropQuery.h +++ b/src/Interpreters/InterpreterDropQuery.h @@ -29,7 +29,7 @@ private: ASTPtr query_ptr; Context & context; - BlockIO executeToDatabase(const String & database_name, ASTDropQuery::Kind kind, bool if_exists); + BlockIO executeToDatabase(const String & database_name, ASTDropQuery::Kind kind, bool if_exists, bool no_delay); BlockIO executeToTable(const StorageID & table_id, const ASTDropQuery & query); diff --git a/src/Parsers/ParserDropQuery.cpp b/src/Parsers/ParserDropQuery.cpp index 31a6250a006..e09642e7b84 100644 --- a/src/Parsers/ParserDropQuery.cpp +++ b/src/Parsers/ParserDropQuery.cpp @@ -46,6 +46,9 @@ bool parseDropQuery(IParser::Pos & pos, ASTPtr & node, Expected & expected, bool if (!ASTQueryWithOnCluster::parse(pos, cluster_str, expected)) return false; } + + if (s_no_delay.ignore(pos, expected) || s_sync.ignore(pos, expected)) + no_delay = true; } else { diff --git a/tests/queries/0_stateless/01530_drop_database_atomic_sync.reference b/tests/queries/0_stateless/01530_drop_database_atomic_sync.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/01530_drop_database_atomic_sync.sql b/tests/queries/0_stateless/01530_drop_database_atomic_sync.sql new file mode 100644 index 00000000000..010b8931448 --- /dev/null +++ b/tests/queries/0_stateless/01530_drop_database_atomic_sync.sql @@ -0,0 +1,34 @@ +drop database if exists db_01530_atomic sync; + +create database db_01530_atomic Engine=Atomic; +create table db_01530_atomic.data (key Int) Engine=ReplicatedMergeTree('/clickhouse/tables/db_01530_atomic/data', 'test') order by key; +drop database db_01530_atomic sync; + +create database db_01530_atomic Engine=Atomic; +create table db_01530_atomic.data (key Int) Engine=ReplicatedMergeTree('/clickhouse/tables/db_01530_atomic/data', 'test') order by key; +drop database db_01530_atomic sync; + + +set database_atomic_wait_for_drop_and_detach_synchronously=1; + +create database db_01530_atomic Engine=Atomic; +create table db_01530_atomic.data (key Int) Engine=ReplicatedMergeTree('/clickhouse/tables/db_01530_atomic/data', 'test') order by key; +drop database db_01530_atomic; + +create database db_01530_atomic Engine=Atomic; +create table db_01530_atomic.data (key Int) Engine=ReplicatedMergeTree('/clickhouse/tables/db_01530_atomic/data', 'test') order by key; +drop database db_01530_atomic; + + +set database_atomic_wait_for_drop_and_detach_synchronously=0; + +create database db_01530_atomic Engine=Atomic; +create table db_01530_atomic.data (key Int) Engine=ReplicatedMergeTree('/clickhouse/tables/db_01530_atomic/data', 'test') order by key; +drop database db_01530_atomic; + +create database db_01530_atomic Engine=Atomic; +create table db_01530_atomic.data (key Int) Engine=ReplicatedMergeTree('/clickhouse/tables/db_01530_atomic/data', 'test') order by key; -- { serverError 253; } +-- TODO: SYSTEM FORCE DROP and uncomment the line below to cleanup the data after test +-- (otherwise the test is not retriable...) +-- +-- drop database db_01530_atomic sync;