Skip to content

Fix flaky Q4 of 03753_join_runtime_filter_dynamically_disable - #114265

Merged
m-selmi merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-03753-q4-pin-runtime-filter-from-fixed-hash-table
Aug 11, 2026
Merged

m-selmi merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-03753-q4-pin-runtime-filter-from-fixed-hash-table

Conversation

@groeneai

@groeneai groeneai commented Aug 11, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Description

03753_join_runtime_filter_dynamically_disable fails on the Q4 line only, printing Q4 0 ...
instead of Q4 1 Ok
(sighting).

Root cause. Q4 asserts RuntimeFilterBlocksProcessed = 0, which only the bloom filter reaches,
via setFullyDisabled() on over-fill. With join_runtime_filter_from_fixed_hash_table on,
HashJoin::publishSharedRuntimeFilters replaces that fully disabled bloom filter with a
SharedFixedHashTableRuntimeFilter, which has no full-disable path. Q4's probe keys all lie inside
the build range, so every row passes and only the pass-ratio heuristic throttles: the failing run
recorded Processed = 12 / Skipped = 290. Processed = 0 is unreachable there.

Onset is #111972, as @ m-selmi identified in review.
max_bytes_ratio_before_external_join defaults to 0.5, so SpillingHashJoin wraps the join by
default and used to inherit hasPostBuildPhase() = false, which kept the shared filter unpublished.
A/B on one host, one test file, one server configuration: with those two overrides removed the
unpinned test passes 8 of 8 runs in one process; with them it passes the first run then fails 7 of 7
at Processed = 12, byte-identical to CI. CIDB shows 5 such failures across 5 PRs within 8 hours of
that merge, none in the preceding 45 days. The first run passes because the arm is
chosen from the process-global hash-table statistics cache, which is also why this is invisible on
master and shows up only in parallel jobs.

The change pins join_runtime_filter_from_fixed_hash_table = 0 for the file, selecting the
implementation whose disabling behaviour Q4 exists to test. It costs no coverage: only Q4 ever
reaches the shared-filter arm (3 runs, 3 publications, all log_comment = Q4), and the other six
queries give identical counters pinned and unpinned. 04241 remains that arm's dedicated test.

Validation. 40 of 40 runs pass (20 randomized, 20 not); removing the pin reddens it 5 of 5.

Noticed, not filed: SharedFixedHashTableRuntimeFilter has no full-disable path at all.

Version info

  • Merged into: 26.8.1.1181 (included in 26.8 and later)

Q4 asserts RuntimeFilterBlocksProcessed = 0, which only the bloom filter can
produce: with join_runtime_filter_exact_values_limit=1 and
join_runtime_bloom_filter_bytes=100, ApproximateRuntimeFilter takes 2000 keys
into 800 bits, so checkBloomFilterWorthiness sees an expected fill rate of
0.9994 against max_ratio_of_set_bits=0.7 and calls setFullyDisabled(). That
short-circuits shouldSkip for every block, so findImpl and updateStats never
run and nothing is counted as processed.

join_runtime_filter_from_fixed_hash_table, whose default flipped to true in
26.6, lets HashJoin::publishSharedRuntimeFilters replace that fully-disabled
bloom filter with a SharedFixedHashTableRuntimeFilter. That implementation has
no full-disable path at all: setFullyDisabled has exactly two call sites in the
tree and neither is reachable from it, and its finishInsertImpl is empty. The
only remaining throttle is the pass-ratio heuristic in updateStats, and Q4's
probe keys 5, 6, 7 and 100 all lie inside the build range 0..1999, so every
probed row passes, the ratio stays at 1.0, and the filter probes one block then
skips thirty, indefinitely. With max_block_size=10 that splits the 302 blocks
into 12 processed and 290 skipped, so Processed = 0 is unreachable.

Which implementation serves the join is not pinned by the test. The file sets
join_algorithm = 'hash,parallel_hash', and PlannerJoins picks ConcurrentHashJoin
when rhs_size_estimation is absent and plain HashJoin when it is present and
below parallel_hash_join_threshold. ConcurrentHashJoin overrides neither
hasPostBuildPhase nor runPostBuildPhase, so it never publishes the shared
filter and Q4 passes there. rhs_size_estimation is overwritten from the
process-global HashTablesStatistics cache, which is written when a join with the
same cache key is destroyed and which collect_hash_table_stats_during_joins
populates by default. Whether Q4 sees an estimate therefore depends on what ran
earlier in the same server process, which is why the failure is invisible on
master, appears in parallel jobs where one server runs the suite concurrently,
and is fully deterministic once it starts: the in-job diagnostic rerun without
randomized settings failed 104 out of 104.

Pin join_runtime_filter_from_fixed_hash_table = 0 in Q4's SETTINGS clause,
selecting the implementation whose dynamic-disable behaviour Q4 exists to test.
The same pin for the same reason already exists at
04357_join_runtime_filter_size_from_hash_table_stats.sql:13. The pin is scoped
to Q4 alone so the other six queries keep the default and the file still covers
the shared fixed hash table filter end to end; 04241 remains its dedicated
test.

Verified locally: the forced arms give 12/290 with the setting on and 0/302 with
it off, RuntimeFiltersCreated = 1 in both; the test fails before this change and
passes after on one server and binary; 50 runs with randomized settings and 50
without all pass; and reverting the pin reddens the test 5 out of 5.
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (Gate B, cold) - 0 findings; own cold review - 3 nits, all resolved

Two independent reviews ran against 0266e3d171bb30e06e5a61bc39f18c0bd99b29cb before this PR was
pushed: an independent cold review of the resulting code (no access to the implementation notes),
then a second-model gate review (codex, $12.87). The gate returned 0 findings on a diffstat of
1 file changed, 1 insertion(+), 1 deletion(-), having traced the setting's consumers, the
optimizer and runtime-filter functions, the join-algorithm callers and the sibling tests, and having
verified off = 0/302 against on = 12/290 by direct ProfileEvents probe.

The cold review raised three nits, none blocking:

💡 The pin carries no comment, while the cited precedent 04357:13 pins the same setting with
one.
Declined. The line above the query already reads -- Too many rows in bloom filter, so the
pin's purpose follows from that plus the setting name, and a comment explaining it in terms of this
fix is what the review doctrine asks to keep out of the diff and put in the commit message - which
is where it is.

💡 The commit message's 12 / 290 reads like a derivation from "one block probed per 31".
Declined as a wording objection only: the counters are measured (byte-identical to the CI dump, and
12 + 290 = 302 = ceil(3010/10)), and the skip window is sized in rows
(rows_checked * blocks_to_skip_before_reenabling, RuntimeFilterLookup.cpp:141-143), not blocks,
so short blocks shorten it. The description above says "recorded", not "derived".

⚠️ The root-cause narrative attributed rhs_size_estimation only to the process-global statistics
cache.
Agreed and corrected in the description before the gate ran:
JoinStepLogical.cpp:1790-1792 sets it from right_relation.estimated_rows first and only then
overwrites it from the cache, so there are two sources. This strengthens rather than weakens the
change: pinning the setting makes the shared-filter arm unreachable whichever source supplies the
estimate.

💡 The carrier sweep was narrower than the invariant it tested. A sweep for any absolute
RuntimeFilter* counter (not just RuntimeFilterBlocksProcessed) also reaches
04611_join_runtime_filters_index_analysis_skip_index.sql:108,116 and
03777_join_runtime_filter_unsupported_type.sql:20,35. Both are safe: 04611 pins the setting to
1 on its own shared-filter query (:90) and its = 0 assertions concern skip-index granule
pruning rather than full-disable; 03777 builds on a tuple key, and a shared descriptor is
registered only in the non-tuple branch (joinRuntimeFilter.cpp:549-553), so that implementation
cannot serve it. No further change needed.

The reviewer did not edit any source file; the tree is fingerprint-identical to the one handed over
for review.

Session id: cron:clickhouse-review-slot-8:20260811-031900

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (a-i)
# Check Result
a Deterministic repro? YES. Forced-arm A/B reproduces on demand: join_runtime_filter_from_fixed_hash_table=1 gives RuntimeFilterBlocksProcessed=12 / Skipped=290 (byte-identical to the CI failure), =0 gives 0 / 302. The real test fails 5/5 with the pin reverted. Not a percentage-rate flake.
b Root cause explained? YES. Q4 asserts Processed = 0, reachable only via ApproximateRuntimeFilter::checkBloomFilterWorthiness -> setFullyDisabled(). join_runtime_filter_from_fixed_hash_table (default true since 26.6) lets HashJoin::publishSharedRuntimeFilters replace that fully-disabled bloom filter with a SharedFixedHashTableRuntimeFilter, which has no full-disable path (setFullyDisabled has exactly two call sites in the tree, neither reachable from it). Arm selection follows rhs_size_estimation, overwritten from the process-global hash-table statistics cache.
c Fix matches root cause? YES. It pins the setting that selects the filter implementation whose behaviour Q4 asserts. Not a widened bound, not a no-random-* tag, not a dataset reduction, not a defensive guard. no-random-settings was considered and rejected as ineffective: the in-job rerun without randomized settings failed 104/104, and this setting is not in the runner's randomization list.
d Test intent preserved / new tests? YES. The assertion is unchanged; the fix makes the existing assertion reachable. The test still catches its bug class, proven by the negative control below. No test weakened or removed. No src/ change, so no new test is owed.
e Demonstrated in BOTH directions? YES. Same server, same Build ID, no rebuild between the two runs: FAIL before (+Q4 0 ... 'RuntimeFilterBlocksProcessed':12,'RuntimeFilterBlocksSkipped':290), OK after.
f Fix is general across CODE paths? YES. grep -rln RuntimeFilterBlocksProcessed tests/queries/0_stateless/ returns exactly one file, 03753 itself, so no other test in the tree carries this defect. All six sibling queries were measured individually and deliberately left unpinned; 04241, 04357 and 04611 already pin correctly.
g Generalizes across INPUTS? N/A for a settings pin (no type-wrapper or boundary surface). Covered empirically by 100 runs spanning both randomization modes, which varied use_statistics, MergeTree settings and index granularity.
h Backward compatible? YES. Test-only. No setting default changed, so no SettingsChangesHistory.cpp entry. No format change, no backport label.
i Invariants and contracts preserved? YES. No code path touched. The pin narrows Q4 to the implementation it was written for; the other six queries keep the default, so the file retains end-to-end coverage of the shared fixed hash table filter.

Negative control: reverting the pin to =1 reddens the test 5/5 deterministically, so the
50/50 green is caused by this one line rather than an insensitive harness or a fresh-cache
vacuous pass.

Carrier check (measured from system.query_log after a passing run): Q4 Processed=0 / Skipped=302
with the pin; Q1 6/98, Q2 9/195, Q3 11/293, Q5 8/197, Q6 5/100, Q7 104/0, all with the
setting absent, i.e. still on the default. RuntimeFiltersCreated=1 on every line.

Randomized runs: 50 with randomization and 50 without, all passing, on a server whose
hash-table statistics cache had already been warmed by the repro (a cold server takes the
ConcurrentHashJoin path where the bug cannot appear, so a fresh-server green would prove
nothing).

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @davenger, could you review this? Q4 asserts RuntimeFilterBlocksProcessed = 0, which only the bloom filter reaches via setFullyDisabled() on over-fill, but join_runtime_filter_from_fixed_hash_table lets publishSharedRuntimeFilters swap in a SharedFixedHashTableRuntimeFilter that has no full-disable path, so this pins the setting in Q4 alone (as 04357:13 already does) and leaves the other six queries on the default.

WHERE
c_nationkey = n.number::Int32
SETTINGS join_runtime_filter_exact_values_limit=1, join_runtime_bloom_filter_bytes=100, max_block_size=10, max_threads=1, log_comment='Q4';
SETTINGS join_runtime_filter_exact_values_limit=1, join_runtime_bloom_filter_bytes=100, join_runtime_filter_from_fixed_hash_table=0, max_block_size=10, max_threads=1, log_comment='Q4';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@groeneai Please verify that join_runtime_filter_from_fixed_hash_table = 1 causes a test failure and join_runtime_filter_from_fixed_hash_table = 0 prevents it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Verified both ways on one server and one binary (Build ID 53ddd385f2deb04f2f4662f81d806984f44580f7, no rebuild between arms), running the real test, not just a ProfileEvents probe:

join_runtime_filter_from_fixed_hash_table in Q4 runs result
0 (as committed) 3 3 OK
1 5 5 FAIL
0 again 2 2 OK

The = 1 failure is byte-identical to the CI one: RuntimeFiltersCreated: 1, RuntimeFilterBlocksProcessed: 12, RuntimeFilterBlocksSkipped: 290, so Q4's Processed = 0 conjunct is what fails. Created = 1 in both arms, so = 0 does not pass merely because no filter was built.

One caveat worth stating, because it means a single run of the toggle is not a sufficient demonstration: with = 1 on a freshly restarted server I get OK, FAIL, FAIL on three consecutive runs. The first run has no rhs_size_estimation yet, so PlannerJoins.cpp:1247 picks ConcurrentHashJoin, which inherits hasPostBuildPhase() = false and therefore never publishes the shared filter, leaving the bloom arm and its setFullyDisabled path intact. Once any earlier join populates the process-global HashTablesStatistics cache, the estimate is 2000, plain HashJoin is chosen, publishSharedRuntimeFilters replaces the fully disabled bloom filter with a SharedFixedHashTableRuntimeFilter, and that implementation has no full-disable path at all, so Processed = 0 becomes unreachable. That is why the failure is invisible on master, shows up in parallel jobs where one server runs many tests, and was fully deterministic once it started in CI (the in-job rerun without randomized settings failed 104 of 104).

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.

@groeneai move SET join_runtime_filter_from_fixed_hash_table = 0; to the settings sections above, this test is not meant to test the runtime filter from fixed hash table.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Both done, and you were right on both counts.

Moved the pin to the settings section in 1549b82. I had scoped it to Q4 to keep the
other queries exercising the filter built from the fixed hash table, but that rationale does
not survive measurement: no query in this file except Q4 ever reaches that arm. Using the
publication trace in HashJoin::publishSharedRuntimeFilters as the observable, with no pin
anywhere I get exactly 1 publication per run (3 runs, 3 publications), and mapping those
query ids through system.query_log gives log_comment = Q4 for all 3. Q1/Q2/Q3/Q5/Q6/Q7
never publish. Their counters are identical with the setting pinned for the whole file and
with it absent: Q1 6/98, Q2 9/195, Q3 11/293, Q5 8/197, Q6 5/100, Q7 104/0,
RuntimeFiltersCreated = 1 throughout. So the wider scope costs no coverage, and 04241 stays
the dedicated test for that arm. 40 of 40 runs pass with the new form (20 randomized, 20 not);
removing the pin reddens it 5 of 5.

Your onset call is confirmed too. I built the pre-#111972 arm locally by dropping just the two
SpillingHashJoin post-build overrides, and A/B'd on one host with one test file and one server
configuration: without them the unpinned test passes 8 of 8 runs in a single process; with them
it passes the first run and then fails 7 of 7 with RuntimeFilterBlocksProcessed = 12,
byte-identical to CI. max_bytes_ratio_before_external_join defaults to 0.5, so
SpillingHashJoin wraps the join by default and used to inherit hasPostBuildPhase() = false,
which is what kept publishSharedRuntimeFilters from displacing the fully disabled bloom filter.
CIDB agrees on timing: 5 +Q4 0 failures across 5 different PRs all within 8 hours of your PR
merging, and none in the preceding 45 days.

The first-run-passes detail is why the flake looked random: the arm is chosen from the
process-global HashTablesStatistics cache, so a cold process takes ConcurrentHashJoin (no
post-build phase) and every later run in the same process takes plain HashJoin.

@m-selmi m-selmi added the can be tested Allows running workflows for external contributors label Aug 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1549b82]

Summary: ✅


AI Review

Summary

This PR moves join_runtime_filter_from_fixed_hash_table = 0 from Q4 into the file-level settings block of 03753_join_runtime_filter_dynamically_disable, keeping the flaky Q4 assertion on the bloom-filter full-disable path after the SpillingHashJoin post-build changes. I reviewed the current diff, the touched test, the relevant HashJoin / SpillingHashJoin / runtime-filter code, the prior inline thread, and the current PR discussion and CI report; I did not find a remaining correctness, coverage, or metadata issue in the current head.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 11, 2026

@m-selmi m-selmi left a comment

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.

Probably started failing because #111972 fixed the issue where fixed hash table conversion was disabled by mistake.

WHERE
c_nationkey = n.number::Int32
SETTINGS join_runtime_filter_exact_values_limit=1, join_runtime_bloom_filter_bytes=100, max_block_size=10, max_threads=1, log_comment='Q4';
SETTINGS join_runtime_filter_exact_values_limit=1, join_runtime_bloom_filter_bytes=100, join_runtime_filter_from_fixed_hash_table=0, max_block_size=10, max_threads=1, log_comment='Q4';

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.

@groeneai move SET join_runtime_filter_from_fixed_hash_table = 0; to the settings sections above, this test is not meant to test the runtime filter from fixed hash table.

Requested in review: 03753 is not the test of the runtime filter built from
the fixed hash table, so the setting belongs in the file's settings section
rather than only in Q4.

Measured that the wider scope costs no coverage. With the setting pinned to 0
for the whole file and with it absent, Q1/Q2/Q3/Q5/Q6/Q7 produce identical
RuntimeFilter counters (Q1 6/98, Q2 9/195, Q3 11/293, Q5 8/197, Q6 5/100,
Q7 104/0, RuntimeFiltersCreated=1 throughout); only Q4 differs, 0/302 with
the pin against 12/290 without it. 04241 remains the dedicated test of the
shared fixed hash table filter.

The onset is ClickHouse#111972, also identified in review. Verified by A/B on one host
with one test file and one server configuration: with the two SpillingHashJoin
post-build overrides removed, the unpinned test passes 8 of 8 runs in one
process; with them present it passes the first run and then fails 7 of 7 with
RuntimeFilterBlocksProcessed=12, byte-identical to CI. max_bytes_ratio_before_external_join
defaults to 0.5, so SpillingHashJoin wraps the join by default and previously
inherited hasPostBuildPhase() = false, which kept publishSharedRuntimeFilters
from displacing the fully disabled bloom filter.

40 of 40 runs pass with the new form (20 randomized, 20 not). Removing the
pin reddens the test 5 of 5.
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 1549b82

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

CI is fully finished on this head: 175 checks, 0 incomplete, 39 real jobs OK, 135 skipped
(every skip carries a reason), 0 dropped in the praktika report, so the run carries real coverage.

Check / test Reason Owner / fixing PR
Stress test (arm_tsan) / Hung check failed, possible deadlock found deadlock, not PR-caused: the stuck query is DROP TABLE prometheus (elapsed 1289s, is_cancelled=1), blocked in DatabaseCatalog::waitTableFinallyDropped under InterpreterDropQuery::waitForTableToBeActuallyDroppedOrDetached, with DROP DATABASE ... SYNC and DETACH DATABASE queued behind its DDLGuard. The database is the one created by 04811_promql_topk_bottomk_limitk. This PR only moves one SET line inside a join test and touches no TimeSeries code. fixing PR #114326 (external, open)

Notes on two rows that are deliberately not ledger lines:

  • Stress test (amd_tsan) failed with the same signature at 14:31Z and then passed on the
    re-run at 16:03Z, so its final conclusion on this head is success.
  • Build (arm_release) / Post Hooks shows FAIL in the CI database while the GitHub check
    concluded success; that is reporting-sink bookkeeping, not a test failure.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114265&sha=1549b82d3ee2055db6ba957bcc4459b41d27d04b&name_0=PR&name_1=Stress%20test%20%28arm_tsan%29

Session id: cron:our-pr-ci-monitor:20260811-180000

@m-selmi
m-selmi enabled auto-merge August 11, 2026 18:28
@m-selmi
m-selmi disabled auto-merge August 11, 2026 18:28
@m-selmi
m-selmi added this pull request to the merge queue Aug 11, 2026
Merged via the queue into ClickHouse:master with commit 45ccfdf Aug 11, 2026
528 of 531 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 11, 2026
@groeneai groeneai added the groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding label Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding pr-ci 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