Forum Moderators: open

Message Too Old, No Replies

MySQL ORDER BY is making the query slow.

         

avera

8:37 am on Jul 2, 2009 (gmt 0)

10+ Year Member



Hi Guys,

I have the following query:


SELECT
i.iditems,
MIN(d.price) AS price,
MAX(d.price)AS pricefrom,
COUNT(d.iddeals) AS deals,
i.name,
i.summary
FROM
items AS i
INNER JOIN
deals AS d
ON d.iditems = i.iditems
GROUP BY
(i.iditems)
ORDER BY
deals DESC
LIMIT
10;

This query take 4 seconds to run on a very fast dedicated server with no other server load.

When I remove this line:


ORDER BY
deals DESC

It goes from 4 seconds to 0.0023 seconds.

What can I do to optimise the order by as I am ordering on a COUNT() column?