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
  • Loading branch information
ti-chi-bot authored Jul 31, 2024
1 parent 04f4e2b commit e81a6a8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/statistics/handle/globalstats/global_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/model"
"github.com/pingcap/tidb/pkg/sessionctx"
"github.com/pingcap/tidb/pkg/statistics"
statslogutil "github.com/pingcap/tidb/pkg/statistics/handle/logutil"
statstypes "github.com/pingcap/tidb/pkg/statistics/handle/types"
"github.com/pingcap/tidb/pkg/types"
"github.com/pingcap/tidb/pkg/util/logutil"
Expand Down Expand Up @@ -94,6 +95,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 @@ -104,6 +109,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 e81a6a8

Please sign in to comment.