wangyum commented on code in PR #37565:
URL: https://github.com/apache/spark/pull/37565#discussion_r954475934


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala:
##########
@@ -769,6 +769,16 @@ object LimitPushDown extends Rule[LogicalPlan] {
     // Push down local limit 1 if join type is LeftSemiOrAnti and join 
condition is empty.
     case j @ Join(_, right, LeftSemiOrAnti(_), None, _) if 
!right.maxRows.exists(_ <= 1) =>
       j.copy(right = maybePushLocalLimit(Literal(1, IntegerType), right))
+
+    case GlobalLimit(l, p @ Project(projectList, child))
+      if child.outputSet.subsetOf(p.references) =>
+      Project(projectList, GlobalLimit(l, child))
+    case LocalLimit(l, p @ Project(projectList, child))
+      if child.outputSet.subsetOf(p.references) =>
+      Project(projectList, LocalLimit(l, child))
+    case Limit(l, p @ Project(projectList, child))
+      if child.outputSet.subsetOf(p.references) =>
+      Project(projectList, Limit(l, child))

Review Comment:
   So we are trying to optimize this case?
   ```scala
   spark.sql("select *,ss_sold_time_sk + 3  from (select *, ss_sold_time_sk + 2 
from (select *, ss_sold_time_sk + 1 from store_sales limit 10) limit 9) limit 
8").show()
   ```



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

Reply via email to