wumrwds opened a new pull request, #60717: URL: https://github.com/apache/spark/pull/60717
### What changes were proposed in this pull request? This PR addresses [SPARK-48486](https://issues.apache.org/jira/browse/SPARK-48486) in two commits: 1. **Cache DPP subquery planning within a query.** Cache planning and preparation of eligible DPP build-side requests within a query, and reuse results for matching cache keys across dependency paths. This covers AQE and non-AQE execution and both broadcast and independent pruning. Cache keys retain planning-relevant hints, keys, projections and modes; consumer attributes are rebound to the shared plan. Reuse is bypassed when subquery reuse is disabled or cache inputs are ineligible, such as nondeterministic plans or key expressions containing subqueries. 2. **Deduplicate shared plan descriptions.** Render a shared subquery body once per rendering in `EXPLAIN` and plan text, and write repeated DPP plan bodies in SQL listener events as event-local references. The SQL UI resolves those references into graph edges. The reference metadata is versioned; events without it use the existing rendering path. ### Why are the changes needed? With nested DPP, the same build-side plan can be constructed along multiple dependency paths, so planning work, memory use, and plan/DAG size can grow rapidly with join depth. Earlier proposal [#47911](https://github.com/apache/spark/pull/47911) proposed limiting DPP based on plan length; this PR reuses eligible construction instead. It also avoids repeatedly expanding shared bodies when rendering plans and serializing SQL events. For example, with `dpp_b` and `dpp_c` partitioned by `k`, the following query can produce nested independent DPP subqueries. `DynamicPruningPlanningSuite` contains the complete fixture and SQL settings: ```sql SELECT sum(b.payload + c.payload) FROM dpp_dim a LEFT JOIN dpp_b b ON a.k = b.k LEFT JOIN dpp_c c ON a.k = c.k WHERE a.flag = 1 ``` ### Does this PR introduce _any_ user-facing change? Yes, in unreleased branches only (master). - `EXPLAIN` and `treeString` plan text now render shared subquery bodies once per rendering, with later occurrences replaced by a reference. In `EXPLAIN FORMATTED`, `ReusedSubqueryExec` retains its existing heading-only display; `treeString` may also reference shared non-DPP subqueries. - SQL listener events can carry versioned (v1) DPP reference metadata. Events without it use the existing rendering path. Older SQL UIs do not resolve these references and may show reference nodes instead of expanded shared bodies. - Query results and DPP eligibility are unchanged. ### How was this patch tested? - Added `DynamicPruningSubqueryCacheSuite`, `DynamicPruningPlanningSuite`, `DynamicPruningCacheRegressionSuite` and `DynamicPruningDisplaySuite`, and extended the subquery, explain and SQL UI suites. - Locally: 47 targeted tests passed (44 in the four DPP suites and 3 DPP cases in `PerPartitionRuntimeFilterSuite`): ```bash build/sbt -batch -no-colors \ 'sql/testOnly *DynamicPruningSubqueryCacheSuite *DynamicPruningPlanningSuite *DynamicPruningCacheRegressionSuite *DynamicPruningDisplaySuite' \ 'sql/testOnly *PerPartitionRuntimeFilterSuite -- -z "DPP"' ``` - *Production workload: an earlier version of this fix was deployed in a Spark 3.4-based build within our company and ran on a real production DPP-heavy job; the job completed successfully and the previously severe plan/DAG expansion no longer occurred.* ### Was this patch authored or co-authored using generative AI tooling? Generated-by: OpenAI Codex (GPT-6 Astra) -- 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]
