|
Помогите оптимизировать запрос
#38332808
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
|
|
|
|
Привет всем,
надо оптимизировать запрос, сильно время растет если я ставлю ORDER BY в конце запроса от 31ms до 15sec, и это учитывая что я показываю всего 50 записей из базы.
Помогите пожайлуста решить данную задачу, я почти уверен что чтото я неправильно делаю, опыта в запросах у меня небольшой.
Вот сам запрос:
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39.
SELECT
descriptions.identify,
CONCAT('[', categories.code, '] ', categories.name) AS category,
CONCAT(categories.code, ' ', identifications.number) AS number,
(SELECT users.caption FROM users WHERE users.identify = descriptions.owner LIMIT 1) AS owner,
identifications.folder,
CONCAT('(', countries.name, ') ', locations.name) AS location,
IF(descriptions.owner = ".$_SESSION["identify"].", 'N', 'Y') AS blocked,
IFNULL((SELECT COUNT(files.identify) FROM files WHERE files.identification = descriptions.identification GROUP BY files.identification LIMIT 1), 0) AS attached,
countries.name,
descriptions.title,
descriptions.recorded,
descriptions.encoded,
descriptions.timekeeping,
descriptions.notes,
descriptions.published,
IFNULL((SELECT GROUP_CONCAT(CONCAT('<b>', characters.name, ':</b> ', styles.name) ORDER BY characters.name SEPARATOR '<br>')
FROM styles INNER JOIN creations ON (styles.identify = creations.style) INNER JOIN characters ON (styles.character = characters.identify)
WHERE creations.description = descriptions.identify GROUP BY creations.description), '') AS d_creations,
IFNULL((SELECT GROUP_CONCAT(CONCAT('<b>', languages.name, ':</b> ', indications.notes) ORDER BY languages.code SEPARATOR '<br>')
FROM indications INNER JOIN languages ON (indications.language = languages.identify)
WHERE indications.description = descriptions.identify GROUP BY indications.description), '') AS d_indications,
IFNULL((SELECT GROUP_CONCAT(CONCAT('<b>', contributions.name, ':</b> ', CONCAT(people.first_name, ' ', people.last_name, ', <span style=\'color:#747474\'>[născut(ă)', IF(people.birthyear <> '', CONCAT(' la ', people.birthyear), ''), ' în ', countries.name, ']</span>')) ORDER BY countries.code SEPARATOR '<br>')
FROM people INNER JOIN collaborations ON (people.identify = collaborations.person) INNER JOIN countries ON (people.country = countries.identify) INNER JOIN contributions ON (collaborations.contribution = contributions.identify)
WHERE collaborations.description = descriptions.identify GROUP BY collaborations.description), '') AS d_collaborations,
IFNULL((SELECT GROUP_CONCAT(CONCAT('<b>', contributions.name, ':</b> ', CONCAT(teams.name, ', <span style=\'color:#747474\'>[din ', countries.name, IF(IFNULL(tools.name, '') <> '', CONCAT(', cântă la ', tools.name), ''), ']</span>')) ORDER BY countries.code SEPARATOR '<br>')
FROM teams INNER JOIN countries ON (countries.identify = teams.country) LEFT JOIN tools ON (teams.tool = tools.identify) INNER JOIN interpretations ON (teams.identify = interpretations.team) INNER JOIN contributions ON (interpretations.contribution = contributions.identify)
WHERE interpretations.description = descriptions.identify GROUP BY interpretations.description), '') AS d_interpretations
FROM
identifications
LEFT JOIN descriptions ON (identifications.identify = descriptions.identification)
LEFT JOIN categories ON (identifications.category = categories.identify)
LEFT JOIN locations ON (descriptions.location = locations.identify)
LEFT JOIN countries ON (locations.country = countries.identify)
ORDER BY
categories.code,
identifications.number
LIMIT
0, 50;
Индексы у меня стоят в таблицах:
categories: code, name
identifications: category, owner, number
descriptions: identification, owner, location
locations: country, name
|
|
|