Repository navigation
Fix LOGICAL_ERROR on runtime filter lookup before build finished - #107108
alexey-milovidov merged 19 commits into
Conversation
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-28:20260610-231742 |
|
cc @davenger @vdimir — could you review this? It fixes the |
|
Workflow [PR], commit [542998c] Summary: ✅
AI ReviewSummaryThis PR adds Findings
Final VerdictLLVM Coverage ReportMeasured on commit 542998c.
Changed lines: Changed C/C++ lines covered: 25/25 (100.00%) · Uncovered code |
|
CI on
Ready for review. |
055aea6 to
e325ea4
Compare
|
@groeneai, please replace the unit test with a functional test. |
e325ea4 to
0a2da52
Compare
|
@alexey-milovidov done. Replaced the unit test with a functional test: It joins a multi-part build table with |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260627-004000 |
CI finish ledger — 0a2da52Every 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
This PR's diff ( Session id: cron:our-pr-ci-monitor:20260627-053000 |
CI finish ledger — 0a2da52Every 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
None PR-caused: this PR changes only Session id: cron:our-pr-ci-monitor:20260629-043000 |
|
Updating the branch to fix the |
|
The Pushed This doesn't touch the fix itself or the open design discussion at |
|
Thanks @alexey-milovidov, the trim looks right. Keeping the 8 build parts + join_overflow_mode='break'/max_bytes_in_join=1 + 30 repetitions preserves the early-termination window and the independent trials, so pass-all-when-unfinished is still exercised; shrinking only the probe scan is the right lever. Your 7/15 pre-fix repro on the trimmed test confirms the regression is still caught. Not re-pushing over 9722f46. The RuntimeFilterLookup.cpp design point raised earlier remains open for whenever you and vdimir want to weigh in; happy to switch to disabling the filter on early build termination instead of the find() guard if that is preferred. |
|
Addressed both points in 59e9ead (test only; fix source and the open RuntimeFilterLookup.cpp design thread untouched):
Verified in a debug build, both directions, deterministic:
|
CI finish ledger — 59e9eadEvery 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
No PR-caused failure. The prior AST-fuzzer STID 0993-2cc2 (fixing PR #107719) did not recur on this SHA. Session id: cron:our-pr-ci-monitor:20260707-033000 |
|
Pushed |
CI finish ledger — 5a3b8f5Every failure below has an owner (a fixing PR). This PR's own diff (runtime-filter
Session id: cron:our-pr-ci-monitor:20260714-223000 |
Internal second-model review (Gate B) adjudication for 6d7d029Two rounds of an independent second-model review were run against the resulting code. Findings and dispositions:
Verification: fixed Build-ID 2555bd9a; |
| return nullptr; | ||
| /// Read the set only after the last build stream published it (seq_cst acquire); before that a | ||
| /// merge stream may still be mutating it. Same publication guard as getRecordedKeyRanges(). | ||
| if (!inserts_are_finished.load()) |
There was a problem hiding this comment.
This nullptr is not only a temporary fail-open for the unfinished window. HashJoin::publishSharedRuntimeFilters() snapshots existing->getRecordedKeyRanges() / getRecordedKeyValues() once into SharedFixedHashTableRuntimeFilter at HashJoin.cpp:2657-2666, then replace() drops the unfinished Set/Bloom filter. If post-build runs before the last BuildRuntimeFilterTransform::finish() (the same window this PR is fixing), every later add() merges into the shared filter's no-op merge(), so key32/key64 joins that convert to FixedHashMap permanently lose exact-value/range pruning for the rest of the query instead of only during the unfinished phase.
Please either delay the shared-filter replacement until the original runtime filter is finished, or derive the recorded exact values / key range directly from the fixed hash table when publishing the shared filter.
There was a problem hiding this comment.
Verified. The asymmetry is real: SharedFixedHashTableRuntimeFilter::merge() is a no-op (RuntimeFilterLookup.h:342), and publishSharedRuntimeFilters() snapshots the recorded values/range once (HashJoin.cpp:2662-2663) then replace()s the original, so a later add() is lost.
In the current code this is a pruning/perf concern, not wrong results:
- Both snapshot getters already fail open before the finish flag.
getRecordedKeyRanges()guards oninserts_are_finished(RuntimeFilterLookup.cpp:76) andgetRecordedKeyValues()got the same guard in6d7d029earlier today. So in the unfinished window the snapshot is empty, not partial, and the read-time path prunes nothing rather than on a partial IN-set. - The published filter's row probe uses
probe_fn, built from the fully populated FixedHashMap inrunPostBuildPhase(), so join results stay complete regardless of the snapshot.
Residual: if publishSharedRuntimeFilters() runs before the last BuildRuntimeFilterTransform::finish(), the shared filter is published with an empty recorded set and loses index pruning for the rest of the query (perf, on the experimental fixed-hash-table path). Whether that ordering is reachable is the same question as the open discussion on this file: instrumented runs today showed the read-time granule-pruning consumer never observed an unfinished filter (0 of 400+ runs) while the row-level find() did (293), i.e. the read-time consumers run after the pipeline barrier.
Your three options (delay the replacement until finished, derive the recorded values from the fixed hash table at publish, or keep per-consumer fail-open) are a design choice that ties into the still-open discussion on this file about fixing the ordering invariant vs failing open per consumer. This is the fourth finding of that same class, so rather than keep adding per-consumer guards I would prefer maintainer direction on the approach. Holding further changes for that.
There was a problem hiding this comment.
🕵 Implemented the first of your two options in f31279b: HashJoin::publishSharedRuntimeFilters now skips the replacement while the original filter is unfinished (IRuntimeFilter::insertsAreFinished), and logs a trace when it does. Keeping the original Set/bloom filter is strictly better than publishing a shared filter with an empty snapshot: the original finishes and prunes on its own, so no pruning is lost for the rest of the query.
Also applied the second major from the AI review summary in the same commit: getRecordedKeyRanges now loads inserts_are_finished before reading has_range/range_min/range_max, so the publication flag actually guards the range fields the build side writes.
New test 04615_join_runtime_filters_shared_fixed_hash_table_pruning drives a build side through the fixed-hash-table conversion and the shared-filter publication (verified locally: Converted join hash map to fixed hash map (range: 7999, keys: 4000) + Published shared fixed-hash-table runtime filter) and asserts both exact results and that granule pruning still engages afterwards (RuntimeFilterGranulesDropped = 718 of 781 considered). Note that reaching the conversion at all requires max_bytes_ratio_before_external_join = 0, which is why the earlier index-analysis test did not cover this path.
There was a problem hiding this comment.
This still looks present in the current tree. HashJoin::publishSharedRuntimeFilters still goes straight from lookup->find to lookup->replace without any existing->isReady() guard or deferred-publication path in src/Interpreters/HashJoin/HashJoin.cpp:2799. And RuntimeFilter::merge still drops late merges once the lookup entry has been replaced by a SharedFixedHashTable in src/Processors/QueryPlan/RuntimeFilterLookup.cpp:790. So the original “publish before the last BuildRuntimeFilterTransform::finish() loses pruning metadata for the rest of the query” problem does not appear to be fixed yet.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 11/13 (84.62%) · Uncovered code |
|
Fixing PR for the 04325 BACKUP hang created: #115531. Root cause was not in this PR: |
…lookup-before-build-finished-v2
CI finish ledger -
|
| Check / test | Reason | Owner / fixing PR |
|---|---|---|
Stress test (arm_tsan) / Logical error: A data stream row of AlignStreams has no matching metadata stream row (block number A, block offset B) (STID 0250-16db) |
trunk regression, server abort. The assertion lives in src/Storages/MergeTree/Streaming/ReadingPlan/AlignStreams.cpp and arrived with merged #116128, which split the streaming read round into aligned metadata and data streams. The signature first appears 2026-08-26 and measures 31 rows over 28 distinct pull requests plus 3 distinct master commits in 30 days, across 9 different Stress test arms. This diff touches HashJoin.cpp, RuntimeFilterLookup.{cpp,h}, FailPoint.cpp, ProfileEvents.cpp and four stateless tests, and nothing under src/Storages/MergeTree/Streaming. |
#116531 (external, open) |
The six Bugfix validation (functional tests, amd64/aarch64) FAIL rows are not failures: they
carry check_status = success, the documented inversion where this PR's regression test is
expected to fail against the master binary, which is the proof the bug reproduces.
Session id: cron:our-pr-ci-monitor:20260828-080000
…lookup-before-build-finished-v2
|
🕵 Refreshed the branch onto current master (merge Correction to the previous ledger entry. The sole red on Verification on the merged tree:
No code changes in this push. The one open item remains the design question on |
…lookup-before-build-finished-v2 Master rewrote the runtime filter classes (`RuntimeFilter` with a mutex-protected `RuntimeFilterBuildState`) and already carries most of this fix: `finishInsert` finalizes before publishing readiness, `getRecordedKeyValues` / `getRecordedKeyRanges` return nothing until the filter is ready, `RuntimeFilter::merge` ignores a late merge into an already published shared fixed-hash-table filter, and `__applyFilter` passes all rows through when the registered filter is not ready yet (`RuntimeFilter::isReady`). Conflict resolution keeps master's versions of `RuntimeFilterLookup.cpp` / `.h` and re-applies only what master lacks: the `runtime_filter_skip_finish_insert` fail point in `RuntimeFilterLookup::add`, and the `RuntimeFilterLookupsBeforeBuildFinished` profile event, which now lives in `FunctionApplyFilter` next to the pass-through branch. The `HashJoin::publishSharedRuntimeFilters` skip for unfinished filters is dropped in favour of master's approach (publish, and ignore the late merge). Test comments are updated to the current code, and the witness test pins `join_runtime_filter_from_fixed_hash_table = 0` so the held Set/bloom filter is not replaced by a prebuilt shared filter. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 Merged current master (merge The resolution keeps master's versions of both files and re-applies only what master lacks:
The The single red on the previous head @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107108&sha=12bee7bf9499c87f8d4ca3efffc9331ed28a36b6&name_0=PR&name_1=Stress%20test%20%28arm_release%29 and provide a fix in a separate PR (a re-fix of #118489 that does not reintroduce the |
|
Investigated. The
The fix is already in progress and approved: #119465 (@qoega, 2026-09-11). It suppresses this signature by a different route than #118489: rather than naming functions in the deny-list, it re-reads the reference query on the mismatch path only and drops the report when that read does not reproduce. Measured before I posted it: 5/5 mismatches on unpatched master, 0/5 with the patch, and 5/5 again with It cannot reintroduce the It has not merged because of one unrelated red, Master exposure meanwhile: 4 CI runs hit this false mismatch since the revert, 2 on master (2026-09-14 15:55Z, 2026-09-15 06:11Z) and 2 on pull requests, the latest 2026-09-16 23:25Z. If you would rather have #118489's deny-list re-landed on top of that guard, say so and I will open it. Over 30 days of CI data it would not cover anything #119465 misses: of the order-dependent aggregates the oracle's static list does not name, only |
A shared fixed-hash-table runtime filter is published already finished and replaces the registered Set/bloom filter, so with the setting at its default the probe reaches a ready filter and the unfinished-lookup window this test covers is never entered. 04681 pins the same setting for the same reason. Measured on 5cca83d (debug, clickhouse-test with randomized settings, 20 runs x 60 joins each): unpinned, all 1200 queries report RuntimeFiltersCreated and none report RuntimeFilterLookupsBeforeBuildFinished; pinned, every one of the 20 runs enters the branch (302 of 1200 queries, 1427 lookups). On a binary with the __applyFilter not-ready guard removed, the unpinned test passes 3 x 60 queries, while the pinned test aborts the server with "Trying to lookup values in runtime filter before building it was finished". Co-Authored-By: Claude Opus 5 <[email protected]>
|
The re-land asked for here is open: #120508 It restores #118489's
50 randomized runs of each test are 100/100 green and stderr-clean. |
CI finish ledger -
|
| Check / test | Reason | Owner / fixing PR |
|---|---|---|
Stress test (arm_msan) / Logical error: Invalid number of columns in chunk pushed to OutputPort. Expected 2, found 1 (STID 2270-38be) |
trunk defect, server abort. The chunk header names s AggregateFunction(countResample(10, 5, 1), UInt64, UInt64), i.e. the parameterisation whose state serializes to zero bytes and reaches ISource::prepare one column short. Measured over 30 days: 55 rows on 46 distinct pull requests plus 6 distinct master commits, across 11 check flavours. This diff touches FailPoint.cpp, ProfileEvents.cpp, FunctionApplyFilter.cpp, RuntimeFilterLookup.cpp and four stateless tests, nothing on the aggregate-state or chunk-shape path. |
#119728 (ours, open) |
Build profile diff |
infra, and the job exits before any comparison runs: RuntimeError: CI logs cluster query failed from the binary_sizes read in has_pr_data (build_profile_diff_job.py:723). 219 distinct pull requests by other authors hit that same frame in the last 24 hours. |
#120121 (ours, open) |
Mergeable Check and PR are rollups, red only because of the Stress test (arm_msan) row.
Session id: cron:our-pr-ci-monitor:20260917-080221
|
🕵 Merged current master ( Verified locally on the merged tree (RelWithDebInfo build): |
alexey-milovidov
left a comment
There was a problem hiding this comment.
Ok, this is no-op right now.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add the
RuntimeFilterLookupsBeforeBuildFinishedprofile event, counting blocks that a JOIN runtime filter passed through unfiltered because its build side had not finished yet (for example withjoin_overflow_mode = 'break'and a finitemax_rows_in_join/max_bytes_in_join), and regression tests for that window.Description
Found by the AST fuzzer (STID 2210-585c).
A JOIN runtime filter is built on the right (build) side by N parallel
BuildRuntimeFilterTransformstreams. The filter becomes findable in theIRuntimeFilterLookupafter the FIRST stream registers it, but it is ready (RuntimeFilter::isReady) only after the LAST stream merges its partial filter. Normally the join's pull discipline guarantees the build side is fully consumed before the probe side runs, but when the join stops reading the build side early (join_overflow_mode = 'break'with a finitemax_rows_in_join/max_bytes_in_join, or an empty/short-circuited right side) the probe side can reach the registered filter while it is still unfinished. The runtime filter is a best-effort optimization: correctness always comes from the JOIN itself, so passing the block through unfiltered is the correct behaviour in that window.Current master already implements the fix itself as part of the runtime filter rework:
__applyFilterpasses all rows through when the registered filter is not ready yet,RuntimeFilter::finishInsertfinalizes the underlying set/bloom filter before publishing readiness, the index-analysis accessorsgetRecordedKeyValues/getRecordedKeyRangesreturn nothing until the filter is ready, and a late merge into an already published shared fixed-hash-table filter is ignored.RuntimeFilter::findkeeps theLOGICAL_ERRORas an invariant that consumers must checkisReadyfirst.This PR adds the observability and regression coverage for that window:
RuntimeFilterLookupsBeforeBuildFinishedprofile event, incremented inFunctionApplyFilterwhen a registered but unfinished filter is passed through.runtime_filter_skip_finish_insertfail point, which holds a filter in the registered-but-unfinished state deterministically.04337_runtime_filter_lookup_before_finished: drives a real JOIN pipeline withjoin_overflow_mode = 'break'and a tinymax_bytes_in_joinover a multi-part build table, repeated so the probabilistic race is hit with high probability; a binary that probes the unfinished filter aborts.04614_join_runtime_filters_index_analysis_partial_filter: the read-time exact IN-set pruning path must not expose a partially merged key set.04615_join_runtime_filters_shared_fixed_hash_table_pruning: the shared fixed-hash-table publication may race the last build streams; results must stay exact and pruning must engage.04681_runtime_filter_lookup_unfinished_witness: uses the fail point to make the pass-through branch observable through the profile event, and asserts the join row counts.Report (AST fuzzer, amd_debug, targeted): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=103322&sha=eeec76f833a27b148d130ef8f504ac362f26caef&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29
Workflow [PR]
Sync PR [sync-upstream/pr/107108]
Version info
26.10.1.1489-master(included in26.10and later)