Skip to content

Commit fca131a

Browse files
committed
perf(cube): logical plan optimization: combine Limit(fetch)>Sort into Sort(fetch) in one pass
1 parent 20d3495 commit fca131a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

datafusion/optimizer/src/push_down_limit.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,13 @@ impl OptimizerRule for PushDownLimit {
136136
}
137137
} else {
138138
sort.fetch = new_fetch;
139-
limit.input = Arc::new(LogicalPlan::Sort(sort));
140-
Ok(Transformed::yes(LogicalPlan::Limit(limit)))
139+
let new_plan = if skip > 0 {
140+
limit.input = Arc::new(LogicalPlan::Sort(sort));
141+
LogicalPlan::Limit(limit)
142+
} else {
143+
LogicalPlan::Sort(sort)
144+
};
145+
Ok(Transformed::yes(new_plan))
141146
}
142147
}
143148
LogicalPlan::Projection(mut proj) => {

0 commit comments

Comments
 (0)