Skip to content

[Roadmap]: converge spill around topology capability, hard budgets, and bounded lifecycle #26563

Closed as not planned

Description

@XuPeng-SH

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

  1. [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_mem value.
  2. 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.
  3. [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.
  4. [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.
  5. [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

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/op must 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

Activity

  1. self-assigned this
    on Aug 1, 2026
  2. XuPeng-SH commented on Aug 1, 2026

    @XuPeng-SH
    ContributorAuthor

    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.

  3. XuPeng-SH commented on Aug 3, 2026

    @XuPeng-SH
    ContributorAuthor

    Phase 0 validation is in #26638, exercised on main@b18cdee19b.

    The SQL-protocol witness uses a low-NDV broadcast LEFT JOIN with 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 that Reset returns 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.

  4. XuPeng-SH commented on Aug 5, 2026

    @XuPeng-SH
    ContributorAuthor

    Capability audit and follow-up boundary

    Audited against main@ab28d1b4ac and the current #26736 head 6173a85b6d. This is a roadmap status update, not a claim that join and aggregate spill are complete.

    Delivered or validated

    Current support boundary

    Area Supported today Explicit remaining boundary
    Join Single-consumer shuffle HashJoin, DedupJoin, and RightDedupJoin build-side initial spill and recursive repartition Shared/broadcast JoinMap spill; recursive input; LoopJoin, IndexJoin, Product variants; RightDedupJoin probe-side resident map
    Aggregate Grouped H8/HStr generic spill with serialized intermediate state and bounded reload/remerge; ordered H0 GROUP_CONCAT executor-owned spill Generic H0 aggregate spill; ordinary DISTINCT aggregate spill

    Two corrections are important:

    1. fix: prevent H0 aggregate spill panic #26736 fixes a correctness bug in capability selection. It does not add universal H0 spilling. Small fixed-state H0 aggregates such as COUNT do not need a generic spill framework; genuinely unbounded aggregate-owned states need their own bounded representation and cleanup contract.
    2. [Feature Request]: New impl of agg(distinct X) #22725 is closed, but current main still 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

    1. Merge and validate fix: prevent H0 aggregate spill panic #26736, then close [Bug]: low agg spill threshold panics on ungrouped COUNT(*) #26453 with both H0 and grouped-spill regression evidence.
    2. Inventory H0 aggregate states by actual memory behavior. Add aggregate-owned spill only for concrete unbounded states; do not introduce a new framework for fixed-state COUNT/SUM-style execution.
    3. Specify a focused DISTINCT spill contract before implementation: supported aggregate functions, NULL and duplicate semantics, serialized state format, repartition/reload behavior, cancellation, and lifecycle accounting. Add resident-versus-spill differential tests and multi-pass tests.
    4. Continue join closure through the existing focused issues: [Bug]: unify join typed-key canonicalization across resident and spill paths #26432 typed-key canonicalization, [Design]: make join spill thresholds explicitly versioned and unit-safe #26434 threshold contract, [Design]: spill storage v2 with segment indexes, bounded active FDs, and adaptive fanout #26435 storage/FD fanout, [Design]: add a terminal spill fallback for extreme join-key skew #26436 terminal skew, [Design]: make in-flight spill I/O and decoding interruptible #26437 interruptible I/O, and [Design]: replace estimator-driven HashBuild admission with allocation-accounted memory ownership #26459 allocation-accounted ownership.
    5. Keep broadcast spill a deliberate non-goal unless production evidence justifies a shared bucket/task scheduler. The current safety contract is resident execution with a hard-budget controlled error, not probabilistic overcommit.

    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.

  5. XuPeng-SH commented on Aug 12, 2026

    @XuPeng-SH
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions