Bug #118920 Optimize: change CHAR column charset from utf8mb3 to utf8mb4 can Inplace
Submitted: 1 Sep 11:29 Modified: 4 Sep 1:34
Reporter: George Ma (OCA) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:8.0.43 OS:Any
Assigned to: MySQL Verification Team CPU Architecture:Any
Tags: DDL

[1 Sep 11:29] George Ma
Description:
In WL#11605, MySQL support to change the column charset from utf8mb3 to utf8mb4 on inplace way, for example:

CREATE TABLE `t1` (
  `id` int NOT NULL,
  `c1` char(60) DEFAULT NULL,
  `c2` varchar(60) DEFAULT NULL,
  `c3` char(80) DEFAULT NULL,
  `c4` varchar(80) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

Column c1 and c2 can change inplace:

mysql> alter table t1 modify column c1 char(60) CHARACTER SET utf8mb4, algorithm = inplace;
Query OK, 0 rows affected (0.04 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> alter table t1 modify column c2 varchar(60) CHARACTER SET utf8mb4, algorithm = inplace;
Query OK, 0 rows affected (0.04 sec)
Records: 0  Duplicates: 0  Warnings: 0

But column c3 and c4 can not:

mysql> alter table t1 modify column c3 char(80) CHARACTER SET utf8mb4, algorithm = inplace;
ERROR 1846 (0A000): ALGORITHM=INPLACE is not supported. Reason: Cannot change column type INPLACE. Try ALGORITHM=COPY.
mysql> alter table t1 modify column c4 varchar(80) CHARACTER SET utf8mb4, algorithm = inplace;
ERROR 1846 (0A000): ALGORITHM=INPLACE is not supported. Reason: Cannot change column type INPLACE. Try ALGORITHM=COPY.

For column c4, it's reasonable because such change of charset will also affect the length stored on the row record (80 * 3 < 256 && 80 * 4 > 256). But for column c3, this problem does not exist.

So, change CHAR column charset from utf8mb3 to utf8mb4 can Inplace without considering the length.

How to repeat:
In the above description.
[3 Sep 10:07] MySQL Verification Team
Hi,

Thank you for your report. 63 will work, 64 won't "fit" as the utf8mb4 uses 4 bytes and utf8mb3 uses 3 bytes per character. 

This is known, documented and expected behavior.
[4 Sep 1:34] George Ma
Yes, I know this is the current limitation. What I want to discuss is that it's reasonable for the VARCHAR type to have this limitation because it needs to store the actual length, which could be 1 byte or 2 bytes. However, the CHAR type doesn't need to store length information at all so this limitation could be directly removed.