ulysses-you commented on code in PR #37129:
URL: https://github.com/apache/spark/pull/37129#discussion_r941137063


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/PushLocalTopKThroughOuterJoin.scala:
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.catalyst.optimizer
+
+import org.apache.spark.sql.catalyst.expressions.{Literal, SortOrder}
+import org.apache.spark.sql.catalyst.planning.{ExtractEquiJoinKeys, 
ExtractTopK}
+import org.apache.spark.sql.catalyst.plans.{JoinType, LeftOuter, RightOuter}
+import org.apache.spark.sql.catalyst.plans.logical.{Join, LocalLimit, 
LogicalPlan, Project, RebalancePartitions, Repartition, 
RepartitionByExpression, Sort, Union}
+import org.apache.spark.sql.catalyst.rules.Rule
+import org.apache.spark.sql.catalyst.trees.TreePattern.{LIMIT, OUTER_JOIN, 
SORT}
+import org.apache.spark.sql.internal.SQLConf
+
+/**
+ * This rule supports push down local limit and local sort from TopK through 
outer join:
+ *   - for a left outer join, the references of ordering of TopK come from the 
left side and
+ *     the limits of TopK is smaller than left side max rows
+ *   - for a right outer join, the references of ordering of TopK come from 
the right side and
+ *     the limits of TopK is smaller than right side max rows
+ *
+ * Note that, this rule only push down local topK to the bottom outer join 
which is different with
+ * [[LimitPushDown]]. This is to avoid regression due to the overhead of local 
sort.

Review Comment:
   yes, it will hit small regression if the acutal row count is smaller than 
the configured threshold. At this case we do a one more local sort but can not 
reduce the data size. So we can avoid regression by configuring a small enough 
threshold.
   
   Or to be more conservative, we can put this rule to AQE Optimizer. Then we 
can decide whether do push down according to the accurate row count.



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to