From cfb8e60e275fb506e6c3f83c6054780ee08d0c7f Mon Sep 17 00:00:00 2001 From: Arthur Schreiber Date: Tue, 7 May 2024 11:52:41 +0000 Subject: [PATCH 1/3] Fix collation issues with `schemacopy` table. Signed-off-by: Arthur Schreiber --- go/mysql/schema.go | 4 ++-- .../schema/schematracker/schemacopy.sql | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/go/mysql/schema.go b/go/mysql/schema.go index 933ce657c3a..dfb8a35b4d2 100644 --- a/go/mysql/schema.go +++ b/go/mysql/schema.go @@ -39,13 +39,13 @@ const ( DetectSchemaChange = ` SELECT DISTINCT table_name FROM ( - SELECT table_name, column_name, ordinal_position, character_set_name, collation_name, data_type, column_key + SELECT table_name COLLATE utf8mb3_bin AS table_name, column_name COLLATE utf8mb3_general_ci AS column_name, ordinal_position, character_set_name COLLATE utf8mb3_general_ci AS character_set_name, collation_name COLLATE utf8mb3_general_ci AS collation_name, data_type COLLATE utf8mb3_bin AS data_type, column_key COLLATE utf8mb3_bin AS column_key FROM information_schema.columns WHERE table_schema = database() UNION ALL - SELECT table_name, column_name, ordinal_position, character_set_name, collation_name, data_type, column_key + SELECT table_name COLLATE utf8mb3_bin AS table_name, column_name COLLATE utf8mb3_general_ci AS column_name, ordinal_position, character_set_name COLLATE utf8mb3_general_ci AS character_set_name, collation_name COLLATE utf8mb3_general_ci AS collation_name, data_type COLLATE utf8mb3_bin AS data_type, column_key COLLATE utf8mb3_bin AS column_key FROM %s.schemacopy WHERE table_schema = database() ) _inner diff --git a/go/vt/sidecardb/schema/schematracker/schemacopy.sql b/go/vt/sidecardb/schema/schematracker/schemacopy.sql index 296bb34df14..30e07856a48 100644 --- a/go/vt/sidecardb/schema/schematracker/schemacopy.sql +++ b/go/vt/sidecardb/schema/schematracker/schemacopy.sql @@ -16,13 +16,13 @@ limitations under the License. CREATE TABLE IF NOT EXISTS schemacopy ( - `table_schema` varchar(64) NOT NULL, - `table_name` varchar(64) NOT NULL, - `column_name` varchar(64) NOT NULL, - `ordinal_position` bigint unsigned NOT NULL, - `character_set_name` varchar(32) DEFAULT NULL, - `collation_name` varchar(32) DEFAULT NULL, - `data_type` varchar(64) NOT NULL, - `column_key` varchar(3) NOT NULL, + `table_schema` varchar(64) COLLATE utf8_bin NOT NULL, + `table_name` varchar(64) COLLATE utf8_bin NOT NULL, + `column_name` varchar(64) COLLATE utf8_general_ci NOT NULL, + `ordinal_position` bigint unsigned NOT NULL, + `character_set_name` varchar(32) COLLATE utf8_general_ci DEFAULT NULL, + `collation_name` varchar(32) COLLATE utf8_general_ci DEFAULT NULL, + `data_type` varchar(64) COLLATE utf8_bin NOT NULL, + `column_key` varchar(3) COLLATE utf8_bin NOT NULL, PRIMARY KEY (`table_schema`, `table_name`, `ordinal_position`) ) ENGINE = InnoDB From b0640fa9f516d79642aed94fa065e51f7314ae18 Mon Sep 17 00:00:00 2001 From: Arthur Schreiber Date: Tue, 7 May 2024 21:34:27 +0000 Subject: [PATCH 2/3] Explicitly specify the character set. Signed-off-by: Arthur Schreiber --- .../schema/schematracker/schemacopy.sql | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/go/vt/sidecardb/schema/schematracker/schemacopy.sql b/go/vt/sidecardb/schema/schematracker/schemacopy.sql index 30e07856a48..9cd6d22ee91 100644 --- a/go/vt/sidecardb/schema/schematracker/schemacopy.sql +++ b/go/vt/sidecardb/schema/schematracker/schemacopy.sql @@ -16,13 +16,13 @@ limitations under the License. CREATE TABLE IF NOT EXISTS schemacopy ( - `table_schema` varchar(64) COLLATE utf8_bin NOT NULL, - `table_name` varchar(64) COLLATE utf8_bin NOT NULL, - `column_name` varchar(64) COLLATE utf8_general_ci NOT NULL, - `ordinal_position` bigint unsigned NOT NULL, - `character_set_name` varchar(32) COLLATE utf8_general_ci DEFAULT NULL, - `collation_name` varchar(32) COLLATE utf8_general_ci DEFAULT NULL, - `data_type` varchar(64) COLLATE utf8_bin NOT NULL, - `column_key` varchar(3) COLLATE utf8_bin NOT NULL, + `table_schema` varchar(64) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL, + `table_name` varchar(64) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL, + `column_name` varchar(64) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL, + `ordinal_position` bigint unsigned NOT NULL, + `character_set_name` varchar(32) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `collation_name` varchar(32) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `data_type` varchar(64) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL, + `column_key` varchar(3) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL, PRIMARY KEY (`table_schema`, `table_name`, `ordinal_position`) ) ENGINE = InnoDB From c875fac26f59117134db9ff141afc07af993619e Mon Sep 17 00:00:00 2001 From: Arthur Schreiber Date: Wed, 8 May 2024 12:22:45 +0000 Subject: [PATCH 3/3] Try being explicit about table charset. Signed-off-by: Arthur Schreiber --- go/vt/sidecardb/schema/schematracker/schemacopy.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/vt/sidecardb/schema/schematracker/schemacopy.sql b/go/vt/sidecardb/schema/schematracker/schemacopy.sql index 9cd6d22ee91..3abb922f81f 100644 --- a/go/vt/sidecardb/schema/schematracker/schemacopy.sql +++ b/go/vt/sidecardb/schema/schematracker/schemacopy.sql @@ -25,4 +25,4 @@ CREATE TABLE IF NOT EXISTS schemacopy `data_type` varchar(64) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL, `column_key` varchar(3) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL, PRIMARY KEY (`table_schema`, `table_name`, `ordinal_position`) -) ENGINE = InnoDB +) ENGINE = InnoDB, CHARACTER SET = utf8mb3