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: fix db charset modification panic in an uppercase schema (#19286) #19302

Merged
merged 1 commit into from
Aug 20, 2020
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
7 changes: 7 additions & 0 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,13 @@ func (s *testIntegrationSuite5) TestChangingDBCharset(c *C) {

tk.MustExec("ALTER SCHEMA CHARACTER SET = 'utf8mb4' COLLATE = 'utf8mb4_general_ci'")
verifyDBCharsetAndCollate("alterdb2", "utf8mb4", "utf8mb4_general_ci")

// Test changing charset of schema with uppercase name. See https://github.com/pingcap/tidb/issues/19273.
tk.MustExec("drop database if exists TEST_UPPERCASE_DB_CHARSET;")
tk.MustExec("create database TEST_UPPERCASE_DB_CHARSET;")
tk.MustExec("use TEST_UPPERCASE_DB_CHARSET;")
tk.MustExec("alter database TEST_UPPERCASE_DB_CHARSET default character set utf8;")
tk.MustExec("alter database TEST_UPPERCASE_DB_CHARSET default character set utf8mb4;")
}

func (s *testIntegrationSuite4) TestDropAutoIncrementIndex(c *C) {
Expand Down
3 changes: 2 additions & 1 deletion infoschema/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (b *Builder) applyModifySchemaCharsetAndCollate(m *meta.Meta, diff *model.S
fmt.Sprintf("(Schema ID %d)", diff.SchemaID),
)
}
newDbInfo := b.copySchemaTables(di.Name.O)
newDbInfo := b.copySchemaTables(di.Name.L)
newDbInfo.Charset = di.Charset
newDbInfo.Collate = di.Collate
return nil
Expand Down Expand Up @@ -362,6 +362,7 @@ func (b *Builder) copySchemasMap(oldIS *infoSchema) {

// copySchemaTables creates a new schemaTables instance when a table in the database has changed.
// It also does modifications on the new one because old schemaTables must be read-only.
// Note: please make sure the dbName is in lowercase.
func (b *Builder) copySchemaTables(dbName string) *model.DBInfo {
oldSchemaTables := b.is.schemaMap[dbName]
newSchemaTables := &schemaTables{
Expand Down