Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statistics: make sure that get max table id when to init stats #53606

Merged
merged 1 commit into from
May 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 statstypes.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 statstypes.
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 @@ -78,7 +79,7 @@ func (h *Handle) initStatsMeta4Chunk(is infoschema.InfoSchema, cache statstypes.
}
maxTidRecord.mu.Lock()
defer maxTidRecord.mu.Unlock()
if maxTidRecord.tid.Load() < physicalID {
if maxTidRecord.tid.Load() < maxPhysicalID {
maxTidRecord.tid.Store(physicalID)
}
}
Expand Down