Bug #119741 internal_tmp_mem_storage_engine = MEMORY setting makes the DISTINCTROW returns incorrect result on 0 and -0

Submitted: 22 Jan 7:00 Modified: 13 Oct 9:31
Reporter: chi zhang (OCA) Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S1 (Critical)
Version:8.0.44 OS:Any
Assigned to: CPU Architecture:Any

[22 Jan 7:00] chi zhang
Description:
Hi,

In the following test case, there are two equivalent queries, the normal SELECT returns 0 and -0 for ref0, while the prepared SELECT only returns 0. If I remove the `SET SESSION internal_tmp_mem_storage_engine = MEMORY;`, then both queries only return `0`.

```
CREATE TABLE t0(c1 DOUBLE  ) ;
SET SESSION internal_tmp_mem_storage_engine = MEMORY;
INSERT INTO t0(c1) VALUES(-0.0), ("-0.0");
ref0    ref2
0       0
-0      0

SELECT DISTINCTROW t0.c1 AS ref0, ('a') NOT IN ((- ((CAST(0.8 AS DOUBLE)) LIKE (t0.c1)))) AS ref2 FROM t0 GROUP BY t0.c1, ('a') NOT IN ((- ((CAST(0.8 AS DOUBLE)) LIKE (t0.c1))));
SET @a = 0.8;
SET @b = 0.8;
PREPARE prepare_query FROM "SELECT DISTINCTROW t0.c1 AS ref0, ('a') NOT IN ((- ((CAST(? AS DOUBLE)) LIKE (t0.c1)))) AS ref2 FROM t0 GROUP BY t0.c1, ('a') NOT IN ((- ((CAST(? AS DOUBLE)) LIKE (t0.c1))))";
EXECUTE prepare_query USING @a,@b;
ref0    ref2
0       0
```

How to repeat:
```
CREATE TABLE t0(c1 DOUBLE  ) ;
SET SESSION internal_tmp_mem_storage_engine = MEMORY;
INSERT INTO t0(c1) VALUES(-0.0), ("-0.0");
SELECT DISTINCTROW t0.c1 AS ref0, ('a') NOT IN ((- ((CAST(0.8 AS DOUBLE)) LIKE (t0.c1)))) AS ref2 FROM t0 GROUP BY t0.c1, ('a') NOT IN ((- ((CAST(0.8 AS DOUBLE)) LIKE (t0.c1))));
SET @a = 0.8;
SET @b = 0.8;
PREPARE prepare_query FROM "SELECT DISTINCTROW t0.c1 AS ref0, ('a') NOT IN ((- ((CAST(? AS DOUBLE)) LIKE (t0.c1)))) AS ref2 FROM t0 GROUP BY t0.c1, ('a') NOT IN ((- ((CAST(? AS DOUBLE)) LIKE (t0.c1))))";
EXECUTE prepare_query USING @a,@b;
```
[22 Jan 8:34] 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.056 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.