maryannxue commented on a change in pull request #27971: [SPARK-31206][SQL] AQE 
should not use the same SubqueryExec when reuse is off
URL: https://github.com/apache/spark/pull/27971#discussion_r395710982
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/InsertAdaptiveSparkPlan.scala
 ##########
 @@ -112,21 +112,24 @@ case class InsertAdaptiveSparkPlan(
    * For each sub-query, generate the adaptive execution plan for each 
sub-query by applying this
    * rule, or reuse the execution plan from another sub-query of the same 
semantics if possible.
    */
-  private def buildSubqueryMap(plan: SparkPlan): Map[Long, SubqueryExec] = {
-    val subqueryMap = mutable.HashMap.empty[Long, SubqueryExec]
+  private def buildSubqueryMap(plan: SparkPlan): Map[Long, 
mutable.Queue[SubqueryExec]] = {
+    val reuseSubquery = conf.subqueryReuseEnabled
+    val subqueryMap = mutable.HashMap.empty[Long, mutable.Queue[SubqueryExec]]
     plan.foreach(_.expressions.foreach(_.foreach {
       case expressions.ScalarSubquery(p, _, exprId)
-          if !subqueryMap.contains(exprId.id) =>
+          if !(reuseSubquery && subqueryMap.contains(exprId.id)) =>
         val executedPlan = compileSubquery(p)
         verifyAdaptivePlan(executedPlan, p)
         val subquery = SubqueryExec(s"subquery${exprId.id}", executedPlan)
-        subqueryMap.put(exprId.id, subquery)
+        val subqueries = subqueryMap.getOrElseUpdate(exprId.id, 
mutable.Queue())
+        subqueries.enqueue(subquery)
       case expressions.InSubquery(_, ListQuery(query, _, exprId, _))
-          if !subqueryMap.contains(exprId.id) =>
+          if !(reuseSubquery && subqueryMap.contains(exprId.id)) =>
         val executedPlan = compileSubquery(query)
         verifyAdaptivePlan(executedPlan, query)
         val subquery = SubqueryExec(s"subquery#${exprId.id}", executedPlan)
-        subqueryMap.put(exprId.id, subquery)
+        val subqueries = subqueryMap.getOrElseUpdate(exprId.id, 
mutable.Queue())
 
 Review comment:
   Not that I think it actually matters... but just for the argument itself, 
how can we guarantee it's the same de-queue order?
   It's just some sort of waste to add duplicates for the mere sake of 
consistency...

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


With regards,
Apache Git Services

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

Reply via email to