I got a query:
SELECT a.nick,grp,count(*) FROM
help_mails
h JOIN accounts a ON h.helper=a.id WHERE closed=1 GROUP BY helper, grp, a.nick
What is wrong with this join? When I made 2 queries:
SELECT helper,grp,count(*) FROM
It is 100 times faster.help_mails
h WHERE closed=1 GROUP BY helper, grp;
SELECT nick FROM accounts WHERE id IN (...)
EXPLAIN returns this:
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE h ref closed closed 1 const 1846 Using temporary; Using filesort 1 SIMPLE a ref PRIMARY PRIMARY 4 margonem.h.helper 1 Using where; Using index
accounts.id, help_mails.grp and help_mails.closed got indexes.