Skip to content

Commit

Permalink
rowexec: account for some additional memory used by stats collection
Browse files Browse the repository at this point in the history
Prior to this commit, we did not account for the memory used in the
sampleAggregator when we copy all samples into a new slice before
generating a histogram. This commit adds some additional memory
accounting for this overhead.

Informs cockroachdb#45812

Release note: None
  • Loading branch information
rytaft committed Apr 7, 2020
1 parent de1b706 commit 9bf1e76
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pkg/sql/rowexec/sample_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func (s *sampleAggregator) writeResults(ctx context.Context) error {
colIdx := int(si.spec.Columns[0])
typ := &s.inTypes[colIdx]

h, err := generateHistogram(
h, err := s.generateHistogram(
s.EvalCtx,
s.sr.Get(),
colIdx,
Expand Down Expand Up @@ -382,7 +382,7 @@ func (s *sampleAggregator) writeResults(ctx context.Context) error {
// generateHistogram returns a histogram (on a given column) from a set of
// samples.
// numRows is the total number of rows from which values were sampled.
func generateHistogram(
func (s *sampleAggregator) generateHistogram(
evalCtx *tree.EvalContext,
samples []stats.SampledRow,
colIdx int,
Expand All @@ -391,10 +391,15 @@ func generateHistogram(
distinctCount int64,
maxBuckets int,
) (stats.HistogramData, error) {
var da sqlbase.DatumAlloc
// Account for the memory we'll use copying the samples into values.
if err := s.memAcc.Grow(evalCtx.Context, sizeOfDatum * int64(len(samples))); err != nil {
return stats.HistogramData{}, err
}
values := make(tree.Datums, 0, len(samples))
for _, s := range samples {
ed := &s.Row[colIdx]

var da sqlbase.DatumAlloc
for _, sample := range samples {
ed := &sample.Row[colIdx]
// Ignore NULLs (they are counted separately).
if !ed.IsNull() {
if err := ed.EnsureDecoded(colType, &da); err != nil {
Expand Down

0 comments on commit 9bf1e76

Please sign in to comment.