Skip to content

Commit

Permalink
statistics: prioritize low selectivity indexes in ... (#20038) (#20154)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Oct 3, 2020
1 parent 81388ab commit 928d9fa
Show file tree
Hide file tree
Showing 5 changed files with 99,430 additions and 3 deletions.
32 changes: 32 additions & 0 deletions planner/core/cbo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,38 @@ func (s *testAnalyzeSuite) TestLimitCrossEstimation(c *C) {
}
}

func (s *testAnalyzeSuite) TestLowSelIndexGreedySearch(c *C) {
defer testleak.AfterTest(c)()
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
testKit := testkit.NewTestKit(c, store)
defer func() {
dom.Close()
store.Close()
}()
testKit.MustExec("use test")
testKit.MustExec("drop table if exists t")
testKit.MustExec("create table t (a varchar(32) default null, b varchar(10) default null, c varchar(12) default null, d varchar(32) default null, e bigint(10) default null, key idx1 (d,a), key idx2 (a,c), key idx3 (c,b), key idx4 (e))")
err = s.loadTableStats("analyzeSuiteTestLowSelIndexGreedySearchT.json", dom)
c.Assert(err, IsNil)
var input []string
var output []struct {
SQL string
Plan []string
}
// The test purposes are:
// - index `idx2` runs much faster than `idx4` experimentally;
// - estimated row count of IndexLookUp should be 0;
s.testData.GetTestCases(c, &input, &output)
for i, tt := range input {
s.testData.OnRecord(func() {
output[i].SQL = tt
output[i].Plan = s.testData.ConvertRowsToStrings(testKit.MustQuery(tt).Rows())
})
testKit.MustQuery(tt).Check(testkit.Rows(output[i].Plan...))
}
}

func (s *testAnalyzeSuite) TestUpdateProjEliminate(c *C) {
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
Expand Down
Loading

0 comments on commit 928d9fa

Please sign in to comment.