2010YOUY01 opened a new pull request, #27980:
URL: https://github.com/apache/datafusion/pull/27980
## Which issue does this PR close?
<!-- Add the related issue, if any. -->
Related work: this adapts the co-partitioning optimization and test cases
from #25304 by @stuhood. It is a separate draft to demonstrate that
optimization on top of the two-pass refactor, with the decision inside
`HashJoinExec::choose_partition_mode` and explicitly selected partition modes
preserved.
Depends on #27979, which separates build-side selection from partition-mode
selection.
## Rationale for this change
A small build input currently makes an `Auto` hash join choose
`CollectLeft`, even when both inputs are already compatibly partitioned on the
join keys. This unnecessarily gathers the build partitions. Prefer
`Partitioned` when the existing layout already satisfies the join's
distribution requirements.
For example, join a small dimension table with a fact table when both expose
matching range partitions on the join key:
```sql
SELECT * FROM dimension d JOIN fact f ON d.d_dkey = f.f_dkey;
```
Even below the broadcast threshold, the join can use the existing partitions:
```text
Before: After:
HashJoinExec: CollectLeft HashJoinExec: Partitioned
CoalescePartitionsExec dimension: Range(key, [B, C], 3)
dimension: Range(key, [B, C], 3) fact: Range(key, [B, C], 3)
fact: Range(key, [B, C], 3)
```
## What changes are included in this PR?
Suggested reading order:
1. `datafusion/physical-plan/src/joins/hash_join/exec/optimizations.rs` —
`HashJoinExec::choose_partition_mode` checks existing co-partitioning before
the broadcast threshold, using the existing distribution compatibility check.
2. `datafusion/core/tests/physical_optimizer/join_selection.rs` —
`PartitionCase` and the co-partitioned join tests show which layouts qualify
and how this interacts with build-side swapping.
3. `datafusion/sqllogictest/test_files/repartition_subset_satisfaction.slt`
— updated plans show a range-partitioned join retaining its partitions and
removing `CoalescePartitionsExec`.
## What is the testing strategy for this PR?
UTs
## Are there any user-facing changes?
No behavior change.
--
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]