Skip to content

Commit

Permalink
executor: fix invalid key error of fast analyze (#11072)
Browse files Browse the repository at this point in the history
  • Loading branch information
alivxxx committed Jul 4, 2019
1 parent 862a2be commit 9eb2379
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
4 changes: 3 additions & 1 deletion executor/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,9 @@ func (e *AnalyzeFastExec) handleSampTasks(bo *tikv.Backoffer, workID int, err *e
if *err != nil {
return
}
kvMap[string(iter.Key())] = iter.Value()
if iter.Valid() {
kvMap[string(iter.Key())] = iter.Value()
}
}

*err = e.handleBatchSeekResponse(kvMap)
Expand Down
46 changes: 20 additions & 26 deletions executor/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (s *testSuite1) TestFastAnalyze(c *C) {
dom, err = session.BootstrapSession(store)
c.Assert(err, IsNil)
tk := testkit.NewTestKit(c, store)
executor.MaxSampleSize = 1000
executor.MaxSampleSize = 6
executor.RandSeed = 123

tk.MustExec("use test")
Expand All @@ -251,12 +251,12 @@ func (s *testSuite1) TestFastAnalyze(c *C) {
c.Assert(err, IsNil)
tid := tblInfo.Meta().ID

// construct 5 regions split by {600, 1200, 1800, 2400}
splitKeys := generateTableSplitKeyForInt(tid, []int{600, 1200, 1800, 2400})
// construct 6 regions split by {10, 20, 30, 40, 50}
splitKeys := generateTableSplitKeyForInt(tid, []int{10, 20, 30, 40, 50})
manipulateCluster(cluster, splitKeys)

for i := 0; i < 3000; i++ {
tk.MustExec(fmt.Sprintf(`insert into t values (%d, %d, "char")`, i, i))
for i := 0; i < 20; i++ {
tk.MustExec(fmt.Sprintf(`insert into t values (%d, %d, "char")`, i*3, i*3))
}
tk.MustExec("analyze table t with 5 buckets")

Expand All @@ -265,27 +265,21 @@ func (s *testSuite1) TestFastAnalyze(c *C) {
c.Assert(err, IsNil)
tableInfo := table.Meta()
tbl := dom.StatsHandle().GetTableStats(tableInfo)
c.Assert(tbl.String(), Equals, "Table:41 Count:3000\n"+
"column:1 ndv:3000 totColSize:0\n"+
"num: 603 lower_bound: 0 upper_bound: 658 repeats: 1\n"+
"num: 603 lower_bound: 663 upper_bound: 1248 repeats: 1\n"+
"num: 603 lower_bound: 1250 upper_bound: 1823 repeats: 1\n"+
"num: 603 lower_bound: 1830 upper_bound: 2379 repeats: 1\n"+
"num: 588 lower_bound: 2380 upper_bound: 2998 repeats: 1\n"+
"column:2 ndv:3000 totColSize:0\n"+
"num: 603 lower_bound: 0 upper_bound: 658 repeats: 1\n"+
"num: 603 lower_bound: 663 upper_bound: 1248 repeats: 1\n"+
"num: 603 lower_bound: 1250 upper_bound: 1823 repeats: 1\n"+
"num: 603 lower_bound: 1830 upper_bound: 2379 repeats: 1\n"+
"num: 588 lower_bound: 2380 upper_bound: 2998 repeats: 1\n"+
"column:3 ndv:1 totColSize:12000\n"+
"num: 3000 lower_bound: char upper_bound: char repeats: 3000\n"+
"index:1 ndv:3000\n"+
"num: 603 lower_bound: 0 upper_bound: 658 repeats: 1\n"+
"num: 603 lower_bound: 663 upper_bound: 1248 repeats: 1\n"+
"num: 603 lower_bound: 1250 upper_bound: 1823 repeats: 1\n"+
"num: 603 lower_bound: 1830 upper_bound: 2379 repeats: 1\n"+
"num: 588 lower_bound: 2380 upper_bound: 2998 repeats: 1")
c.Assert(tbl.String(), Equals, "Table:41 Count:20\n"+
"column:1 ndv:20 totColSize:0\n"+
"num: 6 lower_bound: 3 upper_bound: 15 repeats: 1\n"+
"num: 7 lower_bound: 18 upper_bound: 33 repeats: 1\n"+
"num: 7 lower_bound: 39 upper_bound: 57 repeats: 1\n"+
"column:2 ndv:20 totColSize:0\n"+
"num: 6 lower_bound: 3 upper_bound: 15 repeats: 1\n"+
"num: 7 lower_bound: 18 upper_bound: 33 repeats: 1\n"+
"num: 7 lower_bound: 39 upper_bound: 57 repeats: 1\n"+
"column:3 ndv:1 totColSize:72\n"+
"num: 20 lower_bound: char upper_bound: char repeats: 18\n"+
"index:1 ndv:20\n"+
"num: 6 lower_bound: 3 upper_bound: 15 repeats: 1\n"+
"num: 7 lower_bound: 18 upper_bound: 33 repeats: 1\n"+
"num: 7 lower_bound: 39 upper_bound: 57 repeats: 1")

// Test CM Sketch built from fast analyze.
tk.MustExec("create table t1(a int, b int, index idx(a, b))")
Expand Down

0 comments on commit 9eb2379

Please sign in to comment.