-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enhancement] split chunk of HashTable #51175
Open
murphyatwork
wants to merge
6
commits into
StarRocks:main
Choose a base branch
from
murphyatwork:murphy_opt_split_build_chunk
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Enhancement] split chunk of HashTable #51175
murphyatwork
wants to merge
6
commits into
StarRocks:main
from
murphyatwork:murphy_opt_split_build_chunk
+424
−55
Conversation
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
Signed-off-by: Murphy <[email protected]>
const std::vector<ChunkPtr>& SegmentedChunk::segments() const { | ||
return _segments; | ||
} | ||
|
||
} // namespace starrocks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most risky bug in this code is:
Dereferencing a null pointer when appending chunks, as _segments
might contain null values.
You can modify the code like this:
void SegmentedChunk::append_chunk(const ChunkPtr& chunk, const std::vector<SlotId>& slots) {
if (_segments.empty() || !_segments[0]) {
_segments.resize(1);
_segments[0] = std::make_shared<Chunk>();
}
ChunkPtr open_segment = _segments[_segments.size() - 1];
size_t append_rows = chunk->num_rows();
size_t append_index = 0;
while (append_rows > 0) {
size_t open_segment_append_rows = std::min(_segment_size - open_segment->num_rows(), append_rows);
for (int i = 0; i < slots.size(); i++) {
SlotId slot = slots[i];
ColumnPtr column = chunk->get_column_by_slot_id(slot);
open_segment->columns()[i]->append(*column, append_index, open_segment_append_rows);
}
append_index += open_segment_append_rows;
append_rows -= open_segment_append_rows;
if (open_segment->num_rows() == _segment_size) {
_segments.emplace_back(std::make_shared<Chunk>());
open_segment = _segments[_segments.size() - 1]; // Ensure open_segment points to the new segment.
}
}
}
murphyatwork
force-pushed
the
murphy_opt_split_build_chunk
branch
from
September 19, 2024 12:42
201bf7d
to
e2c9d16
Compare
Signed-off-by: Murphy <[email protected]>
murphyatwork
force-pushed
the
murphy_opt_split_build_chunk
branch
from
September 20, 2024 02:22
e2c9d16
to
e9206b6
Compare
Signed-off-by: Murphy <[email protected]>
murphyatwork
force-pushed
the
murphy_opt_split_build_chunk
branch
from
September 20, 2024 03:49
4917b65
to
9c9ba6f
Compare
Signed-off-by: Murphy <[email protected]>
murphyatwork
force-pushed
the
murphy_opt_split_build_chunk
branch
3 times, most recently
from
September 21, 2024 02:40
8afc5c2
to
dcd84b6
Compare
Signed-off-by: Murphy <[email protected]>
murphyatwork
force-pushed
the
murphy_opt_split_build_chunk
branch
from
September 21, 2024 02:42
dcd84b6
to
932d08b
Compare
Signed-off-by: Murphy <[email protected]>
[Java-Extensions Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[FE Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[BE Incremental Coverage Report]❌ fail : 111 / 223 (49.78%) file detail
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why I'm doing:
JoinHashTable::build_chunk
is aChunk
which contains all data from build side, it means it can be very large for particular cases. As a result, it can easily encounter the memory allocation issue, when jemalloc/os cannot allocate a large continuous memory, as above exception.The particular cases can be:
What I'm doing:
Split that chunk into multiple smaller segments(whose rows is usually 131072) to get rid of this issue:
SegmentedChunk
andSegmentedColumn
to replace originalChunk
andColumn
offset%segment_size
, rather than maintaining a index for it. It's effective enough with static segment_size.Potential downside and considerations of this approach:
JoinHashMap
, it needs to randomly copy data from thebuild_chunk
according tobuild_index
. WithSegmentedChunk
, since the memory address is not continuous anymore, we need to lookup the segment first then lookup the record in it. To deal with it, we try best to use theSegmentedChunkVisitor
to reduce this overhead via eliminating the virtual function callkey_column
ofJoinHashMap
cannot not use columns ofbuild_chunk
anymore. Since their memory layout is different,key_column
use a continuous column, butbuild_chunk
uses a segmented way. It would introduce some memory overhead and memory copy overhead.key_column
segmented ? The overhead is relatively larger for the probe procedure, and also it needs to change a lot of code, which is beyond the scope. So we choose the easy pathFixes #issue
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: