diff --git a/src/Storages/MergeTree/MergeTreeData.cpp b/src/Storages/MergeTree/MergeTreeData.cpp index 764f5d7adf7..86cbd9f1484 100644 --- a/src/Storages/MergeTree/MergeTreeData.cpp +++ b/src/Storages/MergeTree/MergeTreeData.cpp @@ -2588,17 +2588,25 @@ void MergeTreeData::tryRemovePartImmediately(DataPartPtr && part) LOG_TRACE(log, "Trying to immediately remove part {}", part->getNameWithState()); - auto it = data_parts_by_info.find(part->info); - if (it == data_parts_by_info.end() || (*it).get() != part.get()) - throw Exception("Part " + part->name + " doesn't exist", ErrorCodes::LOGICAL_ERROR); + if (part->getState() != DataPartState::Temporary) + { + auto it = data_parts_by_info.find(part->info); + if (it == data_parts_by_info.end() || (*it).get() != part.get()) + throw Exception("Part " + part->name + " doesn't exist", ErrorCodes::LOGICAL_ERROR); - part.reset(); + part.reset(); - if (!((*it)->getState() == DataPartState::Outdated && it->unique())) - return; + if (!((*it)->getState() == DataPartState::Outdated && it->unique())) + return; - modifyPartState(it, DataPartState::Deleting); - part_to_delete = *it; + modifyPartState(it, DataPartState::Deleting); + + part_to_delete = *it; + } + else + { + part_to_delete = std::move(part); + } } try