diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index e2e0e3dfeba8a..bb045d6ff80b0 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -2951,10 +2951,6 @@ func (s *testIntegrationSuite3) TestCreateTemporaryTable(c *C) { ON DUPLICATE KEY UPDATE variable_value = '%[2]s', comment = '%[3]s'`, safePointName, safePointValue, safePointComment) tk.MustExec(updateSafePoint) - - // Considering snapshot, local temporary table is always visible. - tk.MustExec("set @@tidb_snapshot = '2016-01-01 15:04:05.999999'") - tk.MustExec("select * from overlap") } func (s *testIntegrationSuite3) TestAvoidCreateViewOnLocalTemporaryTable(c *C) { 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 6d1edbc3bf7fe..8d20f0f48e2c4 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -8955,9 +8955,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()) } }