gatorsmile commented on a change in pull request #25111: [SPARK-28346][SQL] 
clone the query plan between analyzer, optimizer and planner
URL: https://github.com/apache/spark/pull/25111#discussion_r305204236
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/QueryExecution.scala
 ##########
 @@ -60,36 +60,31 @@ class QueryExecution(
 
   lazy val analyzed: LogicalPlan = 
tracker.measurePhase(QueryPlanningTracker.ANALYSIS) {
     SparkSession.setActiveSession(sparkSession)
+    // We can't clone `logical` here, which will reset the `_analyzed` flag.
     sparkSession.sessionState.analyzer.executeAndCheck(logical, tracker)
   }
 
   lazy val withCachedData: LogicalPlan = {
     assertAnalyzed()
     assertSupported()
-    sparkSession.sharedState.cacheManager.useCachedData(analyzed)
+    sparkSession.sharedState.cacheManager.useCachedData(analyzed.clone())
   }
 
   lazy val optimizedPlan: LogicalPlan = 
tracker.measurePhase(QueryPlanningTracker.OPTIMIZATION) {
-    sparkSession.sessionState.optimizer.executeAndTrack(withCachedData, 
tracker)
+    
sparkSession.sessionState.optimizer.executeAndTrack(withCachedData.clone(), 
tracker)
 
 Review comment:
   > Since now query plan is mutable, I think it's better to limit the life 
cycle of a query plan instance. We can clone the query plan between analyzer, 
optimizer and planner, so that the life cycle is limited in one stage.
   
   If we decide to clone the plan after each stage, will any test fail if we do 
not clone it?

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