Description:
Dear verification team,
A query result of rpad function unexpectedly contains messy code when there is Chines string in rpad_str.
Please reference to `How to repeat` part for detail.
How to repeat:
1. charset of my charset configured like this
mysql> show variables like '%char%';
+--------------------------+-------------------------------+
| Variable_name | Value |
+--------------------------+-------------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /home/yxx_git/share/charsets/ |
+--------------------------+-------------------------------+
8 rows in set (0.04 sec)
2. create a table `t1` with utf8mb4 charset
CREATE TABLE `t1` (
`id` int(11) NOT NULL,
`c1` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
mysql> insert into t1 values (111,'111');
Query OK, 1 row affected (0.01 sec)
3. query fields of table `t1` with pad functions (pad with Chinese string)
mysql> select rpad(id, 11, '中文'), rpad(c1, 11, '中文') from t1;
+-------------------------------------------------------------+-----------------------------+
| rpad(id, 11, '中文') | rpad(c1, 11, '中文') |
+-------------------------------------------------------------+-----------------------------+
| 111ä¸æ–‡ä¸æ–‡ä¸æ–‡ä¸æ–‡ | 111中文中文中文中文 |
+-------------------------------------------------------------+-----------------------------+
1 row in set (0.01 sec)
mysql> select lpad(id, 11, '中文'), lpad(c1, 11, '中文') from t1;
+-----------------------------+-----------------------------+
| lpad(id, 11, '中文') | lpad(c1, 11, '中文') |
+-----------------------------+-----------------------------+
| 中文中文中文中文111 | 中文中文中文中文111 |
+-----------------------------+-----------------------------+
1 row in set (0.00 sec)
4. problem
Now that I have configured charset as utf8mb4, why did I get messy code ?
Suggested fix:
None