Repository navigation
Conversation
… join `inner_10to1` joins 10 streamed rows to each buffered row, as a fact table joins a dimension on its key. `left_1to1000_selective_filtered` runs the inputs and filter of `inner_1to1000_selective_filtered` as a Left join.
…first A streamed row and the run of buffered rows it matches are now recorded as one `PairRun`, in a vector that the freezes reuse, instead of a pair of `u64` indices per match in chunks allocated for each buffered batch. At the freeze a side whose rows form a range is sliced as before, long runs of buffered rows are copied as ranges, and the streamed row of a long run is repeated for primitive columns. Short runs are still gathered row by row. Left, Right and Full joins with a filter now evaluate it before materializing pairs, like Inner joins. They keep the pairs that pass and the first pair of each streamed row whose pairs all fail, which the deferred filter null-joins as before.
Buffered batches kept every input column while they waited for their key group, and spilled them all. Once its join keys are computed, a buffered batch now keeps only the columns that the join emits or its filter reads, so its reservation and spill files no longer include, for example, a join key that the projection drops.
This file contains hidden or 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
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.
Which issue does this PR close?
Rationale for this change
#27278 filters Inner sort-merge join pairs before materializing them. Its profiles showed where the join still spends its time:
inner_1to1000_selective_filtered), gathering the filter's columns through per-pair indices took about 30% of the CPU, and recording those indices 11%.What changes are included in this PR?
append_output_pairsrecords a streamed row and its run of buffered rows as onePairRun, in a vector that the freezes reuse. Before, it stored au64pair per match, in chunks allocated for each buffered batch. At the freeze, a side whose rows form a range is still sliced. Long runs are copied: the buffered rows as ranges (MutableArrayData), and the streamed row repeated for primitive columns. Runs shorter than 12 pairs on average are still gathered row by row, as are dictionary columns from several buffered batches, whichinterleavemerges.sort_merge_joinbenchmark cases,inner_10to1andleft_1to1000_selective_filtered, are in a separate first commit.What is the testing strategy for this PR?
The existing sort-merge join tests cover the new paths. They compare with
HashJoinExecand with projected joins, and they cover spilling. A check with 16 mutants of the new code found two gaps, which the first two of these tests close:join_runs_continue_only_within_a_buffered_batch: a key group starts at row 32 of one buffered batch and ends at row 32 of the next, so runs from the two batches line up.join_with_projection_matches_projected_joinnow also runs with spilling. Its projections drop the buffered key.join_dictionary_column_of_several_buffered_batches: copying ranges would concatenate the batches' dictionaries pastInt8keys, which fails without theinterleavefallback.The join fuzz tests and the sort-merge join sqllogictest files pass.
Benchmarks:
cargo bench -p datafusion-physical-plan --features test_utils --bench sort_merge_join, this PR against its base plus the bench commit (the head of #27278, whose sort-merge join codemainnow has), with thin LTO on an Apple M5 Max. The two builds and a second copy of the base ran alternately for four rounds. The table shows each case's best round.inner_1to1000_selective_filtered/20000left_1to1000_selective_filtered/20000(new)left_1to100_filtered/20000inner_1to100/20000inner_1to100_filtered/20000inner_group_spans_buffered_batches/8inner_group_spans_buffered_batches/64inner_1to1/100000inner_10to1/100000(new)inner_1to10/100000inner_1to10_high_pass_filtered_narrow/100000The other cases changed by 2% or less, and the second copy of the base stayed within 2% of the first. Runs of about 10 pairs are a few percent slower, because the freeze now expands them into indices that pairing used to write.
For item 3, in a scratch Inner join whose projection drops the buffered key and a string column, with 50,000 buffered rows per key, the peak reservation fell from 2.99 MB to 1.38 MB. With a 1 MB pool, the spilled bytes fell from 4.71 MB to 0.49 MB.
Are there any user-facing changes?
No.