Bug #121751 Query with `~ CAST(FALSE AS BINARY)` and IN subquery fails with ERROR 3854 when index access is disabled

Submitted: 12 Nov 8:09 Modified: 19 Nov 7:08
Reporter: Hao Wang Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:8.0.46, 8.4.13, 9.7.4, 26.10 OS:Any
Assigned to: CPU Architecture:Any

[12 Nov 8:09] Hao Wang
Description:
The same query returns 1 row normally with the `/*+ INDEX(t1 c1) */` hint, but fails with `ERROR 3854 (HY000): Cannot convert string '\xCF' from binary to utf8mb4` when the index is disabled with `/*+ NO_INDEX(t1)*/`. 

How to repeat:
mysql> CREATE TABLE t1 (c1 TINYTEXT, UNIQUE (c1(1)));
Query OK, 0 rows affected (0.334 sec)

mysql> INSERT INTO t1 (c1) VALUES ('m8NdIyAU01');
Query OK, 1 row affected (0.113 sec)

-- with NO_INDEX hint
mysql> SELECT * FROM t1 WHERE (NOT ((~ CAST(FALSE AS BINARY)) IN (SELECT /*+ NO_INDEX(t1)*/ c1 FROM t1))) ORDER BY c1;
ERROR 3854 (HY000): Cannot convert string '\xCF' from binary to utf8mb4

-- with INDEX hint
mysql> SELECT * FROM t1 WHERE (NOT ((~ CAST(FALSE AS BINARY)) IN (SELECT /*+ INDEX(t1 c1) */c1 FROM t1))) ORDER BY c1;
+------------+
| c1         |
+------------+
| m8NdIyAU01 |
+------------+
1 row in set, 1 warning (0.007 sec)

-- check warnings
mysql> show warnings;
+---------+------+---------------------------------------------------------+
| Level   | Code | Message                                                 |
+---------+------+---------------------------------------------------------+
| Warning | 1366 | Incorrect string value: '\xCF' for column 'c1' at row 1 |
+---------+------+---------------------------------------------------------+
1 row in set (0.004 sec)
[19 Nov 7:08] Chaithra Marsur Gopala Reddy
Hi Hao Wang,

Thank you for the test case. Verified as described.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.048 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.