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

*: Support create local temporary table if not exist #25983

Merged
merged 2 commits into from
Jul 7, 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
6 changes: 6 additions & 0 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2825,6 +2825,12 @@ func (s *testIntegrationSuite3) TestCreateTemporaryTable(c *C) {
tk.MustExec("rollback")
tk.MustQuery("select * from check_data").Check(testkit.Rows())

// Check create temporary table for if not exists
tk.MustExec("create temporary table b_local_temp_table (id int)")
_, err = tk.Exec("create temporary table b_local_temp_table (id int)")
c.Assert(infoschema.ErrTableExists.Equal(err), IsTrue)
tk.MustExec("create temporary table if not exists b_local_temp_table (id int)")

// Stale read see the local temporary table but can't read on it.
tk.MustExec("START TRANSACTION READ ONLY AS OF TIMESTAMP NOW(3)")
tk.MustGetErrMsg("select * from overlap", "can not stale read temporary table")
Expand Down
9 changes: 8 additions & 1 deletion executor/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,14 @@ func (e *DDLExec) createSessionTemporaryTable(s *ast.CreateTableStmt) error {
sessVars.LocalTemporaryTables = infoschema.NewLocalTemporaryTables()
}
localTempTables := sessVars.LocalTemporaryTables.(*infoschema.LocalTemporaryTables)
return localTempTables.AddTable(dbInfo, tbl)
err = localTempTables.AddTable(dbInfo, tbl)

if err != nil && s.IfNotExists && infoschema.ErrTableExists.Equal(err) {
e.ctx.GetSessionVars().StmtCtx.AppendNote(err)
return nil
}

return err
}

func (e *DDLExec) executeCreateView(s *ast.CreateViewStmt) error {
Expand Down