forked from pingcap/tiflash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge output blocks if need in hash join (pingcap#6529)
close pingcap#6533
- Loading branch information
1 parent
957d2d4
commit 816b8d5
Showing
12 changed files
with
307 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright 2022 PingCAP, Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <DataStreams/SquashingHashJoinBlockTransform.h> | ||
|
||
namespace DB | ||
{ | ||
|
||
SquashingHashJoinBlockTransform::SquashingHashJoinBlockTransform(UInt64 max_block_size_) | ||
: output_rows(0) | ||
, max_block_size(max_block_size_) | ||
, join_finished(false) | ||
{} | ||
|
||
void SquashingHashJoinBlockTransform::handleOverLimitBlock() | ||
{ | ||
// if over_limit_block is not null, we need to push it into blocks. | ||
if (over_limit_block) | ||
{ | ||
assert(!(output_rows && blocks.empty())); | ||
output_rows += over_limit_block->rows(); | ||
blocks.push_back(std::move(over_limit_block.value())); | ||
over_limit_block.reset(); | ||
} | ||
} | ||
|
||
void SquashingHashJoinBlockTransform::appendBlock(Block & block) | ||
{ | ||
if (!block) | ||
{ | ||
// if append block is {}, mark join finished. | ||
join_finished = true; | ||
return; | ||
} | ||
size_t current_rows = block.rows(); | ||
|
||
if (!output_rows || output_rows + current_rows <= max_block_size) | ||
{ | ||
blocks.push_back(std::move(block)); | ||
output_rows += current_rows; | ||
} | ||
else | ||
{ | ||
// if output_rows + current_rows > max block size, put the current result block into over_limit_block and handle it in next read. | ||
assert(!over_limit_block); | ||
over_limit_block.emplace(std::move(block)); | ||
} | ||
} | ||
|
||
Block SquashingHashJoinBlockTransform::getFinalOutputBlock() | ||
{ | ||
Block final_block = mergeBlocks(std::move(blocks)); | ||
reset(); | ||
handleOverLimitBlock(); | ||
return final_block; | ||
} | ||
|
||
void SquashingHashJoinBlockTransform::reset() | ||
{ | ||
blocks.clear(); | ||
output_rows = 0; | ||
} | ||
|
||
bool SquashingHashJoinBlockTransform::isJoinFinished() const | ||
{ | ||
return join_finished; | ||
} | ||
|
||
bool SquashingHashJoinBlockTransform::needAppendBlock() const | ||
{ | ||
return !over_limit_block && !join_finished; | ||
} | ||
|
||
} // namespace DB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2022 PingCAP, Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <Core/Block.h> | ||
|
||
namespace DB | ||
{ | ||
|
||
class SquashingHashJoinBlockTransform | ||
{ | ||
public: | ||
SquashingHashJoinBlockTransform(UInt64 max_block_size_); | ||
|
||
void appendBlock(Block & block); | ||
Block getFinalOutputBlock(); | ||
bool isJoinFinished() const; | ||
bool needAppendBlock() const; | ||
|
||
|
||
private: | ||
void handleOverLimitBlock(); | ||
void reset(); | ||
|
||
Blocks blocks; | ||
std::optional<Block> over_limit_block; | ||
size_t output_rows; | ||
UInt64 max_block_size; | ||
bool join_finished; | ||
}; | ||
|
||
} // namespace DB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.