我在让MySQL在多对多查询上使用索引时遇到了问题,我已经粘贴了下面的相关信息。
EXPLAIN SELECT *
FROM interviews
JOIN interview_category_links ON interviews.id = interview_category_links.inter_id
JOIN categories ON interview_category_links.cat_id = categories.id
WHERE categories.category_safe = 'news'
ORDER BY date DESC
LIMIT 15
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE categories ALL PRIMARY,id NULL NULL NULL 16 Using where; Using temporary; Using filesort
1 SIMPLE interview_category_links ref inter_id,inter_id_2,cat_id cat_id 4 devel.categories.id 893
1 SIMPLE interviews eq_ref PRIMARY PRIMARY 4 devel.interview_category_links.in... 1在categories表上我有索引(id,cat_id),在interview_category_links表上我有(cat_id,inter_id)和单个索引(cat_id)和(inter_id)
发布于 2010-01-30 19:05:13
你有面试的索引(Id)吗?
如果你删除了"order by date desc“会怎么样?查询是否运行得更快?如果是这样,您可能想要向该字段添加一个索引(我假设它是interviews表中的一列)。
https://stackoverflow.com/questions/2167499
复制相似问题