Repository navigation
Description
Goal
Converge the spill work around a small set of first-principles contracts instead of continuing to grow a generic spill state machine. This issue is a roadmap and decision boundary; each behavioral change must remain independently reviewable and revertible.
Execution contracts
Broadcast / shared JoinMap
= resident-only
+ hard memory-budget admission
+ controlled terminal query error when admission fails
Shuffle / single-consumer JoinMap
= resident execution below the soft threshold
+ threshold- or admission-triggered spill
+ hard memory/disk/FD/depth bounds
+ controlled terminal error when bounded recovery cannot proceed
The spill threshold is a policy switch for a spill-capable topology. It is not the memory-safety boundary. The hard budget is the safety boundary for every topology.
As of main@ffad68fdb75, normal broadcast HashBuild already cannot spill: both threshold decisions require IsShuffle && NeedHashMap, broadcast compilation creates a shared JoinMap, and shuffle compilation creates a single-consumer JoinMap. The !IsShuffle guard also predates #26412. Therefore, adding another broadcast threshold special case is not a root fix.
First-principles audit
| Area | Invariant | Current decision |
|---|---|---|
| Topology capability | Spill requires shuffle routing and single ownership | Keep broadcast resident-only; never infer capability from refcount alone |
| Q1: ownership | Files, FD/disk reservations, and build payload have exactly one owner | Keep the move-only aggregate payload and idempotent cleanup from #26412 |
| Q2: termination | Producer failure/cancellation must terminate every dependent consumer | Keep terminal build-error publication; fix proven phase-boundary cancellation gaps locally |
| Q3: bounded growth | Memory, disk, FD count, spill depth, and queued work are hard-bounded | Keep hard admission as the universal safety mechanism |
| Planner | Equivalent equality-predicate order must not change shuffle eligibility | Fix #26556 in the planner without changing executor protocols |
| Threshold semantics | The resolved unit/mode must be unambiguous | Treat #26434 as separate compatibility work; do not couple raw values to planner byte estimates |
Phased plan
Phase 0: validate the existing safety closure
Re-run a #25782-like grouped-subquery/LEFT JOIN topology on current main with a deliberately small hard HashBuild budget. Acceptance:
- broadcast creates no spill file even with a minimal soft threshold;
- budget rejection returns a controlled resource-exhausted query error rather than process/node OOM;
- every JoinMap consumer observes the terminal build error and no partial probe result is emitted;
- Reset/Free returns memory, disk, FD, and budget accounting to baseline.
If this passes, narrow #25782 from a node-safety problem to the remaining planner/availability work. If it fails, fix only the missing admission or terminal-publication closure first.
Phase 1: small, independent correctness PRs
- [Bug]: multi-key join predicate order can bypass shuffle spill #26556, planner only: evaluate every supported equi-join candidate, choose the best known eligible NDV deterministically, preserve the existing rule that unknown NDV is not low NDV, and retain broadcast when all known candidates are low-cardinality. Predicate permutation must not change shuffle eligibility. Do not compare planner bytes with the legacy raw
join_spill_memvalue. - Optional HashBuild hardening: only if it reduces duplicated logic, centralize spill capability as one pure predicate equivalent to
IsShuffle && NeedHashMap && JoinMapRefCnt == 1; make every threshold/admission-recovery entry use it and assert it before file/token side effects. Add no enum, stored policy state, scheduler, or consumer protocol. - [Bug]: low agg spill threshold panics on ungrouped COUNT(*) #26453: gate generic group spill by the H0/group-hash capability, not by a
COUNT(*)special case and not by a nil check that hides invalid non-H0 state. - [Bug]: Group continues spill reload after cancellation arrives at input EOF #26444/[Bug]: MergeOrder continues spill final merge after cancellation arrives at input EOF #26446/[Bug]: Top returns spilled results after cancellation arrives at input EOF #26447: apply one phase-boundary rule: after child EOF, observe cancellation before reload/final merge/materialization; check long work at bucket/run/chunk boundaries, not in per-row hot loops. Reuse test fixtures, not a new global cancellation framework.
- [Bug]: unify join typed-key canonicalization across resident and spill paths #26432: keep typed-key canonicalization as a separate correctness PR; do not bundle it with threshold, planner, or storage changes.
Phase 2: threshold contract and minimal observability
For #26434, start with boundary tests (0, 1, 100000, 100001), local/remote round-trip coverage, documentation of legacy magnitude inference, and reporting of original/resolved mode in EXPLAIN/operator stats. Add an explicit unit enum only when there is a demonstrated need to express currently ambiguous values and a concrete mixed-version requirement. Do not build a general version-negotiation framework preemptively.
Use existing spill-start, budget cap/peak/reject, depth, disk, and FD observability before adding more signals. Recoverable admission pressure should increment a fixed-cardinality metric, not log. An unrecoverable terminal failure may emit one diagnostic summary per operator/query, never per batch/bucket/file. Query IDs, SQL, table names, and keys must not become Prometheus labels.
Phase 3: evidence-gated availability/performance work
- [Design]: spill storage v2 with segment indexes, bounded active FDs, and adaptive fanout #26435: start a minimal segment/index storage change only after normal workloads show FD admission failures, active FDs approach the cap, or file create/close/scatter is a material part of spill wall time. Durable format, checksum, mixed-version spill-file compatibility, and adaptive fanout are not current requirements.
- [Design]: add a terminal spill fallback for extreme join-key skew #26436: first measure exact/consecutive no-progress rewrites. Evaluate a terminal fallback only if this is observed in production and the product requires completion rather than controlled failure. Do not implement sort-merge fallback for every join type in advance.
- [Design]: make in-flight spill I/O and decoding interruptible #26437: first measure cancellation latency after the phase-boundary fixes. Build context-aware I/O only if blocked-I/O/decode evidence dominates the remaining latency; do not add cancellation goroutines that concurrently close another owner's FD.
Test and performance gates
- Broadcast with row/byte/auto thresholds, including refcount 1 and greater than 1: zero spill starts/files/FD/disk charge.
- Broadcast over hard budget: one controlled error reaches all consumers, no partial output, all accounting returns to zero.
- Shuffle with one consumer: threshold and budget pressure spill correctly and preserve results.
- Invalid shuffle with multiple consumers: fail before physical spill side effects.
- Multi-key join predicate permutations: identical spill eligibility across supported join types, including unsupported-first and unknown-stat cases.
- Cancellation/reset/reuse: bounded completion and exactly-once cleanup across generations.
- Resident hot paths gain no lock, channel select, per-row cancellation check, or allocation.
allocs/opmust not increase; a statistically significant non-spill regression above roughly 2% requires explanation or blocks merge.
Scope and PR discipline
- One reachable root cause, one behavioral contract, one PR.
- Planner, executor protocol, and spill storage changes are separate rollback units.
- Every PR description must include the reachable reproducer, invariant, acceptance tests, and explicit non-goals.
- A change crossing planner, compiler, executor, consumer protocol, and storage layers must be split unless the same invariant cannot be proved otherwise.
- Do not add feature flags for small deterministic correctness fixes; flags add another state dimension and are harder to verify than an isolated revertible commit.
Treatment of #26412
#26412 mixed several valid but independently reviewable Q1/Q2/Q3 fixes into one large change. Do not roll back the already-proven hard budget, move-only payload, terminal dependency publication, cancellation/generation cleanup, or ownership fixes merely to reduce line count. Freeze the unsupported shared-broadcast spill direction and keep future work aligned to the contracts above.
Related issues
- Safety and incident: [Bug]: HashBuild can bypass spill and trigger system OOM during large hash table growth #25782
- Unsupported shared broadcast spill topology: [Bug]: parallel broadcast dedupjoin/hashjoin spill consumers lose bucket ownership or wait forever #26408; implementation history: fix join spill ownership and lifecycle #26412
- Typed-key correctness: [Bug]: unify join typed-key canonicalization across resident and spill paths #26432
- Threshold semantics: [Design]: make join spill thresholds explicitly versioned and unit-safe #26434
- Conditional storage/skew/I/O designs: [Design]: spill storage v2 with segment indexes, bounded active FDs, and adaptive fanout #26435, [Design]: add a terminal spill fallback for extreme join-key skew #26436, [Design]: make in-flight spill I/O and decoding interruptible #26437
- Phase-boundary cancellation: [Bug]: Group continues spill reload after cancellation arrives at input EOF #26444, [Bug]: MergeOrder continues spill final merge after cancellation arrives at input EOF #26446, [Bug]: Top returns spilled results after cancellation arrives at input EOF #26447
- H0 aggregate spill capability: [Bug]: low agg spill threshold panics on ungrouped COUNT(*) #26453
- Planner predicate-order bug: [Bug]: multi-key join predicate order can bypass shuffle spill #26556
Activity
XuPeng-SH commentedon Aug 1, 2026
Phase 1 planner work is implemented in #26565. The PR is planner-only and preserves existing eligible first-key plans, including unknown-stat and child-AGG shuffle reuse. It falls through only from unsupported or known-low candidates, covers predicate permutations across join types and remap modes, and does not touch executor, threshold units, logging, metrics, or broadcast spill.
fix(plan): select eligible shuffle key across join predicates (#26565)
XuPeng-SH commentedon Aug 3, 2026
Phase 0 validation is in #26638, exercised on
main@b18cdee19b.The SQL-protocol witness uses a low-NDV broadcast
LEFT JOINwith a 1 MiB hard HashBuild budget. It stays non-shuffle; the oversized build returns the controlled resource-exhausted error before any result set, does not enter spill, and leaves the CN queryable. The companion HashBuild test now also proves all shared consumers receive the terminal failure and thatResetreturns memory, disk, and FD accounting to zero.This validates the existing safety closure; it does not add a broadcast spill path or change threshold semantics. After the regression PR lands, the next independent Phase 1 item remains #26453.
test(hashbuild): verify broadcast budget fails closed (#26638)
fix(colexec): honor cancellation at spill phase boundaries (#26675)
XuPeng-SH commentedon Aug 5, 2026
Capability audit and follow-up boundary
Audited against
main@ab28d1b4acand the current #26736 head6173a85b6d. This is a roadmap status update, not a claim that join and aggregate spill are complete.Delivered or validated
Current support boundary
Two corrections are important:
mainstill disables generic spill for ordinary DISTINCT aggregates by raising the threshold to 1 TiB. Therefore DISTINCT spill must be treated as an open capability gap until semantics, state serialization, reload/merge, cancellation, and Reset/Free are covered by a focused implementation and regressions.Proposed implementation order
Acceptance should remain invariant-driven: resident and forced-spill results must match; NULL and duplicate semantics must match; cancellation and injected I/O errors must terminate; and Reset/Free must restore memory, disk, and FD accounting. Performance checks must separately protect the non-spill path.
XuPeng-SH commentedon Aug 12, 2026
This roadmap has completed its consolidation role and is now superseded by concrete issues.
Delivered foundations include ownership/lifecycle (#26412), physical allocation accounting (#26531), recovery leases (#26585), broadcast fail-closed behavior (#26638), and the focused capability/cancellation fixes tracked here. Remaining work is intentionally separated:
Issues already transferred for testing are not modified by this consolidation. Closing the broad roadmap as superseded, not as a claim that every availability case is complete.
fix(plan): select eligible shuffle key across join predicates (matrix…
test(hashbuild): verify broadcast budget fails closed (matrixorigin#2…
fix(colexec): honor cancellation at spill phase boundaries (matrixori…
fix(plan): select eligible shuffle key across join predicates (matrix…
test(hashbuild): verify broadcast budget fails closed (matrixorigin#2…
fix(colexec): honor cancellation at spill phase boundaries (matrixori…
fix(plan): select eligible shuffle key across join predicates (matrix…
test(hashbuild): verify broadcast budget fails closed (matrixorigin#2…
fix(colexec): honor cancellation at spill phase boundaries (matrixori…