MySQL查询的索引

MySQL查询的索引,mysql,indexing,Mysql,Indexing,我有下面的SQL查询,它目前正在检查636653行,因此需要调整索引 SELECT c.*, g.name AS groupname, cc.name, u.name AS editor, f.content_id AS frontpage, s.title AS section_name, v.name AS author FROM jos_content AS c LEFT JOIN jos_categories AS cc ON cc.id = c.catid LEFT JOIN j

我有下面的SQL查询,它目前正在检查636653行,因此需要调整索引

SELECT c.*, g.name AS groupname, cc.name, u.name AS editor, f.content_id AS frontpage, s.title AS section_name, v.name AS author
 FROM jos_content AS c
 LEFT JOIN jos_categories AS cc ON cc.id = c.catid
 LEFT JOIN jos_sections AS s ON s.id = c.sectionid
 LEFT JOIN jos_groups AS g ON g.id = c.access
 LEFT JOIN jos_users AS u ON u.id = c.checked_out
 LEFT JOIN jos_users AS v ON v.id = c.created_by
 LEFT JOIN jos_content_frontpage AS f ON f.content_id = c.id
 WHERE c.state  >= 0 AND c.catid    = cc.id AND cc.section = s.id AND s.scope   = 'content'
 ORDER BY s.title, c.catid, cc.ordering, cc.title, c.ordering
LIMIT 30;


# Time: 111006 16:17:48
# Query_time: 2.228918  Lock_time: 0.000156 Rows_sent: 30  Rows_examined: 636653
这些是EXPLAIN返回的查询使用的索引

select_type table   type    possible_keys   key key_len ref rows    Extra
1   SIMPLE  c   range   idx_section,idx_state,idx_catid idx_state   1   NULL    636653  Using where; Using temporary; Using filesort
1   SIMPLE  cc  eq_ref  PRIMARY,cat_idx,idx_section PRIMARY 4   borrar.c.catid  1   Using where
1   SIMPLE  s   eq_ref  PRIMARY,idx_scope   PRIMARY 4   borrar.c.sectionid  1   Using where
1   SIMPLE  g   eq_ref  PRIMARY PRIMARY 1   borrar.c.access 1    
1   SIMPLE  u   eq_ref  PRIMARY PRIMARY 4   borrar.c.checked_out    1    
1   SIMPLE  v   eq_ref  PRIMARY PRIMARY 4   borrar.c.created_by 1    
1   SIMPLE  f   eq_ref  PRIMARY PRIMARY 4   borrar.c.id 1   Using index
应该添加哪些索引来提高此MySQL查询的性能


非常感谢,

不太可能有任何实际效果,但是为什么where子句和join条件中都有
c.catid=cc.id
?查询是由CMS生成的,不幸的是更改对性能没有任何影响。我猜这些是Joomla表。。。jos_内容表有多少行?请记住,您正在进行左联接,以便它可以正确地拾取整个表。@GeorgePsarakis jos_内容表有149.743行jos_内容表上唯一的实际情况是状态>=0。如果您有许多活动文章,这将返回所有这些记录。您需要使用不同表中的多个字段对要执行的行进行排序。我认为这里没有多少事情要做。也许您可以隔离特定的部分和类别,从而减少返回的行数?