Skip to content

Commit

Permalink
executor: implement memDelta for count funcs to track memUsage (#19770)
Browse files Browse the repository at this point in the history
* executor: implement memDelta for count funcs to track memUsage

* fix stdlib unsafe need be group together and before non-stdlib group in ../../executor/aggfuncs/func_count.go

* fix UpdatePartialResult memDelta return if err != nil

* fix
1 DefPartialResult4CountSize is the memory usage of AllocPartialResult, UpdatePartialResult will not use more memory, return 0, err.
2 in testcase TestMemCount count funcs are not distinct, use defaultUpdateMemDeltaGens and set isDistinct false

* fix UpdatePartialResult not use more memory

* fix  MergePartialResult memDelta

Co-authored-by: ti-srebot <66930949+ti-srebot@users.noreply.github.com>
  • Loading branch information
AntiKnot and ti-srebot authored Sep 5, 2020
1 parent 4117677 commit 7cd20c0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 8 additions & 1 deletion executor/aggfuncs/func_count.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,25 @@
package aggfuncs

import (
"unsafe"

"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/util/chunk"
)

const (
// DefPartialResult4CountSize is the size of partialResult4Count
DefPartialResult4CountSize = int64(unsafe.Sizeof(partialResult4Count(0)))
)

type baseCount struct {
baseAggFunc
}

type partialResult4Count = int64

func (e *baseCount) AllocPartialResult() (pr PartialResult, memDelta int64) {
return PartialResult(new(partialResult4Count)), 0
return PartialResult(new(partialResult4Count)), DefPartialResult4CountSize
}

func (e *baseCount) ResetPartialResult(pr PartialResult) {
Expand Down
14 changes: 14 additions & 0 deletions executor/aggfuncs/func_count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ func (s *testSuite) TestCount(c *C) {

func (s *testSuite) TestMemCount(c *C) {
tests := []aggMemTest{
buildAggMemTester(ast.AggFuncCount, mysql.TypeLonglong, 5,
aggfuncs.DefPartialResult4CountSize, defaultUpdateMemDeltaGens, false),
buildAggMemTester(ast.AggFuncCount, mysql.TypeFloat, 5,
aggfuncs.DefPartialResult4CountSize, defaultUpdateMemDeltaGens, false),
buildAggMemTester(ast.AggFuncCount, mysql.TypeDouble, 5,
aggfuncs.DefPartialResult4CountSize, defaultUpdateMemDeltaGens, false),
buildAggMemTester(ast.AggFuncCount, mysql.TypeNewDecimal, 5,
aggfuncs.DefPartialResult4CountSize, defaultUpdateMemDeltaGens, false),
buildAggMemTester(ast.AggFuncCount, mysql.TypeString, 5,
aggfuncs.DefPartialResult4CountSize, defaultUpdateMemDeltaGens, false),
buildAggMemTester(ast.AggFuncCount, mysql.TypeDate, 5,
aggfuncs.DefPartialResult4CountSize, defaultUpdateMemDeltaGens, false),
buildAggMemTester(ast.AggFuncCount, mysql.TypeDuration, 5,
aggfuncs.DefPartialResult4CountSize, defaultUpdateMemDeltaGens, false),
buildAggMemTester(ast.AggFuncCount, mysql.TypeLonglong, 5,
aggfuncs.DefPartialResult4CountDistinctIntSize, distinctUpdateMemDeltaGens, true),
buildAggMemTester(ast.AggFuncCount, mysql.TypeFloat, 5,
Expand Down

0 comments on commit 7cd20c0

Please sign in to comment.