Skip to content

Commit

Permalink
statistics: update some vars for internal sessions correctly (#53977)
Browse files Browse the repository at this point in the history
close #53972
  • Loading branch information
Rustin170506 authored Jun 13, 2024
1 parent 2ee6d22 commit f124165
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 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,10 @@ func MergePartitionStats2GlobalStats(
histIDs []int64,
) (globalStats *GlobalStats, err error) {
if sc.GetSessionVars().EnableAsyncMergeGlobalStats {
statslogutil.SingletonStatsSamplerLogger().Info("use async merge global stats",
zap.Int64("tableID", globalTableInfo.ID),
zap.String("table", globalTableInfo.Name.L),
)
worker, err := NewAsyncMergePartitionStats2GlobalStats(statsHandle, globalTableInfo, histIDs, is)
if err != nil {
return nil, errors.Trace(err)
Expand All @@ -113,6 +117,10 @@ func MergePartitionStats2GlobalStats(
}
return worker.Result(), nil
}
statslogutil.SingletonStatsSamplerLogger().Info("use blocking merge global stats",
zap.Int64("tableID", globalTableInfo.ID),
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)

// analyzer version
verInString, err := sctx.GetSessionVars().GlobalVarsAccessor.GetGlobalSysVar(variable.TiDBAnalyzeVersion)
if err != nil {
Expand Down

0 comments on commit f124165

Please sign in to comment.