fix: avoid overlapping scan output buffers - #810
Open
lizhen-0710 wants to merge 1 commit into
Open
Conversation
HiveDataSource keeps a backing reader output RowVector in output_ while returning a projected RowVector to the operator pipeline. The returned RowVector holds references to the child vectors from output_. If output_ is reused for the next splitReader::next() call, HiveDataSource also keeps the previous backing RowVector alive while the next batch allocates selective column values. This makes the previous output children and current output allocation overlap, which can temporarily double scan-side memory. Recreate the backing reader output before every splitReader::next() call so HiveDataSource drops its reference to the previous backing RowVector before the next batch allocation. The returned output still owns the previous child vectors, but HiveDataSource no longer adds an extra reference that extends their lifetime into the next read. Also bound SelectiveColumnReader values_ reuse to buffers no larger than 1.5x the current request. This preserves useful same-size reuse while allowing oversized buffers from larger batches to be released before smaller batches allocate replacement values. Add targeted tests covering the HiveDataSource backing RowVector lifetime and the SelectiveColumnReader reuse, oversize-release, and shared-buffer paths. Co-authored-by: TRAE CLI <noreply@bytedance.com>
guhaiyan0221
reviewed
Aug 1, 2026
| if (!output_) { | ||
| output_ = BaseVector::create(readerOutputType_, 0, pool_); | ||
| } | ||
| output_ = BaseVector::create(readerOutputType_, 0, pool_); |
Collaborator
There was a problem hiding this comment.
performance concern: this now allocates a new top-level RowVector for every batch. The overhead is likely small compared with the child value buffers, but it gives up top-level vector reuse. Have you benchmarked small-batch scans?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
HiveDataSource keeps a backing reader output RowVector in output_ while returning a projected RowVector to the operator pipeline. The returned RowVector holds references to the child vectors from output_. If output_ is reused for the next splitReader::next() call, HiveDataSource also keeps the previous backing RowVector alive while the next batch allocates selective column values. This makes the previous output children and current output allocation overlap, which can temporarily double scan-side memory.
Type of Change
Description
Recreate the backing reader output before every splitReader::next() call so HiveDataSource drops its reference to the previous backing RowVector before the next batch allocation. The returned output still owns the previous child vectors, but HiveDataSource no longer adds an extra reference that extends their lifetime into the next read.
Also bound SelectiveColumnReader values_ reuse to buffers no larger than 1.5x the current request. This preserves useful same-size reuse while allowing oversized buffers from larger batches to be released before smaller batches allocate replacement values.
Add targeted tests covering the HiveDataSource backing RowVector lifetime and the SelectiveColumnReader reuse, oversize-release, and shared-buffer paths.
Performance Impact
No Impact: This change does not affect the critical path (e.g., build system, doc, error handling).
Positive Impact: I have run benchmarks.
Click to view Benchmark Results
Negative Impact: Explained below (e.g., trade-off for correctness).
Release Note
Please describe the changes in this PR
Release Note:
Checklist (For Author)
Breaking Changes
No
Yes (Description: ...)
Click to view Breaking Changes