From 4920411f3dd81db6a81079a1e90325ef8300624f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=B6=85?= Date: Wed, 9 Jun 2021 21:14:29 +0800 Subject: [PATCH] executor: add tablesample compatibility for temporary table (#25288) --- executor/builder.go | 4 ++-- executor/executor_test.go | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) 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", },