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.
There are 4.5 million rows in the dals table and 2.2M in the items table.
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?