From 0ed8eafa9bf269eb2c3974ce67184aa05fbabc38 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 64204b4b61211..70f76120d5dcf 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -4151,8 +4151,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 38dea78d1ac5b..5cdd7516b8005 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -8521,7 +8521,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" @@ -8542,6 +8542,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 }{ @@ -8566,9 +8568,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", },