Repository navigation
Use deterministic names for runtime filters in query plan - #106137
Conversation
|
Workflow [PR], commit [58cc1e4] Summary: ✅
AI ReviewSummaryThis PR splits join runtime-filter identity into a stable structural name for Findings
Tests
Final VerdictStatus: Minimum required actions: remove the volatile rendezvous key from the plan hash / serialized |
|
@ClickHouse/integrations team, please, take a look |
b16b23b to
bf4780d
Compare
|
The failures of They were introduced by #104690 ("Add #104690 was merged in violation of the ClickHouse team rules: its own CI already showed these two tests failing (10 times between May 12 and June 1) before it was merged. Please update your branch to pick up the revert; the tests should pass again. |
|
📊 Cloud Performance Report 🟢 AI verdict: This PR reworks JOIN runtime filters: it splits the filter handle into a stable structural id (shown in EXPLAIN, hashed into the plan) and a random per-build rendezvous key, marks __applyFilter non-deterministic to keep stale results out of the query condition cache, and skips build work for inert/placeholder filters. The two TPC-H join queries that improved (Q7 -37%, Q20 -51%) are directly on this path, so the gains are plausible and the Q7 result is clear and consistent; Q20 is also a real shift but its history is noisy, so treat the exact magnitude cautiously. The two flagged ClickBench improvements (Q22, Q23) were downgraded: ClickBench queries are single-table with no joins, so this change cannot affect them, and the consistent-looking deltas (Q22 especially, with very noisy measurements) are run-to-run variance, not a PR effect. clickbenchFlagged queries (2 of 43)
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🟢 2 improved Flagged queries (2 of 22)
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. Debug info
|
1cbf59b to
16dfe3c
Compare
…L key Refactor the JOIN runtime filter so it works with automatic parallel replicas (Auto-PR) while keeping the master-style rendezvous. The probe-side `__applyFilter` carries the filter's stable structural id (`_runtime_filter_<hash>`) as its label argument, so it appears in EXPLAIN and in the Auto-PR plan-step hash. The two plan builds (single-replica and parallel-replicas) therefore hash identically and Auto-PR can match them, without any runtime-filter special-casing in the hasher. The actual rendezvous key registered in the per-query `IRuntimeFilterLookup` is a random per-plan-build value, carried out of band on the `__applyFilter` function instance and on `BuildRuntimeFilterStep` -- never materialized in the DAG -- so it never enters a plan-step hash. Because the key is fresh per plan build, every re-execution (recursive-CTE iterations, materialized-view blocks) gets its own filter and a sealed filter is never merged into again. Squashes PR #106137. Co-Authored-By: Claude Opus 4.8 <[email protected]>
16dfe3c to
7b57527
Compare
…L key Refactor the JOIN runtime filter so it works with automatic parallel replicas (Auto-PR) while keeping the master-style rendezvous. The probe-side `__applyFilter` carries the filter's stable structural id (`_runtime_filter_<hash>`) as its label argument, so it appears in EXPLAIN and in the Auto-PR plan-step hash. The two plan builds (single-replica and parallel-replicas) therefore hash identically and Auto-PR can match them, without any runtime-filter special-casing in the hasher. The actual rendezvous key registered in the per-query `IRuntimeFilterLookup` is a random per-plan-build value, carried out of band on the `__applyFilter` function instance and on `BuildRuntimeFilterStep` -- never materialized in the DAG -- so it never enters a plan-step hash. Because the key is fresh per plan build, every re-execution (recursive-CTE iterations, materialized-view blocks) gets its own filter and a sealed filter is never merged into again. Squashes PR #106137. Co-Authored-By: Claude Opus 4.8 <[email protected]>
| { | ||
| auto string_type = std::make_shared<DataTypeString>(); | ||
| auto id_column = string_type->createColumnConst(0, id.key); | ||
| return actions_dag.addColumn(std::move(id_column), std::move(string_type), id.name, /*is_deterministic_constant=*/false); |
There was a problem hiding this comment.
This does not actually keep the random rendezvous id out of the hashes used for AutoPR matching. ActionsDAG::Node::updateHash still calls column->updateHashWithValue(0, ...) regardless of is_deterministic_constant, SourceStepWithFilter hashes prewhere_actions.updateHash, and FilterStep::serialize also serializes the ActionsDAG without honoring skip_cache_key. Since this const's value is _rf_rnd..., the single-replica and parallel-replica plans still get different hashes as soon as the runtime filter is part of a FilterStep or pushed to PREWHERE, so findCorrespondingNodeInSingleNodePlan can continue to miss the matching node. Please either add a hash/serialization mode that skips non-deterministic constant values for these cache-key paths, or keep the random lookup key out of the ActionsDAG.
Represent each join runtime filter with a STABLE structural id in the plan and a fresh RANDOM rendezvous key. The structural id is the `__applyFilter` const argument's NAME (`_runtime_filter_<hash>`) and drives EXPLAIN and the plan-step hash; it is identical across structurally identical plans (so Auto-PR's two plan builds hash equally). The random key is the const argument's VALUE and is what the build and probe sides actually meet on in the per-query `IRuntimeFilterLookup`, so every plan build -- including recursive-CTE iterations and MV blocks -- gets its own registry slot. `__applyFilter` is stateless and reads the rendezvous key from its const argument. The const is marked `is_deterministic_constant=false`, so it is kept out of the query condition cache (via `Node::isDeterministic`) and is never treated as a stable plan-hash component; the hash-table statistics cache key is taken before runtime filters are added. A key-less `BuildRuntimeFilterStep` (e.g. a deserialized plan) is a passthrough. The pretty EXPLAIN keys the runtime-filter label on the structural id, not the volatile value. Updates affected test references and adds a query-condition-cache interaction test. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Two structurally identical joins in separate scopes (scalar subqueries) get the same runtime-filter structural fingerprint and coexist in one query's registry under that name, with distinct random rendezvous keys. The test asserts the collision happens and that a hash over the joined keys and payloads is identical with runtime filters on and off -- a cross-wire would prune the wrong rows. Co-Authored-By: Claude Opus 4.8 <[email protected]>
aeef627 to
1c63e19
Compare
…le names Two consequences of representing a filter by a stable structural NAME and a random rendezvous KEY (registered/looked-up under the KEY): - `HashJoin::publishSharedRuntimeFilters` looked the filter up by the shared-runtime-filter descriptor's first element, which carried the stable NAME. Since the filter is registered under the random KEY (and the probe-side `__applyFilter` looks it up by the KEY), the find missed and the SharedFixedHashTableRuntimeFilter replacement was silently skipped, disabling enable_join_runtime_filter_shared_fixed_hash_table. Carry the rendezvous key in the descriptor and find/replace by it. - `IRuntimeFilterLookup::logStats` logged the opaque random key. Give `IRuntimeFilter` a `display_name` (the stable structural id), set by the builder and preserved across the shared-filter replacement, and log it. Co-Authored-By: Claude Opus 4.8 <[email protected]>
… lock The previous change stored a readable `display_name` as a public mutable field on `IRuntimeFilter`, set after the filter was added to the lookup. Although both writes happen to thread-local filter objects before they are published under the lookup's lock (so it is not actually a data race), a public mutable field accessed from `logStats` under a shared lock is fragile. Move the name into the lookup itself: `add` records it keyed by the rendezvous key, `logStats` reads it, and `replace` keeps the original registration's name -- all under the same lock, with no field on the filter and no constructor plumbing through the filter hierarchy. Co-Authored-By: Claude Opus 4.8 <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 158/180 (87.78%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 22 line(s) · Uncovered code |
Changelog category (leave one):
Needed for AutoPR's plan-step matching between the local and distributed plans.
Version info
26.6.1.730