mysql> explain SELECT a.id account_id, e.item_type, e.default, d.amount, SUM(b.duration) FROM accounts a RIGHT JOIN call_log b ON (a.id = b.account_id) RIGHT JOIN accounts_items c ON (a.id = b.account_id) RIGHT JOIN items_call_rates d ON (c.id = d.item_id) LEFT JOIN items e ON (c.reference_id = e.id) GROUP BY e.item_type;
+----+-------------+-------+--------+---------------+---------+---------+----------------------+-------+---------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+--------+---------------+---------+---------+----------------------+-------+---------------------------------+
| 1 | SIMPLE | d | ALL | NULL | NULL | NULL | NULL | 13 | Using temporary; Using filesort |
| 1 | SIMPLE | c | eq_ref | id | id | 8 | table.d.item_id | 1 | |
| 1 | SIMPLE | a | index | PRIMARY,id | PRIMARY | 8 | NULL | 200 | Using index |
| 1 | SIMPLE | b | ALL | NULL | NULL | NULL | NULL | 54848 | |
| 1 | SIMPLE | e | eq_ref | id | id | 8 | table.c.reference_id | 1 | |
+----+-------------+-------+--------+---------------+---------+---------+----------------------+-------+---------------------------------+
5 rows in set (0.00 sec)