diff --git a/src/Storages/StorageMergeTree.cpp b/src/Storages/StorageMergeTree.cpp index b710965271e..ab42da1dfa0 100644 --- a/src/Storages/StorageMergeTree.cpp +++ b/src/Storages/StorageMergeTree.cpp @@ -1447,6 +1447,11 @@ void StorageMergeTree::replacePartitionFrom(const StoragePtr & source_table, con void StorageMergeTree::movePartitionToTable(const StoragePtr & dest_table, const ASTPtr & partition, ContextPtr local_context) { + /// MOVE PARTITION cannot be run in parallel with merges/mutations, + /// since otherwise there can be some merge/mutation in progress, + /// that will be created in the source table after MOVE PARTITION. + std::unique_lock background_lock(currently_processing_in_background_mutex); + auto lock1 = lockForShare(local_context->getCurrentQueryId(), local_context->getSettingsRef().lock_acquire_timeout); auto lock2 = dest_table->lockForShare(local_context->getCurrentQueryId(), local_context->getSettingsRef().lock_acquire_timeout); @@ -1509,7 +1514,6 @@ void StorageMergeTree::movePartitionToTable(const StoragePtr & dest_table, const transaction.commit(&lock); } - clearOldMutations(true); clearOldPartsFromFilesystem(); PartLog::addNewParts(getContext(), dst_parts, watch.elapsed());