How to reproduce bug:

```

CREATE TABLE broken_partition
(
    date Date,
    key UInt64
)
ENGINE = ReplicatedMergeTree('/clickhouse/test_01925_{database}/rmt', 'r1')
ORDER BY tuple()
PARTITION BY date;

ALTER TABLE broken_partition DROP PARTITION ID '20210325_0_13241_6_12747';

ALTER TABLE broken_partition DROP PARTITION ID '20210325_0_13241_6_12747';

2021.06.25 16:56:47.994597 [ 12133 ] {} <Fatal> BaseDaemon: (version 21.7.1.1, build id: 4D0F6EE29A7F8AAB48AB6DE9984AB510674ABDB0) (from thread 12263) Terminate called for uncaught exception:                                                
2021.06.25 16:56:47.995991 [ 12396 ] {} <Fatal> BaseDaemon: ########################################                                                                                                                                           
2021.06.25 16:56:47.996217 [ 12396 ] {} <Fatal> BaseDaemon: (version 21.7.1.1, build id: 4D0F6EE29A7F8AAB48AB6DE9984AB510674ABDB0) (from thread 12263) (no query) Received signal Aborted (6)                                                  
2021.06.25 16:56:47.996344 [ 12396 ] {} <Fatal> BaseDaemon:                                                                                                                                                                                    
2021.06.25 16:56:47.996526 [ 12396 ] {} <Fatal> BaseDaemon: Stack trace: 0x7f375eecff47 0x7f375eed18b1 0x1c54e134 0x257f0e92 0x257f0dc2 0x1e1a4fe8 0x1dc44bc7 0x1dc84558 0x1dc844fd 0x1dc844bd 0x1dc84495 0x1dc8445d 0x12a90069 0x12a8f195 0x1c
db2aca 0x1cdb70c6 0x1cdb4a00 0x1cdb5bf8 0x1cdb5bbd 0x1cdb5b61 0x1cdb5a72 0x1cdb5967 0x1cdb587d 0x1cdb583d 0x1cdb5815 0x1cdb57e0 0x12a90069 0x12a8f195 0x12ab5a2e 0x12abcd44 0x12abcc9d 0x12abcbc5 0x12abc4e2 0x7f375f6956db 0x7f375efb2a3f     
2021.06.25 16:56:47.997902 [ 12396 ] {} <Fatal> BaseDaemon: 4. /build/glibc-2ORdQG/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51: raise @ 0x3ef47 in /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.27.so                                
2021.06.25 16:56:48.002153 [ 12396 ] {} <Fatal> BaseDaemon: 5. /build/glibc-2ORdQG/glibc-2.27/stdlib/abort.c:81: __GI_abort @ 0x408b1 in /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.27.so                                                      
2021.06.25 16:56:48.321740 [ 12396 ] {} <Fatal> BaseDaemon: 6. /home/alesap/code/cpp/ClickHouse/base/daemon/BaseDaemon.cpp:435: terminate_handler() @ 0x1c54e134 in /home/alesap/code/cpp/BuildCH/programs/clickhouse                          
2021.06.25 16:56:48.384684 [ 12396 ] {} <Fatal> BaseDaemon: 7. /home/alesap/code/cpp/ClickHouse/contrib/libcxxabi/src/cxa_handlers.cpp:59: std::__terminate(void (*)()) @ 0x257f0e92 in /home/alesap/code/cpp/BuildCH/programs/clickhouse      
2021.06.25 16:56:48.447969 [ 12396 ] {} <Fatal> BaseDaemon: 8. /home/alesap/code/cpp/ClickHouse/contrib/libcxxabi/src/cxa_handlers.cpp:89: std::terminate() @ 0x257f0dc2 in /home/alesap/code/cpp/BuildCH/programs/clickhouse                  
2021.06.25 16:56:49.112745 [ 12396 ] {} <Fatal> BaseDaemon: 9. /home/alesap/code/cpp/ClickHouse/src/Storages/MergeTree/ReplicatedMergeTreeQueue.cpp:608: DB::ReplicatedMergeTreeQueue::pullLogsToQueue(std::__1::shared_ptr<zkutil::ZooKeeper>,
 std::__1::function<void (Coordination::WatchResponse const&)>) @ 0x1e1a4fe8 in /home/alesap/code/cpp/BuildCH/programs/clickhouse                                                                                                              
2021.06.25 16:56:50.151217 [ 12396 ] {} <Fatal> BaseDaemon: 10. /home/alesap/code/cpp/ClickHouse/src/Storages/StorageReplicatedMergeTree.cpp:3052: DB::StorageReplicatedMergeTree::queueUpdatingTask() @ 0x1dc44bc7 in /home/alesap/code/cpp/Bu
ildCH/programs/clickhouse                                                                                                                                                                                                                      
2021.06.25 16:56:51.262776 [ 12396 ] {} <Fatal> BaseDaemon: 11. /home/alesap/code/cpp/ClickHouse/src/Storages/StorageReplicatedMergeTree.cpp:298: DB::StorageReplicatedMergeTree::StorageReplicatedMergeTree(std::__1::basic_string<char, std::
__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool, DB::StorageID const&, std::__1::basic_string<char, std::__1::char_traits<char>,
 std::__1::allocator<char> > const&, DB::StorageInMemoryMetadata const&, std::__1::shared_ptr<DB::Context>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::MergeTreeData::MergingParams cons
t&, std::__1::unique_ptr<DB::MergeTreeSettings, std::__1::default_delete<DB::MergeTreeSettings> >, bool, bool)::$_3::operator()() const @ 0x1dc84558 in /home/alesap/code/cpp/BuildCH/programs/clickhouse                                      
2021.06.25 16:56:52.400173 [ 12396 ] {} <Fatal> BaseDaemon: 12. /home/alesap/code/cpp/ClickHouse/contrib/libcxx/include/type_traits:3676: decltype(std::__1::forward<DB::StorageReplicatedMergeTree::StorageReplicatedMergeTree(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool, DB::StorageID const&, std::__1::basic_string<char, std::__1:
:char_traits<char>, std::__1::allocator<char> > const&, DB::StorageInMemoryMetadata const&, std::__1::shared_ptr<DB::Context>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::MergeTreeData:
:MergingParams const&, std::__1::unique_ptr<DB::MergeTreeSettings, std::__1::default_delete<DB::MergeTreeSettings> >, bool, bool)::$_3&>(fp)()) std::__1::__invoke<DB::StorageReplicatedMergeTree::StorageReplicatedMergeTree(std::__1::basic_s
tring<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool, DB::StorageID const&, std::__1::basic_string<char, std::__1::c
har_traits<char>, std::__1::allocator<char> > const&, DB::StorageInMemoryMetadata const&, std::__1::shared_ptr<DB::Context>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::MergeTreeData::MergingParams const&, std::__1::unique_ptr<DB::MergeTreeSettings, std::__1::default_delete<DB::MergeTreeSettings> >, bool, bool)::$_3&>(DB::StorageReplicatedMergeTree::StorageReplicatedMergeTree(std::__1::basic_string<char, std::__1::char_t
raits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool, DB::StorageID const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::
allocator<char> > const&, DB::StorageInMemoryMetadata const&, std::__1::shared_ptr<DB::Context>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::MergeTreeData::MergingParams const&, std::__
1::unique_ptr<DB::MergeTreeSettings, std::__1::default_delete<DB::MergeTreeSettings> >, bool, bool)::$_3&) @ 0x1dc844fd in /home/alesap/code/cpp/BuildCH/programs/clickhouse                                                                   
2021.06.25 16:56:53.487741 [ 12396 ] {} <Fatal> BaseDaemon: 13. /home/alesap/code/cpp/ClickHouse/contrib/libcxx/include/__functional_base:349: void std::__1::__invoke_void_return_wrapper<void>::__call<DB::StorageReplicatedMergeTree::StorageReplicatedMergeTree(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool, DB::StorageID const&, st
d::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::StorageInMemoryMetadata const&, std::__1::shared_ptr<DB::Context>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocato
r<char> > const&, DB::MergeTreeData::MergingParams const&, std::__1::unique_ptr<DB::MergeTreeSettings, std::__1::default_delete<DB::MergeTreeSettings> >, bool, bool)::$_3&>(DB::StorageReplicatedMergeTree::StorageReplicatedMergeTree(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool, DB::StorageID const&, std::__1::basic_string<char, s
td::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::StorageInMemoryMetadata const&, std::__1::shared_ptr<DB::Context>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::MergeT
reeData::MergingParams const&, std::__1::unique_ptr<DB::MergeTreeSettings, std::__1::default_delete<DB::MergeTreeSettings> >, bool, bool)::$_3&) @ 0x1dc844bd in /home/alesap/code/cpp/BuildCH/programs/clickhouse                             
2021.06.25 16:56:54.585446 [ 12396 ] {} <Fatal> BaseDaemon: 14. /home/alesap/code/cpp/ClickHouse/contrib/libcxx/include/functional:1608: std::__1::__function::__default_alloc_func<DB::StorageReplicatedMergeTree::StorageReplicatedMergeTree(
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool, DB::StorageID const&, std::__1::basic_string<
char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::StorageInMemoryMetadata const&, std::__1::shared_ptr<DB::Context>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::MergeTreeData::MergingParams const&, std::__1::unique_ptr<DB::MergeTreeSettings, std::__1::default_delete<DB::MergeTreeSettings> >, bool, bool)::$_3, void ()>::operator()() @ 0x1dc84495 in /home/alesap/code/cpp/BuildCH/programs/clickhouse
2021.06.25 16:56:55.697832 [ 12396 ] {} <Fatal> BaseDaemon: 15. /home/alesap/code/cpp/ClickHouse/contrib/libcxx/include/functional:2089: void std::__1::__function::__policy_invoker<void ()>::__call_impl<std::__1::__function::__default_alloc_func<DB::StorageReplicatedMergeTree::StorageReplicatedMergeTree(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<c
har> > const&, bool, DB::StorageID const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::StorageInMemoryMetadata const&, std::__1::shared_ptr<DB::Context>, std::__1::basic_string<char, st
d::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::MergeTreeData::MergingParams const&, std::__1::unique_ptr<DB::MergeTreeSettings, std::__1::default_delete<DB::MergeTreeSettings> >, bool, bool)::$_3, void ()> >(std::__1::_
_function::__policy_storage const*) @ 0x1dc8445d in /home/alesap/code/cpp/BuildCH/programs/clickhouse
2021.06.25 16:56:55.899475 [ 12396 ] {} <Fatal> BaseDaemon: 16. /home/alesap/code/cpp/ClickHouse/contrib/libcxx/include/functional:2221: std::__1::__function::__policy_func<void ()>::operator()() const @ 0x12a90069 in /home/alesap/code/cpp
/BuildCH/programs/clickhouse
2021.06.25 16:56:56.106791 [ 12396 ] {} <Fatal> BaseDaemon: 17. /home/alesap/code/cpp/ClickHouse/contrib/libcxx/include/functional:2560: std::__1::function<void ()>::operator()() const @ 0x12a8f195 in /home/alesap/code/cpp/BuildCH/programs
/clickhouse
2021.06.25 16:56:56.207032 [ 12396 ] {} <Fatal> BaseDaemon: 18. /home/alesap/code/cpp/ClickHouse/src/Core/BackgroundSchedulePool.cpp:106: DB::BackgroundSchedulePoolTaskInfo::execute() @ 0x1cdb2aca in /home/alesap/code/cpp/BuildCH/programs/
clickhouse
2021.06.25 16:56:56.317005 [ 12396 ] {} <Fatal> BaseDaemon: 19. /home/alesap/code/cpp/ClickHouse/src/Core/BackgroundSchedulePool.cpp:19: DB::TaskNotification::execute() @ 0x1cdb70c6 in /home/alesap/code/cpp/BuildCH/programs/clickhouse
2021.06.25 16:56:56.420614 [ 12396 ] {} <Fatal> BaseDaemon: 20. /home/alesap/code/cpp/ClickHouse/src/Core/BackgroundSchedulePool.cpp:265: DB::BackgroundSchedulePool::threadFunction() @ 0x1cdb4a00 in /home/alesap/code/cpp/BuildCH/programs/c
lickhouse
2021.06.25 16:56:56.532224 [ 12396 ] {} <Fatal> BaseDaemon: 21. /home/alesap/code/cpp/ClickHouse/src/Core/BackgroundSchedulePool.cpp:161: DB::BackgroundSchedulePool::BackgroundSchedulePool(unsigned long, unsigned long, char const*)::$_1::o
perator()() const @ 0x1cdb5bf8 in /home/alesap/code/cpp/BuildCH/programs/clickhouse

```
extern const int NO_SUCH_DATA_PART;
    extern const int NOT_IMPLEMENTED;
    extern const int DIRECTORY_ALREADY_EXISTS;
    extern const int TOO_MANY_UNEXPECTED_DATA_PARTS;
    extern const int DUPLICATE_DATA_PART;
    extern const int NO_SUCH_COLUMN_IN_TABLE;
    extern const int LOGICAL_ERROR;
    extern const int ILLEGAL_COLUMN;
    extern const int ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER;
    extern const int CORRUPTED_DATA;
    extern const int BAD_TYPE_OF_FIELD;
    extern const int BAD_ARGUMENTS;
    extern const int INVALID_PARTITION_VALUE;
    extern const int METADATA_MISMATCH;
    extern const int PART_IS_TEMPORARILY_LOCKED;
    extern const int TOO_MANY_PARTS;
    extern const int INCOMPATIBLE_COLUMNS;
    extern const int BAD_TTL_EXPRESSION;
    extern const int INCORRECT_FILE_NAME;
    extern const int BAD_DATA_PART_NAME;
    extern const int READONLY_SETTING;
    extern const int ABORTED;
    extern const int UNKNOWN_PART_TYPE;
    extern const int UNKNOWN_DISK;
    extern const int NOT_ENOUGH_SPACE;
    extern const int ALTER_OF_COLUMN_IS_FORBIDDEN;
    extern const int SUPPORT_IS_DISABLED;
    extern const int TOO_MANY_SIMULTANEOUS_QUERIES;
}
static void checkSampleExpression(const StorageInMemoryMetadata & metadata, bool allow_sampling_expression_not_in_primary_key, bool check_sample_column_is_correct)