Skip to content

Commit

Permalink
statistics: fix puting wrong stats into cache (#52421) (#52422) (#52434)
Browse files Browse the repository at this point in the history
close #52419
  • Loading branch information
hawkingrei committed Apr 9, 2024
1 parent 03a9cf3 commit b175150
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/statistics/handle/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (h *Handle) initStatsHistograms4ChunkLite(is infoschema.InfoSchema, cache u
tblID := row.GetInt64(0)
if table == nil || table.PhysicalID != tblID {
if table != nil {
cache.Put(tblID, table) // put this table in the cache because all statstics of the table have been read.
cache.Put(table.PhysicalID, table) // put this table in the cache because all statstics of the table have been read.
}
var ok bool
table, ok = cache.Get(tblID)
Expand Down
6 changes: 6 additions & 0 deletions pkg/statistics/handle/handletest/statstest/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ func testInitStatsMemTrace(t *testing.T) {
tStats := h.GetTableStats(tbl.Meta())
memCostTot += tStats.MemoryUsage().TotalMemUsage
}
tables := h.StatsCache.Values()
for _, tt := range tables {
tbl, ok := h.StatsCache.Get(tt.PhysicalID)
require.True(t, ok)
require.Equal(t, tbl.PhysicalID, tt.PhysicalID)
}

require.Equal(t, h.MemConsumed(), memCostTot)
}
Expand Down

0 comments on commit b175150

Please sign in to comment.