cloud-fan commented on a change in pull request #30368:
URL: https://github.com/apache/spark/pull/30368#discussion_r549942541



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -1452,11 +1452,27 @@ object PushPredicateThroughJoin extends 
Rule[LogicalPlan] with PredicateHelper {
 }
 
 /**
- * Combines two adjacent [[Limit]] operators into one, merging the
- * expressions into one single expression.
+ * 1. Eliminate [[Limit]] operators if it's child max row <= limit.
+ * 2. Combines two adjacent [[Limit]] operators into one, merging the
+ *    expressions into one single expression.
  */
-object CombineLimits extends Rule[LogicalPlan] {
-  def apply(plan: LogicalPlan): LogicalPlan = plan transform {
+object EliminateLimits extends Rule[LogicalPlan] {
+  private def canEliminate(limitExpr: Expression, child: LogicalPlan): Boolean 
= {
+    // We skip such case that Sort is after Limit since
+    // SparkStrategies will convert them to TakeOrderedAndProjectExec
+    val skipEliminate = child match {
+      case Sort(_, true, _) => true

Review comment:
       This reminds me that we can optimize root `SortExec` by collecting data 
to the driver and sort locally, to avoid the shuffle, if the input data size is 
small. @ulysses-you do you have interests to run some experiments?




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to