liuzqt opened a new pull request, #45054:
URL: https://github.com/apache/spark/pull/45054

   
   ### What changes were proposed in this pull request?
   
   https://github.com/apache/spark/pull/43435 and 
https://github.com/apache/spark/pull/43760 are fixing a correctness issue which 
will be triggered when AQE applied on cached query plan, specifically, when AQE 
coalescing the final result stage of the cached plan.
   
    
   
   The current semantic of 
`spark.sql.optimizer.canChangeCachedPlanOutputPartitioning`
   
   ([source 
code](https://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/execution/CacheManager.scala#L403-L411)):
   
   when true, we enable AQE, but disable coalescing final stage (default)
   when false, we disable AQE
    
   
   But let’s revisit the semantic of this config: actually for caller the only 
thing that matters is whether we change the output partitioning of the cached 
plan. And we should only try to apply AQE if possible.  Thus we want to modify 
the semantic of spark.sql.optimizer.canChangeCachedPlanOutputPartitioning
   
   when true, we enable AQE and allow coalescing final: this might lead to perf 
regression, because it introduce extra shuffle
   when false, we enable AQE, but disable coalescing final stage. (this is 
actually the `true` semantic of old behavior)
   Also, to keep the default behavior unchanged, we might want to flip the 
default value of spark.sql.optimizer.canChangeCachedPlanOutputPartitioning to 
`false`
   
   ### Why are the changes needed?
   
   To allow AQE coalesce final stage in SQL cached plan. Also make the semantic 
of `spark.sql.optimizer.canChangeCachedPlanOutputPartitioning` more reasonable.
   
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as 
the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes 
- provide the console output, description and/or an example to show the 
behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to 
the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   
   ### How was this patch tested?
   
   Updated UTs.
   
   
   ### Was this patch authored or co-authored using generative AI tooling?
   No
   


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