Repository navigation
Add a per-step serialization version to query plan steps - #119535
Conversation
Each step owns a version that travels on the wire and is bumped on any change to the step's bytes. A reader refuses a step version it does not know rather than misparsing it, so the global plan version only has to move once per release. The registry picks the version to write for the stable global version. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…_version Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Workflow [PR], commit [30f31ec] Summary: ❌
AI ReviewSummaryThis PR adds per-step query-plan serialization versions, threads them through Findings
Final VerdictChanges requested. LLVM Coverage ReportMeasured on commit 30f31ec.
Changed lines: Changed C/C++ lines covered: 157/163 (96.32%) · Uncovered code |
| static constexpr auto DBMS_QUERY_PLAN_SERIALIZATION_VERSION = 16; | ||
| /// Version 17 writes a per-step serialization version next to every step, so a step can change its | ||
| /// own bytes without moving this global version (see the constant below). | ||
| static constexpr auto DBMS_QUERY_PLAN_SERIALIZATION_VERSION = 17; |
There was a problem hiding this comment.
Version 17 changes the wire layout of the QueryPlan packet's plan payload, but docs/reference/interfaces/specs/NativeProtocol.mdx still describes QueryPlan as just {serialization_version, max_threads, concurrency_control, plan} and never mentions the per-step step_version field or its >= 17 gate.
The review rules require protocol/spec sync for native TCP changes. Please update the QueryPlan section in docs/reference/interfaces/specs/NativeProtocol.mdx in the same PR so the inter-server contract stays documented.
Build profile diff (arm_release)Comparing commit See the job log for details. |
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…_version Co-Authored-By: Claude Fable 5.1 <[email protected]>
| /// The serialization versions of one step. | ||
| /// | ||
| /// A step owns its version. The author bumps it when the bytes the step's own `serialize` and | ||
| /// `deserialize` write and read change. The version travels on the wire, so a reader refuses a | ||
| /// version it does not know instead of misparsing the bytes. | ||
| /// | ||
| /// The contract this relies on: | ||
| /// - Several steps may change in one release cycle, each bumping its own version. One bump of | ||
| /// the global plan version per release covers all of them. | ||
| /// - On master a step may change several times between releases; each change bumps its version. | ||
| /// When a release branch is cut, each step keeps the previous release's version plus the one | ||
| /// new version, and the global plan version moves once. | ||
| /// - Within a released line step versions are frozen, so two servers that advertise the same | ||
| /// global version agree on every step. Only critical bugfixes are backported. When one has to | ||
| /// change a step's bytes, it bumps the step version without a global bump; during that fix's | ||
| /// rolling upgrade a peer that does not know the new version refuses it, and the affected | ||
| /// queries fail with an error until the rollout completes. That is accepted: a fix critical | ||
| /// enough to backport matters more than mixed-version compatibility while it rolls out. The | ||
| /// on-wire version only makes sure the failure is a clean error, not misparsed bytes. | ||
| /// - `write` is keyed by the global plan version: the writer serializes at the version the peers | ||
| /// agreed on (the lowest both support, or one pinned in config) and picks the step version | ||
| /// stored for it, so an older-release peer gets the encoding it knows. | ||
| /// - This covers the step's own payload only. The step settings channel (`serializeSettings` and | ||
| /// the changed-settings blob) is versioned by the global plan version, so a change to a step's | ||
| /// settings schema also needs a global plan-version bump. | ||
| /// | ||
| /// `readable` lists every step version this binary can deserialize. `write` maps a global plan | ||
| /// version to the step version to write at it: the writer takes the entry with the highest plan | ||
| /// version not above the one it serializes with. A step that has never changed its bytes stays at | ||
| /// version 0 and needs none of this. | ||
| struct Versions | ||
| { | ||
| std::vector<UInt64> readable = {0}; | ||
| /// (global plan version, step version), sorted by the plan version ascending. | ||
| std::vector<std::pair<UInt64, UInt64>> write = {{0, 0}}; | ||
| }; |
There was a problem hiding this comment.
This looks somewhat too complicated to me.
- The comment above is not human-readable.
- Idk why we need to split read and write. Usually, code is symmetric. Technically, we can support a wider range of reading versions. However, I can hardly imagine the usecase when sending plan
old -> newis allowed, butnew -> oldis not. - Do we need a vector of versions, not just min and max? Do we want to have gups?
- Idk if connecting step version to plan version make sense. There are cases when they are orthogonal (e.g. we change a format of plan header serialization, or a packet structure). It could be that we want to change plan version and step version at the same time (e.g. if we switch to protobuf, want json, or something) - but this looks more like a format setting. Anyway, I don't want to have a new copy of the versions vector every time the global plan version changes (which has increased 10 times for the last month!)
There was a problem hiding this comment.
Thanks — you're right on 0–2; reworked in afcadea.
0. Simplified the comment.
1. There is no read/write split any more. Each step has one list of {version, since_plan_version}: its supported serialization versions and the global version when each was introduced. The reader accepts only a listed version. The writer picks the newest version the peer's global version allows. So both directions work.
2. It is an explicit list, not [min, max], on purpose. It stays short: only the versions needed for the few latest supported releases are kept. And a range does not always fit: after a backport a release can support versions 1 and 3 but not 2, and a range would accept 2.
3. The dependency on the global version cannot be avoided: it is the only number peers negotiate, so something has to map it to a step version to send an older peer the bytes it knows. Today that mapping is the ctx.version >= WITH_X checks inside each step. In the registry it is in one place, visible and easy to prune, instead of spread over every step. An entry changes only when the step's own bytes change, never when the global version moves for another reason. The eleven global-version bumps of the last month would have touched zero entries; UnrelatedPlanVersionBumpsDoNotTouchTheStep checks this.
… list Co-Authored-By: Claude Fable 5.1 <[email protected]>
KochetovNicolai
left a comment
There was a problem hiding this comment.
Discussed offline, LGTM.
Let's merge this version.
…he key Co-Authored-By: Claude Fable 5.1 <[email protected]>
Master moved to per-step serialization versions (#119535) and documented that a change to a step's bytes must bump the step's own version rather than the global `DBMS_QUERY_PLAN_SERIALIZATION_VERSION` (#123241). Flag bit 128 of `AggregatingStep` is now taken by `only_merge`. Resolve accordingly: drop the global version bump and the bit-128 top-K flag, and carry the top-K parameters as a trailing presence byte plus payload in version 1 of the `Aggregating` step, introduced at plan version 20 (the 26.10 value). Towards a peer that reads step version 0 the parameters are omitted, as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Query plan serialization is used to send a plan to other servers for distributed execution and parallel replicas. Today every change to how a step is serialized bumps the single global
DBMS_QUERY_PLAN_SERIALIZATION_VERSION. This ties all steps to one counter. It also gives no protection when a step's bytes change without a bump: a reader built from different code misparses them instead of failing with an error.This change gives each step its own serialization version.
serializeanddeserializehandle change.INCORRECT_DATAinstead of misparsing.Versioning rules:
QueryPlanpacket, or the server's own version for the stateless-worker task path, which does not negotiate (as before).serializeSettings) are still versioned by the global version, so a change to them still needs a global bump.Why the list lives in the registry: the global version is the only number peers negotiate, so something must map it to a step version. Keeping that map as one list per step means pruning at release time is an edit in one place, a version the step never implemented is rejected instead of accepted by a range, and the selection logic has one unit test. An entry changes only when the step's own bytes change, never when the global version moves for another reason.
Compatibility: the step version is written only from plan serialization version 19 on; below it the format is unchanged, and mixed-version clusters keep working through the existing negotiation. A step that never changed its bytes stays at version 0 and declares nothing.
Changelog category (leave one):
Changelog entry:
Not for changelog. Internal change to query plan serialization: each step now has its own serialization version. A reader rejects an unknown step version instead of misparsing it, and the global plan version is bumped once per release instead of on every step change.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/119535]
Version info
26.9.1.1569(included in26.9and later)