From a6b44b7a5055ac2e2943ae256166ed913596cd8f Mon Sep 17 00:00:00 2001 From: sylzd Date: Thu, 19 Aug 2021 12:13:04 +0800 Subject: [PATCH] done --- executor/builder.go | 4 ++++ executor/executor_test.go | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/executor/builder.go b/executor/builder.go index c888facf4e369..e95c638919bc5 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -4525,6 +4525,10 @@ func (b *executorBuilder) validCanReadTemporaryTable(tbl *model.TableInfo) error sessionVars := b.ctx.GetSessionVars() + if tbl.TempTableType == model.TempTableLocal && sessionVars.SnapshotTS != 0 { + return errors.New("can not read local temporary table when 'tidb_snapshot' is set") + } + if sessionVars.TxnCtx.IsStaleness || b.isStaleness { return errors.New("can not stale read temporary table") } diff --git a/executor/executor_test.go b/executor/executor_test.go index efe01e6c9e9c9..d2688b4ccaf4b 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -8947,9 +8947,13 @@ func (s *testStaleTxnSuite) TestInvalidReadTemporaryTable(c *C) { tk.MustExec("set @@tidb_snapshot=NOW(6)") for _, query := range queries { + // forbidden historical read local temporary table + if strings.Contains(query.sql, "tmp2") { + tk.MustGetErrMsg(query.sql, "can not read local temporary table when 'tidb_snapshot' is set") + continue + } // Will success here for compatibility with some tools like dumping - rs := tk.MustQuery(query.sql) - rs.Check(testkit.Rows()) + tk.MustQuery(query.sql).Check(testkit.Rows()) } }