Skip to content

Commit

Permalink
executor: add tablesample compatibility for temporary table (pingcap#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lcwangchao authored and tiancaiamao committed Jun 23, 2021
1 parent 727a217 commit 4920411
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4211,8 +4211,8 @@ func fullRangePartition(idxArr []int) bool {
}

func (b *executorBuilder) buildTableSample(v *plannercore.PhysicalTableSample) *TableSampleExecutor {
if err := b.validCanReadTemporaryTable(v.TableInfo.Meta()); err != nil {
b.err = err
if v.TableInfo.Meta().TempTableType != model.TempTableNone {
b.err = errors.New("TABLESAMPLE clause can not be applied to temporary tables")
return nil
}

Expand Down
7 changes: 3 additions & 4 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8560,7 +8560,7 @@ func (s *testResourceTagSuite) TestResourceGroupTag(c *C) {
}
}

func (s *testStaleTxnSuite) TestStaleOrHistoryReadTemporaryTable(c *C) {
func (s *testStaleTxnSuite) TestInvalidReadTemporaryTable(c *C) {
tk := testkit.NewTestKit(c, s.store)
// For mocktikv, safe point is not initialized, we manually insert it for snapshot to use.
safePointName := "tikv_gc_safe_point"
Expand All @@ -8581,6 +8581,8 @@ func (s *testStaleTxnSuite) TestStaleOrHistoryReadTemporaryTable(c *C) {
// sleep 1us to make test stale
time.Sleep(time.Microsecond)

tk.MustGetErrMsg("select * from tmp1 tablesample regions()", "TABLESAMPLE clause can not be applied to temporary tables")

queries := []struct {
sql string
}{
Expand All @@ -8605,9 +8607,6 @@ func (s *testStaleTxnSuite) TestStaleOrHistoryReadTemporaryTable(c *C) {
{
sql: "select /*+use_index(tmp1, code)*/ code from tmp1 where code > 1",
},
{
sql: "select * from tmp1 tablesample regions()",
},
{
sql: "select /*+ use_index_merge(tmp1, primary, code) */ * from tmp1 where id > 1 or code > 2",
},
Expand Down

0 comments on commit 4920411

Please sign in to comment.