2012-12-21 168 views
1

我有一个MySQL查询到13秒执行是有什么办法可以减少执行时间在这里是在查询的每个原子部分解释优化MySQL查询

EXPLAIN 
SELECT SQL_CALC_FOUND_ROWS st.store_id as st_id, `st`.`store_id` 
FROM `store` AS `st` 
LEFT JOIN `coupon` AS `cp` ON st.store_id = cp.store_id 
LEFT JOIN `deal` AS `dl` ON st.store_id = dl.store_id 
LEFT JOIN `store_category_relations` AS `scr` ON st.store_id = scr.store_id 
GROUP BY `st`.`store_id`; 

+----+-------------+-------+-------+-----------------------+-----------------------+---------+---------------------+------+-------------+ 
| id | select_type | table | type | possible_keys   | key     | key_len | ref     | rows | Extra  | 
+----+-------------+-------+-------+-----------------------+-----------------------+---------+---------------------+------+-------------+ 
| 1 | SIMPLE  | st | index | NULL     | PRIMARY    | 4  | NULL    | 1 | Using index | 
| 1 | SIMPLE  | cp | ref | store_id    | store_id    | 4  | sonicqa.st.store_id | 5 | Using index | 
| 1 | SIMPLE  | dl | ref | idx_deal_fid_store_id | idx_deal_fid_store_id | 4  | sonicqa.st.store_id | 287 | Using index | 
| 1 | SIMPLE  | scr | ref | store_id    | store_id    | 4  | sonicqa.st.store_id | 2 | Using index | 
+----+-------------+-------+-------+-----------------------+-----------------------+---------+---------------------+------+-------------+ 
4 rows in set (0.00 sec) 
+0

store_id(s):它们是否在所有表格中编制索引? –

+0

如果我正确地读取了SQL,它只是从不同的第一个表中取回store_id,而剩下的其他表将与其他表无关。 – Kickstart

+0

是的,他们被索引在所有表 –

回答

0

Using index ...没有临时文件,不是遍历所有行...

您可能已经有了最快的解决方案。

虽然有一个问题:您是使用InnoDB还是其他数据库引擎?

+1

这应该是评论不回答。 –

+0

是的,都是InnoDB。 –