diff --git a/statistics/dump_test.go b/statistics/dump_test.go index 5283855dc0a8d..bea2821052839 100644 --- a/statistics/dump_test.go +++ b/statistics/dump_test.go @@ -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) +} diff --git a/statistics/table.go b/statistics/table.go index 21e5ad83b9922..1655878b49cb1 100644 --- a/statistics/table.go +++ b/statistics/table.go @@ -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