planner: skip stats warnings for temporary table during optimize (#43147)

close pingcap/tidb#43142
This commit is contained in:
tangenta
2023-04-18 19:13:35 +08:00
committed by GitHub
parent 47e7432054
commit 7908f697b4

View File

@ -178,11 +178,11 @@ func recordTableRuntimeStats(sctx sessionctx.Context, tbls map[int64]struct{}) {
tblStats = map[int64]interface{}{}
}
for tblID := range tbls {
tblJSONStats, err := recordSingleTableRuntimeStats(sctx, tblID)
tblJSONStats, skip, err := recordSingleTableRuntimeStats(sctx, tblID)
if err != nil {
logutil.BgLogger().Warn("record table json stats failed", zap.Int64("tblID", tblID), zap.Error(err))
}
if tblJSONStats == nil {
if tblJSONStats == nil && !skip {
logutil.BgLogger().Warn("record table json stats failed due to empty", zap.Int64("tblID", tblID))
}
tblStats[tblID] = tblJSONStats
@ -190,15 +190,17 @@ func recordTableRuntimeStats(sctx sessionctx.Context, tbls map[int64]struct{}) {
sctx.GetSessionVars().StmtCtx.TableStats = tblStats
}
func recordSingleTableRuntimeStats(sctx sessionctx.Context, tblID int64) (*statistics.Table, error) {
func recordSingleTableRuntimeStats(sctx sessionctx.Context, tblID int64) (stats *statistics.Table, skip bool, err error) {
dom := domain.GetDomain(sctx)
is := dom.InfoSchema()
statsHandle := dom.StatsHandle()
is := sctx.GetDomainInfoSchema().(infoschema.InfoSchema)
tbl, ok := is.TableByID(tblID)
if !ok {
return nil, nil
return nil, false, nil
}
tableInfo := tbl.Meta()
stats := statsHandle.GetTableStats(tableInfo)
return stats, nil
stats = statsHandle.GetTableStats(tableInfo)
// Skip the warning if the table is a temporary table because the temporary table doesn't have stats.
skip = tableInfo.TempTableType != model.TempTableNone
return stats, skip, nil
}