This commit is contained in:
Alexander Tokmakov 2023-01-24 14:36:30 +01:00
parent 42a976fe3d
commit cd8c3bbcc5

View File

@ -379,10 +379,14 @@ void DatabaseOnDisk::renameTable(
if (dictionary && table && !table->isDictionary())
throw Exception(ErrorCodes::INCORRECT_QUERY, "Use RENAME/EXCHANGE TABLE (instead of RENAME/EXCHANGE DICTIONARY) for tables");
table_lock = table->lockExclusively(
local_context->getCurrentQueryId(), local_context->getSettingsRef().lock_acquire_timeout);
/// We have to lock the table before detaching, because otherwise lockExclusively will throw. But the table may not exist.
bool need_lock = table != nullptr;
if (need_lock)
table_lock = table->lockExclusively(local_context->getCurrentQueryId(), local_context->getSettingsRef().lock_acquire_timeout);
detachTable(local_context, table_name);
if (!need_lock)
throw Exception(ErrorCodes::LOGICAL_ERROR, "Table was detached without locking, it's a bug");
UUID prev_uuid = UUIDHelpers::Nil;
try