Bug #114922 Incorrect query results caused by different data conversion
Submitted: 8 May 9:25 Modified: 8 May 9:57
Reporter: John Jove Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S1 (Critical)
Version:8.0.36 OS:Any
Assigned to: CPU Architecture:Any

[8 May 9:25] John Jove
Description:
Run the following statements, in which the query returns an incorrect query result.

The possible root cause could be that an incorrect data conversion is used when comparing 1 and '1a', since when evaluating SELECT 1='1a', 1 is returned. For SELECT 0='a', 1 is also returned.

Moreover, I got the following warnings when evaluating the query.
mysql> SHOW WARNINGS;
+---------+------+--------------------------------------------------------+
| Level   | Code | Message                                                |
+---------+------+--------------------------------------------------------+
| Warning | 1366 | Incorrect decimal value: 'a' for column 'c1' at row 1  |
| Warning | 1366 | Incorrect decimal value: '1a' for column 'c1' at row 2 |
+---------+------+--------------------------------------------------------+
2 rows in set (0.00 sec)

How to repeat:
CREATE TABLE t1 ( c1 decimal(10,0), UNIQUE KEY i1 (c1));
CREATE TABLE t2 ( c1 text NOT NULL);
INSERT INTO t1(c1) VALUES (0), (1);
INSERT INTO t2(c1) VALUES ('a'), ('1a');

SELECT  /*+ JOIN_ORDER(t2,t1) */ t1.c1 FROM t1 USE INDEX (i1) NATURAL JOIN t2; -- actual: {0}, expected: {0,1}
[8 May 9:57] MySQL Verification Team
Hello John,

Thank you for the report and test case.
Verified as described.

regards,
Umesh