hi all, i have this query in a table with about 100k records, it runs quite slow (3-4s), when I take out the group it's much faster (less than 0.5s). I'm quite at loss what to do to fix this :
select msg.id, msg.thread_id, msg.senderid,msg.recipientid, 
from_user.username as from_name, to_user.username as to_name
from msgtable as msg
left join usertable as from_user on msg.senderid = from_user.id
left join usertabe as to_user on msg.recipientid = to_user.id
GROUP BY msg.thread_id ORDER BY msg.id desc
msgtable has indexes on thread_id,id, senderid and recipientid
explain returns :
id  select_type table   type    possible_keys   key key_len ref rows    Extra
1   SIMPLE  msg ALL NULL    NULL    NULL    NULL    162346  Using temporary; Using filesort
1   SIMPLE  from_user   eq_ref  PRIMARY PRIMARY 4   db.msg.senderid 1    
1   SIMPLE  to_user eq_ref  PRIMARY PRIMARY 4   db.msg.recipientid  1
Any ideas how to speed this up while returning the same result (there are multiple messages per thread, i want to return only one message per thread in this query).
thanks in advance.