Benderlio
Новичок
Запрос такой
SELECT shop.* FROM shop
join city on (shop.city=city.city_id)
join region using (region_id)
join shop_cat on using (id_shop)
where shop.state=1 and shop_cat.id_cat>0
group by shop.id_shop
ORDER BY shop.pay DESC limit 10
Анализ
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE shop_cat range id_shop,id_cat id_cat 4 NULL 130282 Using where; Using temporary; Using filesort
1 SIMPLE shop eq_ref PRIMARY,state,city PRIMARY 4 guru_shop_temp.shop_cat.id_shop 1 Using where
1 SIMPLE city eq_ref PRIMARY,region_id PRIMARY 4 guru_shop_temp.shop.city 1
1 SIMPLE region eq_ref PRIMARY PRIMARY 4 guru_shop_temp.city.region_id 1
Отрабатывает 5 секунд. Индексы по всем связям стоят. убираю group by shop.id_shop - уменьшается до 1 сек. Подскажите как оптимизировать. Спасибо.
SELECT shop.* FROM shop
join city on (shop.city=city.city_id)
join region using (region_id)
join shop_cat on using (id_shop)
where shop.state=1 and shop_cat.id_cat>0
group by shop.id_shop
ORDER BY shop.pay DESC limit 10
Анализ
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE shop_cat range id_shop,id_cat id_cat 4 NULL 130282 Using where; Using temporary; Using filesort
1 SIMPLE shop eq_ref PRIMARY,state,city PRIMARY 4 guru_shop_temp.shop_cat.id_shop 1 Using where
1 SIMPLE city eq_ref PRIMARY,region_id PRIMARY 4 guru_shop_temp.shop.city 1
1 SIMPLE region eq_ref PRIMARY PRIMARY 4 guru_shop_temp.city.region_id 1
Отрабатывает 5 секунд. Индексы по всем связям стоят. убираю group by shop.id_shop - уменьшается до 1 сек. Подскажите как оптимизировать. Спасибо.