mysql - Slow SQL query because of ORDER BY not using index -
i've got query:
select cl.title, cl.url, cl.id ad_id, cl.cat_id, cl.price, cs.name cat_name, pix.file_name, area.area_name 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 cl.confirmed = 1 , cl.price != '' , cl.country = 'de' group cl.advertiser_id order cl.timestamp desc limit 5 it takes > 1 sec when classifieds contains 168k rows, long. force index (advertiser_id) allowed me bring down 0.00x secs without order by clause. timestamp column indexed, too, , tried adding force index (timestamp), didn't help.
explain says using where; using temporary; using filesort on first select classifieds table - causes performance issue.
can me out on one?
thanks in advance!
ps: purpose of query 5 latest classifieds (including additional information such picture, category, zip code , area name). furthermore, 1 classified should shown per advertiser. can hard?
pps: tried pin problem down as possible , ended query:
select cl.title classifieds cl group cl.advertiser_id order cl.timestamp desc limit 5 it takes incredible 23 secs! force index (advertiser_id) can take 1 sec. if remove either group or order by, goes down 0.0003 secs.
something's gotta wrong tables/indexes? should not need force index (btw: use index doesn't work - need force it!) , shouldn't take long!
i don't think there way of avoiding fact sorting 168k rows going take doing, regardless of indexing. it's 1 thing locate rows in table index, once it's found them engine still has sort them.
1s seems pretty reasonable me btw.
(removed edit suggesting alternative indexes; op tried no success)
Comments
Post a Comment