Bug #110984 Subqueries with 'limit 1' cause concat strings to report errors
Submitted: 11 May 2023 2:24 Modified: 1 Jul 12:17
Reporter: hao chen Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S1 (Critical)
Version:8031, 5.7.42, 8.0.33 OS:Linux
Assigned to: CPU Architecture:x86

[11 May 2023 2:24] hao chen
Description:
Subqueries with 'limit 1' cause concat strings to report errors

How to repeat:

Here are the steps to reproduce:

mysql> create database test_db;
Query OK, 1 row affected (0.01 sec)

mysql> use test_db;
Database changed
mysql> create table t1 (
    ->  flowid varchar(32)
    -> ) charset=gbk collate=gbk_bin;
Query OK, 0 rows affected (0.30 sec)

mysql> show create table t1 \G
*************************** 1. row ***************************
       Table: t1
Create Table: CREATE TABLE `t1` (
  `flowid` varchar(32) COLLATE gbk_bin DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=gbk COLLATE=gbk_bin
1 row in set (0.01 sec)

mysql> insert t1 values('xxx');
Query OK, 1 row affected (0.01 sec)

mysql> select * from t1 ;
+--------+
| flowid |
+--------+
| xxx    |
+--------+
1 row in set (0.00 sec)

mysql>
mysql> select concat(abc, flowid) from (select 'yyy-' as abc, flowid from t1) as alias;
+---------------------+
| concat(abc, flowid) |
+---------------------+
| yyy-xxx             |
+---------------------+
1 row in set (0.00 sec)

mysql> select concat(abc, flowid) from (select 'yyy-' as abc, flowid from t1 limit 1) as alias;
ERROR 1267 (HY000): Illegal mix of collations (utf8mb4_0900_ai_ci,COERCIBLE) and (gbk_bin,IMPLICIT) for operation 'concat'
mysql>

Suggested fix:
Expected results:
	The last SQL does not report an error.
[11 May 2023 6:57] MySQL Verification Team
Hello hao chen,

Thank you for the report and test case.

regards,
Umesh
[1 Jul 12:15] Roy Lyseng
Posted by developer:
 
Fixed in release 9.1 with the patch for bug#34646522