Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

session: do not allow historical read in local temporary tables #27363

Merged
merged 8 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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