哪些表和列應該有索引?我有一個關於flow_permanent_id和entry_id的索引,但似乎使用的是filesort?mysql索引和優化,使用where;臨時使用;使用filesort
我能做些什麼來優化這個?
mysql> explain SELECT COUNT(*) AS count_all, entry_id AS entry_id FROM `votes` WHERE `votes`.`flow_permanent_id` = '4fab490cdc1c82cfa800000a' GROUP BY entry_id;
+----+-------------+-------+------+----------------------------------+----------------------------------+---------+-------+------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+----------------------------------+----------------------------------+---------+-------+------+----------------------------------------------+
| 1 | SIMPLE | votes | ref | index_votes_on_flow_permanent_id | index_votes_on_flow_permanent_id | 74 | const | 1 | Using where; Using temporary; Using filesort |
+----+-------------+-------+------+----------------------------------+----------------------------------+---------+-------+------+----------------------------------------------+
1 row in set (0.00 sec)
Oleg,在COUNT(*)上使用COUNT(1)沒有性能改進。事實上,他們被視爲平等。 – Ami
@Ami雖然我基本同意你的看法,但這對你來說可能是一個有趣的讀物。 http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/ – fancyPants