diff --git a/statistics/handle/dump_test.go b/statistics/handle/dump_test.go index 72fa7d3a6b7c0..5e5572b5c0e03 100644 --- a/statistics/handle/dump_test.go +++ b/statistics/handle/dump_test.go @@ -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) +} diff --git a/statistics/table.go b/statistics/table.go index c95979e81dbde..5805b177e347b 100644 --- a/statistics/table.go +++ b/statistics/table.go @@ -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