xudong963 opened a new pull request, #27850: URL: https://github.com/apache/datafusion/pull/27850
## Which issue does this PR close? - Backport of #26261 to `branch-56`, for #24463. - Closes #26260 for the 56 line. #26261 has not merged to `main` yet, so this stays a draft until it does. Once it merges, I will replace these commits with the merge commit. ## Rationale for this change With `prefer_hash_join = false`, the planner hardcodes `ASC NULLS FIRST` for every sort-merge join key. Inputs already sorted `DESC`, `NULLS LAST`, or with different options per key get sorted again. With `target_partitions = 1`, `prefer_hash_join = false` is ignored and a hash join is planned. #26261 fixes both. ## What changes are included in this PR? The four commits of #26261 (head `f9bae8c`), cherry-picked with `-x`. The conflicts were all in `physical_planner.rs`. `main` has a null-aware sort-merge join path for single-key `LeftAnti` joins that `branch-56` does not have. I kept the `branch-56` structure without it and applied only the parts of #26261: the key order and sort option derivation (`sort_merge_join_keys`) and the new SMJ condition. I adjusted the nearby comments, which on `main` describe the null-aware path. ## What is the testing strategy for this PR? The `physical_planner` unit tests, `sort_merge_join*.slt` (including the new `sort_merge_join_sort_options.slt` and the new `target_partitions = 1` cases), `joins.slt` and `subquery.slt` pass on this branch. Applied on `branch-56` together with the backports of #27021, #27150, #27547 and #27732 (opened alongside this one), the full sqllogictest suite, `cargo fmt --check` and clippy on the touched crates also pass. ## Are there any user-facing changes? Plans change only with `prefer_hash_join = false`. Fewer `SortExec`s are added under `SortMergeJoinExec` when the inputs are already sorted on the join keys. With `target_partitions = 1`, a sort-merge join is planned instead of a hash join. Results are unchanged. No API changes. -- 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]
