wiedld commented on code in PR #14907: URL: https://github.com/apache/datafusion/pull/14907#discussion_r1974080657
########## datafusion/physical-optimizer/src/enforce_sorting/mod.rs: ########## @@ -316,25 +369,43 @@ fn replace_with_partial_sort( /// are transformed into /// ```text /// "SortPreservingMergeExec: \[a@0 ASC\]", -/// " ...nodes..." -/// " SortExec: expr=\[a@0 ASC\]", +/// " SortExec: expr=\[a@0 ASC\]", +/// " ...nodes..." +/// " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", +/// ``` +/// by following connections from [`CoalescePartitionsExec`]s to [`SortExec`]s. +/// By performing sorting in parallel, we can increase performance in some scenarios. +/// +/// This requires that there are no nodes between the [`SortExec`] and [`CoalescePartitionsExec`] +/// which require single partitioning. Do not parallelize when the following scenario occurs: +/// ```text +/// "SortExec: expr=\[a@0 ASC\]", +/// " ...nodes requiring single partitioning..." +/// " CoalescePartitionsExec", /// " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", /// ``` pub fn parallelize_sorts( mut requirements: PlanWithCorrespondingCoalescePartitions, ) -> Result<Transformed<PlanWithCorrespondingCoalescePartitions>> { + requirements = requirements.update_plan_from_children()?; update_coalesce_ctx_children(&mut requirements); + let coalesce_can_be_removed = requirements.children.iter().any(|child| child.data); Review Comment: I switched it to be docs only: https://github.com/apache/datafusion/pull/14907#issuecomment-2688656333 Then if I move forward with another refactoring attempt, I'll first make an issue justify the refactor. ########## datafusion/physical-optimizer/src/enforce_sorting/mod.rs: ########## @@ -316,25 +369,43 @@ fn replace_with_partial_sort( /// are transformed into /// ```text /// "SortPreservingMergeExec: \[a@0 ASC\]", -/// " ...nodes..." -/// " SortExec: expr=\[a@0 ASC\]", +/// " SortExec: expr=\[a@0 ASC\]", +/// " ...nodes..." +/// " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", +/// ``` +/// by following connections from [`CoalescePartitionsExec`]s to [`SortExec`]s. +/// By performing sorting in parallel, we can increase performance in some scenarios. +/// +/// This requires that there are no nodes between the [`SortExec`] and [`CoalescePartitionsExec`] +/// which require single partitioning. Do not parallelize when the following scenario occurs: +/// ```text +/// "SortExec: expr=\[a@0 ASC\]", +/// " ...nodes requiring single partitioning..." +/// " CoalescePartitionsExec", /// " RepartitionExec: partitioning=RoundRobinBatch(8), input_partitions=1", /// ``` pub fn parallelize_sorts( mut requirements: PlanWithCorrespondingCoalescePartitions, ) -> Result<Transformed<PlanWithCorrespondingCoalescePartitions>> { + requirements = requirements.update_plan_from_children()?; update_coalesce_ctx_children(&mut requirements); + let coalesce_can_be_removed = requirements.children.iter().any(|child| child.data); Review Comment: I switched it to be docs only: https://github.com/apache/datafusion/pull/14907#issuecomment-2688656333 Then if I move forward with another refactoring attempt, I'll first make an issue to justify the refactor. -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org