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 incorrect rows returned by TABLESAMPLE (#25357) #25795

Merged
merged 3 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
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