From 57822ad59213ec5a70843e0bc418007083bf15e1 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Wed, 26 Sep 2018 04:30:07 +0300 Subject: [PATCH] Improvement #3205 --- .../MergeSortingBlockInputStream.cpp | 20 +++++++++++++------ .../MergeSortingBlockInputStream.h | 1 + 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/dbms/src/DataStreams/MergeSortingBlockInputStream.cpp b/dbms/src/DataStreams/MergeSortingBlockInputStream.cpp index c8b3e8aecaa..6122f54630d 100644 --- a/dbms/src/DataStreams/MergeSortingBlockInputStream.cpp +++ b/dbms/src/DataStreams/MergeSortingBlockInputStream.cpp @@ -102,12 +102,20 @@ Block MergeSortingBlockInputStream::readImpl() removeConstantsFromBlock(block); blocks.push_back(block); + sum_rows_in_blocks += block.rows(); sum_bytes_in_blocks += block.allocatedBytes(); /** If significant amount of data was accumulated, perform preliminary merging step. */ - if (blocks.size() > 1 && limit && remerge_is_useful && max_bytes_before_remerge && sum_bytes_in_blocks > max_bytes_before_remerge) + if (blocks.size() > 1 + && limit + && limit * 2 < sum_rows_in_blocks /// 2 is just a guess. + && remerge_is_useful + && max_bytes_before_remerge + && sum_bytes_in_blocks > max_bytes_before_remerge) + { remerge(); + } /** If too many of them and if external sorting is enabled, * will merge blocks that we have in memory at this moment and write merged stream to temporary (compressed) file. @@ -130,6 +138,7 @@ Block MergeSortingBlockInputStream::readImpl() blocks.clear(); sum_bytes_in_blocks = 0; + sum_rows_in_blocks = 0; } } @@ -264,21 +273,19 @@ Block MergeSortingBlocksBlockInputStream::mergeImpl(std::priority_queue impl;