Skip to content

Commit

Permalink
executor: fix incorrect rows returned by TABLESAMPLE (#25357) (#25795)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Jun 28, 2021
1 parent c8b2f25 commit 18d69e5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion executor/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func splitIntoMultiRanges(store kv.Storage, startKey, endKey kv.Key) ([]kv.KeyRa
if kv.Key(start).Cmp(startKey) < 0 {
start = startKey
}
if kv.Key(end).Cmp(endKey) > 0 {
if end == nil || kv.Key(end).Cmp(endKey) > 0 {
end = endKey
}
ranges = append(ranges, kv.KeyRange{StartKey: start, EndKey: end})
Expand Down
14 changes: 14 additions & 0 deletions executor/sample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ func (s *testTableSampleSuite) TestTableSampleMultiRegions(c *C) {
tk.MustExec("drop table t2;")
}

func (s *testTableSampleSuite) TestTableSampleNoSplitTable(c *C) {
tk := s.initSampleTest(c)
atomic.StoreUint32(&ddl.EnableSplitTableRegion, 0)
tk.MustExec("drop table if exists t1;")
tk.MustExec("drop table if exists t2;")
tk.MustExec("create table t1 (id int primary key);")
tk.MustExec("create table t2 (id int primary key);")
tk.MustExec("insert into t2 values(1);")
rows := tk.MustQuery("select * from t1 tablesample regions();").Rows()
rows2 := tk.MustQuery("select * from t2 tablesample regions();").Rows()
c.Assert(len(rows), Equals, 0)
c.Assert(len(rows2), Equals, 1)
}

func (s *testTableSampleSuite) TestTableSampleSchema(c *C) {
tk := s.initSampleTest(c)
tk.Se.GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeOn
Expand Down

0 comments on commit 18d69e5

Please sign in to comment.