Repository navigation
Enforce storage limits for reads inside a shipped plan fragment - #119958
Conversation
A deserialized plan carries no storage limits: every step's `deserialize` builds a fresh `SelectQueryInfo` and nothing fills its `storage_limits`, so the sources run unchecked. The limits reach `ReadProgressCallback` only through the source that reports the progress, and `ISource` falls back to an empty list, so the byte limits and the read-speed and timeout checks were silently ignored for every read in a fragment shipped by plan-based parallel replicas or by `make_distributed_plan`. The query-based implementation does not have this gap: the replica receives SQL and re-plans it, so its own interpreter derives the limits from the settings. Derive them the same way on the receiving side, from the settings that arrived with the query, and attach them to the sources of the deserialized plan. `getStorageLimits` is a pure function of the settings and the stage, so it is reused rather than duplicated - passing the stage also keeps the minimal-speed limits to the initiator, which is the only node that sees the whole query. Measured on a three-replica cluster reading a 100000-row table with `max_bytes_to_read_leaf = 1000`: query-based raised `TOO_MANY_BYTES` while plan-based returned the full result; now both raise it. The row-count limits were already enforced on both paths, because `MergeTree` checks those while selecting parts. Closes: #119953 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [69a0c31] Summary: ✅
AI ReviewSummaryThis PR moves Final Verdict
LLVM Coverage ReportMeasured on commit 69a0c31.
Changed lines: Changed C/C++ lines covered: 8/8 (100.00%) · Uncovered code |
| @@ -0,0 +1,37 @@ | |||
| -- A read inside a shipped plan fragment has to honour the byte limits, as it does when the query is | |||
| -- shipped as SQL instead. Every step's `deserialize` builds a fresh `SelectQueryInfo`, so a | |||
| -- deserialized plan carries no `StorageLimitsList` and the receiving node derives one from the | |||
There was a problem hiding this comment.
This regression only proves the top-level settings case. The code at src/Interpreters/executeQuery.cpp:3278-3281 recreates one outer-query StorageLimits object, but the original plan can carry different limits on different query nodes: nested subqueries keep their own SETTINGS in their QueryNode context (src/Analyzer/QueryTreeBuilder.cpp:313-325), and the planner turns each node's context into select_query_info.storage_limits (src/Planner/Planner.cpp:2612-2615). None of the read-step serializers preserve that list (for example ReadFromMergeTree::serialize writes filters/modifiers/bucket state but not query_info.storage_limits), so after the round-trip a worker fragment with a remote subquery like ... IN (SELECT ... SETTINGS max_bytes_to_read = ...) still loses the inner limit. Restoring one global list on every processor fixes the common top-level case, but not per-subquery limits.
There was a problem hiding this comment.
🕵 Agreed, this is not covered, and the PR description now says so. The StorageLimitsList isn't part of any step's serialized state, so after the round-trip only the query-level settings are left to derive it from. Keeping a subquery's own SETTINGS max_bytes_to_read* would mean serializing the per-node list with the read step: a new ReadFromMergeTree step version plus a plan serialization version bump, which changes the wire format. This PR closes the gap where no limits were enforced at all. It is not a regression, since before it the inner limit was lost as well. I am leaving this thread open for a maintainer to decide whether the per-node list should be serialized as a follow-up.
There was a problem hiding this comment.
🕵 Opened #122724 for the per-subquery SETTINGS limits, and the PR description links it. This PR stays scoped to the query-level limits. The thread stays open for a maintainer to decide whether that scope is enough to merge.
There was a problem hiding this comment.
Note
Copilot was unable to run its full agentic suite in this review.
Pull request overview
Fixes missing enforcement of storage byte/speed/timeout limits when executing reads from a query plan fragment shipped to another node (plan-based parallel replicas / make_distributed_plan), by deriving limits on the receiving side and attaching them to the deserialized plan’s sources/processors.
Changes:
- Derive
StorageLimitsfrom settings/stage on the receiver and attach them to the deserialized pipeline processors. - Expose
IInterpreterUnionOrSelectQuery::getStorageLimitsfor reuse outside the interpreter. - Add a stateless regression test verifying
max_bytes_to_read/max_bytes_to_read_leaferrors on plan-shipped fragments.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| tests/queries/0_stateless/05216_storage_limits_for_shipped_plan.sql | Adds regression test validating byte limits for plan-shipped reads. |
| tests/queries/0_stateless/05216_storage_limits_for_shipped_plan.reference | Expected output for the new regression test. |
| src/Interpreters/executeQuery.cpp | Derives storage limits on receiver and assigns them to processors in deserialized plan pipelines. |
| src/Interpreters/IInterpreterUnionOrSelectQuery.h | Makes getStorageLimits publicly accessible for reuse. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 31 s compile time in total, 7 of them have a recent master baseline. |
…its-for-shipped-plan
…lize` The limits were attached to the processors of the built pipeline in the TCP shipped-plan branch of `executeQuery` only, so the `make_distributed_plan` tasks built by `DistributedPlanExecutor::doExecuteTask` still ran without them, and a subquery read that index analysis builds an `IN` set from during `readFromParts` ran before the loop, also without them. Set `query_info.storage_limits` in `ReadFromMergeTree::deserialize` instead, before `readFromParts`, with the free function `buildStorageLimits` - the same way `resolveStorages` already does for `ReadFromTableStep`. That covers every execution path of a shipped plan and only the storage reads, so exchange sources and other processors are no longer given the limits, and `IInterpreterUnionOrSelectQuery::getStorageLimits` stays protected. The test gains `make_distributed_plan` cases and an `IN` subquery case; all five error assertions fail without the change. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
A deserialized plan carries no storage limits: every step's
deserializebuilds a freshSelectQueryInfoand nothing fills itsstorage_limits. The limits reachReadProgressCallbackonly through the source that reports the progress, andISourcefalls back to an empty list, so the byte limits and the read-speed and timeout checks were silently ignored for every read in a fragment shipped by plan-based parallel replicas or bymake_distributed_plan.The query-based implementation does not have this gap: the replica receives SQL and re-plans it, so its own interpreter derives the limits from the settings.
So derive them from the settings that arrived with the query in
ReadFromMergeTree::deserialize, withbuildStorageLimits, the same wayresolveStoragesalready does for a deserializedReadFromTableStep. Doing it at deserialization, beforereadFromParts, covers every execution path of a shipped plan (the TCP path and themake_distributed_plantasks built byDistributedPlanExecutor), and also the subquery reads that index analysis buildsINsets from. The stage passed is not the initiator's, which keeps the minimal-speed limits to the initiator, the only node that sees the whole query.Per-subquery
SETTINGSoverrides of these limits are still not carried: the limits are not part of any step's serialized state, so the query-level limits are restored. Carrying the per-node list would need a newReadFromMergeTreestep version that serializesStorageLimitsList. This is tracked in #122724.Measured on a three-replica cluster reading a 100000-row
MergeTreetable:parallel_replicas_plan_based = 0parallel_replicas_plan_based = 1, beforemax_bytes_to_read_leaf = 1000TOO_MANY_BYTESTOO_MANY_BYTESmax_bytes_to_read = 1000TOO_MANY_BYTESTOO_MANY_BYTESThe row-count limits were already enforced on both paths, because
MergeTreechecks those while selecting parts - which is why this went unnoticed.Closes: #119953
Related: #119862
Related: #122724
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
max_bytes_to_read,max_bytes_to_read_leafand the read-speed and timeout limits being ignored for reads executed from a query plan shipped to another node, which happens withparallel_replicas_plan_basedand withmake_distributed_plan.Workflow [PR]
Sync PR [sync-upstream/pr/119958]
Version info
26.10.1.994-master(included in26.10and later)