Skip to content

Add setting join_runtime_filter_min_probe_rows - #104860

Merged
vdimir merged 25 commits into
masterfrom
vdimir/skip-runtime-filter-for-small-probe
Jul 23, 2026
Merged

vdimir merged 25 commits into
masterfrom
vdimir/skip-runtime-filter-for-small-probe

Conversation

@vdimir

@vdimir vdimir commented May 13, 2026

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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

  • Skip JOIN runtime filter when the probe side is estimated to be small. New setting join_runtime_filter_min_probe_rows (default 1000) controls the threshold

For cases like in https://github.com/ClickHouse/ClickHouse/blob/master/tests/performance/one_thousand_joins.xml runtime filters may add significant overhead

@vdimir
vdimir requested a review from davenger May 13, 2026 14:31
@vdimir
vdimir force-pushed the vdimir/skip-runtime-filter-for-small-probe branch from 20db9a1 to 2d23cbe Compare May 13, 2026 14:32
@clickhouse-gh

clickhouse-gh Bot commented May 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7347be7]

Summary: ❌

job_name test_name status info comment
AST fuzzer (amd_debug, targeted) FAIL
Logical error: ScatterExchangeStep should have one source shard, got A (STID: 4636-3f0c) FAIL cidb
AST fuzzer (amd_debug, targeted, old_compatibility) FAIL
Logical error: ScatterExchangeStep should have one source shard, got A (STID: 4636-3f0c) FAIL cidb

AI Review

Summary

This PR adds join_runtime_filter_min_probe_rows, defaults it to 1000, wires it into runtime-filter planning, and backfills many tests to keep runtime-filter coverage deterministic. The core idea is reasonable, but the setting still silently does nothing on several common planning paths, and two existing regressions no longer exercise runtime filters at all, so I would not merge it in the current form.

Findings

⚠️ Majors

  • [src/Processors/QueryPlan/Optimizations/joinRuntimeFilter.cpp:251, src/Processors/QueryPlan/Optimizations/optimizeJoin.cpp:1521-1543, src/QueryPipeline/DistributedPlanExecutor.cpp:668] join_runtime_filter_min_probe_rows only works when left_rows_estimation happens to be populated. The non-reorder path still calls join_step->setOptimized() with no estimates, and distributed workers still force query_plan_optimize_join_order_limit = 0, so the new setting silently becomes a no-op on those plans. Suggested fix: populate left/right estimates before the early setOptimized() returns, for example by reusing estimateReadRowsCount on both children. [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/104860#discussion_r3235150282] I still consider this real because the current code path means the new setting is ignored for whole classes of joins, including distributed-worker fragments.
  • [src/Core/Settings.cpp:8504] The PR changes the default behavior of enable_join_runtime_filters for every join whose probe estimate is <= 1000, but there is still no benchmark artifact or regression guard showing that 1000 is the right default rather than just an exposed knob. The perf jobs for this PR were skipped, and the description only points at one workload. Suggested fix: attach measurements that justify the cutoff, or keep the compatibility-preserving default 0 until the threshold is backed by data.
  • [tests/queries/0_stateless/04303_join_runtime_filter_query_condition_cache.sql:16] This regression now runs with the new default threshold, and its probe table has only 40 MergeTree rows. The runtime filter is therefore skipped before __applyFilter is built, so the test still passes even if the query-condition-cache exclusion regresses. Suggested fix: pin join_runtime_filter_min_probe_rows = 0 there, or assert BuildRuntimeFilter in EXPLAIN, so the test keeps covering the runtime-filter path it is meant to guard.
  • [tests/queries/0_stateless/04327_join_runtime_filter_json.sql:1, src/Processors/QueryPlan/Optimizations/optimizeJoin.cpp:424] The new system.one estimate makes every query in this regression look like a 1-row probe, so the default threshold suppresses runtime-filter creation and the test now validates only ordinary join results. Suggested fix: pin join_runtime_filter_min_probe_rows = 0 in this test, or add an EXPLAIN assertion that BuildRuntimeFilter is still present.
Final Verdict

Changes requested.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label May 13, 2026
/// Planning and pipeline overhead outweighs any saving on a tiny probe.
if (optimization_settings.join_runtime_filter_min_probe_rows > 0)
{
auto probe_size = join_step->getInputRowsEstimation(JoinTableSide::Left);

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.

join_runtime_filter_min_probe_rows currently depends on join_step->getInputRowsEstimation(JoinTableSide::Left), but this estimation is often unset (for example when query_plan_optimize_join_order_limit = 0, or other non-reorderable joins where optimizeJoinLogicalImpl calls setOptimized without row estimates).

In those paths this check never triggers, so the new setting silently becomes a no-op and runtime filters are still installed for tiny probes. Could we add a fallback estimate path (for example from the left child) or populate left/right estimates before setOptimized on the non-reorder path?

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.

Still seeing this in current HEAD.

joinRuntimeFilter.cpp now gates on join_step->getInputRowsEstimation(JoinTableSide::Left), but optimizeJoinLogicalImpl still has early-return paths that call join_step->setOptimized() without left/right estimates (e.g. query_plan_optimize_join_order_limit = 0, non-reorderable join shapes, and the use_parallel_replicas path that forces join-order limit to 0 in QueryPlanOptimizationSettings).

In those cases probe_size stays empty, so join_runtime_filter_min_probe_rows never applies and runtime filters are always installed even for tiny probes.

Could we populate left_rows_estimation/right_rows_estimation in the non-reorder path (for example via estimateReadRowsCount on both children) so the setting remains effective outside join-reorder runs as well?

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.

It's ok to miss estimation in some cases for now

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 still looks live in current HEAD.

join_runtime_filter_min_probe_rows only works when join_step->left_rows_estimation is populated, but optimizeJoinLogicalImpl still takes several non-reorder paths that call join_step->setOptimized without left/right estimates (for example when query_plan_optimize_join_order_limit = 0; this is also forced under parallel replicas in QueryPlanOptimizationSettings).

Then joinRuntimeFilter.cpp reads an empty probe estimate at this check, so the new setting silently becomes a no-op and runtime filters are still installed for tiny probes.

Could we populate left_rows_estimation / right_rows_estimation on the non-reorder path (e.g. from child estimateReadRowsCount) so the setting works consistently outside join-reorder runs too?

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.

I rechecked this on current HEAD and the gap is still in the code path.

joinRuntimeFilter.cpp now uses join_step->getInputRowsEstimation(JoinTableSide::Left) at tryAddJoinRuntimeFilter (line 160), but optimizeJoinLogicalImpl still has multiple early-return paths that call join_step->setOptimized() without row estimates (lines 1305-1313 and 1328-1333 in optimizeJoin.cpp).

Also, QueryPlanOptimizationSettings still forces query_plan_optimize_join_order_limit = 0 when parallel replicas are enabled (lines 156-157 in QueryPlanOptimizationSettings.cpp), which sends this through the no-estimate path.

So in those cases the probe estimate remains empty and join_runtime_filter_min_probe_rows is skipped, even for very small probes. I still think this setting should be effective outside join-reorder runs too.

@vdimir
vdimir force-pushed the vdimir/skip-runtime-filter-for-small-probe branch from 5f70379 to 3697d7f Compare May 19, 2026 09:50
@vdimir
vdimir force-pushed the vdimir/skip-runtime-filter-for-small-probe branch from 3697d7f to b121448 Compare May 19, 2026 11:16
vdimir added a commit that referenced this pull request May 20, 2026
The flaky check's `Shell.run(timeout=...)` is the only wall-clock guard:
`clickhouse-test` itself never knows about the budget, so it keeps running
until the wrapper SIGTERMs it.  That kill can land mid-query — e.g. the
post-test `system.trace_log` aggregate on a debug build with a huge
accumulated `trace_log` — failing a run where every test actually passed.

Seen on PR #104860 (touches ~32 stateless tests; flaky check ran them all
50x); job timed out at 2180s with `clickhouse-test exited with code -15`,
even though `All tests have finished.` printed 69 s earlier and every
iteration passed.

Two changes:

1. `tests/clickhouse-test`: cap the post-`All tests have finished.`
   diagnostics with `SETTINGS max_execution_time` and matching HTTP
   timeouts — the `MemoryAllocatedWithoutCheck` aggregate, the
   `SYSTEM FLUSH LOGS system.trace_log`, and the per-test-coverage
   queries.  If the server is overloaded they are skipped with a
   logged exception instead of blocking shutdown.

2. `ci/jobs/functional_tests.py`: forward `--global_time_limit` to
   `clickhouse-test` (budget minus 180 s of shutdown headroom).
   `clickhouse-test` stops scheduling new test iterations gracefully
   and has time to run the hung-check + (now-bounded) diagnostics
   before the outer `Shell.run` SIGTERM fires.  The outer timeout
   stays as a last-resort kill.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104860&sha=0bd90393d11807d0090b718e119cb03889f31fd7&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20flaky%20check%29
PR: #104860

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@vdimir

vdimir commented May 20, 2026

Copy link
Copy Markdown
Member Author

Stateless tests (amd_debug, flaky check) FAIL
clickhouse-test FAIL cidb

Seems like flaky check could not finish due to many changed tests while each individual test succeed, let's try to address it in #105405

Comment thread src/Core/SettingsChangesHistory.cpp Resolved
Comment thread src/Core/Settings.cpp Outdated
If the number of set bits in a runtime bloom filter exceeds this ratio the filter is completely disabled to reduce the overhead.
)", EXPERIMENTAL) \
DECLARE(UInt64, join_runtime_filter_min_probe_rows, 1000, R"(
Minimum number of rows to install a JOIN runtime filter. Skip filter installation for tiny probes to reduce overhead. Set to 0 to always install.

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.

The reader is a bit confused:

  • the setting name says the setting is about the probe size size, also the description says "probes".
  • the description also says "installation" which translates to building a runtime filter on the build side, and that's what users would also intuitively expect as it doesn't make sense to build the RT filter but then not use it during probe.

EDIT: I read the rest of the PR ... I think we can just say that the decision is made at optimization time based on the estimated probe side size.

/// Planning and pipeline overhead outweighs any saving on a tiny probe.
if (optimization_settings.join_runtime_filter_min_probe_rows > 0)
{
auto probe_size = join_step->getInputRowsEstimation(JoinTableSide::Left);

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.

(unrelated: maybe we can rename Left/Right in enum JoinTableSide to Probe/Build?)

alexey-milovidov added a commit that referenced this pull request Jul 24, 2026
…26.7 to 26.8

The 26.7 release has been cut (master is 26.8), so this setting first ships
in 26.8; the Upgrade check flags a new setting whose history entry is not
newer than the old (26.7 release) binary. Also move the
`join_runtime_filter_min_probe_rows` entry (from #104860, merged after the
26.8 version bump) the same way, matching the pending fix in
#111671.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107667&sha=23d8ad1774ba1cc0fa12661c6fd61152ed4e0c00&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29
PR: #107667

Co-Authored-By: Claude Fable 5 <[email protected]>
leshikus pushed a commit to leshikus/ClickHouse that referenced this pull request Jul 24, 2026
…6.7 to 26.8

The setting join_runtime_filter_min_probe_rows was added in ClickHouse#104860 with its
SettingsChangesHistory.cpp entry placed in the 26.7 version section. Master is
now 26.8.1.1, so the entry belongs in the 26.8 section.

The Upgrade check counts a setting as documented only when its history-entry
version is strictly greater than the previous release version (upgrade_runner.sh:
(major*100 + minor) > old_version). The previous release is now v26.7.1.1315-stable,
so old_version = 2607. With the entry in 26.7, 2607 > 2607 is false, so the check
reports the setting as an undocumented new/changed setting and Upgrade check
(amd_release) fails on every PR. Moving it to 26.8 gives 2608 > 2607 = true and the
check passes. Same-day precedent: bce71f1 moved another straggler 26.7 -> 26.8
for the same reason; ClickHouse#104860 merged after that move.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
grantholly-clickhouse pushed a commit to grantholly-clickhouse/ClickHouse that referenced this pull request Jul 31, 2026
…ilter effects

ClickHouse#104860 added the setting `join_runtime_filter_min_probe_rows` (default 1000) and
randomizes it in `clickhouse-test` between 0 and 10000. Tests that assert side
effects of the runtime filter being built — `BuildRuntimeFilter` in `EXPLAIN`
output or `RuntimeFilterGranules*`/index-analysis counters — over probe sides
of only tens to a few thousand rows now fail whenever the randomized threshold
exceeds the probe size, because the filter is skipped.

Pin `join_runtime_filter_min_probe_rows = 0` in those tests, restoring the
behavior they were written against. Observed failing in CI:
`03394_distributed_shuffle_join_with_filter`, `_with_in`, `_with_aggregation`
and `04612_join_runtime_filters_index_analysis_multi_key_anti`
(https://d1k2gkhrlfqv31.cloudfront.net/clickhouse-test-reports-private/json.html?PR=65003&sha=a867fe9e119f88fd563055ae403e90120a26e374&name_0=PR);
the remaining tests assert the same effects with sub-threshold probe sizes.

Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ime-filter-for-small-probe

Add setting join_runtime_filter_min_probe_rows
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…6.7 to 26.8

The setting join_runtime_filter_min_probe_rows was added in ClickHouse#104860 with its
SettingsChangesHistory.cpp entry placed in the 26.7 version section. Master is
now 26.8.1.1, so the entry belongs in the 26.8 section.

The Upgrade check counts a setting as documented only when its history-entry
version is strictly greater than the previous release version (upgrade_runner.sh:
(major*100 + minor) > old_version). The previous release is now v26.7.1.1315-stable,
so old_version = 2607. With the entry in 26.7, 2607 > 2607 is false, so the check
reports the setting as an undocumented new/changed setting and Upgrade check
(amd_release) fails on every PR. Moving it to 26.8 gives 2608 > 2607 = true and the
check passes. Same-day precedent: bce71f1 moved another straggler 26.7 -> 26.8
for the same reason; ClickHouse#104860 merged after that move.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The flaky check's `Shell.run(timeout=...)` is the only wall-clock guard:
`clickhouse-test` itself never knows about the budget, so it keeps running
until the wrapper SIGTERMs it.  That kill can land mid-query — e.g. the
post-test `system.trace_log` aggregate on a debug build with a huge
accumulated `trace_log` — failing a run where every test actually passed.

Seen on PR ClickHouse#104860 (touches ~32 stateless tests; flaky check ran them all
50x); job timed out at 2180s with `clickhouse-test exited with code -15`,
even though `All tests have finished.` printed 69 s earlier and every
iteration passed.

Two changes:

1. `tests/clickhouse-test`: cap the post-`All tests have finished.`
   diagnostics with `SETTINGS max_execution_time` and matching HTTP
   timeouts — the `MemoryAllocatedWithoutCheck` aggregate, the
   `SYSTEM FLUSH LOGS system.trace_log`, and the per-test-coverage
   queries.  If the server is overloaded they are skipped with a
   logged exception instead of blocking shutdown.

2. `ci/jobs/functional_tests.py`: forward `--global_time_limit` to
   `clickhouse-test` (budget minus 180 s of shutdown headroom).
   `clickhouse-test` stops scheduling new test iterations gracefully
   and has time to run the hung-check + (now-bounded) diagnostics
   before the outer `Shell.run` SIGTERM fires.  The outer timeout
   stays as a last-resort kill.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104860&sha=0bd90393d11807d0090b718e119cb03889f31fd7&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20flaky%20check%29
PR: ClickHouse#104860

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
VighneshPath pushed a commit to VighneshPath/ClickHouse that referenced this pull request Sep 16, 2026
Two stateless tests from ClickHouse#113291 cannot run on 26.6 as cherry-picked, so
they fail before any assertion executes.

04672: join_runtime_filter_min_probe_rows does not exist on 26.6 (added by
ClickHouse#104860, settings history 26.8), so the SET at line 21 aborts the test with
UNKNOWN_SETTING. Dropping that one clause makes the line identical to the
merged 26.7 backport. max_bytes_ratio_before_external_join does exist here,
so it stays and 04029 needs no change.

04695: the t_utc block was removed from this branch but the trailing
DROP TABLE t_utc and the three matching reference lines were left behind,
so the test dies with UNKNOWN_TABLE.

Both files: EXPLAIN PLAN defaults to actions=1, compact=1, pretty=1 only
from 26.7 via explain_query_plan_default, which does not exist on 26.6, so
the references written for master do not match. Pinning the three options
explicitly restores the byte-exact output. All three are needed: compact
and pretty without actions collapse the plan and hide the sort description
rows.

Verified with clickhouse local on stock 26.6.3.30 and on a master build.
On 26.6 both tests now run to completion and every remaining difference is
the defect ClickHouse#113291 fixes. On master the same files match the references
byte for byte, so the pinning loses no coverage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements 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