Skip to content

Commit

Permalink
colexec: fix a couple of places in sort where we under-account
Browse files Browse the repository at this point in the history
Release justification: bug fix.

Release note: None
  • Loading branch information
yuzefovich committed Aug 18, 2022
1 parent 0be82d9 commit 984487b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
24 changes: 20 additions & 4 deletions pkg/sql/colexec/sort.eg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pkg/sql/colexec/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ func (p *sortOp) sort() {
sizeAfter := memsize.Int * int64(spooledTuples)
p.allocator.AdjustMemoryUsage(sizeAfter - sizeBefore)
p.order = make([]int, spooledTuples)
// Finalize the accounting in case the capacity of the new slice is
// larger than we asked for.
extraCap := cap(p.order) - len(p.order)
p.allocator.AdjustMemoryUsageAfterAllocation(memsize.Int * int64(extraCap))
}
order := p.order[:spooledTuples]

Expand Down
6 changes: 5 additions & 1 deletion pkg/sql/colexec/sort_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func (s *sort_TYPE_DIR_HANDLES_NULLSOp) init(
s.allocator = allocator
s.allocator.AdjustMemoryUsage(memsize.Uint64 * int64(s.sortCol.Len()))
s.abbreviatedSortCol = s.sortCol.Abbreviated()
// Finalize the accounting in case the capacity of the new slice is larger
// than we asked for.
extraCap := cap(s.abbreviatedSortCol) - len(s.abbreviatedSortCol)
s.allocator.AdjustMemoryUsageAfterAllocation(memsize.Uint64 * int64(extraCap))
// {{end}}
s.nulls = col.Nulls()
s.order = order
Expand All @@ -130,7 +134,7 @@ func (s *sort_TYPE_DIR_HANDLES_NULLSOp) init(

func (s *sort_TYPE_DIR_HANDLES_NULLSOp) reset() {
// {{if .CanAbbreviate}}
s.allocator.AdjustMemoryUsage(0 - memsize.Uint64*int64(s.sortCol.Len()))
s.allocator.AdjustMemoryUsage(0 - memsize.Uint64*int64(cap(s.abbreviatedSortCol)))
s.allocator = nil
s.abbreviatedSortCol = nil
// {{end}}
Expand Down

0 comments on commit 984487b

Please sign in to comment.