Bug #118071 Indexed table fails WHERE filtering with different charset value
Submitted: 28 Apr 13:09 Modified: 28 Apr 14:04
Reporter: Eimantas Jatkonis Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:8.0.41, 8.0.42, 8.4.5, 9.3.0 OS:Any
Assigned to: CPU Architecture:Any

[28 Apr 13:09] Eimantas Jatkonis
Description:
Table "CountryIndexed" with utf8mb4 charset and indexed column "Name" fails WHERE Name LIKE @Name.
@Name is latin7 charset.

If table has no index on column "Name", like in table "CountryRaw", everything works as expected. 

Example contains tables with few values, and 4 SELECT's with "=" or "LIKE" conditions
All SELECT's expected to give result, but 2nd is missing result.

How to repeat:
SET names utf8mb4;

DROP DATABASE IF EXISTS TestCharset;
CREATE DATABASE TestCharset;
USE TestCharset;

CREATE TABLE CountryIndexed (Name CHAR(255), INDEX LK_Name (Name)) ENGINE=InnoDB CHARSET utf8mb4;
INSERT INTO CountryIndexed VALUES ('India'), ('Šri Lanka');

CREATE TABLE CountryRaw (Name CHAR(255)) ENGINE=InnoDB CHARSET utf8mb4;
INSERT INTO CountryRaw VALUES ('India'), ('Šri Lanka');

SET @Name = CONVERT('Šri Lanka' USING latin7);
SELECT CHARSET(@Name), COLLATION(@Name);

SELECT * FROM CountryIndexed WHERE Name = @Name;
#THIS ONE FAILS, THE RESULT IS EXPECTED, NONE IS GIVEN
SELECT * FROM CountryIndexed WHERE Name LIKE @Name;

SELECT * FROM CountryRaw WHERE Name = @Name;
SELECT * FROM CountryRaw WHERE Name LIKE @Name;
[28 Apr 14:04] MySQL Verification Team
Hello Eimantas Jatkonis,

Thank you for the report and test case.

Thanks,
Umesh