peter-toth commented on code in PR #41046:
URL: https://github.com/apache/spark/pull/41046#discussion_r1185821589


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/ReuseAdaptiveSubquery.scala:
##########
@@ -33,10 +33,13 @@ case class ReuseAdaptiveSubquery(
 
     
plan.transformAllExpressionsWithPruning(_.containsPattern(PLAN_EXPRESSION)) {
       case sub: ExecSubqueryExpression =>
-        val newPlan = reuseMap.getOrElseUpdate(sub.plan.canonicalized, 
sub.plan)
-        if (newPlan.ne(sub.plan)) {
-          sub.withNewPlan(ReusedSubqueryExec(newPlan))
-        } else {
+        // `InsertAdaptiveSparkPlan` compiles subquery for each exprId, then 
the java object
+        // is always `eq` if two subqueries have same exprId.
+        // Check if the subquery can be reused manually instead of call 
`getOrElseUpdate`.
+        reuseMap.get(sub.plan.canonicalized).map { subquery =>
+          sub.withNewPlan(ReusedSubqueryExec(subquery))
+        }.getOrElse {
+          reuseMap.put(sub.plan.canonicalized, sub.plan)

Review Comment:
   Thanks! 
https://github.com/apache/spark/pull/41046/commits/99f810c4084576eea19231590f4ddf9a9afaf7b4
 looks ok to me.



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