Skip to content

perf(spill): amortize bounded writes and incremental recovery projection - #30284

Merged
XuPeng-SH merged 7 commits into
mainfrom
fix/spill-recovery-overhead
Oct 16, 2026
Merged

XuPeng-SH merged 7 commits into
mainfrom
fix/spill-recovery-overhead

Conversation

@aptend

@aptend aptend commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #29755. This is a partial performance repair, not a claim that the remaining BigData regression is fully resolved.

What this PR does / why we need it:

Reduce repeated writeback work in bounded HashBuild spill writes and repeated metadata scans in JOIN recovery without removing memory, disk, or FD admission.

  • Keep main's per-physical-write FD lifetime: each write closes its descriptor and returns its FD reservation. Cross-write FD caching has been withdrawn because local eviction cannot protect mandatory admission by other spill owners sharing the query/CN budget.
  • Allow a fully memory-accounted 4 MiB write-cache window when admission permits, retaining the 256 KiB fallback. Submit writeback in bounded ranges and submit all tails before waiting at handoff. Return writer cache charges before recovery readers are admitted.
  • Observe GROUPING key metadata incrementally for each recovery bucket instead of rescanning all retained batches for every input record. Observe the pending input before copying, including a late GROUPING sentinel.

Cross-write FD reuse, the conditional post-copy-check optimization, and all newly added sampled diagnostics/worker logs have been removed from this PR. Recovery retains main's per-input pre-copy AND post-copy budget checks. Physical allocation admission remains authoritative. No cross-owner reclamation mechanism or new FD admission API is introduced.

No planner, statistics, SQL, spill-record format, DOP, benchmark-input, or resource-limit changes. The legacy varlena-copy optimization is already on main through #30114 and is not duplicated here. The experimental EXPLAIN build repair is also excluded. Diagnostic fixtures, raw profiles, investigation documents, and harness changes stay outside this PR. Logical spill-record coalescing remains a future experiment and is not included.

Historical measurements from the unchanged TKE I3 + Q7 workload, not current-head results (3 CNs, each 14 CPU / 55 GiB; original SQL/data/concurrency and default spill settings):

Measured revision/run I3 INSERT Q7 sum of 60 SQL durations
Original pre-#29646 main, 37489307309 88.817 min 140.255 min
Earlier experimental revision d9b972252b, 38379899443 106.472 min 137.366 min
Incremental projection + varlena repair, 38534959447 attempt 2, 3331b03b27 96.042 min 130.399 min
Latest experimental revision, 38675199995, 9316d94277 95.942 min 131.458 min

The latest run passed I3 result comparison and all 60 Q7 checks. Relative to the earlier experimental revision, I3 elapsed time decreased by 9.9%; relative to the original baseline, I3 remains 8.02% slower and Q7 is 6.27% faster. The 153.63-minute I3 result reported in #29755 is historical context, not a matched control for this PR. I3 and Q7 overlap, so these durations must not be added as suite wall time.

These are single-run historical comparisons, not isolated speedups attributable entirely to this diff: the earlier-to-latest improvement also includes the varlena repair now in main. The final redundant-check change alone produced no meaningful whole-query speedup (I3 5762.514 -> 5756.537 seconds). The remaining I3 regression is still under investigation.

Component evidence: incremental projection over 8192 retained prefixes reduced 106.458 ms to 0.120 ms with zero allocations. This establishes the local mechanism, not a predicted SQL percentage. The earlier combined writer benchmark included FD reuse and is no longer presented as evidence for the remaining writeback implementation.

Delivery is based on main 76deafc806. Only bounded writeback amortization and incremental recovery projection remain. The full-workload numbers above were collected on the named experimental revisions, which included FD reuse and diagnostic instrumentation, before this delivery cleanup. They are not an exact-current-head full-workload measurement or a fresh comparison against today's main. Removing FD reuse gives up its potential reopen/seek/close savings; current-head end-to-end BigData/TPCH/TPC-DS performance has not been measured.

The retained tests cover finite shared query/CN FD caps across spill owners, optional cache-memory fallback, cancellation and failed handoff, exact read-back and terminal charges, and late GROUPING sentinels with per-bucket reset. Diagnostic-only assertions/benchmarks, optional-FD admission tests and the test specific to conditional post-copy checks have been removed with their implementations. Main's mandatory FD admission tests remain. No benchmark wall-time assertions or large diagnostic fixtures were added to unit tests.

Review repair (ca3fda5588): cross-owner FD caching is withdrawn, rather than introducing a shared eviction mechanism. Both same-generation and cross-generation pressure regressions failed before the repair with requested=1 used=2 cap=2 and pass afterward. The tests retain a real active-reader FD, exercise both writers and handoff, and verify exact bytes and resource charges. HashBuild's physical-write path and mandatory FD admission are restored to main; batch writeback and incremental projection remain.

Current validation: native artifacts rebuilt successfully through the repository build owner; 8 owning/consumer packages passed normal tests with vet; 4 related packages passed race; the new cross-owner regression passed 100 race repetitions; incremental lint reported 0 issues. New remote CI is pending. No exact-head whole-workload performance result is claimed.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify mergify Bot added the kind/bug Something isn't working label Oct 15, 2026
@matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Oct 15, 2026
@aptend aptend changed the title perf(spill): amortize bounded writes and incremental recovery checks perf(spill): amortize bounded writes and incremental recovery projection Oct 15, 2026
@aptend
aptend force-pushed the fix/spill-recovery-overhead branch 2 times, most recently from b992aed to eaf1a84 Compare October 15, 2026 09:53
@XuPeng-SH

XuPeng-SH commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: eaf1a8443684b9c2a647282b7c5833743e7013ea

Review completed. Read the assessment.

@aptend

aptend commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

Fixed in ca3fda5588, rebased onto latest fetched main 76deafc806.

The cross-owner counterexample is valid. I withdrew cross-write FD caching from this PR instead of adding a shared eviction/lease mechanism. HashBuild now uses main's per-physical-write open/close lifetime, and ReserveSpillFD is restored to main. The optional FD API and its tests are removed. No idle writer can consume another owner's required FD between writes.

The accounted larger write-cache window, batched/all-tail writeback and incremental GROUPING projection remain. This gives up FD-reopen savings; the PR body now removes the combined writer benchmark as evidence for the remaining implementation and explicitly labels earlier SQL runs as historical, not current-head results.

TestSpillWriterCrossOwnerFDPressure covers both two bundles sharing a generation and separate generations sharing the CN budget, with a real active-reader FD and cap 2. Both cases failed before repair with requested=1 used=2 cap=2; both pass afterward, including repeated writes, handoff, exact readback and resource checks.

Validation: 8 related packages passed normal tests with vet; 4 passed race; the new regression passed 100 race repetitions; incremental lint reported 0 issues. Native artifacts were rebuilt after rebase. Existing handoff/cache/cancellation/error-path assertions remain, except descriptor-reuse assertions that no longer describe the implementation. Remote CI for this revision is pending.

@XuPeng-SH

XuPeng-SH commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: ca3fda5588a96685e053d7faca2550b1921d444e

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: ca3fda5588a96685e053d7faca2550b1921d444e

Assessment: approve

Reviewed the complete eight-file delta and affected ownership chains. The design reuses existing spill and budget owners, releases optional cache charges before recovery, and replaces repeated GROUPING scans with bucket-local state. Both prior FD-pressure findings are resolved. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

Validation:

  • All 180 tests in hashbuild, spillio and spillutil passed in normal and race modes. Five writer-lifecycle tests each passed 100 race repetitions, covering shared FD pressure, cancellation, failed handoff and resource cleanup. Targeted go vet passed.

  • Base/head component measurements: 8,192 growing recovery prefixes improved from 172.881 ms to 0.126 ms with zero allocations. Small-file writing/handoff improved from 4.180 ms to 2.923 ms; streaming writes were approximately unchanged at 33.392 ms versus 33.158 ms.

  • Measured handoff costs explicitly: small-file allocations increased from 2,031 to 2,671 per operation. Optional cache capacity is fully charged and bounded at 128 MiB per 32-bucket bundle.

  • Reconciled native provenance, commands, source fingerprints, terminal results, logs and benchmark overlays in /home/xupeng/.local/state/mo-bot/jobs/c86aa077f948c1e09688477a/attempt-1/validation-audit.json. Final audit receipt: checks/1792123117270679951-4.json, exit 0. Source remains unchanged.

  • Frozen current-head CI records successful build, Ubuntu unit tests, static analysis and multi-CN BVT checks.

Limitations:

  • Component benchmarks used three samples of three iterations on Linux/amd64; they do not establish end-to-end SQL performance or statistical significance.

  • No exact-head BigData, TPCH or TPCDS run was available. The linked issue body was absent, and the PR explicitly claims only a partial optimization, not closure of the broader performance regression.

@mergify mergify Bot added the queued label Oct 16, 2026
@mergify

mergify Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-16 04:00 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-16 07:25 UTC · at 9a51f4c16fee5da0bca5fd76600ef7b4af0bed6c

This pull request spent 3 hours 24 minutes 12 seconds in the queue, with no time running CI.

Reason

Pull request #30284 has been merged manually at 2305954

Hint

You were too fast!

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

This branch was previously deployed

1 inactive deployment
ci — 9a51f4c1 Deployed Oct 16, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/enhancement size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants