Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stats: fix panic when dump pseudo columns #11430

Merged
merged 4 commits into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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