Bug #119686 Incorrect result when joined table has PRIMARY KEY and WHERE predicate involves CASE

Submitted: 15 Jan 8:37 Modified: 15 Jan 13:10
Reporter: Weipeng Wang Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:8.0.44 OS:Linux
Assigned to: CPU Architecture:x86

[15 Jan 8:37] Weipeng Wang
Description:
Adding a PRIMARY KEY changes the result from non-empty to empty.

Further simplification of the CASE expressions or replacing the DOUBLE constant (0.1) with an INTEGER prevents the issue from reproducing.

How to repeat:
--------------------------

DROP TABLE IF EXISTS t0;
DROP TABLE IF EXISTS t1;
CREATE TABLE t0(c0 INT);
CREATE TABLE t1(c0 INT);

INSERT INTO t0(c0) VALUES(1);
INSERT INTO t1(c0) VALUES(0);

SELECT * FROM t0, t1 WHERE (0 IN (CASE WHEN 0 THEN t1.c0 ELSE 2 END)) LIKE (CASE 0 WHEN t1.c0 IS NOT NULL THEN 0.1 ELSE 0 END) ;

result:
+------+------+
| c0   | c0   |
+------+------+
|    1 |    0 |
+------+------+
1 row in set (0.00 sec)

---------------------------

DROP TABLE IF EXISTS t0;
DROP TABLE IF EXISTS t1;
CREATE TABLE t0(c0 INT);     
CREATE TABLE t1(c0 INT PRIMARY KEY);

INSERT INTO t0(c0) VALUES(1);
INSERT INTO t1(c0) VALUES(0);

SELECT *FROM t0, t1 WHERE (0 IN (CASE WHEN 0 THEN t1.c0 ELSE 2 END)) LIKE (CASE 0 WHEN t1.c0 IS NOT NULL THEN 0.1 ELSE 0 END) ; 

Empty set (0.01 sec)
[15 Jan 13:10] Roy Lyseng
Thank you for the bug report.
Verified as described.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.051 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.