Bug #112910 Incorrect results when add an uncorrelated row
Submitted: 1 Nov 2023 7:20 Modified: 1 Nov 2023 7:30
Reporter: Wang Ke Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:8.1.0, 8.0.35 OS:Any
Assigned to: CPU Architecture:Any
Tags: incorrect result

[1 Nov 2023 7:20] Wang Ke
Description:
Hello, consider this statement:

```
mysql> SELECT ( CAST( 1/16 AS DOUBLE PRECISION ) ) ;
+--------------------------------------+
| ( CAST( 1/16 AS DOUBLE PRECISION ) ) |
+--------------------------------------+
|                               0.0625 |
+--------------------------------------+
1 row in set (0.00 sec)

```

Yes, the result is correct, and it's exactly as expected.

And then, consider this statement:

```
mysql> SELECT * FROM ( VALUES ROW ( 'a', 0 ) ) t0 WHERE t0.column_1 = ( CAST( 1/16 AS DOUBLE PRECISION ) ) ;
Empty set (0.00 sec)

```

Since the second column (column_1) values 0, not equals to 0.0625, the where condition is false, and the result is as expected, empty.

But when we add another row to this temporary table:

```
mysql> SELECT * FROM ( VALUES ROW ( 'a', 0 ), ROW ( 'b', 1 ) ) t0 WHERE t0.column_1 = ( CAST( 1/16 AS DOUBLE PRECISION ) ) ;
+----------+----------+
| column_0 | column_1 |
+----------+----------+
| a        |        0 |
+----------+----------+
1 row in set (0.01 sec)

```

The result is not expected, it's not empty.

How to repeat:
Test case:

```
SELECT * FROM ( VALUES ROW ( 'a', 0 ) ) t0 WHERE t0.column_1 = ( CAST( 1/16 AS DOUBLE PRECISION ) ) ; -- expected: empty, actually: empty

SELECT * FROM ( VALUES ROW ( 'a', 0 ), ROW ( 'b', 1 ) ) t0 WHERE t0.column_1 = ( CAST( 1/16 AS DOUBLE PRECISION ) ) ; -- expected: empty, actually: 1 row
```
[1 Nov 2023 7:30] MySQL Verification Team
Hello Ke Wang,

Thank you for the report and test case.

regards,
Umesh