Skip to content

[VL] Close ColumnarBatch in ColumnarCollectLimitExec for skipped and sliced batches#11754

Open
acvictor wants to merge 1 commit intoapache:mainfrom
acvictor:acvictor/closeBatch
Open

[VL] Close ColumnarBatch in ColumnarCollectLimitExec for skipped and sliced batches#11754
acvictor wants to merge 1 commit intoapache:mainfrom
acvictor:acvictor/closeBatch

Conversation

@acvictor
Copy link
Contributor

What changes are proposed in this pull request?

This PR closes ColumnarBatch for skipped or sliced batches in ColumnarCollectLimitExec.

ColumnarCollectLimitExec.fetchNextBatch() leaks memory in two cases:

  1. Skipped batches: When a batch falls entirely within the offset range, it is consumed from the input iterator but never closed.
  2. Sliced batches: When a batch is partially within the offset/limit window, VeloxColumnarBatches.slice() creates a new native batch, but the original source batch is never closed.

In both cases the ColumnarBatch object is small but it holds a JNI handle to a native Velox vector. Since ColumnarBatch has no finalizer, the native memory is only freed by an explicit close() call. Queries with large offsets (e.g., OFFSET 10000) would leak one batch per skipped chunk.

How was this patch tested?

Existing UTs

Was this patch authored or co-authored using generative AI tooling?

No

@github-actions github-actions bot added the VELOX label Mar 13, 2026
@acvictor acvictor marked this pull request as ready for review March 13, 2026 10:01
@acvictor
Copy link
Contributor Author

@ArnavBalyan can you please review this fix? Thanks!

batch
} else {
VeloxColumnarBatches.slice(batch, startIndex, needed)
val sliced = VeloxColumnarBatches.slice(batch, startIndex, needed)
Copy link
Contributor

Choose a reason for hiding this comment

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

The sliced calls velox slice API, reuse buffers of batch, so we cannot close it.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants