Repository navigation
Transport join runtime filters across distributed plan stages - #114822
Conversation
… state Carry sizing and self-disabling parameters as `RuntimeFilterGeometry`, serialize `ApproximateRuntimeFilter` exact or bloom state, and bound the exact phase by actual key bytes from `Set::getSetElementsBytes`. Local filters keep `exact_bytes_limit` equal to the bloom size; the serialized plan carries `join_runtime_filter_exact_bytes_limit`. Co-authored-by: Cursor <[email protected]>
When experimental `distributed_plan_join_runtime_filters` is enabled, each build task ships a partial filter through a bounded fan-in merge tree and the root broadcasts the union to probe fragments before the shuffle. Missing or partial filters fail open. Strip runtime-filter-only predicates before `estimateReadRowsCount` so they do not affect join-order cardinality. Co-authored-by: Cursor <[email protected]>
Cover plan placement, admission, bounded merge-tree delivery, and exact-phase string transport for `distributed_plan_join_runtime_filters`, plus a clustered integration test. Co-authored-by: Cursor <[email protected]>
Column-statistics HyperLogLog undershoots distinct keys, so using NDV as the exact-values cap overflowed complete key sets into bloom filters. An unindexed plan-time filter must also keep the settings geometry, which statistics would otherwise override. Co-authored-by: Cursor <[email protected]>
|
From Alexander Gololobov (davenger), 2026-08-04. Not implemented here; recording it so the public review has the same context.
|
|
Workflow [PR], commit [6a3a1ef] Summary: ✅
AI ReviewSummaryThe PR transports inclusion join runtime filters through a bounded merge tree so distributed probe scans can filter before their shuffle. The current code addresses the earlier serialization, cancellation, range-metadata, and stream-memory findings. One contract violation remains: estimate-driven exact states can exceed the configured static transport budget. Findings
Tests
Missing context / blind spots
Final Verdict |
Build profile diff (arm_release)Comparing Binary sizes
The official master build is compiled with Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/CMakeFiles/dbms.dir/Processors/QueryPlan/Optimizations/RuntimeFilterExchangeWiring.cpp.o |
new | 298.56 KiB | +298.56 KiB |
src/CMakeFiles/dbms.dir/Processors/Transforms/MergeRuntimeFiltersTransform.cpp.o |
new | 189.94 KiB | +189.94 KiB |
src/CMakeFiles/dbms.dir/Processors/QueryPlan/MergeRuntimeFiltersStep.cpp.o |
new | 180.46 KiB | +180.46 KiB |
src/CMakeFiles/dbms.dir/Processors/QueryPlan/BuildRuntimeFilterStep.cpp.o |
114.97 KiB | 241.47 KiB | +126.50 KiB (+110.02%) |
src/CMakeFiles/dbms.dir/Processors/QueryPlan/RuntimeFilterLookup.cpp.o |
592.55 KiB | 675.13 KiB | +82.58 KiB (+13.94%) |
src/CMakeFiles/dbms.dir/QueryPipeline/DistributedPlanExecutor.cpp.o |
889.95 KiB | 951.50 KiB | +61.55 KiB (+6.92%) |
src/CMakeFiles/dbms.dir/Processors/QueryPlan/RuntimeFilterGeometry.cpp.o |
new | 48.45 KiB | +48.45 KiB |
src/CMakeFiles/dbms.dir/Server/StatelessWorker/StatelessWorkerEndpoint.cpp.o |
190.91 KiB | 212.90 KiB | +21.99 KiB (+11.52%) |
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.
Compile time of recompiled translation units
665 translation units recompiled, 5533 s compile time in total, 661 of them have a recent master baseline.
Translation units without a recent master baseline:
src/Processors/QueryPlan/Optimizations/RuntimeFilterExchangeWiring.cpp: 6.2 s
Symbol sizes
| Binary | Symbol | Master | PR | Δ |
|---|---|---|---|---|
programs/clickhouse-keeper |
ProfileEvents::global_counters_storage |
13.00 MiB | 13.06 MiB | +64.00 KiB (+0.48%) |
programs/clickhouse |
ProfileEvents::global_counters_storage |
13.00 MiB | 13.06 MiB | +64.00 KiB (+0.48%) |
Address the review suggestion in #114822 (comment): the transport machinery (partial filters, the bounded fan-in merge tree, the exchange reuse) stays; what changes is how the endpoints get into the plan. `SendRuntimeFilterStep`, `ReceiveRuntimeFilterStep`, and the pre-cut wiring pass `wireDistributedRuntimeFilters` are gone. `BuildRuntimeFilterStep` stays in the plan exactly where the join optimizer put it and gains a sending mode driven by exchange-topology fields that only `wireRuntimeFilterExchangeTopology` sets: the pass now runs purely post-cut, discovering eligible build steps and the `__applyFilter` applications in the cut stage fragments (`FilterStep` predicates and scan PREWHEREs) instead of matching pre-placed step pairs, so nothing has to predict where the plan will be cut. Exact-phase sizing comes from row estimates stamped onto the build steps before the cut, and each consuming site is admitted against its own estimates, with a defensive skip when delivery would create a stage-dependency cycle. The receiving side is no longer a plan step: each consuming task carries a `RuntimeFilterReceiveDescriptor` in `DistributedQueryTask`, and `DistributedPlanExecutor` turns it into a side branch that unions the partial states and registers the result in the task's filter lookup, from where `__applyFilter` works as in the local case, including fail-open while the filter has not arrived. Plans without transport serialize exactly as before; a plan that uses it requires query plan serialization version 7 (serializing topology fields to an older version throws, because an old worker would run the step as a local build and the filter would silently never arrive) and task serialization version 3, chosen per task so descriptor-less tasks stay rolling-upgrade safe. Transport decisions no longer appear in `EXPLAIN`; the stateless tests assert delivery through `system.text_log` registration and admission traces and `system.query_log` task attribution instead of plan shapes. Discovery also reaches consumers the old shape matching missed, so broadcast joins now transport their filters too, gated by the same admission. Co-Authored-By: Claude Fable 5 <[email protected]>
Drop restated essays and reviewer-thread asides. Keep the constraints: empty rendezvous key, persisted-kind deadlock, exact-phase budget, Native payload bound. Co-authored-by: Cursor <[email protected]>
|
@davenger Thanks for your detailed suggestions. I've now modified it along the same lines. One deviation from your sketch: exact-phase sizing still needs the build-side row estimate, but post-cut a build side that is another stage's output ends at an exchange source with nothing to estimate from. So |
…ansport Co-authored-by: Cursor <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
…istory block Co-Authored-By: Claude Fable 5 <[email protected]>
…or database Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
…zer builds Co-Authored-By: Claude Fable 5 <[email protected]>
Same-stage consumers are skipped on the filter exchange (a self-edge would cycle the scheduler). When that producer also ships the filter, transport mode never called lookup.add, so those sites fail-opened. Register the merged partial after serialize, and restore filter_key from a sibling __applyFilter after deserialize. Co-authored-by: Cursor <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e test can repeat Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… wiring Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nalysis Co-Authored-By: Claude Opus 5.5 <[email protected]>
| : estimated_keys * key_width; | ||
| if (exact_transport_bytes > budget.geometry.exact_bytes_limit) | ||
| { | ||
| budget.geometry.exact_bytes_limit = exact_transport_bytes; |
There was a problem hiding this comment.
[P2] Keep estimate-driven exact sets within the configured transport budget
This raises the transmitted exact-state budget above join_runtime_bloom_filter_bytes, contrary to the static wire-size guarantee in the PR description and the linked RFC. With the default 524,288-byte Bloom filter and an estimate of 200,000 distinct UInt64 keys, this sets exact_bytes_limit to 1,600,000 and raises exact_values_limit to 200,000. Both exact-set limits use strict > checks, so the complete union stays exact and AdaptiveSetRuntimeFilter::serialize writes all 1.6 MB of keys. High-entropy keys also prevent exchange compression from hiding the excess.
The estimate can raise this to 16 MiB, 32 times the default budget, and the root broadcasts that state separately to every receiving task. Please keep transmitted exact states within the configured static budget and degrade to the fixed-size Bloom filter when they exceed it, or expose a separate explicit transport byte cap and revise the stated guarantee. Add a focused regression with an estimate-sized exact union above the configured Bloom size.
…artial rows Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lters by the hash table Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e task union Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #114901
A join runtime filter is currently local to its fragment: the build side creates it and only
__applyFiltersites in that fragment see it, so a fact table scan in another stage crosses its shuffle exchange in full even if the filter would have removed most rows. Ifdistributed_plan_join_runtime_filtersis enabled, each build task now ships its partial filter through a bounded fan-in cascade of merge stages, and the final stage broadcasts the complete merged union to the probe-side fragments, which apply it before the shuffle.Filters fail open: rows pass unfiltered until the merged filter arrives, so a filter that never arrives (or half-arrives) can't change results. If a filter's producer disconnects after its stream is established, the stream ends early, and the filter is used only if the producer's state already arrived.
RuntimeFilterReceivesAbandonedcounts these streams. A merge task takes its inputs without waiting for its receivers, so a receiver that never connects holds up neither the build side nor the other receivers. A merge task that fails to start or connect, or reads a malformed stream, fails the query with an exception; it never changes results. The local driver (distributed_plan_execute_locally) waits for the merge stages, so it reports such a failure whenever it happens. The remote driver reports it until its cleanup stops waiting for the cancelled task; after that, the failure is only logged on the worker. Only inclusion filters travel, a shipped filter never costs more on the wire than one of the configured static size, and filters are only shipped when the estimated build key set is small compared to the receiving scan.This replaces an earlier prototype where the initiator collected and merged the filters and probe dispatch was rescheduled around filter readiness; here the partials just ride the exchange layer like any other stream, with no new worker operations, no dispatch changes, and no measurable planning cost.
New settings:
distributed_plan_join_runtime_filters(experimental, default off) is the only user-facing one; with it off, plans and results are identical to master, with one sizing-behavior exception: the exact phase of every runtime filter (including local ones underenable_join_runtime_filters) is now bounded by its actual key bytes rather than the hash-table buffer size, which moves the exact-to-bloom degradation point—earlier for long string keys (their bytes were previously uncounted) and later for short keys (the buffer, transiently up to ~2 MB per stream at the default 10000-row cap, no longer counts against the byte budget). Results are unchanged either way. The serialized plan additionally gainsjoin_runtime_filter_exact_bytes_limit, which carries a transported filter's exact-phase byte budget to the workers, and every distributed task is sent at task version 4, with an empty descriptor list when nothing is transported.On public ClickHouse the transported exact-phase row cap is taken from the scan's row estimate, not from column-statistics NDV. HyperLogLog undershoots distinct keys, so using NDV as the cap overflowed complete key sets into bloom filters. An unindexed plan-time filter is also treated as unknown for transport sizing, so it keeps the settings geometry instead of letting statistics override it.
TPC-H SF1000
r7g.4xlarge, ap-south-2, shared io2 volume read-only on every node, 2 warmups + 3 timed runs per variant, medians. Execution time only (planning excluded; it is identical with the setting on and off).
The other ten campaign queries are ties, with one exception: q16 regresses (+0.15 s at 8 nodes, +0.39 s at 16) because a filter that ends up pruning nothing still gets broadcast and the broadcast grows with node count. The admission heuristic should catch this; tracked in #114901.
TPC-H SF100 on a real network
From an earlier prototype, included because it is the measurement over an actual NIC: 4× m8g.4xlarge, 9.53 Gbps between nodes, 0.116 ms RTT, medians of 5. The mechanism differs but the filters, admission logic, and apply sites are the same.
(q04, q09, q13, q14, q16, q19, q20, q22 were flat there; q05/q08/q15/q18 excluded for environment reasons unrelated to the transport.)
Plan shapes for the two headline queries, from the SF100 evidence runs:
q17 without the transport, both

lineitemscans run in full:q17 with it, both scans collapse ~996x before their shuffles:

q02 without the transport, both 80M-row

partsupparms feed the join unpruned:q02 with it, the union reaches both

partsuppscans and the cascade collapses:Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Join runtime filters now travel across distributed plan stages when
distributed_plan_join_runtime_filtersis enabled: build-side tasks ship partial filters over the exchange layer and probe-side scans apply the merged union before their shuffle exchange, dramatically reducing the number of rows crossing the network. A filter that is lost, late or never built cannot change results.Addendum
The transport adds no plan steps and no worker operations of its own. Send is a mode of the existing
BuildRuntimeFilterStep, receive is a property of the task, and the partial filters ride the exchange layer as ordinary streams. All of it is wired aftermakeDistributedPlanhas cut the plan into stages, so nothing has to predict where a cut will land.wireRuntimeFilterExchangeTopologyruns on the finishedDistributedQueryPlan. It walks the cut fragments and finds both endpoint kinds by inspection: eligibleBuildRuntimeFilterSteps on one side,__applyFilterapplications (FilterSteppredicates and scan PREWHEREs) on the other. A filter is transported only when its builder and a consumer landed in different stages; same-stage pairs stay local and are not touched.__applyFilteris the rendezvous point. Its second argument is a const String column whose result name is a stable_runtime_filter_<hash>and whose value is the key the filter is registered under. Discovery matches builds and applications by the key, so a consumer needs no rewriting: its__applyFilteralready looks up the key the transported filter is registered under. The function is fail-open, rows pass unfiltered until the filter appears in the registry, so results never depend on delivery.Send mode is an optional field on
BuildRuntimeFilterStep:TreeExchange, its position in the merge cascade. The wiring always sends through a merge stage, even from a single build task; the directFilterExchangeform stays in the format but is not planned. When set, the step sends its partial into the exchange and also registers it in its own task for same-stage__applyFiltersites, and its rendezvous key is serialized with it. Merges are a fan-in-16 cascade ofMergeRuntimeFiltersStepstages; the root broadcasts the complete union to every consuming task.Receive is not a step. Each consuming task carries a
RuntimeFilterReceiveDescriptor(key, name, key type, geometry, input streams) andDistributedPlanExecutorattaches a side branch to the fragment pipeline: exchange sources ->MergeRuntimeFiltersTransform-> registration ->EmptySink. The consumer's fragment plan is identical to the untransported one.Sizing has to happen before the cut. The exact-phase cap comes from the build-side row estimate, and post-cut a build side that is another stage's output ends at an exchange source with nothing left to estimate from. So
makeDistributedPlanstampsestimated_build_rowsonto the build steps right before cutting; the field is in-memory only, never serialized. Admission then runs post-cut, per consuming scan, with the same gates and trace messages as local filters.Wiring skips a consumer whose stage the producing stage transitively depends on. Delivering there would add the reverse edge and close a scheduling cycle.
Versioning fails closed. The exchange fields, the rendezvous key,
join_runtime_filter_exact_bytes_limitand theMergeRuntimeFiltersstep are written only at plan version >= 20 (26.9 is at 19). Serializing a step with exchanges below that throwsSUPPORT_IS_DISABLED, because an older worker would run the step as a plain local build and the filter would silently never arrive. The receive descriptors are in task version 4, which every task carries: an older worker rejects the task withNOT_IMPLEMENTED, as it already rejects master's version 20 plans, and a new worker still reads version 3 tasks from a 26.9 initiator.Workflow [PR]
Sync PR [sync-upstream/pr/114822]
Version info
26.10.1.2455-master(included in26.10and later)