executor: trace memory usage of cume_dist() (#19832)
This commit is contained in:
@ -14,10 +14,17 @@
|
||||
package aggfuncs
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/pingcap/tidb/sessionctx"
|
||||
"github.com/pingcap/tidb/util/chunk"
|
||||
)
|
||||
|
||||
const (
|
||||
// DefPartialResult4CumeDistSize is the size of partialResult4CumeDist
|
||||
DefPartialResult4CumeDistSize = int64(unsafe.Sizeof(partialResult4CumeDist{}))
|
||||
)
|
||||
|
||||
type cumeDist struct {
|
||||
baseAggFunc
|
||||
rowComparer
|
||||
@ -30,7 +37,7 @@ type partialResult4CumeDist struct {
|
||||
}
|
||||
|
||||
func (r *cumeDist) AllocPartialResult() (pr PartialResult, memDelta int64) {
|
||||
return PartialResult(&partialResult4CumeDist{}), 0
|
||||
return PartialResult(&partialResult4CumeDist{}), DefPartialResult4CumeDistSize
|
||||
}
|
||||
|
||||
func (r *cumeDist) ResetPartialResult(pr PartialResult) {
|
||||
@ -43,7 +50,8 @@ func (r *cumeDist) ResetPartialResult(pr PartialResult) {
|
||||
func (r *cumeDist) UpdatePartialResult(sctx sessionctx.Context, rowsInGroup []chunk.Row, pr PartialResult) (memDelta int64, err error) {
|
||||
p := (*partialResult4CumeDist)(pr)
|
||||
p.rows = append(p.rows, rowsInGroup...)
|
||||
return 0, nil
|
||||
memDelta += int64(len(rowsInGroup)) * DefRowSize
|
||||
return memDelta, nil
|
||||
}
|
||||
|
||||
func (r *cumeDist) AppendFinalResult2Chunk(sctx sessionctx.Context, pr PartialResult, chk *chunk.Chunk) error {
|
||||
|
||||
35
executor/aggfuncs/func_cume_dist_test.go
Normal file
35
executor/aggfuncs/func_cume_dist_test.go
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright 2020 PingCAP, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package aggfuncs_test
|
||||
|
||||
import (
|
||||
. "github.com/pingcap/check"
|
||||
"github.com/pingcap/parser/ast"
|
||||
"github.com/pingcap/parser/mysql"
|
||||
"github.com/pingcap/tidb/executor/aggfuncs"
|
||||
)
|
||||
|
||||
func (s *testSuite) TestMemCumeDist(c *C) {
|
||||
tests := []windowMemTest{
|
||||
buildWindowMemTester(ast.WindowFuncCumeDist, mysql.TypeLonglong, 0, 1, 1,
|
||||
aggfuncs.DefPartialResult4CumeDistSize, rowMemDeltaGens),
|
||||
buildWindowMemTester(ast.WindowFuncCumeDist, mysql.TypeLonglong, 0, 2, 0,
|
||||
aggfuncs.DefPartialResult4CumeDistSize, rowMemDeltaGens),
|
||||
buildWindowMemTester(ast.WindowFuncCumeDist, mysql.TypeLonglong, 0, 4, 1,
|
||||
aggfuncs.DefPartialResult4CumeDistSize, rowMemDeltaGens),
|
||||
}
|
||||
for _, test := range tests {
|
||||
s.testWindowAggMemFunc(c, test)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user