Bug #100806 Index changes behavior of BETWEEN

Submitted: 11 Sep 2020 5:36 Modified: 11 Sep 2020 7:36
Reporter: Yushan ZHANG Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:8.0.21, 5.7.31 OS:Any
Assigned to: CPU Architecture:Any

[11 Sep 2020 5:36] Yushan ZHANG
Description:
With index,

mysql> CREATE TABLE t1 (
    ->  mychar char(20) DEFAULT NULL,
    ->  KEY mykey (`mychar`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=binary;
Query OK, 0 rows affected (0.09 sec)

mysql> 
mysql> insert into t1 values (1), (2);
Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> 
mysql> SELECT mychar FROM t1 WHERE ( ( mychar)  BETWEEN ( 'd' ) AND (7 ) );
Empty set (0.00 sec)

Without index,

mysql> drop table if exists t1;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> 
mysql> CREATE TABLE t1 (
    ->  mychar char(20) DEFAULT NULL
    ->  #KEY mykey (`mychar`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=binary;
Query OK, 0 rows affected (0.05 sec)

mysql> 
mysql> insert into t1 values (1), (2);
Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> 
mysql> SELECT mychar FROM t1 WHERE ( ( mychar)  BETWEEN ( 'd' ) AND (7 ) );
+----------------------+
| mychar               |
+----------------------+
| 1                    |
| 2                    |
+----------------------+
2 rows in set, 4 warnings (0.00 sec)

How to repeat:
-- with index
drop table if exists t1;

CREATE TABLE t1 (
 mychar char(20) DEFAULT NULL,
 KEY mykey (`mychar`)
) ENGINE=InnoDB DEFAULT CHARSET=binary;

insert into t1 values (1), (2);

SELECT mychar FROM t1 WHERE ( ( mychar)  BETWEEN ( 'd' ) AND (7 ) );

-- without index
drop table if exists t1;

CREATE TABLE t1 (
 mychar char(20) DEFAULT NULL
 #KEY mykey (`mychar`)
) ENGINE=InnoDB DEFAULT CHARSET=binary;

insert into t1 values (1), (2);

SELECT mychar FROM t1 WHERE ( ( mychar)  BETWEEN ( 'd' ) AND (7 ) );
[11 Sep 2020 7:36] MySQL Verification Team
Hello Yushan ZHANG,

Thank you for the report and feedback.

regards,
Umesh

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

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