Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statstics: remove useless cache #48650

Merged
merged 4 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -347,7 +347,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