From 8761adc59fd23787f76928d6f43098e94698c881 Mon Sep 17 00:00:00 2001 From: Shenghui Wu <793703860@qq.com> Date: Thu, 4 Mar 2021 11:34:54 +0800 Subject: [PATCH] executor: make the memory tracker of Jsonobjectagg more accurate (#23024) --- executor/aggfuncs/func_json_objectagg.go | 20 ++++++++++++++++--- executor/aggfuncs/func_json_objectagg_test.go | 4 ++-- executor/aggregate.go | 9 +++------ util/hack/hack.go | 10 ++++++++++ util/set/set_with_memory_usage.go | 17 ++++++++-------- 5 files changed, 41 insertions(+), 19 deletions(-) diff --git a/executor/aggfuncs/func_json_objectagg.go b/executor/aggfuncs/func_json_objectagg.go index 5b34f5be6b442..c2bf3bf985231 100644 --- a/executor/aggfuncs/func_json_objectagg.go +++ b/executor/aggfuncs/func_json_objectagg.go @@ -21,12 +21,15 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/types/json" "github.com/pingcap/tidb/util/chunk" + "github.com/pingcap/tidb/util/hack" "github.com/pingcap/tidb/util/stringutil" ) const ( // DefPartialResult4JsonObjectAgg is the size of partialResult4JsonObject DefPartialResult4JsonObjectAgg = int64(unsafe.Sizeof(partialResult4JsonObjectAgg{})) + // DefMapStringInterfaceBucketSize = bucketSize*(1+unsafe.Sizeof(string) + unsafe.Sizeof(interface{}))+2*ptrSize + DefMapStringInterfaceBucketSize = 8*(1+16+16) + 16 ) type jsonObjectAgg struct { @@ -35,17 +38,20 @@ type jsonObjectAgg struct { type partialResult4JsonObjectAgg struct { entries map[string]interface{} + bInMap int // indicate there are 2^bInMap buckets in entries. } func (e *jsonObjectAgg) AllocPartialResult() (pr PartialResult, memDelta int64) { p := partialResult4JsonObjectAgg{} p.entries = make(map[string]interface{}) - return PartialResult(&p), DefPartialResult4JsonObjectAgg + p.bInMap = 0 + return PartialResult(&p), DefPartialResult4JsonObjectAgg + (1< (1< (1< bucketNum * loadFactor. The memory usage will doubled. - if len(mapper) > (1< (1< bucketNum * loadFactor. The memory usage will doubled. - if len(e.partialResultMap) > (1< (1< (1< (1< (1< (1< (1< (1<