- Автор темы
- #1
Возможно ли оптимизировать запрос:
Время выполнения ~3 секунды
Индексы на своих местах.
Код:
SELECT
companies.id as id,
companies.`name` as name,
GROUP_CONCAT(DISTINCT categories.`name` ORDER BY city.`name` ASC) as categories,
GROUP_CONCAT(DISTINCT city.`name` ORDER BY FIELD(city.`id`, 3, 2, 1) DESC, city.`name` ASC) as cities
FROM
companies,//10000 записей
categories, //20 записей
city,//20000 записей
companytocities,//60000 записей
companytocategories//30000 записей
WHERE
companies.id=companytocities.id
AND
companytocities.city_id=city.id
AND
company2categories.id=companies.id
AND
categories.id=companytocategories.category_id
GROUP BY
companies.id
ORDER BY
companies.date
DESC;
Индексы на своих местах.