comphead opened a new issue, #27910: URL: https://github.com/apache/datafusion/issues/27910
### Is your feature request related to a problem or challenge? Part of https://github.com/apache/datafusion/issues/20910. Follow-ups to https://github.com/apache/datafusion/pull/27278, which filters Inner sort-merge join pairs before materializing them and materializes only the projected columns. Its profiles show where the join still spends its time. ### Describe the solution you'd like 1. **Keep pairs as runs until the freeze.** `append_output_range` gets a streamed row and a range of buffered rows, and expands them into indices per pair that the freeze then gathers through. In `inner_1to1000_selective_filtered` (TPC-DS q72's shape), gathering the filter's columns for every pair takes about 23% of the CPU, recording the pairs 13% and evaluating the filter 9%. Materializing from the runs, with range copies for the buffered side and repeats for the streamed side, would cut most of the first two, for every join type. 2. **Size new chunks by what they hold.** `start_chunk` reserves room for the rest of the output batch in every chunk. When a key group spans many small buffered batches, a freeze makes one chunk per batch, and with 64-row buffered batches about 12% of the CPU went to allocating and freeing them. 3. **Drop unused buffered columns on arrival.** Buffered batches are reserved and spilled with every input column, including those that the join neither emits nor reads. Projecting them once their join keys are computed would shrink the reservation and the spill files. 4. **Filter Outer join pairs before materializing them.** Left, Right and Full joins with a filter still materialize every pair before the deferred filter runs, although a pair that fails needs at most its streamed row. These might fit in one PR. ### Describe alternatives you've considered https://github.com/apache/datafusion/issues/25515 removes the coalescer's second copy of the output, which item 1 complements. ### Additional context Profiled with samply on an Apple M5 Max, on `cargo bench -p datafusion-physical-plan --features test_utils --bench sort_merge_join` and scratch cases. ### Willingness to contribute I plan to contribute to this feature independently -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
