@@ -64,7 +64,9 @@ pub fn assign_initial_requirements(node: &mut SortPushDown) {
64
64
for ( child, requirement) in node. children . iter_mut ( ) . zip ( reqs) {
65
65
child. data = ParentRequirements {
66
66
ordering_requirement : requirement,
67
- fetch : None ,
67
+ // If the parent has a fetch value, assign it to the children
68
+ // Or use the fetch value of the child.
69
+ fetch : child. plan . fetch ( ) ,
68
70
} ;
69
71
}
70
72
}
@@ -95,14 +97,16 @@ fn pushdown_sorts_helper(
95
97
. equivalence_properties ( )
96
98
. ordering_satisfy_requirement ( parent_reqs) ;
97
99
if is_sort ( plan) {
100
+ let sort_fetch = plan. fetch ( ) ;
98
101
let required_ordering = plan
99
102
. output_ordering ( )
100
103
. map ( PhysicalSortRequirement :: from_sort_exprs)
101
104
. unwrap_or_default ( ) ;
102
105
if !satisfy_parent {
103
106
// Make sure this `SortExec` satisfies parent requirements:
104
107
let sort_reqs = requirements. data . ordering_requirement . unwrap_or_default ( ) ;
105
- let fetch = requirements. data . fetch ;
108
+ // It's possible current plan (`SortExec`) has a fetch value.
109
+ let fetch = requirements. data . fetch . or ( sort_fetch) ;
106
110
requirements = requirements. children . swap_remove ( 0 ) ;
107
111
requirements = add_sort_above ( requirements, sort_reqs, fetch) ;
108
112
} ;
@@ -112,7 +116,7 @@ fn pushdown_sorts_helper(
112
116
if let Some ( adjusted) =
113
117
pushdown_requirement_to_children ( & child. plan , & required_ordering) ?
114
118
{
115
- let fetch = child. plan . fetch ( ) ;
119
+ let fetch = sort_fetch . or_else ( || child. plan . fetch ( ) ) ;
116
120
for ( grand_child, order) in child. children . iter_mut ( ) . zip ( adjusted) {
117
121
grand_child. data = ParentRequirements {
118
122
ordering_requirement : order,
0 commit comments