-
Notifications
You must be signed in to change notification settings - Fork 2k
perf: use DynComparator in sort-merge join (SMJ), microbenchmark queries up to 12% faster, TPC-H overall ~5% faster #21484
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
base: main
Are you sure you want to change the base?
Changes from all commits
b6f57cf
b6ac26e
cded5ee
a3a832c
7c16aa5
74859c3
6a0351d
d32d5ae
3947c7e
0cc36fd
e0d06ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,7 +38,7 @@ use crate::handle_state; | |
| use crate::joins::piecewise_merge_join::exec::{BufferedSide, BufferedSideReadyState}; | ||
| use crate::joins::piecewise_merge_join::utils::need_produce_result_in_final; | ||
| use crate::joins::utils::{BuildProbeJoinMetrics, StatefulStreamResult}; | ||
| use crate::joins::utils::{compare_join_arrays, get_final_indices_from_shared_bitmap}; | ||
| use crate::joins::utils::{JoinKeyComparator, get_final_indices_from_shared_bitmap}; | ||
|
|
||
| pub(super) enum PiecewiseMergeJoinStreamState { | ||
| WaitBufferedSide, | ||
|
|
@@ -460,6 +460,14 @@ fn resolve_classic_join( | |
| let buffered_len = buffered_side.buffered_data.values().len(); | ||
| let stream_values = stream_batch.compare_key_values(); | ||
|
|
||
| // Build comparator once for the batch pair | ||
| let cmp = JoinKeyComparator::new( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: piecewise merge join rebuilds the |
||
| &[Arc::clone(&stream_values[0])], | ||
| &[Arc::clone(buffered_side.buffered_data.values())], | ||
| &[sort_options], | ||
| NullEquality::NullEqualsNothing, | ||
| )?; | ||
|
|
||
| let mut buffer_idx = batch_process_state.start_buffer_idx; | ||
| let mut stream_idx = batch_process_state.start_stream_idx; | ||
|
|
||
|
|
@@ -475,17 +483,7 @@ fn resolve_classic_join( | |
| // in the previous stream row. | ||
| for row_idx in stream_idx..stream_batch.batch.num_rows() { | ||
| while buffer_idx < buffered_len { | ||
| let compare = { | ||
| let buffered_values = buffered_side.buffered_data.values(); | ||
| compare_join_arrays( | ||
| &[Arc::clone(&stream_values[0])], | ||
| row_idx, | ||
| &[Arc::clone(buffered_values)], | ||
| buffer_idx, | ||
| &[sort_options], | ||
| NullEquality::NullEqualsNothing, | ||
| )? | ||
| }; | ||
| let compare = cmp.compare(row_idx, buffer_idx); | ||
|
|
||
| // If we find a match we append all indices and move to the next stream row index | ||
| match operator { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
is_join_arrays_equaldidn't supportDictionarykeys — it hit thenot_impl_err!fallthrough. This test was passing because that error counted as the expected "failure."JoinKeyComparatorusesmake_comparatorwhich handles all Arrow types, so the query now correctly spills and succeeds.If you add this on main:
the test passes, confirming it was failing for the wrong reason on main all along.
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.
Claude's assessment:
I'm not sure if the test is worth keeping, but maybe that's a different PR.