stats: replace Copy with ShallowCopy for table stats update logic (#62430)

ref pingcap/tidb#57868
This commit is contained in:
Dongpo Liu
2025-08-18 19:38:32 +02:00
committed by GitHub
parent 215f779264
commit a657e4d06f
2 changed files with 2 additions and 2 deletions

View File

@ -206,7 +206,7 @@ func (s *StatsCacheImpl) Update(ctx context.Context, is infoschema.InfoSchema, t
// If the column/index stats has not been updated, we can reuse the old table stats.
// Only need to update the count and modify count.
if ok && latestHistUpdateVersion > 0 && oldTbl.LastStatsHistVersion >= latestHistUpdateVersion {
tbl = oldTbl.Copy()
tbl = oldTbl.ShallowCopy()
// count and modify count is updated in finalProcess
needLoadColAndIdxStats = false
}

View File

@ -249,7 +249,7 @@ func TestLoadHist(t *testing.T) {
require.False(t, newStatsTbl2 == newStatsTbl)
// The histograms is not updated.
newStatsTbl.ForEachColumnImmutable(func(id int64, hist *statistics.Column) bool {
require.Equal(t, newStatsTbl2.GetCol(id), hist)
require.Equal(t, hist.LastUpdateVersion, newStatsTbl2.GetCol(id).LastUpdateVersion)
return false
})
require.Greater(t, newStatsTbl2.GetCol(3).LastUpdateVersion, newStatsTbl2.GetCol(1).LastUpdateVersion)