我有下表:
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行)进行排序而不是使用索引?
| 归档时间: |
|
| 查看次数: |
174 次 |
| 最近记录: |