ulysses-you commented on a change in pull request #32816:
URL: https://github.com/apache/spark/pull/32816#discussion_r692077822



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/AdaptiveSparkPlanExec.scala
##########
@@ -656,13 +687,54 @@ case class AdaptiveSparkPlanExec(
     // node to prevent the loss of the `BroadcastExchangeExec` node in DPP 
subquery.
     // Here, we also need to avoid to insert the `BroadcastExchangeExec` node 
when the newPlan
     // is already the `BroadcastExchangeExec` plan after apply the 
`LogicalQueryStageStrategy` rule.
-    val finalPlan = currentPhysicalPlan match {
+    def updateBroadcastExchange(plan: SparkPlan): SparkPlan = 
currentPhysicalPlan match {
       case b: BroadcastExchangeLike
-        if (!newPlan.isInstanceOf[BroadcastExchangeLike]) => 
b.withNewChildren(Seq(newPlan))
-      case _ => newPlan
+        if (!plan.isInstanceOf[BroadcastExchangeLike]) => 
b.withNewChildren(Seq(plan))
+      case _ => plan
     }
 
-    (finalPlan, optimized)
+    val optimizedWithSkewedJoin = applyPhysicalRules(
+      optimizedPhysicalPlan,
+      optimizeSkewedJoinWithExtraShuffleRules,
+      Some((planChangeLogger, "AQE Optimize Skewed Join With Extra Shuffle"))
+    )
+    val validatedWithSkewedJoin =
+      checkDistribution(
+        optimizedWithSkewedJoin,
+        optimizedPhysicalPlan,
+        isFinalStage(optimizedWithSkewedJoin),
+        OptimizeSkewedJoin.ruleName)
+
+    // here are three reasons if validatedWithSkewedJoin is equal to 
optimizedPhysicalPlan:
+    // 1. no skewed join optimized
+    // 2. optimize skewed join introduce extra shuffle and force optimize is 
disabled
+    // 3. optimize skewed join change final stage output partitioning
+    val newPhysicalPlans = if 
(validatedWithSkewedJoin.fastEquals(optimizedPhysicalPlan)) {
+      updateBroadcastExchange(optimizedPhysicalPlan) :: Nil

Review comment:
       @cloud-fan in these three case, we will not introduce extra overhead




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