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

release-20.2: sql/rowexec: don't allocate buf per row in sketchInfo.addRow #58197

Merged
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
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