Skip to content
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

Improve performance of join building performance (up to 1.28x speedup) #14861

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions datafusion/physical-plan/src/joins/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,24 +212,36 @@ pub trait JoinHashMapType {
deleted_offset: usize,
) {
let (mut_map, mut_list) = self.get_mut();
for (row, hash_value) in iter {
let item = mut_map.get_mut(*hash_value, |(hash, _)| *hash_value == *hash);
if let Some((_, index)) = item {
// Already exists: add index to next array
let prev_index = *index;
// Store new value inside hashmap
*index = (row + 1) as u64;
// Update chained Vec at `row` with previous value
mut_list[row - deleted_offset] = prev_index;
} else {
mut_map.insert(
*hash_value,
for (row, &hash_value) in iter {
let item = mut_map.find_or_find_insert_slot(
hash_value,
|&(hash, _)| hash_value == hash,
|&(hash, _)| hash,
);
match item {
Ok(bucket) => {
// Already exists: add index to next array
// SAFETY: is already initialized
let index = unsafe { bucket.as_mut() };
let prev_index = index.1;
// Store new value inside hashmap
index.1 = (row + 1) as u64;
// Update chained Vec at `row` with previous value
mut_list[row - deleted_offset] = prev_index;
}
Err(slot) => {
// store the value + 1 as 0 value reserved for end of list
(*hash_value, (row + 1) as u64),
|(hash, _)| *hash,
);
// chained list at `row` is already initialized with 0
// meaning end of list
// SAFETY: slot is valid (retrieved above) and not mutated
unsafe {
mut_map.insert_in_slot(
hash_value,
slot,
(hash_value, (row + 1) as u64),
)
};
// chained list at `row` is already initialized with 0
// meaning end of list
}
}
}
}
Expand Down