Skip to content

Commit

Permalink
statstics: remove useless cache (#48650) (#48651)
Browse files Browse the repository at this point in the history
ref #47275
  • Loading branch information
ti-chi-bot authored Dec 5, 2023
1 parent 96079dd commit 67b143d
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 20 deletions.
1 change: 0 additions & 1 deletion pkg/executor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 3 additions & 17 deletions pkg/executor/analyze_global_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion pkg/statistics/handle/globalstats/global_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 0 additions & 1 deletion pkg/statistics/handle/util/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 67b143d

Please sign in to comment.