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: modify default unique index name #39145

Merged
merged 4 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
26 changes: 26 additions & 0 deletions ddl/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -959,3 +959,29 @@ func TestGetDefaultValueOfColumn(t *testing.T) {
tk.MustQuery("select * from t1").Check(testkit.RowsWithSep("|", ""+
"1962-03-03 1962-03-03 00:00:00 12:23:23 2020-10-13 2020-03-27"))
}

func TestIssue39080(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("CREATE TABLE t1(id INTEGER PRIMARY KEY, authorId INTEGER AUTO_INCREMENT UNIQUE)")

tk.MustQuery("show create table t1").Check(testkit.RowsWithSep("|", ""+
"t1 CREATE TABLE `t1` (\n"+
" `id` int(11) NOT NULL,\n"+
" `authorId` int(11) NOT NULL AUTO_INCREMENT,\n"+
" PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,\n"+
" UNIQUE KEY `authorId` (`authorId`)\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))

//Do not affect the specified name
tk.MustExec("CREATE TABLE `t2`( `id` INTEGER PRIMARY KEY, `authorId` int(11) AUTO_INCREMENT, UNIQUE KEY `authorIdx` (`authorId`))")

tk.MustQuery("show create table t2").Check(testkit.RowsWithSep("|", ""+
"t2 CREATE TABLE `t2` (\n"+
" `id` int(11) NOT NULL,\n"+
" `authorId` int(11) NOT NULL AUTO_INCREMENT,\n"+
" PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,\n"+
" UNIQUE KEY `authorIdx` (`authorId`)\n"+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
}
2 changes: 1 addition & 1 deletion ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,7 @@ func setEmptyConstraintName(namesMap map[string]bool, constr *ast.Constraint) {
}
}
if colName == "" {
colName = constr.Keys[0].Column.Name.L
colName = constr.Keys[0].Column.Name.O
}
constrName := colName
i := 2
Expand Down