From 5a8d61954a6884b1c403933338850b340d226d5f Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Thu, 13 May 2021 22:24:20 +0300 Subject: [PATCH] Call IStorage::flush() for each table on DETACH DATABASE before shutdown --- src/Interpreters/InterpreterDropQuery.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Interpreters/InterpreterDropQuery.cpp b/src/Interpreters/InterpreterDropQuery.cpp index 8a9da0cbb0a..24cff90caea 100644 --- a/src/Interpreters/InterpreterDropQuery.cpp +++ b/src/Interpreters/InterpreterDropQuery.cpp @@ -328,6 +328,14 @@ BlockIO InterpreterDropQuery::executeToDatabaseImpl(const ASTDropQuery & query, query_for_table.database = database_name; query_for_table.no_delay = query.no_delay; + /// Flush should not be done if shouldBeEmptyOnDetach() == false, + /// since in this case getTablesIterator() may do some additional work, + /// see DatabaseMaterializeMySQL<>::getTablesIterator() + for (auto iterator = database->getTablesIterator(getContext()); iterator->isValid(); iterator->next()) + { + iterator->table()->flush(); + } + for (auto iterator = database->getTablesIterator(getContext()); iterator->isValid(); iterator->next()) { DatabasePtr db;