Skip to content

Use deterministic names for runtime filters in query plan - #106137

Merged
nickitat merged 4 commits into
masterfrom
runtime_filter_plan_handle
Jun 12, 2026
Merged

nickitat merged 4 commits into
masterfrom
runtime_filter_plan_handle

Conversation

@nickitat

@nickitat nickitat commented May 29, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Needed for AutoPR's plan-step matching between the local and distributed plans.

Version info

  • Merged into: 26.6.1.730

@clickhouse-gh

clickhouse-gh Bot commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [58cc1e4]

Summary: ✅


AI Review

Summary

This PR splits join runtime-filter identity into a stable structural name for EXPLAIN / plan identity and a random rendezvous key for per-query lookup isolation. The query-condition-cache and fingerprint-collision regressions are covered, and the earlier serialized-plan and shared fixed-hash-table issues appear addressed. The main AutoPR matching contract is still not satisfied because the random lookup key remains inside the hashed ActionsDAG value path.

Findings

⚠️ Majors

  • [src/Processors/QueryPlan/Optimizations/joinRuntimeFilter.cpp:117] The PR promises stable runtime-filter labels so single-replica and AutoPR replica plans can match, but this column still stores the random _rf_rnd... key as the const value. ActionsDAG::Node::updateHash hashes column->updateHashWithValue(0, ...) regardless of is_deterministic_constant, and calculateHashFromStep(const SourceStepWithFilter &) hashes prewhere_actions, so a runtime filter pushed to PREWHERE gives the two plan builds different hashes and findCorrespondingNodeInSingleNodePlan can still miss the corresponding node. FilterStep::serialize also serializes the same value through ActionsDAG::serialize, so serialization does not remove the volatile key either. Existing unresolved thread: Use deterministic names for runtime filters in query plan #106137 (comment)
    Suggested fix: keep the random lookup key out of hashed / serialized ActionsDAG constants, or add an explicit hash / serialization mode that skips non-deterministic constant values for the plan-matching paths while preserving the stable result name.
Tests
  • ⚠️ [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/106137#discussion_r3384444421] The added tests still do not exercise automatic_parallel_replicas_mode = 2 with enable_join_runtime_filters = 1, which is the behavior this PR is meant to make reliable. Please add a focused AutoPR regression that fails when the runtime-filtered single-replica and parallel-replica plan hashes diverge or when runtime dataflow statistics cannot find the matching node.
Final Verdict

Status: ⚠️ Request changes

Minimum required actions: remove the volatile rendezvous key from the plan hash / serialized ActionsDAG paths used for AutoPR matching, and add focused AutoPR coverage for the fixed behavior.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label May 29, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

@ClickHouse/integrations team, please, take a look

Comment thread src/Functions/FunctionApplyFilter.cpp Resolved
@nickitat nickitat added pr-not-for-changelog This PR should not be mentioned in the changelog and removed pr-improvement Pull request with some product improvements labels Jun 1, 2026
@nickitat
nickitat marked this pull request as ready for review June 2, 2026 09:21
@nickitat
nickitat requested a review from davenger June 2, 2026 09:21
Comment thread src/Core/ProtocolDefines.h Resolved
@nickitat
nickitat force-pushed the runtime_filter_plan_handle branch from b16b23b to bf4780d Compare June 2, 2026 21:27
@alexey-milovidov

Copy link
Copy Markdown
Member

The failures of 00175_obfuscator_schema_inference and 00096_obfuscator_save_load in Stateless tests (amd_tsan, parallel) are NOT caused by this PR.

They were introduced by #104690 ("Add UntrackedMemory asynchronous metric"), which made clickhouse-obfuscator abort (SIGABRT) on process teardown: the query results are correct, but the Aborted line on stderr fails the test. #104690 has now been reverted (#106365).

#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.

@clickhouse-gh

clickhouse-gh Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

🟢 AI verdict: improvement — 2 query(s) improved out of 38 analysed

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.

clickbench

⚠️ 2 inconclusive

Flagged queries (2 of 43)
Query Verdict Baseline med (ms) PR med (ms) Change q-value Hint
⚠️ 22 not_sure 334 262 -21.6% <0.0001 ClickBench is single-table with no joins; this join runtime-filter change can't touch it, and measurements were very noi
⚠️ 23 not_sure 297 200 -32.7% <0.0001 ClickBench has no joins, so this join-filter change can't cause it; the consistent delta here is run-to-run variance

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)
Query Verdict Baseline med (ms) PR med (ms) Change q-value Hint
🟢 7 improvement 113 71 -37.2% <0.0001 join_operator: Multi-way join query; the runtime-filter rework plausibly speeds probe-side prefiltering. Large, consistent improvement
🟢 20 improvement 248 121 -51.2% <0.0001 join_operator: Heavy join query plausibly helped by the runtime-filter rework, but history is noisy so read the magnitude cautiously

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
  • StressHouse run: fc2d4642-0a78-405c-82f3-8ece7f18b403
  • MIRAI run: 56bac4c2-378c-4f64-826a-0c8a5424d7fb
  • PR check IDs:
    • clickbench_372384_1781271536
    • clickbench_372398_1781271536
    • clickbench_372404_1781271536
    • tpch_adapted_1_official_372410_1781271536
    • tpch_adapted_1_official_372417_1781271536
    • tpch_adapted_1_official_372428_1781271536

@groeneai groeneai mentioned this pull request Jun 6, 2026
@nickitat
nickitat marked this pull request as draft June 9, 2026 22:41
@nickitat
nickitat force-pushed the runtime_filter_plan_handle branch from 1cbf59b to 16dfe3c Compare June 9, 2026 22:42
nickitat added a commit that referenced this pull request Jun 9, 2026
…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]>
@nickitat
nickitat force-pushed the runtime_filter_plan_handle branch from 16dfe3c to 7b57527 Compare June 9, 2026 23:11
nickitat added a commit that referenced this pull request Jun 9, 2026
…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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is implemented in #106073

nickitat and others added 2 commits June 11, 2026 14:02
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]>
@nickitat
nickitat force-pushed the runtime_filter_plan_handle branch from aeef627 to 1c63e19 Compare June 11, 2026 15:35
nickitat and others added 2 commits June 11, 2026 16:31
…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]>
@nickitat
nickitat marked this pull request as ready for review June 11, 2026 17:50
@nickitat nickitat changed the title Generate deterministic names for runtime filters Use deterministic names for runtime filters in query plan Jun 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.60% 84.60% +0.00%
Functions 92.40% 92.40% +0.00%
Branches 77.30% 77.30% +0.00%

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

Full report · Diff report

@nickitat
nickitat enabled auto-merge June 12, 2026 21:06
@nickitat
nickitat added this pull request to the merge queue Jun 12, 2026
Merged via the queue into master with commit 7daeb04 Jun 12, 2026
326 of 328 checks passed
@nickitat
nickitat deleted the runtime_filter_plan_handle branch June 12, 2026 21:28
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants