淘先锋技术网

首页 1 2 3 4 5 6 7

我有一个拒绝使用索引的表,它总是使用filesort.

该表是:

CREATE TABLE `article` (

`ID` int(11) NOT NULL AUTO_INCREMENT,

`Category_ID` int(11) DEFAULT NULL,

`Subcategory` int(11) DEFAULT NULL,

`CTimestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,

`Publish` tinyint(4) DEFAULT NULL,

`Administrator_ID` int(11) DEFAULT NULL,

`Position` tinyint(4) DEFAULT '0',

PRIMARY KEY (`ID`),

KEY `Subcategory` (`Subcategory`,`Position`,`CTimestamp`,`Publish`),

KEY `Category_ID` (`Category_ID`,`CTimestamp`,`Publish`),

KEY `Position` (`Position`,`Category_ID`,`Publish`),

KEY `CTimestamp` (`CTimestamp`),

CONSTRAINT `article_ibfk_1` FOREIGN KEY (`Category_ID`) REFERENCES `category` (`ID`)

) ENGINE=InnoDB AUTO_INCREMENT=94290 DEFAULT CHARSET=utf8

查询是:

SELECT * FROM article ORDER BY `CTimestamp`;

解释是:

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

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

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

| 1 | SIMPLE | article | ALL | NULL | NULL | NULL | NULL | 63568 | Using filesort |

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

当我删除“ORDER BY”时,所有都正常工作.所有其他索引(子类别,位置等)在其他查询中正常工作.不幸的是,即使使用我的简单选择查询,也会拒绝使用时间戳.我相信我在这里缺少一些重要的东西.

如何让MySQL使用时间戳索引?

谢谢.