Bug #90089 Year type column have index , between operate sql , the result is wrong .
Submitted: 15 Mar 2018 12:57 Modified: 15 Mar 2018 17:35
Reporter: i i Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DML Severity:S2 (Serious)
Version:5.5/5.6/5.7/8.0 OS:Linux
Assigned to: CPU Architecture:Any
Tags: INDEX

[15 Mar 2018 12:57] i i
Description:
When column type is year type and have index . The table of year_test column value is more than 31 . And the table  records more than 6 . The follow sql: select count(*) FROM  select_tab  where 31 between 31 AND (year_test)   have wrong result. Expect result is records count ,but actual is 0.

Mysql version is :5.7.14 

How to repeat:
Here is the test case:
mysql> /* Create table and  index on year_test column */
mysql> CREATE TABLE `select_tab` (
    ->   `pk` bigint(11) NOT NULL AUTO_INCREMENT,
    ->   `year_test` year(4) DEFAULT NULL,
    ->   PRIMARY KEY (`pk`),
    ->   KEY `index_year_test` (`year_test`)
    -> ) ENGINE=InnoDB AUTO_INCREMENT=1001 DEFAULT CHARSET=gbk ROW_FORMAT=DYNAMIC;

mysql>  /* insert 6 records to table */

mysql> insert into  select_tab  (pk , year_test) values(1,2014);
Query OK, 1 row affected (0.00 sec)

mysql> insert into  select_tab  (pk , year_test) values(2,2014);
Query OK, 1 row affected (0.00 sec)

mysql> insert into  select_tab  (pk , year_test) values(3,2014);
Query OK, 1 row affected (0.00 sec)

mysql> insert into  select_tab  (pk , year_test) values(4,2014);
Query OK, 1 row affected (0.00 sec)

mysql> insert into  select_tab  (pk , year_test) values(5,2014);
Query OK, 1 row affected (0.00 sec)

mysql> insert into  select_tab  (pk , year_test) values(6,2014);
Query OK, 1 row affected (0.00 sec)

mysql>  /* execute  follow sql  and have right  result  */
mysql> select count(*) FROM  select_tab  where 31 between 31 AND (year_test) ;
 
+----------+
| count(*) |
+----------+
|        6 |
+----------+
1 row in set (0.00 sec)

mysql>  /*add one more records to table */
mysql> insert into  select_tab  (pk , year_test) values(7,2014);
Query OK, 1 row affected (0.00 sec)

mysql>  /* execute  follow sql  and have wrong result ,expect result is  7 ,but actual is 0  */
mysql> select count(*) FROM  select_tab  where 31 between 31 AND (year_test);
+----------+
| count(*) |
+----------+
|        0 |
+----------+
[15 Mar 2018 17:34] MySQL Verification Team
Results 5.5/5.6/5.7/8.0

Attachment: 90089.txt (text/plain), 15.20 KiB.

[15 Mar 2018 17:35] MySQL Verification Team
Thank you for the bug report.