From 7669c32bf8e3b184efe6cb42b98bd3d34a9602da Mon Sep 17 00:00:00 2001 From: tangenta Date: Wed, 19 Aug 2020 15:56:42 +0800 Subject: [PATCH 1/2] ddl: fix db charset modification panic in uppercase schema --- ddl/db_integration_test.go | 10 ++++++++++ infoschema/builder.go | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index b22d0514227ba..3e508ddbb8f72 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -1933,6 +1933,16 @@ func (s *testIntegrationSuite5) TestChangingDBCharset(c *C) { verifyDBCharsetAndCollate("alterdb2", "utf8mb4", "utf8mb4_general_ci") } +func (s *testIntegrationSuite5) TestChangingUppercaseDBCharset(c *C) { + tk := testkit.NewTestKit(c, s.store) + 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) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("create database if not exists test") diff --git a/infoschema/builder.go b/infoschema/builder.go index 9b2fb7ffcfcd7..6c38352528ff3 100644 --- a/infoschema/builder.go +++ b/infoschema/builder.go @@ -206,7 +206,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 @@ -381,6 +381,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{ From 23cbf2be0b8dd2832dfbd11cda29751c0604272a Mon Sep 17 00:00:00 2001 From: tangenta Date: Wed, 19 Aug 2020 16:51:35 +0800 Subject: [PATCH 2/2] test: merge the test into TestChangingDBCharset --- ddl/db_integration_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index 3e508ddbb8f72..8d07b37929098 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -1931,14 +1931,11 @@ func (s *testIntegrationSuite5) TestChangingDBCharset(c *C) { tk.MustExec("ALTER SCHEMA CHARACTER SET = 'utf8mb4' COLLATE = 'utf8mb4_general_ci'") verifyDBCharsetAndCollate("alterdb2", "utf8mb4", "utf8mb4_general_ci") -} -func (s *testIntegrationSuite5) TestChangingUppercaseDBCharset(c *C) { - tk := testkit.NewTestKit(c, s.store) + // 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;") }