diff --git a/pkg/statistics/handle/globalstats/global_stats.go b/pkg/statistics/handle/globalstats/global_stats.go index 4eff64fc0961b..1e9fbdc201d85 100644 --- a/pkg/statistics/handle/globalstats/global_stats.go +++ b/pkg/statistics/handle/globalstats/global_stats.go @@ -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) @@ -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) } diff --git a/pkg/statistics/handle/util/util.go b/pkg/statistics/handle/util/util.go index f54deffae46a7..1db8addc5fae3 100644 --- a/pkg/statistics/handle/util/util.go +++ b/pkg/statistics/handle/util/util.go @@ -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 {