I have this query:
SELECT cl.title, cl.URL, cl.ID AS ad_id, cl.cat_id, cl.price, cs.name AS cat_name, pix.file_name, area.area_name FROM classifieds cl FORCE INDEX (advertiser_id) INNER JOIN classifieds_pix pix ON cl.ID = pix.classified_id INNER JOIN cat_names_sub cs ON cl.cat_id = cs.ID INNER JOIN zip_codes zip ON cl.zip_id = zip.zip_id INNER JOIN area_names area ON zip.area_id = area.id WHERE cl.confirmed = 1 AND cl.price != '' AND cl.country = 'de' GROUP BY cl.advertiser_id ORDER BY cl.timestamp DESC LIMIT 5
It takes> 1 s when classifieds contains 168k lines that are too long. FORCE INDEX (advertiser_id) allowed me to reduce to 0.00x sec without an ORDER BY . The timestamp column is also indexed, and I tried adding FORCE INDEX (timestamp) , but that didn't help.
EXPLAIN says Using where; Using temporary; Using filesort Using where; Using temporary; Using filesort Using where; Using temporary; Using filesort about the first SELECT from the classifieds table, which obviously causes performance issues.
Can you help me on this?
Thanks in advance!
PS: The purpose of this request is to get the last 5 ads (including some additional information such as image, category, zip code and area name). In addition, only one section should be displayed per advertiser. Can it be that hard?
PPS: I tried to attach the problem as much as possible to the end and received this request:
SELECT cl.title FROM classifieds cl GROUP BY cl.advertiser_id ORDER BY cl.timestamp DESC LIMIT 5
It takes an incredible 23 seconds! With FORCE INDEX (advertiser_id) I can take it up to 1 second. If I delete either GROUP BY or ORDER BY, it will drop to 0.0003 seconds.
Is something supposed to be wrong with my tables / indexes? I do not need FORCE INDEX (btw: USE INDEX does not work - I need to force it!), And it should not last so long!
eWolf source share