Repository navigation
Revert "Revert "Unify the spill trigger for hash joins"" - #119335
Conversation
|
Workflow [PR], commit [edce8ed] Summary: ✅
AI ReviewSummaryThis PR re-applies the spill-trigger unification for hash joins, adds the mixed-version Findings❌ Blockers
Tests
Final VerdictChanges requested. LLVM Coverage ReportMeasured on commit edce8ed.
Changed lines: Changed C/C++ lines covered: 695/732 (94.95%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes69 object files changed (+50.93 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units404 translation units recompiled, 3821 s compile time in total, 404 of them have a recent master baseline. |
…rialization version
…t-117356 # Conflicts: # src/Core/ProtocolDefines.h
… an older peer Skipping the `legacy_join_size_limits_trigger_spilling` name below query-plan serialization version `17` keeps the settings blob parseable, but it does not make the downgraded plan safe: the older peer knows `max_rows_in_join` / `max_bytes_in_join` and still treats them as the spill trigger, and its standalone `GraceHashJoin` ignores `max_bytes_before_external_join`. Such a plan would silently run with the old contract. Fail closed instead: `JoinSettings::updatePlanSettings` throws below version `17` whenever the two contracts can diverge - a non-zero `max_rows_in_join` / `max_bytes_in_join`, or `grace_hash` with a spill threshold - and stays quiet when they agree, including when the query explicitly asks for the legacy mode. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…dy` red `gtest_join_step_logical_decisions.cpp` still built `JoinSettings` from `QueryPlanSerializationSettings` with the one-argument constructor, which this branch replaced with the version-taking one, so `Build (arm_tidy)` failed to compile it. The new `gtest_join_spill_trigger_plan_setting.cpp` locks down what may be downgraded below query-plan serialization version `17`: the name is on the wire towards a current peer and read back as sent; below `17` it is omitted and read back as legacy mode; serialization is refused when the size limits or a `grace_hash` spill threshold make the contracts diverge, and allowed when the query asks for the legacy contract or nothing depends on it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`legacy_join_size_limits_trigger_spilling` is also the way out of the `serialize_query_plan` refusal towards a server that predates it, so say so where the setting is declared. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`spillBehaviorDiffersFromLegacy` treated `join_algorithm = 'grace_hash'` with both spill thresholds cleared as compatible with a peer that predates `legacy_join_size_limits_trigger_spilling`, but it is not: here such a join is not runnable at all - `ExpressionAnalyzer::tryCreateJoin` / `PlannerJoins::tryCreateJoin` demote `grace_hash` to the next entry of the preference list, and `GraceHashJoin` refuses the query when it is listed alone - while a pre-`17` peer still builds a standalone `GraceHashJoin` with `external_join_threshold = 0` and runs it. So `grace_hash` now diverges from the legacy contract whatever the thresholds are, and the gate no longer looks at them. The gtest covers both new cases, listed alone and inside a preference list, and keeps a positive case that still passes the gate: `grace_hash` with `legacy_join_size_limits_trigger_spilling = 1`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`spillBehaviorDiffersFromLegacy` treated any appearance of `grace_hash` in `join_algorithm` as a mixed-version incompatibility, which is broader than the behavior it guards. `join_algorithm` is an ordered preference list, and the `hash` / `parallel_hash` / `prefer_partial_merge` / `default` / `auto` branch of `chooseJoinAlgorithm` ends in an unconditional `HashJoin` / `ConcurrentHashJoin` / `SpillingHashJoin`, so nothing behind such an entry is ever consulted - here or on an older peer, which walks the same list in the same order. A list like `hash,grace_hash` therefore builds the very same join on both sides, and there is nothing to fail closed on. Only a `grace_hash` that is the first entry able to run now counts. The size limits keep failing closed whatever the list looks like, and the gtest covers the unreachable-`grace_hash` lists with and without a spill threshold. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… on a constant `JoinSettings::spillBehaviorDiffersFromLegacy` exempted only an empty `ON` clause (`ON 1`) as a join on a constant. `JoinStepLogical::buildPhysicalJoinImpl` also turns a single predicate of type `Nullable(Nothing)` that is not a binary condition (`ON NULL`) into an always-false `ConstantJoin`, on both sides of a serialized plan, so such a step never consults `join_algorithm` and its size limits are hard caps on both peers. The gate refused it towards a pre-`19` peer as soon as `max_rows_in_join` / `max_bytes_in_join` were set or `grace_hash` was listed. Both constant shapes are now recognized by one predicate, `isJoinOnConstant`, that mirrors the physical build (ASOF excluded, like there). The gtest builds an `ON NULL` operator and covers it for `grace_hash` and for the size limits, and checks that an ASOF join with such a clause is not treated as a join on a constant. Addresses the review thread on `src/Interpreters/JoinOperator.cpp`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
`JoinSettings::spillBehaviorDiffersFromLegacy` refused a downgraded plan for steps that never reach the new spill contract on either side. The only join that treats `max_rows_in_join` / `max_bytes_in_join` as a spill trigger on an old peer is `GraceHashJoin`, standalone or inside the `SpillingHashJoin` of the hash family, and `GraceHashJoin::isSupported` also requires a single join clause (`TableJoin::oneDisjunct`). A step has one exactly when its `ON` clause carries a cross-side equality at the top level: a single `OR` is split into one clause per disjunct, an inequality-only join becomes an `IEJoinStep` (or a CROSS join with a residual filter), and all of those check the limits as hard caps on both sides. `graceHashSupports` now includes that requirement (`hasEqualityKeys`), and the gate returns early for any step it declines, before the preference list is walked, so `join_algorithm = 'ie_join'` or `direct` on such a step is not refused either. A step with an equality next to inequalities stays refused when `ie_join` is listed first: an old peer may not honor that preference. gtest `StepsWithoutASingleEqualityClause` covers a disjunctive `ON` clause and inequality-only steps with the default, hash-family, `ie_join` and `grace_hash` lists, and the contrast cases with a top-level equality. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 The only red, |
… gate `isPlainEquiJoin` accepted only `JoinConditionOperator::Equals`, so for a step joined `ON l.a <=> r.a` the merge algorithms were treated as "unknown" and a spill-capable entry behind `full_sorting_merge` / `partial_merge` made `JoinSettings::spillBehaviorDiffersFromLegacy` refuse the plan towards an old peer. But `JoinStepLogical::addJoinPredicatesToTableJoin` extracts a `NullSafeEquals` predicate as an ordinary key of the same single clause (nullable keys are wrapped into `tuple(...)` on both sides first), and neither `FullSortingMergeJoin::isSupported` nor `MergeJoin::isSupported` tells it apart from `=`, so both sides run the merge join and never consult the later entry. Both `isPlainEquiJoin` and `hasEqualityKeys` now share one `isCrossSideEquality` predicate accepting `Equals` and `NullSafeEquals`. New gtest `NullSafeEqualityIsAKeyForTheMergeAlgorithmsToo` covers the trailing spill-capable fallback behind a merge algorithm on a null-safe key, the kind/strictness split and the still-refused hash-family lists. Co-Authored-By: Claude Fable 5.1 <[email protected]>
`spillBehaviorDiffersFromLegacy` treated every entry that stops the `join_algorithm` walk as the hash-family case, where the size limits stop being hard caps once a spill threshold is present. That is too broad for `prefer_partial_merge`: both `chooseJoinAlgorithm` paths try `MergeJoin` first and fall back to the hash branch only where `MergeJoin::isSupported` declines the step. A plain equi-join with `join_algorithm = 'prefer_partial_merge,grace_hash'` never reaches `grace_hash` and keeps `max_rows_in_join` / `max_bytes_in_join` as hard caps on both sides, so refusing the mixed-version downgrade was a false positive. New `runsStepWithHashFamily` separates "stops the walk" from "uses the hash-family spill semantics": `prefer_partial_merge` counts as the hash family only where `MergeJoin` declines the step (a kind / strictness it does not run, or an `ON` clause that is more than plain equalities, which stays fail-closed). The gtest no longer bakes in the false positive and gets a dedicated test for both outcomes. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…lockToJoin` When the bucket being built crosses `max_rows_in_join` / `max_bytes_in_join` under `join_overflow_mode = 'break'`, `checkSizeLimits` returning `false` only stopped the `FillingRightJoinSideTransform` that saw it. The buckets already spilled to disk were still loaded and joined in `getDelayedBlocks`, because `stop_after_current_bucket` was only set in the delayed phase, so the join returned rows well past the configured cap. Set the latch in `addBlockToJoin` as well, so the join ends with the bucket in memory, the way `HashJoin` ends with the block that crossed the cap. The flag becomes atomic because the build phase is concurrent. Test: `05218_grace_hash_break_stops_delayed_buckets`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 The only red on |
…t-117356 # Conflicts: # src/Core/ProtocolDefines.h
| /// `join_overflow_mode = 'break'`: the caller stops feeding this side, but the buckets already on disk | ||
| /// would still be joined in `getDelayedBlocks` - well past the cap. Latch the stop here as well, so | ||
| /// the join ends with the bucket in memory, the way `HashJoin` ends with the block that crossed the cap. | ||
| stop_after_current_bucket = true; |
There was a problem hiding this comment.
stop_after_current_bucket only changes what getDelayedBlocks does later; it does not stop concurrent build threads from touching the current bucket. GraceHashJoin still supports parallel build, and addBlockToJoinImpl can keep reaching repartitionCurrentBucket afterwards on both the zero-row spill path and the ordinary overflow path.
That makes join_overflow_mode = 'break' timing-dependent. If thread A trips the cap here and thread B already has another right-side chunk, thread B can still split the "kept" bucket and flush part of it into newly created delayed buckets. The later getDelayedBlocks call then drops those buckets because this flag is set, so the query can lose rows from the very bucket it is supposed to keep. This needs a build-phase latch too: once break has fired, later addBlockToJoinImpl calls must stop repartitioning/spilling the current bucket.
…o revert-119334-revert-117356
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=27 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
Related: #117356
Related: #119334
Closes: #110521
Re-applies #117356, which was reverted in #119334.
One control for when a hash join spills. How it spills is still your choice of algorithm.
grace_hashspilled onmax_rows_in_join/max_bytes_in_joinand ignoredmax_bytes_before_external_join; every other hash algorithm did the opposite. Now, for all of them:max_bytes_before_external_join/max_bytes_ratio_before_external_join— the spill threshold.max_rows_in_join/max_bytes_in_joinwithjoin_overflow_mode— a hard cap. It never causes spilling, and a join that spills no longer exceeds it (GraceHashJoinignored thecheck_limitsargument ofaddBlockToJoinentirely).Every algorithm stays selectable.
grace_hashis external from the first block, so it needs a non-zero spill threshold: without one it is passed over for the next algorithm injoin_algorithm, and rejected with a clear error when it is the only one listed.Also fixed on the way:
FillingRightJoinSideTransformdetected spillability withtypeid_cast<GraceHashJoin *>, soMemorySpillSchedulernever reached the adaptiveSpillingHashJoinpath. It now goes through theIJoinvirtualscanSpillToDisk/getSpillableBytes/requestSpill.legacy_join_size_limits_trigger_spilling(defaultfalse, enabled bycompatibilitywith 26.8 and older) restores the earlier meaning: for the part of a join that runs on disk the two limits trigger further spilling instead of stopping the query, and standalonegrace_hashaccepts a zero threshold again.New since #117356: mixed-version
serialize_query_planis fail-closed. The setting is added to the join step settings at query-plan serialization version17; below it the name is omitted (a peer that does not know it would reject the whole blob) and read back as legacy mode, and a join step whose spilling depends on the new contract — a non-zeromax_rows_in_join/max_bytes_in_join, orgrace_hashwith a spill threshold — is refused rather than downgraded, because such a peer would run it with the old contract without saying so.gtest_join_spill_trigger_plan_setting.cpplocks that rule down.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
max_bytes_before_external_joinandmax_bytes_ratio_before_external_joinare now the spill threshold for every hash-basedjoin_algorithm, includinggrace_hash, which previously ignored them and spilled onmax_rows_in_join/max_bytes_in_joininstead. Those two are a hard cap again for every algorithm: they no longer cause spilling, and a join that spills no longer exceeds them. All join algorithms remain available;join_algorithm = 'grace_hash'now needs a non-zero spill threshold, and is skipped in favour of the next algorithm in the list when it has none. Setlegacy_join_size_limits_trigger_spilling = 1(orcompatibilityto 26.8 or older) to restore the previous behavior.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/119335]