bert-beyondloops commented on code in PR #26261:
URL: https://github.com/apache/datafusion/pull/26261#discussion_r4584521438


##########
datafusion/core/src/physical_planner.rs:
##########
@@ -3728,6 +3732,117 @@ enum PlanAsyncExpr {
     Async(AsyncMapper, PlannedExprResult),
 }
 
+/// Chooses the join key order and per-key [`SortOptions`] of a 
[`SortMergeJoinExec`], so that as
+/// few inputs as possible need a `SortExec`.
+///
+/// The join keys are an unordered set of equalities, so they can be permuted 
freely. Candidates
+/// are derived from each known output ordering of each input: its entries 
that (after normalizing
+/// through the equivalence group) are join keys become the leading keys, in 
that order and with
+/// those options, and the remaining keys follow with the default options. 
Each candidate is
+/// scored by how many inputs `ordering_satisfy` confirms are already sorted 
on it, so constants,
+/// equal columns and any key order are handled. The default (original key 
order, default options)
+/// wins ties, so plans that already match are unchanged.
+///
+/// Cost: nothing is done if neither input has an ordering; otherwise one 
candidate per known
+/// ordering, each verified with two `ordering_satisfy` calls.
+fn sort_merge_join_keys(

Review Comment:
   indeed, nice hint. I adopted your proposed 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]

Reply via email to