Skip to content

Commit

Permalink
statistics: make sure that get max table id when to init stats (#53606)…
Browse files Browse the repository at this point in the history
… (#53615)

close #53607
  • Loading branch information
ti-chi-bot committed May 28, 2024
1 parent 2c3afb7 commit 4a95f11
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/statistics/handle/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type MaxTidRecord struct {
}

func (h *Handle) initStatsMeta4Chunk(is infoschema.InfoSchema, cache util.StatsCache, iter *chunk.Iterator4Chunk) {
var physicalID int64
var physicalID, maxPhysicalID int64
for row := iter.Begin(); row != iter.End(); row = iter.Next() {
physicalID = row.GetInt64(1)
// The table is read-only. Please do not modify it.
Expand All @@ -59,6 +59,7 @@ func (h *Handle) initStatsMeta4Chunk(is infoschema.InfoSchema, cache util.StatsC
logutil.BgLogger().Debug("unknown physical ID in stats meta table, maybe it has been dropped", zap.Int64("ID", physicalID))
continue
}
maxPhysicalID = max(physicalID, maxPhysicalID)
tableInfo := table.Meta()
newHistColl := statistics.HistColl{
PhysicalID: physicalID,
Expand All @@ -76,7 +77,7 @@ func (h *Handle) initStatsMeta4Chunk(is infoschema.InfoSchema, cache util.StatsC
}
maxTidRecord.mu.Lock()
defer maxTidRecord.mu.Unlock()
if maxTidRecord.tid.Load() < physicalID {
if maxTidRecord.tid.Load() < maxPhysicalID {
maxTidRecord.tid.Store(physicalID)
}
}
Expand Down

0 comments on commit 4a95f11

Please sign in to comment.