Repository navigation
Conversation
Change the default join_algorithm from 'direct,parallel_hash,hash' to 'direct,grace_hash,hash' so that large joins spill to disk automatically instead of running out of memory. grace_hash is the only hash-based algorithm that honors max_bytes_before_external_join / max_bytes_ratio_before_external_join for automatic disk spilling. parallel_hash keeps the whole right side in RAM and was the reason large joins still OOM with the previous default, so it is dropped from the default chain. direct is kept as the fast path for dictionary / key-value lookups, and hash remains as the fallback for joins that grace_hash cannot perform (asof, cross, multi-disjunct ON, constant ON). A SettingsChangesHistory entry restores the previous default for older compatibility levels. Test updates: tests that assert the default value or validate plans/pipelines specific to ConcurrentHashJoin (parallel_hash) pin the algorithm they were written for. grace_hash reorders rows, so optimizeReadInOrder rejects it by design; the read-in-order-through-join and top-k-through-join tests therefore pin a non-reordering algorithm, and 03711 drops its DEFAULT loop iteration. 03274_join_algorithm_default documents the default pipeline and is updated to grace_hash. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-0:20260618-003800 |
|
cc @antaljanosbenjamin — this is the separate PR @alexey-milovidov asked for in #107461, making grace hash the default for automatic disk spilling. Proposed chain is |
|
Workflow [PR], commit [b21c663] Summary: ❌
AI ReviewSummaryThis PR changes the global default Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block Minimum required action: fix the default path so it still enforces the external-join spill threshold, then add a focused regression test for the default |
| - [join_default_strictness](#join_default_strictness) | ||
| )", IMPORTANT) \ | ||
| DECLARE(JoinAlgorithm, join_algorithm, "direct,parallel_hash,hash", R"( | ||
| DECLARE(JoinAlgorithm, join_algorithm, "direct,grace_hash,hash", R"( |
There was a problem hiding this comment.
This default bypasses the automatic-spill threshold that the PR is meant to enable. With direct,parallel_hash,hash or explicit hash/parallel_hash, tryCreateJoin enters the hash branch and, when max_bytes_before_external_join or max_bytes_ratio_before_external_join is effective, builds a SpillingHashJoin that passes the computed threshold into GraceHashJoin. With the new default, the planner reaches the explicit GRACE_HASH branch instead and constructs standalone GraceHashJoin; that path passes no external_join_threshold, and GraceHashJoin documents that standalone grace_hash deliberately ignores max_bytes_before_external_join and relies only on max_rows_in_join / max_bytes_in_join. Since max_bytes_in_join defaults to 0, a large default join can keep growing the first bucket in memory instead of re-partitioning at the external-join threshold.
Please either keep the default on a hash path that creates SpillingHashJoin, or teach the GRACE_HASH branch to pass and enforce params.max_bytes_before_external_join when grace_hash is part of the default. The tests that exercise max_bytes_before_external_join currently pin hash or parallel_hash, so they would not catch this default-path regression.
There was a problem hiding this comment.
Confirmed correct, reproduced on this branch (2M ⋈ 2M, max_bytes_ratio_before_external_join=0):
direct,grace_hash,hash+max_bytes_before_external_join=20MB:ExternalJoinWritePart=2,SwitchedToGrace=0— invariant at threshold 0/20MB/200MB (the GRACE_HASH branch builds standaloneGraceHashJoinwithexternal_join_threshold=0, andhasMemoryOverflowapplies the byte threshold only whenexternal_join_threshold > 0).direct,parallel_hash,hash+ same threshold:ExternalJoinWritePart=64,SwitchedToGrace=1(honors the threshold viaSpillingHashJoin).
So direct,grace_hash,hash routes large joins to the one path that does not respond to max_bytes_before_external_join. This changes the PR's direction; escalated to the maintainers in a top-level comment, holding the code until they decide.
|
The automated review surfaced a correctness problem with the proposed Finding. With Repro (2M ⋈ 2M,
Under a tight This is a design decision I do not want to make unilaterally. Two coherent directions:
@alexey-milovidov @antaljanosbenjamin — which direction do you want? If (1), I will close this PR (and the override in #107461 becomes unnecessary as you noted). If (2), I will implement the threshold plumbing in the |
|
Closing this. After re-verifying against current master (1322ce4): The roadmap goal (automatic disk spilling by default) is already met on master without this change. The literal The grace-hash owner is already making grace hash the default properly (PRs 108936, 108289) and asked not to enable it naively yet. Deferring to that work rather than shipping a default that regresses spilling. Happy to reopen with the alternative (teach the |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The default
join_algorithmis nowdirect,grace_hash,hashinstead ofdirect,parallel_hash,hash. Large joins now spill to disk automatically (viamax_bytes_before_external_join/max_bytes_ratio_before_external_join) instead of running out of memory, becausegrace_hashis the hash-based algorithm that supports spilling.parallel_hashkeeps the whole right side in RAM and was the reason large joins still ran out of memory; it was removed from the default.directis still used for dictionary and key-value lookups, andhashremains as the fallback for joinsgrace_hashcannot perform (ASOF,CROSS, multi-disjunctON). To restore the previous behavior, setjoin_algorithm = 'direct,parallel_hash,hash'.Description
Implements the global default requested in #107461: grace hash join enabled by default so that automatic disk spilling for JOINs works out of the box.
What changed
src/Core/Settings.cpp:join_algorithmdefaultdirect,parallel_hash,hash->direct,grace_hash,hash.src/Core/SettingsChangesHistory.cpp: 26.6 entry restoring the previous default for oldercompatibilitylevels.Why this chain
direct: fast path for dictionary / EmbeddedRocksDB / MergeTree key lookups, no memory cost. Kept.grace_hash: the only hash-based algorithm that honorsmax_bytes_before_external_joinandmax_bytes_ratio_before_external_joinfor automatic disk spilling. Made the main default.parallel_hash: does NOT spill (keeps the full right side in RAM), which is exactly why large joins still OOM with the old default. Dropped from the default.hash: kept as the fallback for shapesgrace_hashcannot perform (ASOF,CROSS, multi-disjunctON, constantON).Fallback to
hashfor unsupported shapes was verified locally with the new default:JOIN ON <constant>,CROSS JOIN,ASOF JOIN, and multi-disjunctORjoins all execute correctly;FULL JOINusesgrace_hashdirectly.Test updates
join_algorithmis not part of the CI randomization pool, so functional tests rely on the default value. A design note from the read-in-order optimizer (optimizeReadInOrder.cpp) is relevant: "Grace hash join scatters rows into buckets by hash, destroying the input order", so the optimizer rejects grace hash for read-in-order-through-join. The same applies to top-k-through-join and to PK-range sharding (aConcurrentHashJoin/parallel_hashfeature). These optimizations do not apply under the new default by design.Tests were updated to preserve their original intent rather than weakened:
03274_join_algorithm_default,03711_read_in_order_through_join: these document the default's behavior.03274is updated to the grace hash default;03711drops theDEFAULTiteration of its[hash, parallel_hash, DEFAULT]loop because grace hash cannot stream read-in-order through a join.parallel_hash/ConcurrentHashJoinplan or pipeline pinjoin_algorithm = 'parallel_hash'(or'parallel_hash,hash'where a constant/scalar join needs thehashfallback):02236,02835,03036,03357(PK sharding),03405,03545_*,03595,03701,03773,04011,04012,04060,04234_explain_pipeline_compact_repeated_processor_chains.join_algorithm = 'hash'(an order-preserving join):04209,04230,04234_top_k_through_join_final_desc_gate.03786_storage_join_type_conversionpins'hash'(StorageJoin RIGHT JOIN uses a plain HashJoin).02815_join_algorithm_setting: default value-string assertion updated.02995_new_settings_historypasses with the new history entry. All touched tests pass locally on a debug build.