Repository navigation
Make system.one and bounded numbers reads serializable for distributed plan fragments - #119862
Conversation
A plan fragment is serialized before it is sent to a replica, and every step in it has to be serializable: `isSerializable` defaults to `false`, so one step that does not implement it keeps the whole fragment local. `ReadFromSystemOneStep` did not implement it, so a fragment reading `system.one` could not be shipped - for instance the broadcast side of a `RIGHT JOIN` whose left side is `system.one`, where `liftSplitAboveJoin` then leaves the split below the join and only the right side's read is distributed. The step has no state beyond its output header - it produces the single dummy row - so a replica rebuilds it from the header alone. `ReadFromStorageStep::isSerializable` already returns true for `SystemOne` and its `deserialize` rebuilds that single-row chunk, but `StorageSystemOne` has had its own reading step since eb5c15d, so that path stopped being reachable for `system.one`. `05045_distributed_plan_fallback_to_local` used `SELECT 1` as its example of a plan with no distributable source, which held only because of this gap. It now uses a `Memory` table, whose data lives on a single node, and pins that a plan whose only source is `system.one` does ship. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [29f663d] Summary: ✅
AI ReviewSummaryThis PR makes Missing context / blind spots
Findings❌ Blockers
TestsThe new
Final Verdict❌ Block. Enforce source introduction versions on every serialization path and preserve effective subquery read limits, with the focused regressions above. The two dismissed findings remain recorded for visibility; they were not reposted or reopened. No distinct new inline finding was identified. |
Same reason as the previous commit: a plan fragment is serialized before it is sent to a replica, so one non-serializable step keeps the whole fragment local. With `numbers(...)` on the broadcast side of a join - the shape `04724_parallel_replicas_right_join_*` exercises for the query-based implementation - `liftSplitAboveJoin` had to leave the split below the join, so only the right side's read was distributed. A replica rebuilds the read from the table's parameters, so only a read it can reproduce exactly is shipped: the step reports itself serializable only when the domain is bounded and no source filter is attached. - A filter prunes the generated domain. Shipping the read without it is not wrong - the plan keeps its own filtering step - but the replica would generate the whole domain, which for an unbounded read never finishes. Both cases stay local instead. - A LIMIT pushed into the read is carried across, so the replica does not generate rows that are then discarded. `numbers(5)` and `numbers(3, 5)` on the broadcast side now ship the join and answer as they do without parallel replicas; a filtered read and `system.numbers` still keep the fragment local. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…tribute The previous commit refused to ship a filtered `numbers(...)` read, which was stricter than necessary: the plan keeps its own filtering step, so a replica that generated the unpruned domain would still answer correctly. What it would lose is the pruning - `numbers(1e12) WHERE number = 5` generates one value on the initiator and would generate the whole domain on each replica. So serialize the filter along with the table's parameters, the way `FilterStep` does, and let a bounded read ship whether or not it is filtered. An unbounded read still stays local, because nothing would bound what the replica generates there. Measured: `numbers(1e12) WHERE number = 5` on the broadcast side of a join now ships and answers in tens of milliseconds, so the pruning survives the trip. The test pins this with `read_rows` rather than with a query whose regression would hang. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
| registerReadFromSystemOneStep(registry); | ||
| registerReadFromSystemNumbersStep(registry); |
There was a problem hiding this comment.
This needs the usual query-plan serialization version bump. After this PR, version 18 is no longer enough to safely talk to an older peer: a new initiator can now serialize ReadFromSystemOne / ReadFromSystemNumbers into a remote fragment, an older node still advertises query-plan serialization version 18, and QueryPlanStepRegistry::createStep there will fail with Unknown query plan step because these names were not registered yet. Recent additions like LimitRangeStep and FillingStep handled this by bumping DBMS_QUERY_PLAN_SERIALIZATION_VERSION and gating the new step on the new minimum. Without that, mixed-version clusters fail at execution time instead of being excluded up front.
There was a problem hiding this comment.
Done in 868dee8: both steps are registered with since_plan_version = 20 (the 26.10 bump), so the registry never writes them into a stream for an older peer, and the parallel replicas gate excludes replicas below that version.
There was a problem hiding this comment.
The parallel-replica gate is present, but the claim that the registry never writes these names into an older stream is still not true at src/Processors/QueryPlan/Serialization.cpp:162: versionToWrite is called only when the plan version is at least 19. For a one-node ReadFromSystemOne plan, QueryPlan::serialize(out, 18) skips that check and writes the new step name and payload successfully; a version-18 receiver then rejects it with Unknown query plan step. ReadFromSystemNumbers takes the same path.
Please check the step's introduction version for every stream version, and condition only the writing of the per-step version field on version 19. A regression through QueryPlan::serialize at versions 18, 19, and 20 would cover this; checking versionToWrite directly does not exercise the skipped call.
|
|
||
| /// The query info is only read for a pushed-down LIMIT and for storage limits, both of which the | ||
| /// replica applies through its own plan, so an empty one is what the read needs here. | ||
| SelectQueryInfo query_info; |
There was a problem hiding this comment.
This reconstruction drops the original query_info.storage_limits. The local path stores them in storage_limits and initializePipeline attaches them to every source processor, which is what lets ReadProgressCallback enforce byte limits and per-leaf time / speed limits. Here the worker rebuilds the step from an empty SelectQueryInfo, so the shipped numbers(...) read runs with an empty StorageLimitsList: NumbersLikeUtils::checkLimits() still catches the row-count settings, but max_bytes_to_read*, leaf byte limits, and read-speed / per-leaf timeout checks are silently bypassed on the replica path. Please reconstruct the same storage-limit state (or serialize it explicitly) before creating the step.
There was a problem hiding this comment.
The mechanism is right, but this is not specific to this step or new in this PR, so I filed it separately: #119953
Every read inside a shipped plan fragment already runs with an empty StorageLimitsList, including the principal one: ReadFromMergeTree::deserialize builds a fresh SelectQueryInfo and fills only the table-expression modifiers, the row-level filter and prewhere (ReadFromMergeTree.cpp:6736), then attaches query_info.storage_limits at :5333. The receiving side (TCPHandler.cpp:2935, QueryPlan::deserialize) attaches nothing, and neither does DistributedPlanExecutor, so make_distributed_plan has the same gap.
Reconstructing the limits here only would make a numbers(...) read stricter than the MergeTree read beside it in the same fragment, and would close none of the real exposure.
The fix also does not belong in per-step serialization: the receiving node already has the settings the limits are computed from, which is how the row-count limit still works on this path today - NumbersLikeUtils::checkLimits(context->getSettingsRef(), ...). Deriving a StorageLimitsList once on the receiving side and attaching it to the deserialized plan's sources covers ReadFromMergeTree, the system-table sources and make_distributed_plan together. That will start enforcing limits that are silently ignored today, so it wants its own PR and tests, which is what the issue tracks.
Worth recording that query-based parallel replicas do not have the gap: the replica re-plans from SQL and derives the limits from its own settings (InterpreterSelectQuery.cpp:2932/:3012, Planner.cpp:2612).
There was a problem hiding this comment.
This restores outer-query limits, but src/Processors/QueryPlan/ReadFromSystemNumbersStep.cpp:562 still replaces the original limit stack with limits from the single receiving ctx.context. Local planning accumulates outer and subquery limits in Planner.cpp:2723 and passes them into the nested planner at PlannerJoinTree.cpp:3127. A nested SETTINGS clause therefore contributes limits that are absent from the replica's context; the fragment context is taken from the coordinated MergeTree read at applyParallelReplicas.cpp:693.
Using the fixture and settings from 05397, put the byte limit inside the broadcast subquery and leave the outer leaf limit at zero:
SELECT count()
FROM
(SELECT number FROM numbers(100000)
SETTINGS max_bytes_to_read_leaf = 100000,
read_overflow_mode_leaf = 'throw') AS l
RIGHT JOIN t_numbers_limits AS r ON l.number = r.key
SETTINGS max_bytes_to_read_leaf = 0;The local source carries the nested 100000-byte limit for its 800000-byte read. The deserialized source reconstructs a zero leaf-byte limit from the outer context, so that limit is lost. Keep parallel_replicas_local_plan = 0, query_plan_join_swap_table = 0, and enable_join_runtime_filters = 0 as in 05397 when testing this. Please preserve the effective scoped limits, or keep a read local when its limit stack cannot be reconstructed, and cover this nested case as well.
`ReadFromSystemOne` and `ReadFromSystemNumbers` are new step names in the registry, so a peer that does not know them must never be sent one. Two mechanisms cover that, and both key off the version: - Parallel replicas serialize the fragment once and reuse the blob for every replica, so a replica below `DBMS_MIN_QUERY_PLAN_SERIALIZATION_VERSION_WITH_PARALLEL_REPLICAS` is excluded up front. That constant is tied to `DBMS_QUERY_PLAN_SERIALIZATION_VERSION`, so bumping it to 19 is what keeps a replica on the previous version out. - A plan sent over a connection is serialized at the peer's advertised version, so both steps fail closed below version 19, the way `WindowStep` does for its own registration version. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes6 object files changed (+52.95 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units282 translation units recompiled, 2631 s compile time in total, 282 of them have a recent master baseline. |
…-system-one Conflict in `src/Core/ProtocolDefines.h`: master took the query-plan serialization version to 20 (19 for the per-step version, 20 for `legacy_join_size_limits_trigger_spilling`) while this branch had claimed 19 for the new source steps. Moved this branch's bump to 21 and its `DBMS_MIN_QUERY_PLAN_SERIALIZATION_VERSION_WITH_SYSTEM_SOURCE_STEPS` with it, keeping master's entries. Registering a new step name is not what the per-step version added in master's 19 covers - that lets a step change its own bytes - so the global bump is still what keeps an older peer, which does not know the name at all, from being sent one. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…able sources `05185_distributed_plan_fallback_contexts_stress` asserted that every query in its family falls back to local execution. Three of them now distribute their outer plan, because that plan reads only `system.one` or `numbers(...)` and those are exactly the sources this change makes serializable: the scalar subquery rows `06`/`07` and the `INSERT ... SELECT number FROM numbers(1000)` of row `27`. The inner query carrying the `max_rows_to_group_by` limit still falls back, and the row counts the test checks are unchanged. The task-count column becomes a flag. The count of remote tasks depends on how many workers the job's cluster has, which was invisible while every row was zero, and the positive controls of the same test already report `> 0`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119862&sha=004fee431c75a16e5f8bbefe3f6d89e0309b9e17&name_0=PR&name_1=Fast%20test #119862 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
| /// The generated domain has to be reproducible on the replica. The source filter is shipped | ||
| /// along with the table's parameters, so a filtered read is fine; an unbounded one is not, | ||
| /// because nothing then bounds what the replica generates. |
There was a problem hiding this comment.
This does not make sense to me. Why should we care here?
Unbounded read should be allowed. It can make sense. The query should be cancellable if needed.
There was a problem hiding this comment.
Done in 7e6defb: every numbers read is serializable now; an unbounded one is ended by the plan's own LIMIT/filter or by cancellation, as locally.
| const auto & numbers_storage = storage->as<const StorageSystemNumbers &>(); | ||
| chassert(numbers_storage.limit.has_value()); | ||
|
|
||
| writeStringBinary(numbers_storage.column_name, ctx.out); |
There was a problem hiding this comment.
Can it be amy name but number? I think this should not be serialized. Please check.
There was a problem hiding this comment.
It can also be generate_series (from generate_series(...)). It is not serialized anymore: deserialize takes it from the step's output header (28dd286).
| writeBinaryLittleEndian(*numbers_storage.limit, ctx.out); | ||
| writeBinaryLittleEndian(numbers_storage.offset, ctx.out); | ||
| writeBinaryLittleEndian(numbers_storage.step, ctx.out); | ||
|
|
||
| UInt8 flags = 0; | ||
| if (numbers_storage.multithreaded) | ||
| flags |= 1; | ||
| if (numbers_storage.descending) | ||
| flags |= 2; | ||
| if (limit.has_value()) | ||
| flags |= 4; | ||
| if (filter_actions_dag) | ||
| flags |= 8; | ||
| writeIntBinary(flags, ctx.out); | ||
|
|
||
| /// A LIMIT pushed into the read is only a hint - the plan keeps its own limiting steps - but | ||
| /// carrying it keeps the replica from generating rows that are thrown away. | ||
| if (limit.has_value()) | ||
| writeBinaryLittleEndian(static_cast<UInt64>(*limit), ctx.out); |
There was a problem hiding this comment.
There should not be two limits.
I understand that one is pushed down from optimization, and another one is a table-function property.
However, it does not make sense to serialize both. Choose the minimum if both exist.
There was a problem hiding this comment.
They are different quantities: the table's is the length of the value range, the pushed-down one is a row count after the filter, so min is wrong with step > 1 or a filter. Neither needs serializing: the replica optimizes the received plan and sets the limit and the source filter again from the shipped LimitStep/FilterStep, so both are dropped (d37bf2f).
There was a problem hiding this comment.
How can it optimize the one with a value range?
| if (limit.has_value()) | ||
| writeBinaryLittleEndian(static_cast<UInt64>(*limit), ctx.out); | ||
|
|
||
| writeBinaryLittleEndian(static_cast<UInt64>(max_block_size), ctx.out); |
There was a problem hiding this comment.
This one should be serialized via settings (override serializeSettings)
There was a problem hiding this comment.
Done in 8b682b7: max_block_size goes through serializeSettings now.
|
📊 Cloud Performance Report ✅ AI verdict: This PR lets the ReadFromSystemOne and ReadFromSystemNumbers plan steps be serialized, so plans that read system.one or bounded numbers() can be shipped under make_distributed_plan or plan-based parallel replicas. Single-node ClickBench and TPC-H queries never run this code. The one flagged result, clickbench Q23 at -40.0%, has been downgraded to not sure. Q23 does not read either system source, its baseline was very noisy, and the PR median of 51 ms is inside master's recent 48-87 ms range. CPU time also dropped, but because the changed code is off this query's path, that points to baseline variance rather than an effect of the PR. clickbenchFlagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
`04724_parallel_replicas_right_join_ineligible_right_side` is pinned to the query-based implementation, because every assertion in it wants one `EXPLAIN` line carrying both the reading step and the text `RIGHT JOIN`, which is the shipped SQL. What the file is really about survives the implementation: the eligibility decision has to look at the side that is read with replicas, and a shape it rejects has to answer correctly instead of failing on a lookup into the rewritten tree. The new test keeps that. A right side holding no eligible table - a table function, `system.one`, and `RIGHT ANY` / `SEMI` / `ANTI` over a table function - answers exactly as a run without parallel replicas does. Where the right side is eligible and the left is not, plan-based distributes only the right side's read and keeps the join on the initiator, which the counts record; with both sides eligible the join is shipped. The counts of the two arms whose left side reads `system.one` or `numbers(...)` move from 0 to 1 once those sources become serializable (#119862). #121839 (comment) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The arms of `05293_pr_plan_based_right_join_ineligible_right_side` that count what was shipped had `numbers(...)` and `system.one` as their unshippable left side, and both become serializable in #119862, which would move those counts. A `Memory` read is unshippable in either implementation and stays so, so the counting arms read one. Their shapes keep their coverage through the row arms, which the change does not touch. `parallel_replicas_allow_view_over_mergetree` and `parallel_replicas_allow_materialized_views` are settings of the query-based implementation with no plan-based equivalent, so the comment in `05240_pr_plan_based_right_join_materialized_left` says that rather than leaving it open. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…into serialize-read-from-system-one
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…-system-one # Conflicts: # src/Core/ProtocolDefines.h
A plan fragment is serialized before it is sent to a replica, and
IQueryPlanStep::isSerializabledefaults tofalse, so one step that does not implement it keeps the whole fragment local.ReadFromSystemOneStepandReadFromSystemNumbersStepdid not implement it, so a join whose broadcast side readssystem.oneornumbers(...)was never shipped -liftSplitAboveJoinleft the split below the join and only the other side's read was distributed:Both are now serializable.
system.onehas no state beyond its header. Fornumbers(...),numbers_mt(...),system.numbersandgenerate_series(...)only the table's parameters are serialized (range length if any, offset, step, direction), andmax_block_sizegoes through the step settings. The source filter and the pushed-downLIMITare not serialized: the replica optimizes the plan it receives and pushes them into the read again from the shippedFilterStep/LimitStep, so the filter's pruning still applies there. An unbounded read is shipped too; it is ended by the plan's ownLIMITor filter, or by cancelling the query, as it is locally.Both are new step names, so they are registered with
since_plan_version = 20(the 26.10 bump ofDBMS_QUERY_PLAN_SERIALIZATION_VERSION): the registry never writes them into a stream for an older peer, and the parallel replicas gate, tied to that constant, keeps replicas on an older version out.For
system.onethis is a regression fix in reach:ReadFromStorageStep::isSerializablereturns true forSystemOne, butStorageSystemOnehas emitted its own step since eb5c15d, so that path stopped being reachable.Measured with
parallel_replicas_plan_based = 1, all answers matching a run without parallel replicas:system.onenumbers(5),numbers(3, 5)numbers(20) WHERE number % 3 = 0numbers(1e12) WHERE number = 5system.numbers LIMIT 5(unbounded)generate_series(0, 18, 2)05045_distributed_plan_fallback_to_localusedSELECT 1as its "no distributable source" case, which held only because of this gap; it now uses aMemorytable.This does not unify
04724_parallel_replicas_right_join_*with plan-based: 15 of its 33 assertions check forGLOBAL ALL RIGHT JOINtogether with_data_, i.e. that the left side was materialized into a temporary table, which plan-based does not do - it ships the left side's plan.A broadcast side with a non-deterministic function (
rand64()oversystem.one) is evaluated once per replica, as aMergeTreebroadcast side already is today; that is tracked separately.Related: #112351
Related: #125853
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Plan-based parallel replicas can now distribute a join whose broadcast side reads
system.one,numbers(...),system.numbersorgenerate_series(...), instead of keeping the join on the initiator.Workflow [PR]
Sync PR [sync-upstream/pr/119862]
Version info
26.11.1.239-master(included in26.11and later)