Skip to content

Commit

Permalink
Merge pull request #79019 from cockroachdb/blathers/backport-release-…
Browse files Browse the repository at this point in the history
…22.1-78703

release-22.1: colexecop: reset the internal batch in a test operator
  • Loading branch information
yuzefovich authored Mar 30, 2022
2 parents 56222d1 + a6caf6f commit 574b6ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions pkg/col/coldata/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ func (b *Bytes) copyElements(srcElementsToCopy []element, src *Bytes, destIdx in
// Optimize copying of the elements by copying all of them directly into the
// destination. This way all inlined values become correctly set, and we
// only need to set the non-inlined values separately.
//
// Note that this behavior results in losing the references to the old
// non-inlined values, even if they could be reused. If Bytes is not Reset,
// then that unused space in Bytes.buffer can accumulate. However, checking
// whether there are old non-inlined values with non-zero capacity leads to
// performance regressions, and in the production code we do reset the Bytes
// in all cases, so we accept this poor behavior in such a hypothetical /
// test-only scenario. See #78703 for more details.
copy(destElements, srcElementsToCopy)
// Early bounds checks.
_ = destElements[len(srcElementsToCopy)-1]
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/colexecop/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ func (s *RepeatableBatchSource) Next() coldata.Batch {
if s.batchesToReturn != 0 && s.batchesReturned > s.batchesToReturn {
return coldata.ZeroBatch
}
s.output.SetSelection(s.sel != nil)
s.output.ResetInternalBatch()
if s.sel != nil {
s.output.SetSelection(true)
copy(s.output.Selection()[:s.batchLen], s.sel[:s.batchLen])
}
for i, colVec := range s.colVecs {
Expand Down

0 comments on commit 574b6ac

Please sign in to comment.