Bug #118019 Wrong Right Join with a subquery containing distinct and wrong NULL-value expression optimization
| Submitted: | 20 Apr 2025 16:30 | Modified: | 2 Apr 9:47 |
|---|---|---|---|
| Reporter: | Zhaokun Xiang | Email Updates: | |
| Status: | Duplicate | Impact on me: | |
| Category: | MySQL Server: Optimizer | Severity: | S2 (Serious) |
| Version: | 9.0, 8.0, 9.3.0, 8.4.5, 8.0.42 | OS: | Any |
| Assigned to: | CPU Architecture: | Any |
[21 Apr 2025 7:50]
MySQL Verification Team
Hello Zhaokun Xiang, Thank you for the report and feedback. Verified as described. regards, Umesh
[2 Apr 9:47]
Chaithra Marsur Gopala Reddy
This is identified as duplicate of https://bugs.mysql.com/bug.php?id=119780
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.040 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.
Description: Hi, MySQL developers. Please see below test cases. The second query produces empty results, which is wrong, because (subQuery1.col0) IS UNKNOWN should be evaluated as TRUE. ``` CREATE TABLE t1(c0 INT, c1 INT); CREATE TABLE t2(c0 INT, c1 INT); INSERT INTO t1(c0, c1) VALUES(NULL, NULL); SELECT * FROM t2 RIGHT JOIN (SELECT DISTINCT t1.c0 and t1.c1 AS col0 FROM t1) as subQuery1 ON true; -- c0, c1, col0 -- NULL, NULL, NULL SELECT * FROM t2 RIGHT JOIN (SELECT DISTINCT (t1.c0 and t1.c1) AS col0 FROM t1) as subQuery1 ON true where (subQuery1.col0) IS UNKNOWN; -- empty result, which is wrong. -- '(subQuery1.col0) IS UNKNOWN' should be evaluated as true, and then this query should produce NULL,NULL,NULL SELECT * FROM t2 RIGHT JOIN (SELECT DISTINCT (NULL) AS col0 FROM t1) as subQuery1 ON true where (subQuery1.col0) IS UNKNOWN; -- NULL,NULL,NULL -- if I change '(t1.c0 and t1.c1)' to NULL, this query then produces correct result. So I guess there are also some bugs in the optimization of expression '(t1.c0 and t1.c1)'. ``` How to repeat: CREATE TABLE t1(c0 INT, c1 INT); CREATE TABLE t2(c0 INT, c1 INT); INSERT INTO t1(c0, c1) VALUES(NULL, NULL); SELECT * FROM t2 RIGHT JOIN (SELECT DISTINCT t1.c0 and t1.c1 AS col0 FROM t1) as subQuery1 ON true; -- c0, c1, col0 -- NULL, NULL, NULL SELECT * FROM t2 RIGHT JOIN (SELECT DISTINCT (t1.c0 and t1.c1) AS col0 FROM t1) as subQuery1 ON true where (subQuery1.col0) IS UNKNOWN; -- empty result, which is wrong. SELECT * FROM t2 RIGHT JOIN (SELECT DISTINCT (NULL) AS col0 FROM t1) as subQuery1 ON true where (subQuery1.col0) IS UNKNOWN; -- NULL,NULL,NULL