Skip to content

Commit 6160361

Browse files
committed
feat: derive SMJ sort options from left child during plan creation
1 parent a74352d commit 6160361

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

datafusion/core/src/physical_planner.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,15 +1382,29 @@ impl DefaultPhysicalPlanner {
13821382
&& session_state.config().repartition_joins()
13831383
&& !prefer_hash_join
13841384
{
1385-
// Use SortMergeJoin if hash join is not preferred
1386-
let join_on_len = join_on.len();
1385+
// Derive sort options from the left input's existing ordering
1386+
// rather than hardcoding SortOptions::default()
1387+
let sort_options: Vec<SortOptions> = join_on
1388+
.iter()
1389+
.map(|(left_col, _)| {
1390+
physical_left
1391+
.output_ordering()
1392+
.and_then(|ordering| {
1393+
ordering
1394+
.iter()
1395+
.find(|sort_expr| sort_expr.expr.eq(left_col))
1396+
.map(|sort_expr| sort_expr.options)
1397+
})
1398+
.unwrap_or_default()
1399+
})
1400+
.collect();
13871401
Arc::new(SortMergeJoinExec::try_new(
13881402
physical_left,
13891403
physical_right,
13901404
join_on,
13911405
join_filter,
13921406
*join_type,
1393-
vec![SortOptions::default(); join_on_len],
1407+
sort_options,
13941408
*null_equality,
13951409
)?)
13961410
} else if session_state.config().target_partitions() > 1

0 commit comments

Comments
 (0)