mysql - Slow query with where,group by, order by (using filesort) -
hi have trouble optimizing query. have reduced original query (~2 seconds) (0.3s):
select kunden.id, kunden.typ, cache.bestellungen_count cache inner join kunden on kunden.id=cache.kunde_id kunden.kundentyp=1 group kunden.id -- order kunden.id desc order cache.bestellungen_gesamtbetrag desc limit 0,500
explain shows filesort used.
select_type table type possible_keys key key_len ref rows simple kunden ref primary,kundentyp,id_k... kundentyp 4 const 26235 using where; using temporary; using filesort simple cache ref kunde_id,kunde_id_gesamtbetrag kunde_id 4 partyschnaps.kunden.indexh 1 using index condition
i guess problem where, group , order cannot use index, when order kunden.id performance boosts factor of ~30 (0.01s) , can solved index.
index on cache table order column , combined 1 fk kunden_id , order column have no effect.
Comments
Post a Comment