Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: fix invalid key error of fast analyze (#11072) #11098

Merged
merged 3 commits into from
Jul 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -229,7 +229,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 @@ -241,12 +241,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 @@ -255,27 +255,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