Commit becc04a
[SPARK-46996][SQL] Allow AQE coalesce final stage in SQL cached plan
### 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](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?
### How was this patch tested?
Updated UTs.
### Was this patch authored or co-authored using generative AI tooling?
No
Closes #45054 from liuzqt/SPARK-46995.
Authored-by: Ziqi Liu <ziqi.liu@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>1 parent dc73a8d commit becc04a
File tree
6 files changed
+53
-48
lines changed- python/pyspark/sql
- sql
- catalyst/src/main/scala/org/apache/spark/sql/internal
- core/src
- main/scala/org/apache/spark/sql/execution
- adaptive
- test/scala/org/apache/spark/sql
- execution/adaptive
6 files changed
+53
-48
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1711 | 1711 | | |
1712 | 1712 | | |
1713 | 1713 | | |
1714 | | - | |
1715 | | - | |
| 1714 | + | |
1716 | 1715 | | |
1717 | 1716 | | |
1718 | 1717 | | |
| |||
1754 | 1753 | | |
1755 | 1754 | | |
1756 | 1755 | | |
1757 | | - | |
1758 | | - | |
| 1756 | + | |
1759 | 1757 | | |
1760 | 1758 | | |
1761 | 1759 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1561 | 1561 | | |
1562 | 1562 | | |
1563 | 1563 | | |
1564 | | - | |
1565 | | - | |
| 1564 | + | |
| 1565 | + | |
1566 | 1566 | | |
1567 | 1567 | | |
1568 | | - | |
| 1568 | + | |
1569 | 1569 | | |
1570 | 1570 | | |
1571 | 1571 | | |
| |||
Lines changed: 11 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
| |||
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | 62 | | |
75 | 63 | | |
76 | 64 | | |
| |||
395 | 383 | | |
396 | 384 | | |
397 | 385 | | |
398 | | - | |
399 | | - | |
400 | | - | |
| 386 | + | |
| 387 | + | |
401 | 388 | | |
402 | 389 | | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
411 | 398 | | |
| 399 | + | |
412 | 400 | | |
413 | 401 | | |
Lines changed: 1 addition & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
93 | | - | |
| 92 | + | |
94 | 93 | | |
95 | 94 | | |
96 | 95 | | |
| |||
103 | 102 | | |
104 | 103 | | |
105 | 104 | | |
106 | | - | |
107 | | - | |
108 | 105 | | |
109 | 106 | | |
110 | 107 | | |
| |||
Lines changed: 25 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
1630 | 1630 | | |
1631 | 1631 | | |
1632 | 1632 | | |
1633 | | - | |
| 1633 | + | |
1634 | 1634 | | |
1635 | 1635 | | |
1636 | 1636 | | |
1637 | | - | |
| 1637 | + | |
1638 | 1638 | | |
1639 | 1639 | | |
1640 | | - | |
| 1640 | + | |
1641 | 1641 | | |
1642 | 1642 | | |
1643 | 1643 | | |
1644 | 1644 | | |
1645 | 1645 | | |
1646 | 1646 | | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
1647 | 1664 | | |
1648 | 1665 | | |
1649 | 1666 | | |
| |||
1655 | 1672 | | |
1656 | 1673 | | |
1657 | 1674 | | |
1658 | | - | |
| 1675 | + | |
1659 | 1676 | | |
1660 | 1677 | | |
1661 | | - | |
| 1678 | + | |
1662 | 1679 | | |
1663 | 1680 | | |
1664 | 1681 | | |
1665 | | - | |
| 1682 | + | |
1666 | 1683 | | |
1667 | | - | |
| 1684 | + | |
1668 | 1685 | | |
1669 | 1686 | | |
1670 | 1687 | | |
| |||
Lines changed: 11 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2825 | 2825 | | |
2826 | 2826 | | |
2827 | 2827 | | |
2828 | | - | |
2829 | | - | |
2830 | | - | |
2831 | | - | |
2832 | | - | |
2833 | | - | |
| 2828 | + | |
| 2829 | + | |
| 2830 | + | |
| 2831 | + | |
| 2832 | + | |
| 2833 | + | |
| 2834 | + | |
| 2835 | + | |
| 2836 | + | |
| 2837 | + | |
| 2838 | + | |
2834 | 2839 | | |
2835 | 2840 | | |
2836 | 2841 | | |
| |||
0 commit comments