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

planner: fix tablesample 'order by' clause from partitioned table (#27383) #27412

Merged
merged 3 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions executor/sample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ func (s *testTableSampleSuite) TestTableSampleWithPartition(c *C) {
c.Assert(len(rows), Equals, 0)
rows = tk.MustQuery("select * from t partition (p1) tablesample regions();").Rows()
c.Assert(len(rows), Equals, 1)

// Test https://github.com/pingcap/tidb/issues/27349.
tk.MustExec("drop table if exists t;")
tk.MustExec(`create table t (a int, b int, unique key idx(a)) partition by range (a) (
partition p0 values less than (0),
partition p1 values less than (10),
partition p2 values less than (30),
partition p3 values less than (maxvalue));`)
tk.MustExec("insert into t values (2, 2), (31, 31), (12, 12);")
tk.MustQuery("select _tidb_rowid from t tablesample regions() order by _tidb_rowid;").
Check(testkit.Rows("1", "2", "3")) // The order of _tidb_rowid should be correct.
}

func (s *testTableSampleSuite) TestTableSampleGeneratedColumns(c *C) {
Expand Down
6 changes: 6 additions & 0 deletions planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,12 @@ func (ds *DataSource) convertToSampleTable(prop *property.PhysicalProperty, cand
if !prop.IsEmpty() && !candidate.isMatchProp {
return invalidTask, nil
}
if candidate.isMatchProp {
// TableSample on partition table can't keep order.
if ds.tableInfo.GetPartitionInfo() != nil {
return invalidTask, nil
}
}
p := PhysicalTableSample{
TableSampleInfo: ds.SampleInfo,
TableInfo: ds.table,
Expand Down