Skip to content

Commit f17dd06

Browse files
authored
Merge pull request ClickHouse#80328 from bigo-sg/opt_concat_blocks
Trivial opt on `concatenateBlocks`. Maybe it's good for parallel hash join.
2 parents 58e34ff + 6c7f791 commit f17dd06

File tree

5 files changed

+4
-17
lines changed

5 files changed

+4
-17
lines changed

src/Core/Block.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,9 @@ Block concatenateBlocks(const std::vector<Block> & blocks)
943943
if (blocks.empty())
944944
return {};
945945

946+
if (blocks.size() == 1)
947+
return blocks[0];
948+
946949
size_t num_rows = 0;
947950
for (const auto & block : blocks)
948951
num_rows += block.rows();

src/Interpreters/GraceHashJoin.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,11 @@ namespace
6464
if (!block)
6565
{
6666
eof = true;
67-
if (blocks.size() == 1)
68-
return blocks.front();
6967
return concatenateBlocks(blocks);
7068
}
7169
blocks.push_back(std::move(block));
7270
} while (rows_read < result_block_size);
7371

74-
if (blocks.size() == 1)
75-
return blocks.front();
7672
return concatenateBlocks(blocks);
7773
}
7874

@@ -743,10 +739,7 @@ void GraceHashJoin::addBlockToJoinImpl(Block block)
743739
current_blocks.emplace_back(std::move(blocks[bucket_index]));
744740
}
745741

746-
if (current_blocks.size() == 1)
747-
current_block = std::move(current_blocks.front());
748-
else
749-
current_block = concatenateBlocks(current_blocks);
742+
current_block = concatenateBlocks(current_blocks);
750743
}
751744

752745
hash_join = makeInMemoryJoin(fmt::format("grace{}", bucket_index), prev_keys_num);

src/Interpreters/SortedBlocksWriter.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,6 @@ Block SortedBlocksBuffer::mergeBlocks(Blocks && blocks) const
389389
blocks.swap(tmp_blocks);
390390
}
391391

392-
if (blocks.size() == 1)
393-
return blocks[0];
394-
395392
return concatenateBlocks(blocks);
396393
}
397394

src/TableFunctions/TableFunctionExplain.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,6 @@ Block executeMonoBlock(QueryPipeline & pipeline)
167167
break;
168168
}
169169

170-
if (blocks.size() == 1)
171-
return blocks[0];
172-
173170
return concatenateBlocks(blocks);
174171
}
175172

src/TableFunctions/TableFunctionFormat.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ Block TableFunctionFormat::parseData(const ColumnsDescription & columns, const S
125125
while (reader->pull(block))
126126
blocks.push_back(std::move(block));
127127

128-
if (blocks.size() == 1)
129-
return blocks[0];
130-
131128
/// In case when data contains more then 1 block we combine
132129
/// them all to one big block (this is considered a rare case).
133130
return concatenateBlocks(blocks);

0 commit comments

Comments
 (0)