Bug #117945 UNION operation may return wrong result[

Submitted: 11 Apr 2025 11:10 Modified: 13 Oct 9:29
Reporter: jinhui lai Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:9.2.0 OS:Ubuntu (22.04)
Assigned to: CPU Architecture:Any

[11 Apr 2025 11:10] jinhui lai
Description:
Queries generated with logical partitioning (IN & NOT IN) and UNION operation may return incorrect results, inconsistent with their equivalent queries.

How to repeat:
docker run -it --name mysql-latest -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:latest
DROP TABLE IF EXISTS t0,t1;
CREATE TABLE t0(c0 FLOAT PRIMARY KEY) ENGINE = HEAP;
CREATE TABLE IF NOT EXISTS t1 LIKE t0;
INSERT INTO t1(c0) VALUES("-0.0"),(0.0);
INSERT INTO t0(c0) VALUES(0);

-- For the above two tables, i expect the following semantically equivalent queries should return the same results:

SELECT DISTINCT * FROM t0 INNER JOIN t1 ON t0.c0 IN (t1.c0) OR t0.c0 NOT IN (t1.c0); 
+----+----+
| c0 | c0 |
+----+----+
|  0 | -0 |
|  0 |  0 |
+----+----+

SELECT DISTINCT * FROM t0 INNER JOIN t1 ON t0.c0 IN (t1.c0) 
UNION ALL
SELECT DISTINCT * FROM t0 INNER JOIN t1 ON t0.c0 NOT IN (t1.c0); 
+----+----+
| c0 | c0 |
+----+----+
|  0 |  0 |
+----+----+

SELECT DISTINCT * FROM t0 INNER JOIN t1 ON t0.c0 IN (t1.c0) 
UNION
SELECT DISTINCT * FROM t0 INNER JOIN t1 ON t0.c0 NOT IN (t1.c0); 
+----+----+
| c0 | c0 |
+----+----+
|  0 |  0 |
+----+----+

SELECT DISTINCT * FROM t0 INNER JOIN t1; 
+----+----+
| c0 | c0 |
+----+----+
|  0 | -0 |
|  0 |  0 |
+----+----+

However, the actual results are inconsistent. Maybe the UNION operation return wrong result.
[11 Apr 2025 12:23] MySQL Verification Team
Hello jinhui lai,

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

regards,
Umesh
[28 May 1:13] MySQL Admin
Posted by developer: Bug status updated to 'Patch pending'
[13 Oct 9:29] Knut Anders Hatlen
Looks like the same issue as bug#67978. Closing as duplicate.

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

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