diff --git a/dbms/src/Debug/MockTiDB.cpp b/dbms/src/Debug/MockTiDB.cpp index 90626ae69dd..09bb114c86c 100644 --- a/dbms/src/Debug/MockTiDB.cpp +++ b/dbms/src/Debug/MockTiDB.cpp @@ -263,10 +263,45 @@ int MockTiDB::newTables( Timestamp tso, const String & engine_type) { + std::lock_guard lock(tables_mutex); + if (databases.find(database_name) == databases.end()) + { + throw Exception("MockTiDB not found db: " + database_name, ErrorCodes::LOGICAL_ERROR); + } + + version++; + SchemaDiff diff; + diff.type = SchemaActionType::CreateTables; for (const auto & [table_name, columns, handle_pk_name] : tables) { - newTable(database_name, table_name, columns, tso, handle_pk_name, engine_type); + String qualified_name = database_name + "." + table_name; + if (tables_by_name.find(qualified_name) != tables_by_name.end()) + { + throw Exception("Mock TiDB table " + qualified_name + " already exists", ErrorCodes::TABLE_ALREADY_EXISTS); + } + + auto table_info = *parseColumns(table_name, columns, handle_pk_name, engine_type); + table_info.id = table_id_allocator++; + table_info.update_timestamp = tso; + + auto table = std::make_shared