Skip to content

Commit

Permalink
statistics: add log to show reason for partition table's auto analyze (
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Oct 18, 2023
1 parent 2d036e4 commit c53993b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/statistics/handle/autoanalyze/autoanalyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,13 @@ func autoAnalyzePartitionTableInDynamicMode(sctx sessionctx.Context,
if partitionStatsTbl.Pseudo || partitionStatsTbl.RealtimeCount < AutoAnalyzeMinCnt {
continue
}
if needAnalyze, _ := NeedAnalyzeTable(partitionStatsTbl, 20*statsHandle.Lease(), ratio); needAnalyze {
if needAnalyze, reason := NeedAnalyzeTable(partitionStatsTbl, 20*statsHandle.Lease(), ratio); needAnalyze {
partitionNames = append(partitionNames, def.Name.O)
logutil.BgLogger().Info("need to auto analyze", zap.String("category", "stats"),
zap.String("database", db),
zap.String("table", tblInfo.Name.String()),
zap.String("partition", def.Name.O),
zap.String("reason", reason))
statistics.CheckAnalyzeVerOnTable(partitionStatsTbl, &tableStatsVer)
}
}
Expand All @@ -350,6 +355,7 @@ func autoAnalyzePartitionTableInDynamicMode(sctx sessionctx.Context,
}
if len(partitionNames) > 0 {
logutil.BgLogger().Info("start to auto analyze", zap.String("category", "stats"),
zap.String("database", db),
zap.String("table", tblInfo.Name.String()),
zap.Any("partitions", partitionNames),
zap.Int("analyze partition batch size", analyzePartitionBatchSize))
Expand All @@ -364,6 +370,7 @@ func autoAnalyzePartitionTableInDynamicMode(sctx sessionctx.Context,
sql := getSQL("analyze table %n.%n partition", "", end-start)
params := append([]interface{}{db, tblInfo.Name.O}, partitionNames[start:end]...)
logutil.BgLogger().Info("auto analyze triggered", zap.String("category", "stats"),
zap.String("database", db),
zap.String("table", tblInfo.Name.String()),
zap.Any("partitions", partitionNames[start:end]))
execAutoAnalyze(sctx, statsHandle, tableStatsVer, sql, params...)
Expand Down Expand Up @@ -394,6 +401,7 @@ func autoAnalyzePartitionTableInDynamicMode(sctx sessionctx.Context,
params := append([]interface{}{db, tblInfo.Name.O}, partitionNames[start:end]...)
params = append(params, idx.Name.O)
logutil.BgLogger().Info("auto analyze for unanalyzed", zap.String("category", "stats"),
zap.String("database", db),
zap.String("table", tblInfo.Name.String()),
zap.String("index", idx.Name.String()),
zap.Any("partitions", partitionNames[start:end]))
Expand Down

0 comments on commit c53993b

Please sign in to comment.