From a657e4d06fe5db7bd540ee71a06face1363fcee5 Mon Sep 17 00:00:00 2001 From: Dongpo Liu Date: Mon, 18 Aug 2025 19:38:32 +0200 Subject: [PATCH] stats: replace Copy with ShallowCopy for table stats update logic (#62430) ref pingcap/tidb#57868 --- pkg/statistics/handle/cache/statscache.go | 2 +- pkg/statistics/handle/handletest/handle_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/statistics/handle/cache/statscache.go b/pkg/statistics/handle/cache/statscache.go index a39dc7fef3..4a4e794a42 100644 --- a/pkg/statistics/handle/cache/statscache.go +++ b/pkg/statistics/handle/cache/statscache.go @@ -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 } diff --git a/pkg/statistics/handle/handletest/handle_test.go b/pkg/statistics/handle/handletest/handle_test.go index cbe9c139e8..f986ca3f4a 100644 --- a/pkg/statistics/handle/handletest/handle_test.go +++ b/pkg/statistics/handle/handletest/handle_test.go @@ -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)