Maybe better [#METR-22173].

This commit is contained in:
Alexey Milovidov 2016-08-04 07:51:41 +03:00
parent 8f36012d47
commit 6c476974d4
2 changed files with 13 additions and 2 deletions

View File

@ -135,13 +135,16 @@ protected:
SortDescription description;
size_t max_block_size;
const size_t max_block_size;
size_t limit;
size_t total_merged_rows = 0;
bool first = true;
bool has_collation = false;
/// May be smaller or equal to max_block_size. To do 'reserve' for columns.
size_t expected_block_size = 0;
/// Текущие сливаемые блоки.
size_t num_columns = 0;
std::vector<SharedBlockPtr> source_blocks;

View File

@ -32,12 +32,17 @@ void MergingSortedBlockInputStream::init(Block & merged_block, ColumnPlainPtrs &
shared_block_ptr = new detail::SharedBlock(children[i]->read());
if (shared_block_ptr->rowsInFirstColumn() == 0)
const size_t rows = shared_block_ptr->rowsInFirstColumn();
if (rows == 0)
continue;
if (!num_columns)
num_columns = shared_block_ptr->columns();
if (expected_block_size < rows)
expected_block_size = std::min(rows, max_block_size);
cursors[i] = SortCursorImpl(*shared_block_ptr, description, i);
has_collation |= cursors[i].has_collation;
}
@ -99,7 +104,10 @@ void MergingSortedBlockInputStream::init(Block & merged_block, ColumnPlainPtrs &
}
for (size_t i = 0; i < num_columns; ++i)
{
merged_columns.emplace_back(merged_block.getByPosition(i).column.get());
merged_columns.back()->reserve(expected_block_size);
}
}