Repository navigation
fix join spill ownership and lifecycle - #26412
Merged
Merged
Conversation
1 task done
gouhongshen
approved these changes
Jul 30, 2026
gouhongshen
left a comment
Contributor
There was a problem hiding this comment.
Codex automated review
No actionable findings. Existing PR reviews and inline comments contain no reviewer findings. I traced ownership transfer, cancellation, mailbox, generation-reuse, range-shuffle, budget/FD, and error paths. Local package tests could not start because required CGo artifacts/headers are absent; no state was changed.
aptend
approved these changes
Jul 30, 2026
aptend
left a comment
Contributor
There was a problem hiding this comment.
Reviewed the latest changes, including spill payload ownership, cancellation/error cleanup, multi-round lifecycle, reuse-generation isolation, and the SQL regression coverage. No blocking issues found.
This was referenced Jul 30, 2026
Closed
This was referenced Jul 31, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
JoinMapwith one atomic move-onlySpillBuildPayload, and migrate hashjoin, dedupjoin, and rightdedupjoin consumers.Take/FreeMemorycleanup race-safe and exactly-once.RLIMIT_NOFILE.Why
Issue #26408 exposed a split-ownership protocol shared by hashjoin, dedupjoin, and rightdedupjoin. The normal broadcast topology currently cannot produce that payload because non-shuffle HashBuild never spills, so the reported shared-broadcast failure is latent rather than normally reachable. The production-visible design gap is broader: broadcast joins have no spill fallback, while the existing spill path also had ownership, generation reuse, error propagation, cancellation, memory-budget, file-descriptor, file-corruption, and multi-round lifecycle weaknesses.
This PR closes the unsafe cross-join protocol and the concrete reachable unhappy paths without pretending to implement a broadcast spill scheduler or redesign the on-disk format in the same patch.
First-principles closure
Real and unhappy-path validation
io.ErrUnexpectedEOF, clears the decoded destination and reservation, and returns budget usage to zero.CurrNBto baseline and zero memory/disk/FD ledgers.HashBuild -> JoinMap -> DedupJoin UPDATEpipeline covers compact and duplicateGroupSelsmaps, matched and unmatched-finalize paths, emitted value/NULL semantics, vector-owner restoration, and terminal mpool=0.SpillRows/SpillSizeplus depth-1 spill and depth-2 re-spill metrics, and proves the skewed equal-key batch neither panics nor loses rows.Spill regression test plan
BVT remains the minimum SQL correctness and plan smoke layer; this PR does not add a large spill dataset to BVT. Spill correctness is covered by a parameterized regression job in which data size is an input, not a correctness oracle.
Harness and scale contract
N. CI, nightly, and soak jobs may use differentN, DOP, and CN counts; expected results are derived from the generated keys and are never hard-coded to a particular row count.N=4096and accepts only1024 <= N <= 65536. The upper bound protects CI hosts from accidental OOM; larger nightly/soak scales belong in a dedicated external harness rather than BVT or this presubmit test.EXPLAINto contain the intended join and shuffle topology. A spill run passes only whenEXPLAIN ANALYZEreportsSpillRows > 0andSpillSize > 0; a query that happens not to spill is unexercised, not passed.Nis optional, so the regression can run at any practical data scale.SpillRowsto exceed the computed single-pass build-plus-probe row total. The comparison uses generated row counts, not a fixed constant.Required coverage
INSERT ... ON DUPLICATE KEY UPDATEfor primary-key-only and multiple-UNIQUE targets, including mixed matched/new rows and UPDATE expressions that reference nullable or absent source columns. CoverINSERT IGNORE, REPLACE, and RightDedup where their execution topology supports spill. Compare final table contents, affected rows, PK/UK cardinalities, NULL results, and duplicate rejection with the resident run.Correctness oracles and execution tiers
Test matrix
-raceruns pass forvm/message,vm/process,hashbuild,spillutil,hashjoin,dedupjoin, andrightdedupjoin.TestIssue26408JoinSpillSQLRegressionpasses at the default 4,096-row scale, passes two consecutive focused-raceruns, and its full owningpkg/tests/issuespackage passes-race; the test-only CGo compile andgo vet -mod=readonlychecks are clean.go test -list, measured once under-race -json, then repeated withN=clamp(floor(30/T),1,100): the RLIMIT test ran 26 times from a 1.14 s sample; the other 13 ran 100 times each.-race.-racehas exactly three Parquet empty-file fanout failures. The same three tests fail with the same assertions on a clean latestorigin/mainworktree at2e68774061; they are not introduced by this PR.approved=true, 75% threshold); the local affected-package-only profile was 285/375 = 76.00% before CI added cross-package UT/BVT profiles.go vetandgo buildpass for all eight affected packages. Final CGo-wrapper compile checks,make err-check, andgit diff --checkare clean.Performance evidence
For 8,192 build rows / 9,216 probe rows with initial spill and re-spill:
Risks and follow-ups
os.File.Read,os.File.Write, and unmarshal calls cannot be interrupted by context.+0/-0, NaN, JSON numeric forms, scaled FLOAT, and long VECF32 keys.join_spill_memstill overloads values<=100000as rows and larger values as bytes; explicit versioned units and migration are needed.Closes #26408.