You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/03/23 14:31:15 UTC

[GitHub] [spark] cloud-fan commented on a change in pull request #31941: [SPARK-34637][SQL] Improve the performance of AQE and DPP through logical optimization.

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



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/PlanAdaptiveDynamicPruningFilters.scala
##########
@@ -39,21 +55,51 @@ case class PlanAdaptiveDynamicPruningFilters(
       case DynamicPruningExpression(InSubqueryExec(
           value, SubqueryAdaptiveBroadcastExec(name, index, buildKeys,
           adaptivePlan: AdaptiveSparkPlanExec), exprId, _)) =>
+        val currentPhysicalPlan = adaptivePlan.executedPlan
         val packedKeys = BindReferences.bindReferences(
-          HashJoin.rewriteKeyExpr(buildKeys), adaptivePlan.executedPlan.output)
-        val mode = HashedRelationBroadcastMode(packedKeys)
-        // plan a broadcast exchange of the build side of the join
-        val exchange = BroadcastExchangeExec(mode, adaptivePlan.executedPlan)
-        val existingStage = stageCache.get(exchange.canonicalized)
-        if (existingStage.nonEmpty && conf.exchangeReuseEnabled) {
-          val name = s"dynamicpruning#${exprId.id}"
-          val reuseQueryStage = existingStage.get.newReuseInstance(0, exchange.output)
-          val broadcastValues =
-            SubqueryBroadcastExec(name, index, buildKeys, reuseQueryStage)
-          DynamicPruningExpression(InSubqueryExec(value, broadcastValues, exprId))
+          HashJoin.rewriteKeyExpr(buildKeys), currentPhysicalPlan.output)
+        val canReuseExchange = conf.exchangeReuseEnabled && buildKeys.nonEmpty &&
+          hasBroadcastHashJoinExec(currentPhysicalPlan)
+
+        logDebug(s"PlanAdaptiveDynamicPruningFilters: canReuseExchange => $canReuseExchange " +
+          s"currentPhysicalPlan => ${currentPhysicalPlan}  " +
+          s"plan => $plan")
+
+        var dynamicPruningExpression = DynamicPruningExpression(Literal.TrueLiteral)
+        if (canReuseExchange) {
+          val mode = HashedRelationBroadcastMode(packedKeys)
+          // plan a broadcast exchange of the build side of the join
+          val exchange = BroadcastExchangeExec(mode, currentPhysicalPlan)
+          val existingStage = stageCache.get(exchange.canonicalized)
+          val broadcastQueryStage = if (existingStage.isDefined) {
+            val reuseQueryStage = adaptivePlan.reuseQueryStage(existingStage.get, exchange)
+            logDebug(s"PlanAdaptiveDynamicPruningFilters: reuseQueryStage => $reuseQueryStage")
+            Option(reuseQueryStage)
+          } else if (conf.dynamicPartitionPruningCreateBroadcastEnabled) {
+            var newStage = adaptivePlan.newQueryStage(exchange)
+            val queryStage = stageCache.getOrElseUpdate(exchange.canonicalized, newStage)
+            if (queryStage.ne(newStage)) {

Review comment:
       so there is still a chance that two query stages are created at the same time?




-- 
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:
users@infra.apache.org



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