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

ddl: show create table for a local temporary table #26104

Merged
merged 15 commits into from
Jul 30, 2021
Merged
6 changes: 5 additions & 1 deletion executor/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,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)
Comment on lines +311 to +315
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can know from memid.go L28 that NewAllocatorFromTempTblInfo will be return nil when there is not PK or COMMON PK and not exists auto_incr_id

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When alloc is nil, can the current code work?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, the read and write operation ... if alloc is nil ...

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
17 changes: 17 additions & 0 deletions executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1375,4 +1375,21 @@ 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)")
zhaoxugang marked this conversation as resolved.
Show resolved Hide resolved
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"))
}