Bug #107585 Incorrect result in semi-join and left-join

Submitted: 17 Jun 2022 10:29 Modified: 17 Jun 2022 11:16
Reporter: Wang Ke Email Updates:
Status: Verified 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, left join, semijoin

[17 Jun 2022 10:29] Wang Ke
Description:
Hello, I found a test case which causes mysql produce incorrect result. The behavior is as follows:

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

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

mysql> INSERT INTO t0 ( c0 ) VALUES ( '0.5' ) ;
Query OK, 1 row affected (0.03 sec)

mysql> INSERT INTO t1 ( c0 ) VALUES ( 0 ) , ( 1 ) , ( - 4 ) ;
Query OK, 3 rows affected (0.02 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> SELECT t0.c0 FROM t0 WHERE t0.c0 IN ( SELECT ra0.c0 FROM t1 LEFT JOIN ( SELECT t0.c0 FROM t1 ra1 WHERE ra1.c0 > ra1.c0 ) ra0 ON false );
+------+
| c0   |
+------+
| 0.5  |
+------+
1 row in set (0.01 sec)

```

I believe that the result of the SELECT query should be empty, but the server fetched a row, which I think is incorrect.

By the way, for your reference, I notice that the query planner creates a plan which contains three tables, and the access order of these tables is: (t0, t1, ra1). By changing the access order (in my own method), I can get the correct result, of which the access order is: (t1, ra1, t0).

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

Thank you for the report and test case.

regards,
Umesh

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

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