我有一些推荐信表
CREATE TABLE IF NOT EXISTS `testimonials` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`description` text COLLATE utf8_unicode_ci NOT NULL,
`user` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`status` enum('active','test','inactive','') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'active',
`t_order` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `t_order` (`t_order`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=26 ;还有一些简单的任务:启用手动排序。
SELECT 查询外观:
mysql> EXPLAIN SELECT t_order, id, title, description FROM testimonials WHERE status = 'active' ORDER BY t_order DESC;输出:
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
| 1 | SIMPLE | testimonials | ALL | NULL | NULL | NULL | NULL | 23 | Using where; Using filesort |ORDER BY使用索引字段,但EXPLAIN仍然显示Using filesort。
为什么不能从索引中执行排序?查询的内容?
谢谢)
发布于 2016-03-03 13:44:07
key列显示使用的索引及其null。只使用where意味着您正在使用限制行的位置.For查询。
ALTER TABLE testimonials ADD KEY(status,t_order )假设您有足够的行,那么索引是最好的索引。(对于极少数行,表扫描要比索引快。)
https://stackoverflow.com/questions/35773725
复制相似问题