I have a query that runs very slow and using Using temporary; Using
filesort. Is there a way to avoid them using current table structure?
Goal with the query is to find ads (ad_id) that have tags (tag_id) connected
to them, order by antal is used to get the most relevant first. ( the one
that
One optimization I see quickly is changing the left join to an inner join.
You always look for records that exist in tag_ad_map (by checking for
tm.is_active) so the left join is not necessary. That should at least speed
this query up considerably.
Walter
Need MySQL advice?
OlinData.com is the
Not really, the query took 4-5 seconds. The query runs through 13910 rows
according to explain, that isnt alot is it?
SELECT COUNT(*) antal,ad.ad_id FROM ad
INNER JOIN tag_ad_map tm ON tm.ad_id=ad.ad_id
WHERE
tm.tag_id IN (99, 10807, 20728, 21, 135)
AND ad.is_removed = 0 AND ad.is_active=1