Bug #107576 Incorrect result when comparing 0 and -0 when using materialization-lookup

Submitted: 16 Jun 2022 7:34 Modified: 30 Sep 12:39
Reporter: Wang Ke Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:8.0.29 OS:Ubuntu (ubuntu 20.04)
Assigned to: CPU Architecture:x86
Tags: incorrect result, materialization

[16 Jun 2022 7:34] Wang Ke
Description:
I found a test case that causes mysql server to produce incorrect results, the behavior is listed as follows:

```
mysql> CREATE TABLE t0 ( c0 DOUBLE ) ; 
Query OK, 0 rows affected (0.15 sec)

mysql> CREATE TABLE t1 ( c1 DOUBLE ) ; 
Query OK, 0 rows affected (0.13 sec)

mysql> INSERT INTO t0 VALUES  ( 0 ); 
Query OK, 1 row affected (0.02 sec)

mysql> INSERT INTO t1 VALUES ( '-0' );
Query OK, 1 row affected (0.03 sec)

mysql> SELECT t0.c0 FROM t0 WHERE t0.c0 IN (SELECT t1.c1 FROM t1 WHERE t0.c0 = t1.c1);
+------+
| c0   |
+------+
|    0 |
+------+
1 row in set (0.00 sec)

mysql> EXPLAIN SELECT t0.c0 FROM t0 WHERE t0.c0 IN (SELECT t1.c1 FROM t1 WHERE t0.c0 = t1.c1);
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+------------------------------------------------------------+
| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra                                                      |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+------------------------------------------------------------+
|  1 | SIMPLE      | t0    | NULL       | ALL  | NULL          | NULL | NULL    | NULL |    1 |   100.00 | NULL                                                       |
|  1 | SIMPLE      | t1    | NULL       | ALL  | NULL          | NULL | NULL    | NULL |    1 |   100.00 | Using where; FirstMatch(t0); Using join buffer (hash join) |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+------------------------------------------------------------+
2 rows in set, 2 warnings (0.00 sec)

mysql> SET SESSION optimizer_switch='loosescan=off,firstmatch=off,duplicateweedout=off';
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT t0.c0 FROM t0 WHERE t0.c0 IN (SELECT t1.c1 FROM t1 WHERE t0.c0 = t1.c1);
Empty set (0.00 sec)

mysql> EXPLAIN SELECT t0.c0 FROM t0 WHERE t0.c0 IN (SELECT t1.c1 FROM t1 WHERE t0.c0 = t1.c1);
+----+--------------+-------------+------------+--------+---------------------+---------------------+---------+---------------------------+------+----------+-------------+
| id | select_type  | table       | partitions | type   | possible_keys       | key                 | key_len | ref                       | rows | filtered | Extra       |
+----+--------------+-------------+------------+--------+---------------------+---------------------+---------+---------------------------+------+----------+-------------+
|  1 | SIMPLE       | t0          | NULL       | ALL    | NULL                | NULL                | NULL    | NULL                      |    1 |   100.00 | Using where |
|  1 | SIMPLE       | <subquery2> | NULL       | eq_ref | <auto_distinct_key> | <auto_distinct_key> | 18      | mytest.t0.c0,mytest.t0.c0 |    1 |   100.00 | NULL        |
|  2 | MATERIALIZED | t1          | NULL       | ALL    | NULL                | NULL                | NULL    | NULL                      |    1 |   100.00 | NULL        |
+----+--------------+-------------+------------+--------+---------------------+---------------------+---------+---------------------------+------+----------+-------------+
3 rows in set, 2 warnings (0.00 sec)
```

In this test case, when I disabled loosescan, firstmatch and duplicateweedout, and forced the optimizer to use materialization-lookup, the result is incorrect, which failed to fetch the row.

How to repeat:
Just run the test case.
[16 Jun 2022 8:50] MySQL Verification Team
Hello Ke Wang,

Thank you for the report and test case.

regards,
Umesh
[30 Sep 12:39] Knut Anders Hatlen
This seems to have been fixed in MySQL 8.1.0. Closing as duplicate of bug#117845.

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

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