From 4769ce727176007239387909a30a1e5a7d11453a Mon Sep 17 00:00:00 2001 From: Anton Popov Date: Fri, 29 May 2020 02:59:13 +0300 Subject: [PATCH] in-memory parts: several fixes --- src/Storages/MergeTree/MergeTreeData.cpp | 2 +- .../MergeTree/MergeTreeDataPartInMemory.h | 2 +- .../MergeTree/MergeTreeReaderInMemory.cpp | 2 +- src/Storages/StorageMergeTree.cpp | 13 +++++++----- .../01130_in_memory_parts_default.reference | 1 + .../01130_in_memory_parts_default.sql | 20 +++++++++++++++++++ 6 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 tests/queries/0_stateless/01130_in_memory_parts_default.reference create mode 100644 tests/queries/0_stateless/01130_in_memory_parts_default.sql diff --git a/src/Storages/MergeTree/MergeTreeData.cpp b/src/Storages/MergeTree/MergeTreeData.cpp index c6bc54eabe8..d9b6b5e8780 100644 --- a/src/Storages/MergeTree/MergeTreeData.cpp +++ b/src/Storages/MergeTree/MergeTreeData.cpp @@ -1351,7 +1351,7 @@ void MergeTreeData::clearOldWriteAheadLogs() auto is_range_on_disk = [&block_numbers_on_disk](Int64 min_block, Int64 max_block) { - auto lower = std::upper_bound(block_numbers_on_disk.begin(), block_numbers_on_disk.end(), std::make_pair(min_block, -1L)); + auto lower = std::lower_bound(block_numbers_on_disk.begin(), block_numbers_on_disk.end(), std::make_pair(min_block, -1L)); if (lower != block_numbers_on_disk.end() && min_block >= lower->first && max_block <= lower->second) return true; diff --git a/src/Storages/MergeTree/MergeTreeDataPartInMemory.h b/src/Storages/MergeTree/MergeTreeDataPartInMemory.h index 29c01805529..b264ff73436 100644 --- a/src/Storages/MergeTree/MergeTreeDataPartInMemory.h +++ b/src/Storages/MergeTree/MergeTreeDataPartInMemory.h @@ -39,7 +39,7 @@ public: bool isStoredOnDisk() const override { return false; } - bool hasColumnFiles(const String & /* column_name */, const IDataType & /* type */) const override { return true; } + bool hasColumnFiles(const String & column_name, const IDataType & /* type */) const override { return !!getColumnPosition(column_name); } String getFileNameForColumn(const NameAndTypePair & /* column */) const override { return ""; } diff --git a/src/Storages/MergeTree/MergeTreeReaderInMemory.cpp b/src/Storages/MergeTree/MergeTreeReaderInMemory.cpp index 671b36dfe86..5e4c3e49e3b 100644 --- a/src/Storages/MergeTree/MergeTreeReaderInMemory.cpp +++ b/src/Storages/MergeTree/MergeTreeReaderInMemory.cpp @@ -49,7 +49,7 @@ size_t MergeTreeReaderInMemory::readRows(size_t from_mark, bool /* continue_read if (!part_in_memory->block.has(name)) continue; - const auto block_column = part_in_memory->block.getByName(name).column; + const auto & block_column = part_in_memory->block.getByName(name).column; if (total_rows_read == 0 && part_rows <= max_rows_to_read) { res_columns[i] = block_column; diff --git a/src/Storages/StorageMergeTree.cpp b/src/Storages/StorageMergeTree.cpp index 73ae4cdd33c..c97319456ce 100644 --- a/src/Storages/StorageMergeTree.cpp +++ b/src/Storages/StorageMergeTree.cpp @@ -637,13 +637,16 @@ bool StorageMergeTree::merge( merger_mutator.renameMergedTemporaryPart(new_part, future_part.parts, nullptr); DataPartsVector parts_to_remove_immediately; - for (const auto & part : future_part.parts) { - part->notifyMerged(); - if (isInMemoryPart(part)) + auto lock = lockParts(); + for (const auto & part : future_part.parts) { - modifyPartState(part, DataPartState::Deleting); - parts_to_remove_immediately.push_back(part); + part->notifyMerged(); + if (isInMemoryPart(part)) + { + modifyPartState(part, DataPartState::Deleting); + parts_to_remove_immediately.push_back(part); + } } } diff --git a/tests/queries/0_stateless/01130_in_memory_parts_default.reference b/tests/queries/0_stateless/01130_in_memory_parts_default.reference new file mode 100644 index 00000000000..c51afdb6658 --- /dev/null +++ b/tests/queries/0_stateless/01130_in_memory_parts_default.reference @@ -0,0 +1 @@ +0 bbb_aaa diff --git a/tests/queries/0_stateless/01130_in_memory_parts_default.sql b/tests/queries/0_stateless/01130_in_memory_parts_default.sql new file mode 100644 index 00000000000..61e20c84f3d --- /dev/null +++ b/tests/queries/0_stateless/01130_in_memory_parts_default.sql @@ -0,0 +1,20 @@ +-- Test 01266_default_prewhere_reqq, but with in-memory parts +DROP TABLE IF EXISTS t1; + +CREATE TABLE t1 +( + date Date, + s1 String, + s2 String +) ENGINE = MergeTree() PARTITION BY toYYYYMMDD(date) ORDER BY (date, s1) +SETTINGS index_granularity = 8192, min_rows_for_compact_part = 1000, min_rows_for_wide_part = 1000; + + +set max_threads=1; + +insert into t1 (date, s1,s2) values(today()-1,'aaa','bbb'); +alter table t1 add column s3 String DEFAULT concat(s2,'_',s1); +-- insert into t1 (date, s1,s2) values(today(),'aaa2','bbb2'); +select ignore(date), s3 from t1 where s2='bbb'; + +DROP TABLE t1;