Skip to content

Commit

Permalink
Merge pull request #59257 from yuzefovich/backport20.1-59028
Browse files Browse the repository at this point in the history
release-20.1: coldata: fix updating offsets of bytes in Batch.SetLength
  • Loading branch information
yuzefovich authored Jan 25, 2021
2 parents 56029e6 + e7a589b commit 6f3fec0
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions pkg/col/coldata/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,26 @@ func (m *MemBatch) SetSelection(b bool) {
// SetLength implements the Batch interface.
func (m *MemBatch) SetLength(n int) {
m.n = n
for _, v := range m.b {
if v != nil && v.Type() == coltypes.Bytes {
v.Bytes().UpdateOffsetsToBeNonDecreasing(n)
if n > 0 {
// In order to maintain the invariant of Bytes vectors we need to update
// offsets up to the element with the largest index that can be accessed
// by the batch.
maxIdx := n - 1
if m.useSel && m.sel[n-1] > maxIdx {
// Note that here we rely on the fact that selection vectors are
// increasing sequences.
//
// This assumption is only enforced by the invariantsChecker
// starting from 21.1 branches, so we have a "safe" conditional to
// not have a correctness regression, yet we deliberately do not
// want to iterate over the selection vector to find the largest
// index since that could be a performance regression.
maxIdx = m.sel[n-1]
}
for _, v := range m.b {
if v != nil && v.Type() == coltypes.Bytes {
v.Bytes().UpdateOffsetsToBeNonDecreasing(maxIdx + 1)
}
}
}
}
Expand Down

0 comments on commit 6f3fec0

Please sign in to comment.