[SPARK-46995][SQL] Allow AQE coalesce final stage in SQL cached plan #45054
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
#43435 and #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):
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
truesemantic of old behavior)Also, to keep the default behavior unchanged, we might want to flip the default value of spark.sql.optimizer.canChangeCachedPlanOutputPartitioning to
falseWhy are the changes needed?
To allow AQE coalesce final stage in SQL cached plan. Also make the semantic of
spark.sql.optimizer.canChangeCachedPlanOutputPartitioningmore reasonable.Does this PR introduce any user-facing change?
How was this patch tested?
Updated UTs.
Was this patch authored or co-authored using generative AI tooling?
No