From 97b923fd7be36d4b0bcee98c45dc7c18dfc6e199 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 8 Sep 2013 07:30:52 +0000 Subject: [PATCH] dbms: uncompressed cache: better [#CONV-8661]. --- dbms/include/DB/Storages/StorageMergeTree.h | 9 ++++++++- dbms/src/Storages/StorageMergeTree.cpp | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/dbms/include/DB/Storages/StorageMergeTree.h b/dbms/include/DB/Storages/StorageMergeTree.h index c894b54280a..35b4266afe6 100644 --- a/dbms/include/DB/Storages/StorageMergeTree.h +++ b/dbms/include/DB/Storages/StorageMergeTree.h @@ -67,6 +67,11 @@ struct StorageMergeTreeSettings /// Если отрезок индекса может содержать нужные ключи, делим его на столько частей и рекурсивно проверяем их. size_t coarse_index_granularity; + + /** Максимальное количество строк на запрос, для использования кэша разжатых данных. Если запрос большой - кэш не используется. + * (Чтобы большие запросы не вымывали кэш.) + */ + size_t max_rows_to_use_cache; StorageMergeTreeSettings() : max_size_ratio_to_merge_parts(5), @@ -75,7 +80,8 @@ struct StorageMergeTreeSettings merging_threads(2), min_rows_for_concurrent_read(20 * 8192), min_rows_for_seek(5 * 8192), - coarse_index_granularity(8) {} + coarse_index_granularity(8), + max_rows_to_use_cache(1024 * 1024) {} }; /// Пара засечек, определяющая диапазон строк в куске. Именно, диапазон имеет вид [begin * index_granularity, end * index_granularity). @@ -171,6 +177,7 @@ private: size_t min_marks_for_seek; size_t min_marks_for_concurrent_read; + size_t max_marks_to_use_cache; /// Для схлопывания записей об изменениях, если это требуется. String sign_column; diff --git a/dbms/src/Storages/StorageMergeTree.cpp b/dbms/src/Storages/StorageMergeTree.cpp index bf74683a78d..41d04c6d0b1 100644 --- a/dbms/src/Storages/StorageMergeTree.cpp +++ b/dbms/src/Storages/StorageMergeTree.cpp @@ -74,6 +74,7 @@ StorageMergeTree::StorageMergeTree( { min_marks_for_seek = (settings.min_rows_for_seek + index_granularity - 1) / index_granularity; min_marks_for_concurrent_read = (settings.min_rows_for_concurrent_read + index_granularity - 1) / index_granularity; + max_marks_to_use_cache = (settings.max_rows_to_use_cache + index_granularity - 1) / index_granularity; /// создаём директорию, если её нет Poco::File(full_path).createDirectories(); @@ -314,6 +315,9 @@ BlockInputStreams StorageMergeTree::spreadMarkRangesAmongThreads( } sum_marks += sum_marks_in_parts[i]; } + + if (sum_marks > max_marks_to_use_cache) + use_uncompressed_cache = false; BlockInputStreams res; @@ -400,6 +404,14 @@ BlockInputStreams StorageMergeTree::spreadMarkRangesAmongThreads( BlockInputStreams StorageMergeTree::spreadMarkRangesAmongThreadsFinal( RangesInDataParts parts, size_t threads, const Names & column_names, size_t max_block_size, bool use_uncompressed_cache) { + size_t sum_marks = 0; + for (size_t i = 0; i < parts.size(); ++i) + for (size_t j = 0; j < parts[i].ranges.size(); ++j) + sum_marks += parts[i].ranges[j].end - parts[i].ranges[j].begin; + + if (sum_marks > max_marks_to_use_cache) + use_uncompressed_cache = false; + ExpressionActionsPtr sign_filter_expression; String sign_filter_column; createPositiveSignCondition(sign_filter_expression, sign_filter_column);