我有这样的查询
SELECT VID, title, duration, addtime, thumb, thumbs,
viewnumber, rate, likes, dislikes, type, hd
FROM video WHERE active = '1' AND type = 'public'
ORDER BY addtime DESC
LIMIT 2052, 36;
当我用 heidisql 运行 explain 时,结果是:
/* Affected rows: 0 Found rows: 1 Warnings: 0 Duration for 2 queries: 0.999 sec. */
Using index condition; Using where; Using filesort
它里面有文件排序,它对性能有什么影响吗?如果是,如何摆脱它?
最佳答案
当读取索引顺序中的行与您请求的查询请求的 ORDER BY
不匹配时,MySQL 使用文件排序。
在您显示的示例查询中,您可以通过添加此索引来避免文件排序:
ALTER TABLE video ADD INDEX (active, type, addtime);
关于mysql用索引解释文件排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45668543/