[Enhancement] reduce the number of fd hold by hash join spilling (backport #52020) #52083
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:
When hash join triggers spilling, the data will be partitioned and then flushed. The same partition may be flushed multiple times, generating multiple blocks. When the partition is large enough, it will trigger a split, generate two new partitions and delete the existing partitions.
We hope that blocks from different partitions will not be placed in the same container, so that when a partition is no longer used, the data can be deleted in time. Currently, this is achieved by introducing the concept of exclusive for blocks. If a block is marked as exclusive, the container will not be returned to the block manager when it is released, thus achieving the purpose of exclusivity.
However, there is a problem with this. For LogBlockManager, each block will occupy a container, resulting in a lot of small files.
What I'm doing:
In fact, we don’t need to allocate a container for each block. We just need to ensure that the containers occupied by blocks in different partitions do not overlap.
In order to solve the problem of too many small files, the concept of affinity_group is introduced for blocks. Blocks belonging to the same affinity_group will share the same batch of containers, and blocks belonging to different affinity groups will not have overlapping containers.
I tested the following query on the ssb_100g data. Before optimization, the number of fds hold by spilling was 2k+. After optimization, the number of fds did not exceed 200.
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:
This is an automatic backport of pull request #52020 done by [Mergify](https://mergify.com). ## Why I'm doing:
When hash join triggers spilling, the data will be partitioned and then flushed. The same partition may be flushed multiple times, generating multiple blocks. When the partition is large enough, it will trigger a split, generate two new partitions and delete the existing partitions.
We hope that blocks from different partitions will not be placed in the same container, so that when a partition is no longer used, the data can be deleted in time. Currently, this is achieved by introducing the concept of exclusive for blocks. If a block is marked as exclusive, the container will not be returned to the block manager when it is released, thus achieving the purpose of exclusivity.
However, there is a problem with this. For LogBlockManager, each block will occupy a container, resulting in a lot of small files.
What I'm doing:
In fact, we don’t need to allocate a container for each block. We just need to ensure that the containers occupied by blocks in different partitions do not overlap.
In order to solve the problem of too many small files, the concept of affinity_group is introduced for blocks. Blocks belonging to the same affinity_group will share the same batch of containers, and blocks belonging to different affinity groups will not have overlapping containers.
I tested the following query on the ssb_100g data. Before optimization, the number of fds hold by spilling was 2k+. After optimization, the number of fds did not exceed 200.
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist: