Repository navigation
Make ReadNothingStep serializable for distributed query plans - #111941
alexey-milovidov merged 3 commits into
Conversation
ReadNothingStep never overrode isSerializable(), so it inherited the conservative false default from IQueryPlanStep and was absent from QueryPlanStepRegistry. assertFragmentSerializable therefore rejected any multi-stage distributed plan fragment containing it: Code: 344. make_distributed_plan cannot distribute this query: step 'ReadNothing' in stage 'stage_0' is not serializable for remote execution. The step is planted whenever a source provably yields no rows (PlannerJoinTree, InterpreterSelectQuery, StorageFromMergeTreeProjection, ReadFromMergeTree), so this was not specific to the const-false JOIN short-circuit pass: a distributed aggregation over an empty MergeTree table failed on master. The step's entire state is its output header, which QueryPlan::serialize already writes generically per node before calling step->serialize, so its own payload is empty. Wire it into the existing mechanism following ExtremesStep, taking the header from ctx.output_header as source steps do (ReadFromTableStep), plus the registry entry. No serialization version bump. The step-name registry is self-describing and fail-closed: an older receiver throws UNKNOWN_IDENTIFIER before reading any step body, and the payload is empty so no field can be misparsed. The same query already failed loudly before this change, earlier on the initiator, so a loud failure is replaced by a loud failure and nothing that worked stops working. Every step name added so far landed without touching ProtocolDefines.h; the two existing version constants gate a payload bit inside an existing step, which a name cannot express. Bumping instead would make old receivers reject every plan from a newer initiator, and RemoteQueryExecutor disconnects replicas below the minimum plan version. Scope is serialization only: the make_distributed_plan early return in shortCircuitConstantFalseJoin stays, because a ReadNothing leaf changes what the distributed planner sees on that side (shard list, read-rows estimate, join strategy) and deserves its own change. Its comment and 04512's prose are corrected, since both asserted the claim this commit falsifies. One sibling gap is left deliberately: ReadFromSystemOneStep is equally stateless and fails the same way, but system.one reached via ReadFromStorageStep is already special-cased as serializable, and that step lives in clickhouse_storages_system, which is not linked to the query-plan module, so registering it is a layering decision. Follow-up to ClickHouse#110234.
Internal second-model review (2 majors found and fixed, 3 nits)Before opening this PR I ran an independent cold review of the resulting code plus two second-model
The oracle uses a non-aggregating Checks that found nothing, recorded so the ground covered is visible: the empty payload is a I also checked the one way "now proceeds" could be worse than "used to throw": a The no-version-bump decision was re-derived independently rather than taken from the |
Pre-PR validation gate (click to expand)
Verification: Session id: cron:clickhouse-impl-slot-4:20260726-063400 |
|
cc @KochetovNicolai @CurtizJ - could you review this? It wires |
|
Workflow [PR], commit [8d4183b] Summary: ✅
AI ReviewSummaryThis PR wires Final Verdict✅ No findings. |
…ng-step-serializable
CI finish ledger - 21648caEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
None is caused by this PR. Config Workflow, Fast test (amd + arm_darwin) and Style check are green; Bugfix validation is skipped (pr-improvement). On the last line I want to be explicit rather than lean on the family: this PR does touch plan-step serialization, so I checked it directly - the mismatch is an aggregate-state vs Fresh CI is now running on 3e1c729 (the master merge). Session id: cron:our-pr-ci-monitor:20260726-183000 |
|
Fixing PR for the AST fuzzer (amd_debug, targeted) STID 0993-290c The failing build (21648ca) predated that merge. Same root cause as the fix describes: the Verified locally rather than assumed, since the fix's own reproducer uses a shorter chain than this failure. Driving the exact aggregate expression from the abort (recovered from
So #111570 is causally the fix for this signature. No further PR needed from my side, and no test added: #111570 already ships |
…ng-step-serializable
CI finish ledger - 3e1c729Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
No failure is PR-caused: this PR adds I merged master ( Session id: cron:our-pr-ci-monitor:20260727-000000 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 13/13 (100.00%) · Uncovered code |
|
Discharging the ledger row above: One correction to that row's reason column. It said the boost bump that fixes it was already on the branch, so the bump did not resolve that occurrence. That reads as though the bump were the fix; it is not. The merged boost work addresses a different aarch64 MemorySanitizer fiber defect — dirty shadow from struct padding on the fiber stack — and its content is compiled into the very binary that produced this crash, which is why the signature fired anyway. Both are needed. The actual cause is not a false positive either. On aarch64 with #112124 makes the crash unreachable in that one configuration by compiling the fiber-backed remote-I/O paths out of it, at the five places that already choose between an asynchronous and a synchronous implementation. Verification is the signature count over three or more weeks, not a single green run. |
…erializable Make ReadNothingStep serializable for distributed query plans
Cherry pick #111941 to 26.6: Make ReadNothingStep serializable for distributed query plans
Cherry pick #111941 to 26.7: Make ReadNothingStep serializable for distributed query plans
Backport #111941 to 26.7: Make ReadNothingStep serializable for distributed query plans
Backport #111941 to 26.6: Make ReadNothingStep serializable for distributed query plans
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Support distributed query plans (
make_distributed_plan) for queries whose source provably produces no rows at planning time, such as a read from an emptyMergeTreetable. Such queries previously failed withSUPPORT_IS_DISABLED.Description
Related: #110234
Related: #110225
Follow-up to #110234, where @ alexey-milovidov asked for
ReadNothingStepto be made serializable.ReadNothingStepnever overrodeisSerializable(), so it inherited the conservativefalsedefault fromIQueryPlanStep. Any plan fragment containing it was rejected before execution byassertFragmentSerializable:The step is planted whenever a source provably yields no rows (
PlannerJoinTree.cpp,InterpreterSelectQuery.cpp,StorageFromMergeTreeProjection.cpp,ReadFromMergeTree.cpp), so this was not specific to #110234: a distributed aggregation over an empty MergeTree table failed on master. That is the user-visible bite, and the regression test.The step carries no state at all beyond its output header (its constructor takes only a
SharedHeader;clone()just re-wrapsgetOutputHeader();initializePipelineinits aNullSource). SinceQueryPlan::serializealready writes each node's name, description, header and settings generically before callingstep->serialize, the step's own payload is empty. So this wires it into the existing mechanism the same wayExtremesStepdoes, taking the header fromctx.output_headeras source steps do (ReadFromTableStep::deserialize), plus the two-lineQueryPlanStepRegistryentry.I verified the registry entry is load-bearing rather than decorative: with
serialize/deserializein place butregisterReadNothingStepomitted, the same query fails withCode: 47 UNKNOWN_IDENTIFIER: Unknown query plan step: ReadNothingfrom the receiving side, confirming the deserialize path really is exercised (the local executor inDistributedPlanExecutordoes a full serialize/deserialize round trip).No serialization version bump. The plan stream carries one leading version (
DBMS_QUERY_PLAN_SERIALIZATION_VERSION, currently 3), and it does not need to gate a new step name, because the name registry is already self-describing and fail-closed: an older receiver looks the name up inQueryPlanStepRegistry::createStep, does not find it, and throwsUNKNOWN_IDENTIFIERbefore reading any step body: no stream desync, no misparse, and the payload is empty so there is no field a mixed-version pair could disagree about. Downgrade path: an old receiver rejects cleanly, and the same query already failed before this change (earlier, on the initiator, withSUPPORT_IS_DISABLED), so a loud failure is replaced by a loud failure and nothing that worked stops working. Upgrade path: a new receiver understands the name. This matches every step name added so far (ReadFromTable,ObjectFilter,BuildRuntimeFilter, the Shuffle/Gather/Broadcast pairs), none of which touchedProtocolDefines.h; the two existing version constants both gate a payload bit inside an existing step inReadFromMergeTree, which is precisely the case a name cannot express. Bumping the version instead would make an old receiver reject every plan from a newer initiator (andRemoteQueryExecutordisconnects replicas below a minimum plan version), which is a much larger blast radius than the gap being closed.Scope. This PR only makes the step serializable. It deliberately does not remove the
make_distributed_planearly return in the #110234 pass: aReadNothingleaf changes what the distributed planner sees on that side (shard list, read-rows estimate, join strategy), which deserves its own PR. I did correct that guard's comment and 04512's prose, since both asserted the claim this PR falsifies.Sibling coverage. Among the direct
ISourceStepsubclasses lackingisSerializable(), every other one holds state that cannot cross a process boundary: storage/mutations snapshots plusContextPtr(LazilyReadFromMergeTree,LazilyUnorderedReadFromMergeTree,LazyReadReplacingFinalStep,ReadFromStorageLogStep), a liveChunkBufferPtr(ReadFromCommonBufferStep), aPipefactory (ReadFromStreamLikeEngine), aQueryTreeNodePtr(ReadFromRecursiveCTEStep), a whole localQueryPlanPtr(ReadFromLocalParallelReplicaStep), a connection pool plus a reading coordinator (ReadFromParallelReplicasStep,ReadFromMySQLStep), aPipeplus aStorageInput &(ReadFromInput), aMergeTreeData &plus a part snapshot (ReadFromPart), or a rawQueryPlan::Node *into the same plan (CommonSubplanReferenceStep). TheSourceStepWithFiltersubtree is per-storage read plumbing rather than a counterexample: its two wired-up members (ReadFromMergeTree,ReadFromObjectStorageStep) are already serializable, filter DAGs included (FilterDAGInfo::serialize,PrewhereInfo::serialize). One genuine sibling gap remains and I am not fixing it here:ReadFromSystemOneStepis equally stateless and hits the same error (step 'ReadFromSystemOne' ... is not serializable). It is deferred becausesystem.onereached viaReadFromStorageStepis already special-cased as serializable (ReadFromPreparedSource.cpp), so only the dedicated step path is missing, and that step lives inclickhouse_storages_system, which is not linked to the query-plan module (see the existing workaround comment inOptimizations/optimizeJoin.cpp), so registering it needs a layering decision, not this one-line-of-state change. Happy to file that follow-up.Header round-trip is safe for the compound and wrapped types the test covers (
LowCardinality(Nullable(String)),Array,Map,Tuple,Nullable). Only names and types travel:deserializeHeaderrebuilds each column viatype->createColumn(), so the payload is type metadata and nothing else. The post-deserializeassertCompatibleHeadercheck cannot fail for this step, since it adoptsctx.output_headerverbatim and the comparison is then between one and the same header object.Version info
26.8.1.196(included in26.8and later)26.7.4.43,26.6.3.47