From 8cd841c4acd6ea8aeee33ab21ac0c9c2c1245f0e Mon Sep 17 00:00:00 2001 From: vdimir Date: Fri, 2 Apr 2021 16:55:42 +0300 Subject: [PATCH] Handle lowcardinality block in MergeJoin extractMinMax --- src/Interpreters/MergeJoin.cpp | 9 +++++---- src/Interpreters/MergeJoin.h | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Interpreters/MergeJoin.cpp b/src/Interpreters/MergeJoin.cpp index ddeaf053225..e9d1eafbdb9 100644 --- a/src/Interpreters/MergeJoin.cpp +++ b/src/Interpreters/MergeJoin.cpp @@ -86,10 +86,10 @@ Block extractMinMax(const Block & block, const Block & keys) for (size_t i = 0; i < columns.size(); ++i) { - const auto & src_column = block.getByName(keys.getByPosition(i).name); - - columns[i]->insertFrom(*src_column.column, 0); - columns[i]->insertFrom(*src_column.column, block.rows() - 1); + const auto & src_column = block.getByName(min_max.getByPosition(i).name); + /// Cannot use insertFrom because src_column type can differ from keys, e.g. to be LowCardinality + columns[i]->insert((*src_column.column)[0]); + columns[i]->insert((*src_column.column)[block.rows() - 1]); } min_max.setColumns(std::move(columns)); @@ -485,6 +485,7 @@ MergeJoin::MergeJoin(std::shared_ptr table_join_, const Block & right left_blocks_buffer = std::make_shared(left_sort_description, max_bytes); } +/// Has to be called event totals is empty void MergeJoin::setTotals(const Block & totals_block) { totals = totals_block; diff --git a/src/Interpreters/MergeJoin.h b/src/Interpreters/MergeJoin.h index a13d0304907..d145a69ce9d 100644 --- a/src/Interpreters/MergeJoin.h +++ b/src/Interpreters/MergeJoin.h @@ -76,12 +76,15 @@ private: Block right_table_keys; Block right_columns_to_add; SortedBlocksWriter::Blocks right_blocks; + + /// Each block stores first and last row from corresponding sorted block on disk Blocks min_max_right_blocks; std::shared_ptr left_blocks_buffer; std::shared_ptr used_rows_bitmap; mutable std::unique_ptr cached_right_blocks; std::vector> loaded_right_blocks; std::unique_ptr disk_writer; + /// Set of files with sorted blocks SortedBlocksWriter::SortedFiles flushed_right_blocks; Block totals; std::atomic is_in_memory{true};