Commit af0d5c3
committed
[SPARK-59024][SQL] Use the physical plan id as the cached name for anonymous cached tables
### What changes were proposed in this pull request?
Add an internal SQL config `spark.sql.dataframeCache.planIdName.enabled` (default `false`). When it is true and the cached table has no name, `CachedRDDBuilder` uses the physical plan id, e.g. `CachedRDD (plan_id=42)`, as the cached name instead of the abbreviated plan tree string. `cachedName` is also made a `lazy val`, so the name is only computed when it is actually needed:
```scala
lazy val cachedName: String = tableName.map(n => s"In-memory table $n").getOrElse {
if (cachedPlan.conf.getConf(SQLConf.DATAFRAME_CACHE_PLAN_ID_NAME_ENABLED)) {
s"CachedRDD (plan_id=${cachedPlan.id})"
} else {
Utils.abbreviate(cachedPlan.toString, 1024)
}
}
```
### Why are the changes needed?
For anonymous cached tables, the cached name was built from the plan's tree string (`cachedPlan.toString`, abbreviated to 1024 chars) at `CachedRDDBuilder` construction time, even for caches that are never materialized. Rendering the plan tree string can be expensive for large plans, and the name is only used for display.
This is another spot, besides the SQL event plan description addressed in SPARK-59023, that hurts the same customer job: it constructs a huge plan whose `treeString` exceeds 280,000 lines, and rendering the plan tree string takes minutes per iteration and contributes to driver OOM.
### Does this PR introduce _any_ user-facing change?
The new config is internal and defaults to `false`. One nuance: because `cachedName` is now evaluated lazily, the name of anonymous caches is rendered at materialization time, so for adaptive plans the Storage tab shows a name derived from the final AQE plan instead of the pre-execution plan. No other behavior changes.
### How was this patch tested?
New unit tests in `InMemoryRelationSuite`:
- `SPARK-59024: plan id cached name for anonymous cached tables` -- verifies the `CachedRDD (plan_id=<id>)` format, that caches of the same plan share the name, that distinct plans get distinct names, that named tables keep the `In-memory table <name>` name, and that the abbreviated plan tree string is kept when the config is disabled
- `SPARK-59024: anonymous cached name is not rendered before materialization` -- verifies the plan tree string is not rendered at cache construction
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Qwen3.8 Max
Closes #58314 from pan3793/SPARK-59024.
Authored-by: Cheng Pan <pan3793@gmail.com>
Signed-off-by: Cheng Pan <chengpan@apache.org>1 parent f54433a commit af0d5c3
3 files changed
Lines changed: 77 additions & 4 deletions
File tree
- sql
- catalyst/src/main/scala/org/apache/spark/sql/internal
- core/src
- main/scala/org/apache/spark/sql/execution/columnar
- test/scala/org/apache/spark/sql/execution/columnar
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2647 | 2647 | | |
2648 | 2648 | | |
2649 | 2649 | | |
| 2650 | + | |
| 2651 | + | |
| 2652 | + | |
| 2653 | + | |
| 2654 | + | |
| 2655 | + | |
| 2656 | + | |
| 2657 | + | |
| 2658 | + | |
| 2659 | + | |
| 2660 | + | |
| 2661 | + | |
2650 | 2662 | | |
2651 | 2663 | | |
2652 | 2664 | | |
| |||
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
292 | | - | |
293 | | - | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
294 | 301 | | |
295 | 302 | | |
296 | 303 | | |
| |||
Lines changed: 56 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | | - | |
22 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
23 | 27 | | |
24 | 28 | | |
| 29 | + | |
25 | 30 | | |
26 | 31 | | |
| 32 | + | |
27 | 33 | | |
28 | 34 | | |
29 | 35 | | |
| |||
51 | 57 | | |
52 | 58 | | |
53 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
54 | 92 | | |
55 | 93 | | |
56 | 94 | | |
| |||
74 | 112 | | |
75 | 113 | | |
76 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
0 commit comments