Skip to content

fix(group): preserve evaluated inputs across spill retries - #32368

Merged
XuPeng-SH merged 5 commits into
mainfrom
codex/fix-group-spill-retry-evaluation
Nov 9, 2026
Merged

XuPeng-SH merged 5 commits into
mainfrom
codex/fix-group-spill-retry-evaluation

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 8, 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:

Fixes #32369

This bug was found while investigating #32060; the PR does not fix that issue's performance report.

What this PR does / why we need it:

A Group can publish part of an input batch, hit a retryable memory-capacity rejection, and spill that prefix. The retry currently reevaluates every group expression and aggregate argument for the whole batch. A volatile expression can consequently contribute values from two evaluations to the same input batch, producing incorrect groups or aggregates.

Keep the successfully evaluated vectors and grouping-set sentinels alive while recovering the resident group state, and retry from the unpublished chunk. If evaluation itself fails partway through, return the original error rather than replaying expressions that may already have side effects. Ordinary post-batch spill, merge, reload, and cleanup retain their existing lifecycle.

Retaining the input consumes memory until the batch finishes; under severe memory pressure a query that previously succeeded by replaying a pure expression can now return a capacity error. No extra copy or persistent retry state is introduced.

The design reviewed before implementation documents ownership, recovery boundaries, and this tradeoff.

Validation:

  • On the current rebased tree, the complete Group and shared resource-budget packages passed both normal and race tests with matrixone_test enabled. Incremental gofmt, vet, pinned molint, and golangci-lint passed for Group and its compile consumer.

  • Additional controls exercise a real adaptive spill with generation-backed memory admission, H0 DISTINCT recovery after a capacity rejection, terminal errors after publication, and Reset/Prepare reuse after failed recovery with account, spill-disk, and file-descriptor cleanup. The adaptive regression fails with the old Group implementation and passes with the fix.

  • Against rebased main 374ad5847f, four interleaved samples per revision using the existing accounted Group benchmark (with task-local fixture cleanup) had median times of 2.024 ms base vs 1.916 ms fixed for the full key, and 1.204 ms vs 1.172 ms for the integer subset; allocation counts remained 76 and 77 respectively. These local samples show no observed regression for these cases and are not a production bound.

  • At the earlier rebased head 5759789c9d on main 374ad5847f, the full Group normal and race suites, all three original regressions under bounded repeated race (44/100/100) and CI tags, and focused shared-resource admission and set-membership controls passed. Incremental gofmt, vet, molint, and golangci-lint passed for Group and its compile consumer.

  • The original-head UT CI failed in a HAKeeper/CDC test and a CN heartbeat test. Both passed locally on the current rebased tree using -race -short -tags matrixone_test; the original timeouts were not reproduced or fully attributed, and the local run did not reproduce CI-wide load. New-head CI is pending.

  • The remaining validation and performance measurements below were recorded before the rebase; they were not all repeated on the new base.

  • Existing allocation-controller fault injection rejects a real allocation after 256 groups are published. The regression verifies exact output and one evaluation per expression through real spill/reload, with ordinary groups, ROLLUP, partial Group and MergeGroup, exact DISTINCT drain, and borrowed input vectors. It also covers failures while evaluating group/aggregate expressions or allocating a grouping sentinel, and a second capacity rejection after a successful spill. The original expression-replay cases fail on the base and pass on this change; resource cleanup is checked.

  • ./pkg/sql/colexec/group full normal and race suites passed using the repository CGo test wrapper; the final test-only changes were rechecked with focused normal and race runs.

  • Incremental gofmt, go vet, repository-pinned molint, and golangci-lint passed for ./pkg/sql/colexec/group and its direct operator-construction consumer ./pkg/sql/compile.

  • A four-phase ABBA accounted-Group microbenchmark using a corrected, task-local copy of the existing benchmark fixture measured median +1.51% for a full multi-column key and +0.33% for an integer hash subset. Four samples per version and case; no throughput improvement is claimed.

  • Real SQL controls ran on two CN services in one process through both coordinator ports. Across four ABBA phases, 10M-row PK, nonunique, hot, and grouped DISTINCT cases returned the expected results; four samples per version and case had median changes of −0.73%, +0.51%, −6.45%, and +0.13%, respectively. These local samples are regression checks, not a production performance bound.

  • A SQL control with agg_spill_mem=16384 returned the correct 4,096 groups and total on both versions; EXPLAIN ANALYZE reported SpillRows=12288. The logical-node metric does not establish which physical Group or MergeGroup spilled and this SQL test does not deterministically trigger capacity recovery. The controller tests above exercise that boundary.

The PAD SPACE equality issues and the separate primary-key/functional-dependency issue remain outside this fix.

@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 →

@XuPeng-SH

XuPeng-SH commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 18a66af5aef4f80d586fe5dd717d09ff2b3531e4

"interrupted"

@XuPeng-SH

XuPeng-SH commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 2f46da5f9def89abae286a2ba7ae50032b334569

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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: 2f46da5f9def89abae286a2ba7ae50032b334569

Assessment: approve

The fix preserves evaluated inputs across recovery using existing spill/reset owners, without copies or persistent retry state. Cleanup remains complete; reduced recovery headroom is an explicit tradeoff. No actionable findings.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Reviewed the complete delta, affected owners and consumers, linked issues, and all three discussion items; saved the required review records.

  • Local isolation preflight, frozen-source/patch identity, whitespace and gofmt checks passed. Receipts and retained logs are reconciled in validation-ledger.json.

  • Assessed the supplied author reports of regression, normal/race, static, SQL and performance checks. The final commit changes documentation links only.

Limitations:

  • Go tests were not rerun locally: installed Go is 1.26.6 versus required 1.27.1, and native prerequisites are absent. Raw author execution logs were not supplied.

  • Six CI checks remain in progress. The reported SQL spill metric does not independently prove capacity retry.

XuPeng-SH added a commit that referenced this pull request Nov 8, 2026
## What type of PR is this?

- [x] Test and CI

## Which issue(s) this PR fixes:

Refs #32373, #32369, #32372 and #32368.

## What this PR does / why we need it:

Add 4.2 regression coverage for the aggregate input contracts addressed
by the two main-branch PRs. Their production patches do not apply to the
current 4.2 implementation:

- MIN/MAX discard DISTINCT without adding the main branch's
DISTINCT-only PAD SPACE normalization. The SQL case checks exact
returned bytes, NULL/empty inputs, and prepared execution; a planner
test checks that DISTINCT preserves the bound input.
- Group evaluates a batch once and returns build/evaluation errors; it
spills after a complete batch rather than retrying a partially processed
batch. Tests inject capacity errors during evaluation and after one
completed hash chunk, and exercise ordinary spill/reload with exact
results and evaluation counts. The errors are synthetic; this branch
does not have the upstream capacity-recovery path.

There are no production-code or query hot-path changes.

Validation on 4.2-dev base `0351bc89d7478ccd908fbc7b084ff0dd71a0ee80`
(Go 1.26.4, Linux/amd64):

- Full normal tests for `pkg/sql/plan` and `pkg/sql/colexec/group`;
focused new tests in normal and race modes passed.
- Local single-CN SQL: exact trailing-space bytes and session-mode
restoration verified. The 19-statement BVT passed in normal comparison
and with CI flags on the same instance; database teardown was checked
after each run.
- Incremental gofmt, go vet, and golangci-lint v2.6.2 passed for the two
changed Go packages. Pinned molint emitted three pre-existing
`checkrecover` diagnostics, identical on a clean copy of the base; it
reported no new diagnostics.
- The BVT took approximately 0.07 seconds per local comparison run. CI
remains pending.
@XuPeng-SH
XuPeng-SH force-pushed the codex/fix-group-spill-retry-evaluation branch from 2f46da5 to 5759789 Compare November 8, 2026 18:44
@XuPeng-SH

XuPeng-SH commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 5759789c9d681dbead3dad2de8a67f5012130075

"interrupted"

@XuPeng-SH

XuPeng-SH commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: c0c54553dbbb5015adee986a7172e9b7f2d0697a

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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: c0c54553dbbb5015adee986a7172e9b7f2d0697a

Assessment: approve

The fix preserves evaluated inputs across pre-publication recovery using existing spill/reset owners, without copies or persistent retry state. Other spill consumers keep full reset and terminal cleanup. The additional controls cover adaptive spill, H0 DISTINCT, publication errors and failed-retry reuse; reduced recovery headroom remains an explicit accepted tradeoff.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Reviewed the complete five-file delta, affected Group/MergeGroup/reload and expression ownership paths, both linked issues and all six discussion entries. Retained the change map, lifecycle audit and discussion assessment.

  • Local isolation preflight, frozen-source/patch identity, whitespace, gofmt and discussion coverage checks passed; terminal receipts and logs are reconciled in validation-ledger.json.

  • Considered current-head author reports of complete Group/resource-budget normal and race suites with matrixone_test, focused regressions, compile-consumer static checks and rebased benchmark controls. Source reasoning independently verifies the retry boundary and regression oracles.

Limitations:

  • No local Go tests compiled or ran: the focused repository CGo-owner attempt timed out downloading Go 1.27.1; native prerequisites are absent. Raw author execution records were not supplied.

  • Core new-head CI remains pending. Earlier SQL/performance runs were not all repeated after the rebase; SQL SpillRows does not independently prove capacity retry, and local benchmark samples are not production bounds.

This branch was successfully deployed

No deployments
ci — c99fde83 Deployed Nov 9, 2026 by XuPeng-SH
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 size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Group capacity recovery reevaluates partially committed input batches

2 participants