Skip to content

Commit

Permalink
plan: statsInfo.count for LogicalTableDual should be its RowCount (pi…
Browse files Browse the repository at this point in the history
  • Loading branch information
zz-jason authored Mar 30, 2018
1 parent f89f48b commit 83ea321
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
29 changes: 29 additions & 0 deletions plan/cbo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,35 @@ func (s *testAnalyzeSuite) TestStraightJoin(c *C) {
))
}

func (s *testAnalyzeSuite) TestTableDual(c *C) {
defer testleak.AfterTest(c)()
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
defer func() {
dom.Close()
store.Close()
}()

testKit := testkit.NewTestKit(c, store)
testKit.MustExec(`use test`)
h := dom.StatsHandle()
testKit.MustExec(`create table t(a int)`)
testKit.MustExec("insert into t values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10)")
c.Assert(h.HandleDDLEvent(<-h.DDLEventCh()), IsNil)

h.DumpStatsDeltaToKV()
c.Assert(h.Update(dom.InfoSchema()), IsNil)

testKit.MustQuery(`explain select * from t where 1 = 0`).Check(testkit.Rows(
`TableDual_6 Projection_5 root rows:0 0.00`,
`Projection_5 TableDual_6 root test.t.a 0.00`,
))

testKit.MustQuery(`explain select * from t where 1 = 1 limit 0`).Check(testkit.Rows(
`TableDual_5 root rows:0 0.00`,
))
}

func (s *testAnalyzeSuite) TestEstimation(c *C) {
defer testleak.AfterTest(c)()
store, dom, err := newStoreWithBootstrap()
Expand Down
12 changes: 12 additions & 0 deletions plan/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ func (p *basePhysicalPlan) StatsInfo() *statsInfo {
return p.stats
}

func (p *LogicalTableDual) deriveStats() *statsInfo {
profile := &statsInfo{
count: float64(p.RowCount),
cardinality: make([]float64, p.Schema().Len()),
}
for i := range profile.cardinality {
profile.cardinality[i] = float64(p.RowCount)
}
p.stats = profile
return p.stats
}

func (p *baseLogicalPlan) deriveStats() *statsInfo {
if len(p.children) == 0 {
profile := &statsInfo{
Expand Down

0 comments on commit 83ea321

Please sign in to comment.