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

executor: update auto_increment position when executing "show create table" #11820

Closed
wants to merge 1 commit into from
Closed
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
24 changes: 12 additions & 12 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,19 @@ func (e *ShowExec) fetchShowCreateTable() error {
}

buf.WriteString("\n")

buf.WriteString(") ENGINE=InnoDB")

if hasAutoIncID {
autoIncID, err := tb.Allocator(e.ctx).NextGlobalAutoID(tb.Meta().ID)
if err != nil {
return errors.Trace(err)
}
// It's campatible with MySQL.
if autoIncID > 1 {
fmt.Fprintf(&buf, " AUTO_INCREMENT=%d", autoIncID)
}
}

// Because we only support case sensitive utf8_bin collate, we need to explicitly set the default charset and collation
// to make it work on MySQL server which has default collate utf8_general_ci.
if len(tblCollate) == 0 {
Expand All @@ -792,17 +803,6 @@ func (e *ShowExec) fetchShowCreateTable() error {
fmt.Fprintf(&buf, " COMPRESSION='%s'", tb.Meta().Compression)
}

if hasAutoIncID {
autoIncID, err := tb.Allocator(e.ctx).NextGlobalAutoID(tb.Meta().ID)
if err != nil {
return errors.Trace(err)
}
// It's campatible with MySQL.
if autoIncID > 1 {
fmt.Fprintf(&buf, " AUTO_INCREMENT=%d", autoIncID)
}
}

if tb.Meta().ShardRowIDBits > 0 {
fmt.Fprintf(&buf, "/*!90000 SHARD_ROW_ID_BITS=%d ", tb.Meta().ShardRowIDBits)
if tb.Meta().PreSplitRegions > 0 {
Expand Down
4 changes: 2 additions & 2 deletions executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ func (s *testSuite2) TestShowCreateTable(c *C) {
"KEY `IDX_EndTime` (`END_TIME`)," +
"KEY `IDX_RoundId` (`ROUND_ID`)," +
"KEY `IDX_UserId_EndTime` (`USER_ID`,`END_TIME`)" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=505488 " +
") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='comment_x' AUTO_INCREMENT=505488 " +
"PARTITION BY RANGE ( month(`end_time`) ) (" +
"PARTITION p1 VALUES LESS THAN (2)," +
"PARTITION p2 VALUES LESS THAN (3)," +
Expand All @@ -556,7 +556,7 @@ func (s *testSuite2) TestShowCreateTable(c *C) {
" KEY `IDX_EndTime` (`END_TIME`),\n"+
" KEY `IDX_RoundId` (`ROUND_ID`),\n"+
" KEY `IDX_UserId_EndTime` (`USER_ID`,`END_TIME`)\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=505488\n"+
") ENGINE=InnoDB AUTO_INCREMENT=505488 DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='comment_x'\n"+
"PARTITION BY RANGE ( month(`end_time`) ) (\n"+
" PARTITION p1 VALUES LESS THAN (2),\n"+
" PARTITION p2 VALUES LESS THAN (3),\n"+
Expand Down
2 changes: 1 addition & 1 deletion infoschema/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (s *testTableSuite) TestInfoschemaFieldValue(c *C) {
" `c` int(11) NOT NULL AUTO_INCREMENT,\n" +
" `d` int(11) DEFAULT NULL,\n" +
" PRIMARY KEY (`c`)\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=30002"))
") ENGINE=InnoDB AUTO_INCREMENT=30002 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))

// Test auto_increment for table without auto_increment column
tk.MustExec("drop table if exists t")
Expand Down