Bug #114717 Inconsistent behavior of explicit CHARSET/COLLATE column definition
Description:
For some table collations, when columns inherit the default one from table, show create table prints explicit column COLLATE definition wrongly.
Then when the same shown definition is repeated, the column is really set to use explicit charset and collation.
How to repeat:
mysql> CREATE TABLE test (
-> id int NOT NULL AUTO_INCREMENT,
-> a int,
-> b varchar(10),
-> PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Query OK, 0 rows affected (0.02 sec)
mysql> show create table test\G
*************************** 1. row ***************************
Table: test
Create Table: CREATE TABLE `test` (
`id` int NOT NULL AUTO_INCREMENT,
`a` int DEFAULT NULL,
`b` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
1 row in set (0.00 sec)
ibd2sdi /var/lib/mysql/test/test.ibd |grep -A40 '"name": "b"'|grep collation
"collation_id": 224,
"is_explicit_collation": false
mysql> drop table test;
Query OK, 0 rows affected (0.02 sec)
mysql> CREATE TABLE `test` (
-> `id` int NOT NULL AUTO_INCREMENT,
-> `a` int DEFAULT NULL,
-> `b` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
-> PRIMARY KEY (`id`)
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Query OK, 0 rows affected (0.02 sec)
ibd2sdi /var/lib/mysql/test/test.ibd |grep -A40 '"name": "b"'|grep collation
"collation_id": 224,
"is_explicit_collation": true
mysql> show create table test\G
*************************** 1. row ***************************
Table: test
Create Table: CREATE TABLE `test` (
`id` int NOT NULL AUTO_INCREMENT,
`a` int DEFAULT NULL,
`b` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
1 row in set (0.00 sec)
Suggested fix:
When collation is not set explicitly for a column, it should stay that way ;)
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.041 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
Description: For some table collations, when columns inherit the default one from table, show create table prints explicit column COLLATE definition wrongly. Then when the same shown definition is repeated, the column is really set to use explicit charset and collation. How to repeat: mysql> CREATE TABLE test ( -> id int NOT NULL AUTO_INCREMENT, -> a int, -> b varchar(10), -> PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; Query OK, 0 rows affected (0.02 sec) mysql> show create table test\G *************************** 1. row *************************** Table: test Create Table: CREATE TABLE `test` ( `id` int NOT NULL AUTO_INCREMENT, `a` int DEFAULT NULL, `b` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci 1 row in set (0.00 sec) ibd2sdi /var/lib/mysql/test/test.ibd |grep -A40 '"name": "b"'|grep collation "collation_id": 224, "is_explicit_collation": false mysql> drop table test; Query OK, 0 rows affected (0.02 sec) mysql> CREATE TABLE `test` ( -> `id` int NOT NULL AUTO_INCREMENT, -> `a` int DEFAULT NULL, -> `b` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL, -> PRIMARY KEY (`id`) -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; Query OK, 0 rows affected (0.02 sec) ibd2sdi /var/lib/mysql/test/test.ibd |grep -A40 '"name": "b"'|grep collation "collation_id": 224, "is_explicit_collation": true mysql> show create table test\G *************************** 1. row *************************** Table: test Create Table: CREATE TABLE `test` ( `id` int NOT NULL AUTO_INCREMENT, `a` int DEFAULT NULL, `b` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci 1 row in set (0.00 sec) Suggested fix: When collation is not set explicitly for a column, it should stay that way ;)