Skip to content

Commit

Permalink
Merge pull request #58197 from nvanbenschoten/backport20.2-58117
Browse files Browse the repository at this point in the history
release-20.2: sql/rowexec: don't allocate buf per row in sketchInfo.addRow
  • Loading branch information
nvanbenschoten authored Dec 30, 2020
2 parents eb8abb5 + 4be5967 commit e60df47
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/sql/rowexec/sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,14 +500,19 @@ func (s *sketchInfo) addRow(
}

if useFastPath {
var intbuf [8]byte
// Fast path for integers.
// TODO(radu): make this more general.
val, err := row[col].GetInt()
if err != nil {
return err
}

if cap(*buf) < 8 {
*buf = make([]byte, 8)
} else {
*buf = (*buf)[:8]
}

// Note: this encoding is not identical with the one in the general path
// below, but it achieves the same thing (we want equal integers to
// encode to equal []bytes). The only caveat is that all samplers must
Expand All @@ -518,8 +523,8 @@ func (s *sketchInfo) addRow(
// it must be a very good hash function (HLL expects the hash values to
// be uniformly distributed in the 2^64 range). Experiments (on tpcc
// order_line) with simplistic functions yielded bad results.
binary.LittleEndian.PutUint64(intbuf[:], uint64(val))
s.sketch.Insert(intbuf[:])
binary.LittleEndian.PutUint64(*buf, uint64(val))
s.sketch.Insert(*buf)
return nil
}
isNull := true
Expand Down

0 comments on commit e60df47

Please sign in to comment.