beliefer commented on code in PR #36541:
URL: https://github.com/apache/spark/pull/36541#discussion_r873406676
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkStrategies.scala:
##########
@@ -81,55 +81,56 @@ abstract class SparkStrategies extends
QueryPlanner[SparkPlan] {
*/
object SpecialLimits extends Strategy {
override def apply(plan: LogicalPlan): Seq[SparkPlan] = plan match {
- case ReturnAnswer(rootPlan) => rootPlan match {
- case Limit(IntegerLiteral(limit), Sort(order, true, child))
- if limit < conf.topKSortFallbackThreshold =>
- TakeOrderedAndProjectExec(limit, order, child.output,
planLater(child)) :: Nil
- case Limit(IntegerLiteral(limit), Project(projectList, Sort(order,
true, child)))
- if limit < conf.topKSortFallbackThreshold =>
- TakeOrderedAndProjectExec(limit, order, projectList,
planLater(child)) :: Nil
+ // Call `planTakeOrdered` first which matches a larger plan.
+ case ReturnAnswer(rootPlan) =>
planTakeOrdered(rootPlan).getOrElse(rootPlan match {
+ // We should match the combination of limit and offset first, to get
the optimal physical
+ // plan, instead of planning limit and offset separately.
+ case LimitAndOffset(limit, offset, child) =>
+ CollectLimitExec(limit = limit, child = planLater(child), offset =
offset)
+ case OffsetAndLimit(offset, limit, child) =>
+ // 'Offset a' then 'Limit b' is the same as 'Limit a + b' then
'Offset a'.
+ CollectLimitExec(limit = offset + limit, child = planLater(child),
offset = offset)
Review Comment:
ditto
--
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]