[MDEV-28119] Wrong column collation on MODIFY + CONVERT Created: 2022-03-18  Updated: 2022-03-23  Resolved: 2022-03-23

Status: Closed
Project: MariaDB Server
Component/s: Character Sets
Affects Version/s: 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9
Fix Version/s: 10.9.0

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-27743 Remove Lex::charset Closed

 Description   

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a CHAR);
ALTER TABLE t1
  MODIFY a CHAR COLLATE DEFAULT,
  CONVERT TO CHARACTER SET utf8mb3 COLLATE utf8mb3_bin;
SHOW CREATE TABLE t1;

+-------+--------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                   |
+-------+--------------------------------------------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `a` char(1) COLLATE utf8mb3_bin DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin |
+-------+--------------------------------------------------------------------------------------------------------------------------------+

utf8mb3_bin for the column 'a' looks wrong. The ALTER statement asked to use COLLATE DEFAULT for the column "a", which is utf8mb3_general_ci. But COLLATE DEFAULT was erroneously ignored.

Note, if I change the script slightly to ask for:

  • binary collation on the column level
  • default collation on the table level
    it returns the expected result:

    DROP TABLE IF EXISTS t1;
    CREATE TABLE t1 (a CHAR);
    ALTER TABLE t1
      MODIFY a CHAR BINARY,
      CONVERT TO CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci;
    SHOW CREATE TABLE t1;
    

    +-------+----------------------------------------------------------------------------------------------------------------------------------+
    | Table | Create Table                                                                                                                     |
    +-------+----------------------------------------------------------------------------------------------------------------------------------+
    | t1    | CREATE TABLE `t1` (
      `a` char(1) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 |
    +-------+----------------------------------------------------------------------------------------------------------------------------------+
    

Notice, the BINARY on the column level was not ignored, which is correct.

The first script should be fixed not to ingore COLLATE DEFAULT.


Generated at Thu Feb 08 09:58:12 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.