@@ -951,17 +951,16 @@ fn add_spm_on_top(
951951 // (determined by flag `config.optimizer.bounded_order_preserving_variants`)
952952 let should_preserve_ordering = input. plan . output_ordering ( ) . is_some ( ) ;
953953
954+ let ordering = input
955+ . plan
956+ . output_ordering ( )
957+ . cloned ( )
958+ . unwrap_or_else ( LexOrdering :: default) ;
959+
954960 let new_plan = if should_preserve_ordering {
955961 Arc :: new (
956- SortPreservingMergeExec :: new (
957- input
958- . plan
959- . output_ordering ( )
960- . unwrap_or ( & LexOrdering :: default ( ) )
961- . clone ( ) ,
962- Arc :: clone ( & input. plan ) ,
963- )
964- . with_fetch ( fetch. take ( ) ) ,
962+ SortPreservingMergeExec :: new ( ordering, Arc :: clone ( & input. plan ) )
963+ . with_fetch ( fetch. take ( ) ) ,
965964 ) as _
966965 } else {
967966 Arc :: new ( CoalescePartitionsExec :: new ( Arc :: clone ( & input. plan ) ) ) as _
@@ -1405,14 +1404,12 @@ pub fn ensure_distribution(
14051404 // It was removed by `remove_dist_changing_operators`
14061405 // and we need to add it back.
14071406 if fetch. is_some ( ) {
1407+ let ordering = plan
1408+ . output_ordering ( )
1409+ . cloned ( )
1410+ . unwrap_or_else ( LexOrdering :: default) ;
14081411 let plan = Arc :: new (
1409- SortPreservingMergeExec :: new (
1410- plan. output_ordering ( )
1411- . unwrap_or ( & LexOrdering :: default ( ) )
1412- . clone ( ) ,
1413- plan,
1414- )
1415- . with_fetch ( fetch. take ( ) ) ,
1412+ SortPreservingMergeExec :: new ( ordering, plan) . with_fetch ( fetch. take ( ) ) ,
14161413 ) ;
14171414 optimized_distribution_ctx =
14181415 DistributionContext :: new ( plan, data, vec ! [ optimized_distribution_ctx] ) ;
0 commit comments