为什么我的查询不会在我的datetime字段中使用索引?

use*_*084 6 mysql

我有下表:

CREATE TABLE 'tableA'(
 `col1` int(11) NOT NULL AUTO_INCREMENT,
  `col2` varchar(20) NOT NULL,
  `col3` int(11) NOT NULL,
  `col4` varchar(200) NOT NULL,
  `col5` varchar(15) NOT NULL,
  `col6` datetime NOT NULL,
  PRIMARY KEY (`col1`),
  UNIQUE KEY `col2,col3` (`col2`,`col3`),
  KEY `col6` (`col6`)
) ENGINE=InnoDB AUTO_INCREMENT=1881208 DEFAULT CHARSET=utf8
Run Code Online (Sandbox Code Playgroud)

我在col6上有一个索引,一个datetime列.我在表中有近2M行,日期范围从2007年1月1日到2012年11月27日.

当我运行以下内容时,它不使用我的索引:

EXPLAIN SELECT * FROM tableA ORDER BY col6 ASC


+----+-------------+----------+------+---------------+------+---------+------+---------+----------------+
| id | select_type | table    | type | possible_keys | key  | key_len | ref  | rows    | Extra          |
+----+-------------+----------+------+---------------+------+---------+------+---------+----------------+
|  1 | SIMPLE      | tableA | ALL  | NULL          | NULL | NULL    | NULL | 1933765 | Using filesort |
+----+-------------+----------+------+---------------+------+---------+------+---------+----------------+
Run Code Online (Sandbox Code Playgroud)

我尝试将datetime字段转换为整数,并将datetime转换为unix时间戳.但是,它仍然不会使用我的索引.我错过了什么?为什么优化器坚持通过大量行(在这种情况下为1,933,765行)进行排序而不是使用索引?

Ray*_*Ray 4

由于您没有根据索引来选择任何内容来缩小结果集,因此使用它只会导致通过点查找来查找主表中每一行的额外工作。