Bug #119708 INNER JOIN and STRAIGHT_JOIN produce different results with FLOAT UNIQUE column on MEMORY table

Submitted: 16 Jan 14:58 Modified: 13 Oct 9:31
Reporter: Weipeng Wang Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:8.0.44 OS:Linux
Assigned to: CPU Architecture:Any

[16 Jan 14:58] Weipeng Wang
Description:
STRAIGHT_JOIN and INNER JOIN produce different results despite being semantically equivalent and using identical WHERE predicates.

In the example below, the STRAIGHT_JOIN query returns a non-empty result set, while the corresponding INNER JOIN query returns an empty result set.

The difference is reproducible when using a MEMORY table with a FLOAT column defined as UNIQUE. Replacing the storage engine or removing the UNIQUE constraint prevents the issue from reproducing.

How to repeat:
CREATE TABLE t0(c0 FLOAT UNIQUE) ENGINE = MEMORY;
CREATE TABLE t1(c0 FLOAT ) ; 

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

SELECT * FROM t0 STRAIGHT_JOIN t1 WHERE t0.c0 = t1.c0 AND t1.c0 = -t1.c0;
/* returns 1 row: (0, 0) */
SELECT * FROM t0 INNER JOIN t1 WHERE t0.c0 = t1.c0 AND t1.c0 = -t1.c0;
/* returns empty set */
[17 Jan 5:22] Weipeng Wang
I found another minimal example that shows the same inconsistency.

In this case, the issue occurs with a non-UNIQUE index on a FLOAT column, where INNER JOIN incorrectly returns an empty result set, while STRAIGHT_JOIN returns the expected row.

```
CREATE TABLE t0(c0 FLOAT) ENGINE = MEMORY;
CREATE INDEX i0 ON t0(c0);
CREATE TABLE t1(c0 FLOAT);

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

SELECT * FROM t0 STRAIGHT_JOIN t1 WHERE -t1.c0 = t0.c0;
/* returns 1 row: (0, 0) */
SELECT * FROM t0 INNER JOIN t1    WHERE -t1.c0 = t0.c0;
/* returns empty set */
```
[8 Feb 12:32] Roy Lyseng
Thank you for the bug report.
Verified as described.
[13 Oct 9:31] 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.053 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.