Skip to content

fix: free merge group spill aggregate states - #24575

Merged
mergify[bot] merged 2 commits into
matrixorigin:mainfrom
LeftHandCold:fix-mergegroup-spillagg-leak-main
May 25, 2026
Merged

fix: free merge group spill aggregate states#24575
mergify[bot] merged 2 commits into
matrixorigin:mainfrom
LeftHandCold:fix-mergegroup-spillagg-leak-main

Conversation

@LeftHandCold

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:

issue #24570

What this PR does / why we need it:

MergeGroup.buildOneBatch creates ctr.spillAggList for each incoming partial aggregate batch, then restores temporary aggregate state through aggExec.UnmarshalFromReader and merges it into ctr.aggList.

The previous code only released spillAggList on error. On the success path, the next input batch overwrote ctr.spillAggList, so previously restored aggregate state vectors were no longer reachable and their offheap mpool allocations remained live.

This PR:

releases any existing temporary spillAggList before creating a new one;
releases spillAggList after the partial aggregate state is merged and before needSpill() reads ctr.mp.CurrNB();
keeps deferred cleanup for error paths;
adds a regression test asserting that successful batch merge leaves ctr.spillAggList cleared.

Copilot AI review requested due to automatic review settings May 25, 2026 10:21
@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 →

@matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] lines label May 25, 2026
@mergify mergify Bot added the kind/bug Something isn't working label May 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes a memory leak in the MergeGroup operator where temporary aggregate states restored from partial-group payloads (ctr.spillAggList) were not consistently freed on the success path, leaving offheap mpool allocations live across batches.

Changes:

  • Always free any existing ctr.spillAggList before allocating a new temporary aggregate list for an incoming partial batch.
  • Free the temporary spillAggList after merging restored states into the main ctr.aggList and before calling needSpill() (so spill decisions reflect post-merge memory).
  • Add a regression test asserting spillAggList is cleared after each successful partial-batch merge.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pkg/sql/colexec/group/mergeGroup.go Ensures spillAggList is freed on both success and error paths, preventing offheap state leaks across partial batches.
pkg/sql/colexec/group/group_test.go Adds a regression test to verify spillAggList is cleared after each successful buildOneBatch merge.

Comment thread pkg/sql/colexec/group/mergeGroup.go Outdated
@mergify

mergify Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • Entered queue2026-05-25 11:58 UTC · Rule: main
  • Checks skipped · PR is already up-to-date
  • Merged2026-05-25 11:59 UTC · at 0bfe8e4ac01eba846318d5bd6e32eb3be1c58342 · squash

This pull request spent 58 seconds in the queue, including 12 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage

@mergify
mergify Bot merged commit d44131f into matrixorigin:main May 25, 2026
23 of 24 checks passed
@mergify mergify Bot removed the queued label May 25, 2026
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/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants