Bug #118061 wrong inner join result when adding an additional true expression
Submitted: 26 Apr 13:02 Modified: 28 Apr 7:40
Reporter: Zhaokun Xiang Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S1 (Critical)
Version:9.3, 8.4.5, 8.0.42 OS:Any
Assigned to: CPU Architecture:Any

[26 Apr 13:02] Zhaokun Xiang
Description:
Hi, MySQL developers,

Please see the below cases.

```
CREATE TABLE t0(c0 TEXT);
CREATE TABLE t1(c0 INT ZEROFILL);

INSERT INTO t0(c0) VALUES('0.1');
INSERT INTO t1(c0) VALUES(0);

select * from t0 inner join t1 on (((GREATEST(t0.c0, t1.c0)) = (t1.c0)));
-- t0.c0, t1.c0
--   0.1,  0

select * from t0 inner join t1 on (((GREATEST(t0.c0, t1.c0)) = (t1.c0))) and t1.c0=0.0;
-- t0.c0, t1.c0
--   0.1,  0

select * from t0 inner join t1 on (((GREATEST(t0.c0, t1.c0)) = (t1.c0))) and t1.c0=0;
-- empty result
-- wrong, should be same as the above two queries

```

In the second query, when we add a true expression 't1.c0=0.0', the query produces the same result as that of the first query. But when we change 't1.c0=0.0' into 't1.c0=0' as shown in the third query, the third query produces an empty result.

How to repeat:
```
CREATE TABLE t0(c0 TEXT);
CREATE TABLE t1(c0 INT ZEROFILL);

INSERT INTO t0(c0) VALUES('0.1');
INSERT INTO t1(c0) VALUES(0);

select * from t0 inner join t1 on (((GREATEST(t0.c0, t1.c0)) = (t1.c0)));
-- t0.c0, t1.c0
--   0.1,  0

select * from t0 inner join t1 on (((GREATEST(t0.c0, t1.c0)) = (t1.c0))) and t1.c0=0.0;
-- t0.c0, t1.c0
--   0.1,  0

select * from t0 inner join t1 on (((GREATEST(t0.c0, t1.c0)) = (t1.c0))) and t1.c0=0;
-- empty result
-- wrong, should be same as the above two queries

```
[28 Apr 7:40] MySQL Verification Team
Hello Zhaokun Xiang,

Thank you for the report and feedback.
Verified as described.

regards,
Umesh