Skip to content

Commit

Permalink
session: do not allow historical read in local temporary tables (#27363)
Browse files Browse the repository at this point in the history
  • Loading branch information
sylzd authored Aug 20, 2021
1 parent 635c46f commit 203b3b2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 0 additions & 4 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
8 changes: 6 additions & 2 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down

0 comments on commit 203b3b2

Please sign in to comment.