Bug #119635 Returns incorrect query results when using the between keyword
Submitted: 7 Jan 7:27 Modified: 7 Jan 11:07
Reporter: Jason Tang Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:8.0.42+ OS:Any
Assigned to: CPU Architecture:Any

[7 Jan 7:27] Jason Tang
Description:
MySQL 8.0.42 fails to validate an invalid index expression (bitwise OR between float and string literal), allowing creation of a table with malformed index. This causes incorrect query results when using the index, returning empty sets for queries that should return rows.

How to repeat:
This also can be reproduced in the latest version of MySQL.

DROP DATABASE IF EXISTS database2;
CREATE DATABASE database2;
USE database2;
SET SESSION join_buffer_size = 9223372036854775807;
SET SESSION max_sort_length = 4;
 CREATE TABLE `t0` (
  `c0` float NOT NULL /*!50606 STORAGE DISK */ COMMENT 'asdf',
  PRIMARY KEY (`c0`),
  UNIQUE KEY `c0` (`c0`),
  KEY `i0` (((0 = ~((case `c0` when `c0` then -(899345703) else `c0` end))))) USING BTREE,
  KEY `i74` (((((0 = NULL) xor (0 <> -(`c0`))) = (((0 <> 0.8846853433836313) and (0 <> `c0`)) between (0.8858764362024204 | _gbk'GC]d>(r2') and (1.167570634E9 <= `c0`)))))
);
INSERT DELAYED IGNORE INTO t0(c0) VALUES(0), (996880841), (-1);

SELECT t0.c0 AS ref0 FROM t0;
+-----------+
| ref0      |
+-----------+
|        -1 |
|         0 |
| 996881000 |
+-----------+
3 rows in set (0.00 sec)

SELECT t0.c0 AS ref0 FROM t0 WHERE ((t0.c0) BETWEEN (0.9494310423666807) AND (1.7976931348623157E308));
Empty set (0.00 sec)

Expecting to return row 996881000 rather than the empty set.
[7 Jan 11:07] Chaithra Marsur Gopala Reddy
Hi Jason Tang,

Thank you for the test case. Verified as described.