Skip to content

Commit

Permalink
stats: fix panic when dump pseudo columns (#11460)
Browse files Browse the repository at this point in the history
All tests passed, auto merged by Bot
  • Loading branch information
sre-bot authored Jul 26, 2019
1 parent 0dd6760 commit e743395
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
17 changes: 17 additions & 0 deletions statistics/handle/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,20 @@ func (s *testStatsSuite) TestDumpCMSketchWithTopN(c *C) {
cmsFromJSON := stat.Columns[tableInfo.Columns[0].ID].CMSketch.Copy()
c.Check(cms.Equal(cmsFromJSON), IsTrue)
}

func (s *testStatsSuite) 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(), nil)
c.Assert(err, IsNil)
}
5 changes: 4 additions & 1 deletion statistics/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,12 +454,15 @@ func PseudoTable(tblInfo *model.TableInfo) *Table {
PhysicalID: fakePhysicalID,
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 e743395

Please sign in to comment.