From 67b143d4a8ab857d3f90ca1e8fd69c5d1949e6a0 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Tue, 5 Dec 2023 17:58:19 +0800 Subject: [PATCH] statstics: remove useless cache (#48650) (#48651) ref pingcap/tidb#47275 --- pkg/executor/BUILD.bazel | 1 - pkg/executor/analyze_global_stats.go | 20 +++---------------- .../handle/globalstats/global_stats.go | 1 - pkg/statistics/handle/util/interfaces.go | 1 - 4 files changed, 3 insertions(+), 20 deletions(-) diff --git a/pkg/executor/BUILD.bazel b/pkg/executor/BUILD.bazel index 316d0f5f3b3c9..4a6f6d13f9fd4 100644 --- a/pkg/executor/BUILD.bazel +++ b/pkg/executor/BUILD.bazel @@ -274,7 +274,6 @@ go_library( "@org_golang_google_grpc//credentials", "@org_golang_google_grpc//credentials/insecure", "@org_golang_google_grpc//status", - "@org_golang_x_exp//maps", "@org_golang_x_sync//errgroup", "@org_uber_go_atomic//:atomic", "@org_uber_go_zap//:zap", diff --git a/pkg/executor/analyze_global_stats.go b/pkg/executor/analyze_global_stats.go index 3aed3bb4f986a..59d01638524be 100644 --- a/pkg/executor/analyze_global_stats.go +++ b/pkg/executor/analyze_global_stats.go @@ -26,7 +26,6 @@ import ( "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util/logutil" "go.uber.org/zap" - "golang.org/x/exp/maps" ) type globalStatsKey struct { @@ -48,17 +47,15 @@ type globalStatsInfo struct { type globalStatsMap map[globalStatsKey]globalStatsInfo func (e *AnalyzeExec) handleGlobalStats(ctx context.Context, globalStatsMap globalStatsMap) error { - globalStatsTableIDs := make(map[int64]int, len(globalStatsMap)) + globalStatsTableIDs := make(map[int64]struct{}, len(globalStatsMap)) for globalStatsID := range globalStatsMap { - globalStatsTableIDs[globalStatsID.tableID]++ + globalStatsTableIDs[globalStatsID.tableID] = struct{}{} } statsHandle := domain.GetDomain(e.Ctx()).StatsHandle() tableIDs := make(map[int64]struct{}, len(globalStatsTableIDs)) - tableAllPartitionStats := make(map[int64]*statistics.Table) - for tableID, count := range globalStatsTableIDs { + for tableID := range globalStatsTableIDs { tableIDs[tableID] = struct{}{} - maps.Clear(tableAllPartitionStats) for globalStatsID, info := range globalStatsMap { if globalStatsID.tableID != tableID { continue @@ -78,20 +75,12 @@ func (e *AnalyzeExec) handleGlobalStats(ctx context.Context, globalStatsMap glob globalOpts = v2Options.FilledOpts } } - var cache map[int64]*statistics.Table - if count > 1 { - cache = tableAllPartitionStats - } else { - cache = nil - } - globalStatsI, err := statsHandle.MergePartitionStats2GlobalStatsByTableID( e.Ctx(), globalOpts, e.Ctx().GetInfoSchema().(infoschema.InfoSchema), globalStatsID.tableID, info.isIndex == 1, info.histIDs, - cache, ) if err != nil { logutil.BgLogger().Warn("merge global stats failed", @@ -132,9 +121,6 @@ func (e *AnalyzeExec) handleGlobalStats(ctx context.Context, globalStatsMap glob }() FinishAnalyzeMergeJob(e.Ctx(), job, mergeStatsErr) } - for _, value := range tableAllPartitionStats { - value.ReleaseAndPutToPool() - } } for tableID := range tableIDs { diff --git a/pkg/statistics/handle/globalstats/global_stats.go b/pkg/statistics/handle/globalstats/global_stats.go index d5abb16a03ee1..c769daff4f293 100644 --- a/pkg/statistics/handle/globalstats/global_stats.go +++ b/pkg/statistics/handle/globalstats/global_stats.go @@ -52,7 +52,6 @@ func (sg *statsGlobalImpl) MergePartitionStats2GlobalStatsByTableID(sc sessionct physicalID int64, isIndex bool, histIDs []int64, - _ map[int64]*statistics.Table, ) (globalStats interface{}, err error) { return MergePartitionStats2GlobalStatsByTableID(sc, sg.statsHandler, opts, is, physicalID, isIndex, histIDs) } diff --git a/pkg/statistics/handle/util/interfaces.go b/pkg/statistics/handle/util/interfaces.go index 14c85f4ed092d..6086a330a207e 100644 --- a/pkg/statistics/handle/util/interfaces.go +++ b/pkg/statistics/handle/util/interfaces.go @@ -305,7 +305,6 @@ type StatsGlobal interface { physicalID int64, isIndex bool, histIDs []int64, - _ map[int64]*statistics.Table, ) (globalStats interface{}, err error) // UpdateGlobalStats will trigger the merge of global-stats when we drop table partition