Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coldata: minor tweak of flat bytes #45426

Merged
merged 1 commit into from
Feb 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions pkg/col/coldata/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (b *Bytes) UpdateOffsetsToBeNonDecreasing(n uint64) {

// maybeBackfillOffsets is an optimized version of
// UpdateOffsetsToBeNonDecreasing that assumes that all offsets up to
// b.maxSetIndex+1 are non-decreasing. Note that this method can be a noop when
// b.maxSetIndex+1 are non-decreasing. Note that this method is a noop when
// i <= b.maxSetIndex+1.
func (b *Bytes) maybeBackfillOffsets(i int) {
// Note that we're not checking whether this Bytes is a window because
Expand All @@ -96,6 +96,9 @@ func (b *Bytes) maybeBackfillOffsets(i int) {
for j := b.maxSetIndex + 2; j <= i; j++ {
b.offsets[j] = b.offsets[b.maxSetIndex+1]
}
if i > b.maxSetIndex {
b.maxSetIndex = i - 1
}
}

// Get returns the ith []byte in Bytes. Note that the returned byte slice is
Expand Down Expand Up @@ -123,17 +126,12 @@ func (b *Bytes) Set(i int, v []byte) {
),
)
}
if i == b.maxSetIndex {
// We are overwriting an element at the end of b.data, truncate so we can
// append in every path.
b.data = b.data[:b.offsets[i]]
} else {
// We're maybe setting an element not right after the last already present
// element (i.e. there might be gaps in b.offsets). This is probably due to
// NULL values that are stored separately. In order to maintain the
// assumption of non-decreasing offsets, we need to backfill them.
b.maybeBackfillOffsets(i)
}
// We're maybe setting an element not right after the last already present
// element (i.e. there might be gaps in b.offsets). This is probably due to
// NULL values that are stored separately. In order to maintain the
// assumption of non-decreasing offsets, we need to backfill them.
b.maybeBackfillOffsets(i)
b.data = b.data[:b.offsets[i]]
b.offsets[i] = int32(len(b.data))
b.data = append(b.data, v...)
b.offsets[i+1] = int32(len(b.data))
Expand Down