Skip to content

Commit

Permalink
stats: fix panic when dump pseudo columns (pingcap#11430)
Browse files Browse the repository at this point in the history
  • Loading branch information
alivxxx committed Jul 26, 2019
1 parent 711d142 commit 35d5428
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
17 changes: 17 additions & 0 deletions statistics/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,20 @@ func (s *testDumpStatsSuite) TestDumpAlteredTable(c *C) {
_, err = h.DumpStatsToJSON("test", table.Meta())
c.Assert(err, IsNil)
}

func (s *testDumpStatsSuite) TestDumpPseudoColumns(c *C) {
defer cleanEnv(c, s.store, s.do)
testKit := testkit.NewTestKit(c, s.store)
testKit.MustExec("use test")
testKit.MustExec("create table t(a int, b int, index idx(a))")
// Force adding an pseudo tables in stats cache.
testKit.MustQuery("select * from t")
testKit.MustExec("analyze table t index idx")

is := s.do.InfoSchema()
tbl, err := is.TableByName(model.NewCIStr("test"), model.NewCIStr("t"))
c.Assert(err, IsNil)
h := s.do.StatsHandle()
_, err = h.DumpStatsToJSON("test", tbl.Meta())
c.Assert(err, IsNil)
}
10 changes: 8 additions & 2 deletions statistics/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,12 +628,18 @@ func PseudoTable(tblInfo *model.TableInfo) *Table {
}
for _, col := range tblInfo.Columns {
if col.State == model.StatePublic {
t.Columns[col.ID] = &Column{Info: col, isHandle: tblInfo.PKIsHandle && mysql.HasPriKeyFlag(col.Flag)}
t.Columns[col.ID] = &Column{
Info: col,
isHandle: tblInfo.PKIsHandle && mysql.HasPriKeyFlag(col.Flag),
Histogram: *NewHistogram(col.ID, 0, 0, 0, &col.FieldType, 0, 0),
}
}
}
for _, idx := range tblInfo.Indices {
if idx.State == model.StatePublic {
t.Indices[idx.ID] = &Index{Info: idx}
t.Indices[idx.ID] = &Index{
Info: idx,
Histogram: *NewHistogram(idx.ID, 0, 0, 0, types.NewFieldType(mysql.TypeBlob), 0, 0)}
}
}
return t
Expand Down

0 comments on commit 35d5428

Please sign in to comment.