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

statistics: update some vars for internal sessions correctly #53977

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions pkg/statistics/handle/globalstats/global_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func MergePartitionStats2GlobalStats(
histIDs []int64,
) (globalStats *GlobalStats, err error) {
if sc.GetSessionVars().EnableAsyncMergeGlobalStats {
logutil.BgLogger().Info("use async merge global stats", zap.String("table", globalTableInfo.Name.L))
Rustin170506 marked this conversation as resolved.
Show resolved Hide resolved
worker, err := NewAsyncMergePartitionStats2GlobalStats(statsHandle, globalTableInfo, histIDs, is)
if err != nil {
return nil, errors.Trace(err)
Expand All @@ -113,6 +114,7 @@ func MergePartitionStats2GlobalStats(
}
return worker.Result(), nil
}
logutil.BgLogger().Info("use blocking merge global stats", zap.String("table", globalTableInfo.Name.L))
return blockingMergePartitionStats2GlobalStats(sc, statsHandle.GPool(), opts, is, globalTableInfo, isIndex, histIDs, nil, statsHandle)
}

Expand Down
18 changes: 18 additions & 0 deletions pkg/statistics/handle/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ func CallWithSCtx(pool SessionPool, f func(sctx sessionctx.Context) error, flags

// UpdateSCtxVarsForStats updates all necessary variables that may affect the behavior of statistics.
func UpdateSCtxVarsForStats(sctx sessionctx.Context) error {
// async merge global stats
enableAsyncMergeGlobalStats, err := sctx.GetSessionVars().GlobalVarsAccessor.GetGlobalSysVar(variable.TiDBEnableAsyncMergeGlobalStats)
if err != nil {
return err
}
sctx.GetSessionVars().EnableAsyncMergeGlobalStats = variable.TiDBOptOn(enableAsyncMergeGlobalStats)

// concurrency of save stats to storage
analyzePartitionConcurrency, err := sctx.GetSessionVars().GlobalVarsAccessor.GetGlobalSysVar(variable.TiDBAnalyzePartitionConcurrency)
if err != nil {
return err
}
c, err := strconv.ParseInt(analyzePartitionConcurrency, 10, 64)
if err != nil {
return err
}
sctx.GetSessionVars().AnalyzePartitionConcurrency = int(c)

hawkingrei marked this conversation as resolved.
Show resolved Hide resolved
// analyzer version
verInString, err := sctx.GetSessionVars().GlobalVarsAccessor.GetGlobalSysVar(variable.TiDBAnalyzeVersion)
if err != nil {
Expand Down