Bug #110696 A Query with utf8 string literal returns empty set.
Submitted: 14 Apr 2023 11:40 Modified: 14 Apr 2023 12:16
Reporter: Yoshiharu Sato Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:8.0.32 OS:Windows (Windows Server 2019)
Assigned to: CPU Architecture:Any

[14 Apr 2023 11:40] Yoshiharu Sato
Description:
My program runs the query 

select * from
(select '実施済' as CHAPTERSTATUS) A
where A.CHAPTERSTATUS = '実施済';

I expected MySQL to return the '実施済' row.

I received an empty set.

I ran show warnings and got the following message. The query is executed with explain before that.

+---------+------+--------------------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                        |
+---------+------+--------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1300 | Cannot convert string '\xE5\xAE\x9F\xE6\x96\xBD...' from utf8mb3 to binary                                                           |
| Note    | 1003 | /* select#1 */ select NULL AS `CHAPTERSTATUS` from (/* select#2 */ select '実施済' AS `CHAPTERSTATUS` from DUAL  where false) `a`    |
+---------+------+--------------------------------------------------------------------------------------------------------------------------------------+

The same query was executed on MySQL 8.0.31 to get the '実施済' row.

If I modify the query as follows, it returns the correct result.

select * from
(select _utf8'実施済' as CHAPTERSTATUS) A
where A.CHAPTERSTATUS = '実施済';

## Additional Information

mysql> show variables where variable_name like 'character%';

+--------------------------+----------------------------------------------------+
| Variable_name            | Value|
+--------------------------+----------------------------------------------------+
| character_set_client     | utf8mb3|
| character_set_connection | utf8mb3|
| character_set_database   | utf8mb3|
| character_set_filesystem | binary|
| character_set_results    | utf8mb3|
| character_set_server     | utf8mb3|
| character_set_system     | utf8mb3|
| character_sets_dir       | C:\application\mysql-8.0.32-winx64\share\charsets\|
+--------------------------+----------------------------------------------------

How to repeat:
Execute the following SQL

select * from
(select '実施済' as CHAPTERSTATUS) A
where A.CHAPTERSTATUS = '実施済';

Suggested fix:
I want utf8 string literals to be treated as strings with the encoding specified in character_set_connection.
[14 Apr 2023 12:16] MySQL Verification Team
Hello Yoshiharu Sato San,

Thank you for the report and feedback.
Confirmed internally that this is duplicate of Bug #109699, which is fixed in  MySQL Server 8.0.33. Please see Bug #109699 for more details.

As a workaround, please set derived condition pushdown to off like this:
set optimizer_switch="derived_condition_pushdown=off";

regards,
Umesh