diff --git a/executor/builder.go b/executor/builder.go index 0d541a1b33933..6f8eced115b07 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -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 } diff --git a/executor/executor_test.go b/executor/executor_test.go index 4050b5bda2e91..a68631a89b707 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -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" @@ -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 }{ @@ -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", },