From 8eed47857bbd978625da7c07d7bc15befebb9c00 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Thu, 25 Jun 2020 23:18:49 +0300 Subject: [PATCH] Fix estimation of the number of marks for various thresholds --- .../MergeTree/MergeTreeDataSelectExecutor.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp b/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp index f1356663a5a..fefd9dc6e15 100644 --- a/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp +++ b/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp @@ -724,10 +724,15 @@ size_t roundRowsOrBytesToMarks( size_t rows_granularity, size_t bytes_granularity) { + /// Marks are placed whenever threshold on rows or bytes is met. + /// So we have to return the number of marks on whatever estimate is higher - by rows or by bytes. + + size_t res = (rows_setting + rows_granularity - 1) / rows_granularity; + if (bytes_granularity == 0) - return (rows_setting + rows_granularity - 1) / rows_granularity; + return res; else - return (bytes_setting + bytes_granularity - 1) / bytes_granularity; + return std::max(res, (bytes_setting + bytes_granularity - 1) / bytes_granularity); } } @@ -759,7 +764,7 @@ Pipes MergeTreeDataSelectExecutor::spreadMarkRangesAmongStreams( sum_marks += sum_marks_in_parts[i]; if (parts[i].data_part->index_granularity_info.is_adaptive) - adaptive_parts++; + ++adaptive_parts; } size_t index_granularity_bytes = 0; @@ -890,7 +895,7 @@ Pipes MergeTreeDataSelectExecutor::spreadMarkRangesAmongStreamsWithOrder( sum_marks += sum_marks_in_parts[i]; if (parts[i].data_part->index_granularity_info.is_adaptive) - adaptive_parts++; + ++adaptive_parts; } size_t index_granularity_bytes = 0;