Bug #111508 The query results are inconsistent when different optimizer options are used.
Submitted: 21 Jun 2023 7:06 Modified: 21 Jun 2023 8:21
Reporter: Chi Zhang Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:8.0.33 OS:Any
Assigned to: CPU Architecture:Any

[21 Jun 2023 7:06] Chi Zhang
Description:
Query results are inconsistent when the optimizer option block_nested_loop is enabled and disabled.

How to repeat:
1. Import data.

mysql> source test.sql

The test file is attached.

2. Run the SQL statement.

mysql> use test;
Database changed

mysql> set optimizer_switch='block_nested_loop=off';
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT a.datetime_col col1, COUNT(a.varchar_col) col4 FROM t1 a left join t1 b on (a.char_col,a.text_col) in (select char_col col1, text_col col2 from t1 a order by 1,2) group by 1 order by 1,2 limit 10;
+----------------------------+-------+
| col1                       | col4  |
+----------------------------+-------+
| 1000-01-01 00:00:00.000000 |  2675 |
| 1992-03-04 12:20:00.000000 |     0 |
| 1995-09-02 13:20:00.000000 |     0 |
| 1997-09-02 13:20:00.000000 |     0 |
| 1999-09-02 13:20:00.000000 |     0 |
| 2001-01-01 00:00:00.000000 | 29425 |
| 2001-02-01 00:00:00.000000 |  2675 |
| 2001-03-02 00:00:00.000000 | 29425 |
| 2001-04-06 00:00:00.000000 | 29425 |
| 2001-05-09 00:00:00.000000 | 29425 |
+----------------------------+-------+
10 rows in set (0.11 sec)

mysql> set optimizer_switch='block_nested_loop=on';
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT a.datetime_col col1, COUNT(a.varchar_col) col4 FROM t1 a left join t1 b on (a.char_col,a.text_col) in (select char_col col1, text_col col2 from t1 a order by 1,2) group by 1 order by 1,2 limit 10;
+----------------------------+------+
| col1                       | col4 |
+----------------------------+------+
| 1000-01-01 00:00:00.000000 |  535 |
| 1992-03-04 12:20:00.000000 |    0 |
| 1995-09-02 13:20:00.000000 |    0 |
| 1997-09-02 13:20:00.000000 |    0 |
| 1999-09-02 13:20:00.000000 |    0 |
| 2001-01-01 00:00:00.000000 |  535 |
| 2001-02-01 00:00:00.000000 |  535 |
| 2001-03-02 00:00:00.000000 |  535 |
| 2001-04-06 00:00:00.000000 |  535 |
| 2001-05-09 00:00:00.000000 |  535 |
+----------------------------+------+
10 rows in set (0.10 sec)

The query results are inconsistent!
[21 Jun 2023 7:07] Chi Zhang
data file.

Attachment: test.sql (application/octet-stream, text), 6.93 KiB.

[21 Jun 2023 8:21] MySQL Verification Team
Hello Chi Zhang,

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

regards,
Umesh