Skip to content

[Bug]: MergeOrder leaks native batches after in-memory merge on v4.1.4-hotfix-20260831 #30633

Closed

Description

@XuPeng-SH

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

Release tag v4.1.4-hotfix-20260831 (no same-named remote branch at investigation time).

Commit ID

a300787

Other Environment Information

  • Local reproduction: macOS arm64, Go 1.26.4, CGO enabled.
  • Native library built from the release tag's C sources.
  • This is a source/operator reproduction; no claim of a new production load test or RSS measurement.

Actual Behavior

MergeOrder duplicates off-heap input batches into its in-memory merge list. After copying all rows to the independent output buffer, removeInMemoryBatch removes the heap item and frees separately owned sorting columns, but sets batchList[index] = nil without cleaning the input batch. Reset/Free cannot find that batch afterward, so its C-allocated vector data/varlen areas remain allocated.

A four-row/two-input native-vector regression through real vm.Exec returns the correct sorted keys and VARCHAR payloads, but retains 872 native bytes where only 600 bytes belong to the still-owned original inputs and output buffer: 272 bytes are leaked. Both column-key and computed-key variants fail the native accounting assertion; the single-input ownership-transfer control passes.

Expected Behavior

After the final row has been copied, release the consumed input batch exactly once before dropping its owning reference. Keep the output and any still-active inputs valid. Reset/Free should release their remaining resources without leaks or double-free.

Steps to Reproduce

  1. Create two native batches with ascending key runs [1,3] and [2,4], each carrying a distinct non-inline VARCHAR payload.
  2. Feed them through the existing mock child into the real MergeOrder operator, with spilling disabled for this small input.
  3. Drain using vm.Exec; validate the merged keys/payloads.
  4. Before Reset/Free, compare proc.Mp().CurrNB() with original-input native bytes plus ctr.buf.Allocated().
  5. At the above tag the comparison fails by 272 bytes. Heap-backed fixtures do not detect this because this release's CurrNB tracks off-heap allocations.

Additional information

The missing cleanup belongs after heap removal and order-column membership/free checks, before clearing the batch-list slot. The single-input direct-transfer and disk-spill paths are separate and should remain unchanged. A minimal fix and regression tests are being prepared for the requested hotfix release.

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

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions