From a57456a3fd21829d22635df01404f7383ece545d Mon Sep 17 00:00:00 2001 From: Alexander Tokmakov Date: Thu, 28 Jan 2021 22:02:39 +0300 Subject: [PATCH] fix --- src/Interpreters/DDLTask.h | 1 + src/Interpreters/DDLWorker.cpp | 6 ++++++ src/Interpreters/InterpreterCreateQuery.cpp | 6 +++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Interpreters/DDLTask.h b/src/Interpreters/DDLTask.h index a12676ab8a3..5b50413b975 100644 --- a/src/Interpreters/DDLTask.h +++ b/src/Interpreters/DDLTask.h @@ -158,6 +158,7 @@ struct MetadataTransaction void addOps(Coordination::Requests & other_ops) { std::move(ops.begin(), ops.end(), std::back_inserter(other_ops)); + ops.clear(); } void commit(); diff --git a/src/Interpreters/DDLWorker.cpp b/src/Interpreters/DDLWorker.cpp index 83412ab8fb7..7b9d3ef8f5b 100644 --- a/src/Interpreters/DDLWorker.cpp +++ b/src/Interpreters/DDLWorker.cpp @@ -400,6 +400,12 @@ bool DDLWorker::tryExecuteQuery(const String & query, DDLTaskBase & task) auto query_context = task.makeQueryContext(context); query_scope.emplace(*query_context); executeQuery(istr, ostr, false, *query_context, {}); + + if (auto txn = query_context->getMetadataTransaction()) + { + if (txn->state == MetadataTransaction::CREATED) + txn->commit(); + } } catch (const DB::Exception & e) { diff --git a/src/Interpreters/InterpreterCreateQuery.cpp b/src/Interpreters/InterpreterCreateQuery.cpp index 5292ef57d7a..926737ef888 100644 --- a/src/Interpreters/InterpreterCreateQuery.cpp +++ b/src/Interpreters/InterpreterCreateQuery.cpp @@ -800,11 +800,11 @@ BlockIO InterpreterCreateQuery::createTable(ASTCreateQuery & create) String current_database = context.getCurrentDatabase(); auto database_name = create.database.empty() ? current_database : create.database; - auto database = DatabaseCatalog::instance().getDatabase(database_name); // If this is a stub ATTACH query, read the query definition from the database if (create.attach && !create.storage && !create.columns_list) { + auto database = DatabaseCatalog::instance().getDatabase(database_name); bool if_not_exists = create.if_not_exists; // Table SQL definition is available even if the table is detached (even permanently) @@ -869,7 +869,11 @@ BlockIO InterpreterCreateQuery::createTable(ASTCreateQuery & create) } //TODO make code better if possible + DatabasePtr database; bool need_add_to_database = !create.temporary; + if (need_add_to_database) + database = DatabaseCatalog::instance().getDatabase(database_name); + if (need_add_to_database && database->getEngineName() == "Replicated") { auto guard = DatabaseCatalog::instance().getDDLGuard(create.database, create.table);