我查看了多个类似的帖子,试图获得关于如何重新定义我的索引的输入,但无法理解这一点。每次我包含ORDER语句时,它都使用filesort返回结果集。
下面是表定义和查询:
SELECT
`s`.`title`,
`s`.`price`,
`s`.`price_sale`
FROM `style` `s`
WHERE `s`.`isactive`=1 AND `s`.`department`='women'
ORDER
BY `s`.`ctime` DESC
CREATE TABLE IF NOT EXISTS `style` (
`id` mediumint(6) unsigned NOT NULL auto_increment,
`ctime` timestamp NOT NULL default CURRENT_TIMESTAMP,
`department` char(5) NOT NULL,
`isactive` tinyint(1) unsigned NOT NULL,
`price` float(8,2) unsigned NOT NULL,
`price_sale` float(8,2) unsigned NOT NULL,
`title` varchar(200) NOT NULL,
PRIMARY KEY (`id`),
KEY `idx_grid_default` (`isactive`,`department`,`ctime`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=47 ;此外,下面是我得到的解释结果集:
+----+-------------+-------+------+---------------+----------+---------+-------------+------+-----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+----------+---------+-------------+------+-----------------------------+
| 1 | SIMPLE | s | ref | idx_grid | idx_grid | 6 | const,const | 3 | Using where; Using filesort |
+----+-------------+-------+------+---------------+----------+---------+-------------+------+-----------------------------+发布于 2011-06-17 22:33:26
在MySQL中使用文件意味着什么?
它并不意味着您有一个临时文件,它只是表示一个排序已经完成(糟糕的名称,忽略前4个字母)。
来自Baron Schwartz
事实上,文件名很差。任何时候不能从索引中执行一个排序,它都是一个文件。这与文件无关。Filesort应该被称为“排序”。它在心灵上是快速的。
https://stackoverflow.com/questions/6387058
复制相似问题