CREATE TABLE `test_date` (

  `id` int(11) DEFAULT NULL,

  `gmt_create` varchar(100) DEFAULT NULL,

  KEY `ind_gmt_create` (`gmt_create`)

) ENGINE=InnoDB AUTO_INCREMENT=524272;

 

5.5:

mysql> explain  select * from test_date where gmt_create BETWEEN DATE_ADD(NOW(), INTERVAL - 1 MINUTE) AND        DATE_ADD(NOW(), INTERVAL 15 MINUTE) ;

+----+-------------+-----------+-------+----------------+----------------+---------+------+------+-------------+

| id | select_type | table     | type  | possible_keys  | key            | key_len | ref  | rows | Extra       |

+----+-------------+-----------+-------+----------------+----------------+---------+------+------+-------------+

|  1 | SIMPLE      | test_date | range | ind_gmt_create | ind_gmt_create | 303     | NULL |    1 | Using where |

 

5.6:

mysql> explain select * from test_date where gmt_create BETWEEN DATE_ADD(NOW(), INTERVAL - 1 MINUTE) AND        DATE_ADD(NOW(), INTERVAL 15 MINUTE) ; 

+----+-------------+-----------+------+----------------+------+---------+------+---------+-------------+

| id | select_type | table     | type | possible_keys  | key  | key_len | ref  | rows    | Extra       |

+----+-------------+-----------+------+----------------+------+---------+------+---------+-------------+

|  1 | SIMPLE      | test_date | ALL  | ind_gmt_create | NULL | NULL    | NULL | 2849555 | Using where |

+----+-------------+-----------+------+----------------+------+---------+------+---------+-------------+

| Warning | 1739 | Cannot use range access on index 'ind_gmt_create' due to type or collation conversion on field 'gmt_create'      

相关文章:

  • 2022-12-23
  • 2021-12-26
  • 2021-10-20
  • 2022-12-23
  • 1970-01-01
  • 2021-09-19
  • 2021-12-05
  • 2022-12-23
猜你喜欢
  • 2021-10-05
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2022-12-23
相关资源
相似解决方案