readyset icon indicating copy to clipboard operation
readyset copied to clipboard

MySQL binary collate type promotion

Open altmannmarcelo opened this issue 11 months ago • 3 comments

Description

-- start readyset - this requires the table to be received via replication

mysql> CREATE TABLE t (id INT PRIMARY KEY, `col_1`  CHAR(10) NOT NULL DEFAULT 'AXw', `col_2` CHAR(10) COLLATE binary NOT NULL DEFAULT 'AXw');
Query OK, 0 rows affected (0,019 sec)

mysql> INSERT INTO `t` VALUES (0, 'AXw', 'AXw');
Query OK, 1 row affected (0,005 sec)

mysql> SELECT * FROM t;
+----+-------+------------------------+
| id | col_1 | col_2                  |
+----+-------+------------------------+
|  0 | AXw   | 0x41587700000000000000 |
+----+-------+------------------------+
1 row in set (0,001 sec)

readyset> CREATE CACHE FROM SELECT * FROM t;
Query OK, 0 rows affected (0,226 sec)

readyset> SELECT * FROM t;
+------+-------+-------+
| id   | col_1 | col_2 |
+------+-------+-------+
|    0 | AXw   | AXw   |
+------+-------+-------+
1 row in set (0,007 sec)

The issue is that MySQL is doing type promotion, CHAR(10) COLLATE binary is being promoted to BINARY field:

mysql> SHOW CREATE TABLE t;
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                          |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t     | CREATE TABLE `t` (
  `id` int NOT NULL,
  `col_1` char(10) NOT NULL DEFAULT 'AXw',
  `col_2` binary(10) NOT NULL DEFAULT 'AXw\0\0\0\0\0\0\0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0,003 sec)

altmannmarcelo avatar Apr 30 '25 18:04 altmannmarcelo

@altmannmarcelo - What problem does this result in?

gvsg-rs avatar May 01 '25 16:05 gvsg-rs

@gvsg-rs We are producing different results than upstream in the Text protocol:

Upstream: 0x41587700000000000000 Readyset: AXw

altmannmarcelo avatar May 05 '25 13:05 altmannmarcelo

Correctness issue. Must be fixed sooner rather than later.

gvsg-rs avatar May 08 '25 16:05 gvsg-rs

Likely fixed by https://gerrit.readyset.name/c/readyset/+/9326 if I had to guess

mvzink avatar Sep 11 '25 17:09 mvzink