diff --git a/src/Storages/MergeTree/MergeTreeData.cpp b/src/Storages/MergeTree/MergeTreeData.cpp index bdb3471fb01..36ebcf825e5 100644 --- a/src/Storages/MergeTree/MergeTreeData.cpp +++ b/src/Storages/MergeTree/MergeTreeData.cpp @@ -2593,17 +2593,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