Skip to content

Commit

Permalink
statistics: fix wrong behavior for primary key' non-lite init stats (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored and hawkingrei committed Jul 1, 2024
1 parent 30911a2 commit 34d5e43
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 2 additions & 5 deletions statistics/handle/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,8 @@ func (h *Handle) InitStats(is infoschema.InfoSchema) (err error) {
for _, table := range cache.Values() {
for _, col := range table.Columns {
if col.StatsAvailable() {
if mysql.HasPriKeyFlag(col.Info.GetFlag()) {
col.StatsLoadedStatus = statistics.NewStatsFullLoadStatus()
} else {
col.StatsLoadedStatus = statistics.NewStatsAllEvictedStatus()
}
// primary key column has no stats info, because primary key's is_index is false. so it cannot load the topn
col.StatsLoadedStatus = statistics.NewStatsAllEvictedStatus()
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion statistics/handle/handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/statistics"
Expand Down Expand Up @@ -505,9 +506,17 @@ func TestInitStats(t *testing.T) {
require.Equal(t, uint8(0x36), cols[1].LastAnalyzePos.GetBytes()[0])
require.Equal(t, uint8(0x37), cols[2].LastAnalyzePos.GetBytes()[0])
require.Equal(t, uint8(0x38), cols[3].LastAnalyzePos.GetBytes()[0])
table1 := h.GetTableStats(tbl.Meta())
for _, column := range table1.Columns {
if mysql.HasPriKeyFlag(column.Info.GetFlag()) {
// primary key column has no stats info, because primary key's is_index is false. so it cannot load the topn
require.Nil(t, column.TopN)
}
require.False(t, column.IsFullLoad())
}
h.Clear()
require.NoError(t, h.Update(is))
table1 := h.GetTableStats(tbl.Meta())
table1 = h.GetTableStats(tbl.Meta())
assertTableEqual(t, table0, table1)
h.SetLease(0)
}
Expand Down

0 comments on commit 34d5e43

Please sign in to comment.