From d92b1f0e9ad4d2bf20ab1a6a1861fe30f0bcc21c Mon Sep 17 00:00:00 2001 From: feng lv Date: Wed, 19 May 2021 08:56:08 +0000 Subject: [PATCH] Fix mutation of StorageMemory fix fix --- src/Storages/StorageMemory.cpp | 9 +++++- ...1867_fix_storage_memory_mutation.reference | 0 .../01867_fix_storage_memory_mutation.sql | 32 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 tests/queries/0_stateless/01867_fix_storage_memory_mutation.reference create mode 100644 tests/queries/0_stateless/01867_fix_storage_memory_mutation.sql diff --git a/src/Storages/StorageMemory.cpp b/src/Storages/StorageMemory.cpp index 289a17366bb..1deb6a6618f 100644 --- a/src/Storages/StorageMemory.cpp +++ b/src/Storages/StorageMemory.cpp @@ -262,7 +262,14 @@ void StorageMemory::mutate(const MutationCommands & commands, ContextPtr context auto metadata_snapshot = getInMemoryMetadataPtr(); auto storage = getStorageID(); auto storage_ptr = DatabaseCatalog::instance().getTable(storage, context); - auto interpreter = std::make_unique(storage_ptr, metadata_snapshot, commands, context, true); + + /// When max_threads > 1, the order of returning blocks is uncentain, + /// which will lead to inconsistency after updateBlockData. + auto new_context = Context::createCopy(context); + new_context->setSetting("max_streams_to_max_threads_ratio", 1); + new_context->setSetting("max_threads", 1); + + auto interpreter = std::make_unique(storage_ptr, metadata_snapshot, commands, new_context, true); auto in = interpreter->execute(); in->readPrefix(); diff --git a/tests/queries/0_stateless/01867_fix_storage_memory_mutation.reference b/tests/queries/0_stateless/01867_fix_storage_memory_mutation.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/01867_fix_storage_memory_mutation.sql b/tests/queries/0_stateless/01867_fix_storage_memory_mutation.sql new file mode 100644 index 00000000000..4cb80036d73 --- /dev/null +++ b/tests/queries/0_stateless/01867_fix_storage_memory_mutation.sql @@ -0,0 +1,32 @@ +DROP TABLE IF EXISTS mem_test; + +CREATE TABLE mem_test +( + `a` Int64, + `b` Int64 +) +ENGINE = Memory; + +SET max_block_size = 3; + +INSERT INTO mem_test SELECT + number, + number +FROM numbers(100); + +ALTER TABLE mem_test + UPDATE a = 0 WHERE b = 99; +ALTER TABLE mem_test + UPDATE a = 0 WHERE b = 99; +ALTER TABLE mem_test + UPDATE a = 0 WHERE b = 99; +ALTER TABLE mem_test + UPDATE a = 0 WHERE b = 99; +ALTER TABLE mem_test + UPDATE a = 0 WHERE b = 99; + +SELECT * +FROM mem_test +FORMAT Null; + +DROP TABLE mem_test;