This commit is contained in:
Alexander Tokmakov 2021-01-28 22:02:39 +03:00
parent 52e5c0aad7
commit a57456a3fd
3 changed files with 12 additions and 1 deletions

View File

@ -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();

View File

@ -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)
{

View File

@ -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);