Skip to content

Commit

Permalink
ddl: show create table for a local temporary table (#26104)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoxugang authored Jul 30, 2021
1 parent 1e5000c commit 99c4bc1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion executor/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,11 @@ func (e *DDLExec) createSessionTemporaryTable(s *ast.CreateTableStmt) error {

// AutoID is allocated in mocked..
alloc := autoid.NewAllocatorFromTempTblInfo(tbInfo)
tbl, err := tables.TableFromMeta([]autoid.Allocator{alloc}, tbInfo)
allocs := make([]autoid.Allocator, 0, 1)
if alloc != nil {
allocs = append(allocs, alloc)
}
tbl, err := tables.TableFromMeta(allocs, tbInfo)
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,8 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T
switch tableInfo.TempTableType {
case model.TempTableGlobal:
fmt.Fprintf(buf, "CREATE GLOBAL TEMPORARY TABLE %s (\n", tableName)
case model.TempTableLocal:
fmt.Fprintf(buf, "CREATE TEMPORARY TABLE %s (\n", tableName)
default:
fmt.Fprintf(buf, "CREATE TABLE %s (\n", tableName)
}
Expand Down
23 changes: 23 additions & 0 deletions executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1375,4 +1375,27 @@ func (s *testSuite5) TestShowTemporaryTable(c *C) {
" KEY `b` (`b`)\n" +
") ENGINE=memory DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ON COMMIT DELETE ROWS"
tk.MustQuery("show create table t5").Check(testkit.Rows("t5 " + expect))

tk.MustExec("set tidb_enable_noop_functions=true")
tk.MustExec("create temporary table t6 (i int primary key, j int)")
expect = "CREATE TEMPORARY TABLE `t6` (\n" +
" `i` int(11) NOT NULL,\n" +
" `j` int(11) DEFAULT NULL,\n" +
" PRIMARY KEY (`i`) /*T![clustered_index] CLUSTERED */\n" +
") ENGINE=memory DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"
tk.MustQuery("show create table t6").Check(testkit.Rows("t6 " + expect))
tk.MustExec("create temporary table t7 (i int primary key auto_increment, j int)")
defer func() {
tk.MustExec("commit;")
}()
tk.MustExec("begin;")
tk.MustExec("insert into t7 (j) values (14)")
tk.MustExec("insert into t7 (j) values (24)")
tk.MustQuery("select * from t7").Check(testkit.Rows("1 14", "2 24"))
expect = "CREATE TEMPORARY TABLE `t7` (\n" +
" `i` int(11) NOT NULL AUTO_INCREMENT,\n" +
" `j` int(11) DEFAULT NULL,\n" +
" PRIMARY KEY (`i`) /*T![clustered_index] CLUSTERED */\n" +
") ENGINE=memory DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=2"
tk.MustQuery("show create table t7").Check(testkit.Rows("t7 " + expect))
}

0 comments on commit 99c4bc1

Please sign in to comment.