Repository navigation
Enable max_bytes_ratio_before_external_join by default - #104285
alexey-milovidov merged 6 commits into
Conversation
PR #103862 added the new `max_bytes_ratio_before_external_join` setting with a default of `0.` (disabled), with a note that the default would later be flipped to `0.5` to mirror how `max_bytes_ratio_before_external_group_by` and `max_bytes_ratio_before_external_sort` were rolled out. This is the follow-up: switch the default to `0.5` so that hash joins automatically spill to grace hash join once the right-side data exceeds half of available system memory (when memory limits are configured). The behavior is unchanged for environments without configured system memory limits — the ratio is logged and ignored in that case, just as for the analogous group-by and sort settings. Original PR: #103862 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Workflow [PR], commit [59eb5b8] Summary: ✅ AI ReviewSummaryThis PR enables ClickHouse Rules
Final Verdict
|
With `max_bytes_ratio_before_external_join` defaulting to `0.5`, the
fast-test environment (which has memory limits configured) now wraps
hash joins as `SpillingHashJoin(HashJoin)` and `SpillingHashJoin(ConcurrentHashJoin)`,
which breaks tests that:
* compare `EXPLAIN` output containing the join algorithm name,
* rely on optimizer rules that match a bare `HashJoin` (e.g. legacy
join swap, read-in-order through join), or
* exercise behaviour specific to the non-spilling hash join (e.g.
`join_any_take_last_row`, on-the-fly fixed hash table conversion).
Replace the previously preemptive `SET max_bytes_before_external_join = 0`
(which is now a no-op since `0` is the default) with
`SET max_bytes_ratio_before_external_join = 0` to disable automatic
spilling for these tests, restoring their previous behaviour.
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104285&sha=43fe2750b01ab4a0256eb5957efb1e927b86bcfd&name_0=PR&name_1=Fast%20test
PR: #104285
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…spilling The previous fix (commit 4ca1d29) replaced `SET max_bytes_before_external_join = 0` with `SET max_bytes_ratio_before_external_join = 0` in tests that need to disable automatic spilling hash join. However, the test settings randomization in `tests/clickhouse-test` independently sets `max_bytes_before_external_join` to either `0` or `1000000000`. When the randomizer picks `1000000000`, the absolute threshold arms `SpillingHashJoin` even though the ratio is `0`, because `JoinSettings::getMaxBytesBeforeExternalJoin` combines the two and the smaller non-zero of them applies. This breaks tests in two ways: * `EXPLAIN`-based tests still see `SpillingHashJoin(...)` in the output. * Tests like `02302_join_auto_lc_nullable_bug` that rely on `join_algorithm = 'auto'` falling back to merge join when `max_bytes_in_join` is exceeded instead get `SET_SIZE_LIMIT_EXCEEDED`, because the planner returns `SpillingHashJoin` (which doesn't fall back) when the absolute threshold is non-zero. Set both `max_bytes_before_external_join = 0` and `max_bytes_ratio_before_external_join = 0` in the affected tests, which fully disables automatic spilling regardless of which setting the randomizer chooses to override. Also patch `00163_shard_join_with_empty_table` and the `01721_join_implicit_cast_long*` tests, which were already setting only the absolute setting. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104285&sha=4ca1d2965a77344e72b6a6fe7f957e23ad4a6e4f PR: #104285 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
| {"output_format_parquet_unsupported_types_as_binary", false, false, "Obsolete setting, the native writer always throws UNKNOWN_TYPE for unsupported types."}, | ||
| {"input_format_parquet_use_native_reader_v3", true, true, "Obsolete setting, the native reader v3 is now always used."}, | ||
| {"max_bytes_ratio_before_external_join", 0., 0., "New setting: ratio of available memory used as the spill threshold for hash joins. Combined with the absolute `max_bytes_before_external_join` (the smaller of the two applies)."}, | ||
| {"max_bytes_ratio_before_external_join", 0., 0.5, "New setting: ratio of available memory used as the spill threshold for hash joins. Enabled by default at `0.5`, mirroring `max_bytes_ratio_before_external_group_by` and `max_bytes_ratio_before_external_sort`. Combined with the absolute `max_bytes_before_external_join` (the smaller of the two applies)."}, |
There was a problem hiding this comment.
After enabling max_bytes_ratio_before_external_join by default, the description of max_bytes_before_external_join in Settings.cpp became inaccurate: it still says “When set to 0 (default), automatic spilling is disabled.”
Now max_bytes_before_external_join = 0 only disables the absolute byte threshold; spilling can still happen via the ratio default (0.5). Please update that sentence to reflect the new behavior.
With `max_bytes_ratio_before_external_join` defaulting to `0.5`, the
performance comparison environment (which has memory limits configured)
now wraps hash joins in `SpillingHashJoin`. For perf tests that
specifically benchmark in-memory hash join behavior, this causes the
"new" side to use grace hash join while comparing against an "old"
master that still uses pure hash join, reporting them as regressions.
Set `max_bytes_ratio_before_external_join = 0` in the affected tests to
keep them measuring the same in-memory join code path as before:
* `parallel_hash_join_various.xml` — benchmarks `parallel_hash`.
* `join_convert_to_fixed_hash_table.xml` — benchmarks
`enable_join_fixed_hash_table_conversion` with `hash`/`grace_hash`.
* `join_runtime_filter.xml` — benchmarks runtime filter behavior.
* `join_used_flags.xml` — benchmarks `RIGHT JOIN` used-flag tracking.
* `tpch.xml` — keeps the TPC-H benchmark comparable across runs;
adds an inline `<settings>` block that overrides
`../benchmarks/tpc-h/settings.json`.
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104285&sha=c0886206419503145375bf5672cbe990b49ae40b&name_0=PR
PR: #104285
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
After enabling `max_bytes_ratio_before_external_join = 0.5` by default, the description of `max_bytes_before_external_join` was inaccurate: it still claimed that setting it to `0` (the default) disables automatic spilling, but spilling can now still occur via the ratio default. Clarify that `0` only disables the absolute byte threshold and that both settings need to be set to `0` to fully disable automatic spilling. Addresses review feedback on PR #104285. PR: #104285 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…tio-before-external-join-by-default
LLVM Coverage Report
Changed lines: 100.00% (18/18) · Uncovered code |
Follow-up to #103862, which added the
max_bytes_ratio_before_external_joinsetting with a default of0.(disabled). The merged PR's description noted that the default would later be flipped to0.5, mirroring howmax_bytes_ratio_before_external_group_byandmax_bytes_ratio_before_external_sortwere rolled out (both currently default to0.5).This PR makes that flip: by default, hash joins now spill to grace hash join once the right-side data exceeds half of the available system memory (when memory limits are configured). When no system memory limits are configured (e.g. local test runs), the ratio is logged and ignored, just as for the analogous group-by and sort settings — so behavior in unconstrained environments is unchanged.
The
SettingsChangesHistory.cppentry for26.5is updated in place (from0., 0.to0., 0.5) since the setting was introduced in this same release.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The new `max_bytes_ratio_before_external_join` setting is now enabled by default at `0.5`, mirroring `max_bytes_ratio_before_external_group_by` and `max_bytes_ratio_before_external_sort`. Hash joins automatically spill to grace hash join once the right-side data exceeds half of the available system memory (when memory limits are configured).
Documentation entry for user-facing changes
Version info
26.5.1.446