Repository navigation
Let subplans extracted by plan optimizations inherit limits and resources - #130378
Conversation
…rces Split out of #102192. The member `QueryPlan::extractSubplan(Node *)` already copies `max_threads`, `concurrency_control` and the resource holder into the extracted plan, but the static `QueryPlan::extractSubplan(Node *, Nodes &)` used by plan optimizations (`tryConvertJoinToIn`, lazy materialization) did not. A subplan extracted there may be executed after the outer plan has been consumed into a pipeline (e.g. the right side of a `JOIN` converted to `IN` is built later as a set), so it ran with the default thread fan-out, without concurrency control, and without holding the table locks, storage holders and interpreter contexts of the source plan. The static overload now takes the source plan, which `Optimization::ExtraSettings` carries as `source_plan`. The fragment that `applyParallelReplicas` cuts with `cloneSubtree` also gets the thread cap and concurrency control of its plan. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`QueryPlan::cloneSubtree` already copies `max_threads`, `concurrency_control` and the resources of the source plan. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…erit-resources Resolve the conflict in `optimizeLazyMaterialization3.cpp`: keep the extra `query_plan` argument of `assembleSource` and take the `VectorWithMemoryTracking` parameter type from master. Pass `query_plan` to the new `makeExtraSettings` call for `lowerArrayJoinFunctions` that came from master. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [a77e3c8] Summary: ✅
AI ReviewSummaryThis PR preserves execution limits and shared resource ownership for standalone subplans extracted by the Final VerdictStatus: ✅ Approve |
Address review: `assembleSource` in lazy materialization for `JOIN` extracted each source with the overload of `QueryPlan::extractSubplan` that inherits the resources of the outer plan, but `apply` puts the fragments back into that same plan via `unitePlans` and `replaceNodeWithPlan`, which append resources. Every rewrite thus appended the plan's resources to itself several times, and with many `UNION ALL` arms their number grew exponentially until `MEMORY_LIMIT_EXCEEDED`. Restore the plain `extractSubplan(Node *, Nodes &)` overload, which holds no resources, for fragments that are reinserted into their owner, and keep the inheriting overload only for standalone subplans (`tryConvertJoinToIn`). Add a regression test with 12 `UNION ALL` arms under `max_memory_usage`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units292 translation units recompiled, 3216 s compile time in total, 292 of them have a recent master baseline. |
Related: #102192
Split out of #102192 (part 6 of 6).
The member
QueryPlan::extractSubplan(Node *)andQueryPlan::cloneSubtreealready copymax_threads,concurrency_controland the resource holder into the new plan, but the staticQueryPlan::extractSubplan(Node *, Nodes &)used by plan optimizations did not. A subplan extracted there may be executed after the outer plan has been consumed into a pipeline (e.g. the right side of aJOINconverted toINis built later as a set), so it ran with the default thread fan-out, without concurrency control, and without holding the table locks, storage holders and interpreter contexts of the source plan.A new static overload takes the source plan, which
Optimization::ExtraSettingscarries assource_plan, andtryConvertJoinToInuses it. Lazy materialization keeps the overload without resources: its fragments are put back into the source plan, which already holds them, and copying them in would append the plan's resources to itself with every rewrite. Covered by a new case ingtest_query_plan_execution_limitsand by05768_lazy_materialization_join_union_resources, which checks that manyUNION ALLarms rewritten by lazy materialization stay within a memory limit.Changelog category (leave one):
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/130378]
Version info
26.11.1.2775-master(included in26.11and later)