Bug #120581 unique index causes incorrect result for IN comparison with implicit type conversion

Submitted: 31 May 9:02 Modified: 1 Jun 6:16
Reporter: fan liu Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:8.0.44 OS:MacOS
Assigned to: CPU Architecture:Any

[31 May 9:02] fan liu
Description:
A SELECT query returns an empty set when a UNIQUE index exists.
After dropping the index, the expected row is returned.

SELECT t0.c1 FROM t0 WHERE (COALESCE(NULL, '8h')) IN (t0.c1);
empty set;
drop index i0 on t0;
SELECT t0.c1 FROM t0 WHERE (COALESCE(NULL, '8h')) IN (t0.c1);
c1|
--+
 8|

How to repeat:
DROP DATABASE IF EXISTS test;
CREATE DATABASE test;
USE test;
CREATE TABLE `t0` (
  `c1` decimal(10,0) DEFAULT NULL,
  UNIQUE KEY `i0` (`c1`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INSERT INTO t0(c1) VALUES(8);
INSERT INTO t0(c1) VALUES(NULL);
SELECT t0.c1 FROM t0 WHERE (COALESCE(NULL, '8h')) IN (t0.c1);
empty set;
drop index i0 on t0;
SELECT t0.c1 FROM t0 WHERE (COALESCE(NULL, '8h')) IN (t0.c1);
c1|
--+
 8|
[1 Jun 6:16] Chaithra Marsur Gopala Reddy
Hi 	fan liu,

Thank you for the test case . Verified as described.

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

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