該查詢大約需要9秒鐘並返回2條記錄。需要關於加速查詢的建議
SELECT
s.description, s.improvement,
s.first_name, s.last_name, s.finding, s.action, s.share,
s.learned, s.timestamp, d.title as department_title,
group_concat(DISTINCT g.title SEPARATOR " | ") as strategic_goals,
group_concat(DISTINCT m.statement SEPARATOR " | ") as mission_references,
group_concat(DISTINCT meas.statement SEPARATOR " | ") as measure_statement,
group_concat(DISTINCT o.statement SEPARATOR " | ") as outcome_statement,
group_concat(DISTINCT i.title SEPARATOR " | ") as ilo_title,
group_concat(DISTINCT cv.title SEPARATOR " | ") as core_value_title,
y1.year as current_year_title, y2.year as previous_year_title,
u.file_name as file_name
FROM summary s
LEFT JOIN year y1 ON s.current_year_id = y1.id
INNER JOIN year y2 ON s.previous_year_id = y2.id
INNER JOIN strategic_goal_entries sge ON s.id = sge.summary_id
INNER JOIN goal g ON sge.goal_id = g.id
INNER JOIN outcome o ON s.id = o.summary_id
LEFT JOIN measure meas ON o.id = meas.outcome_id
INNER JOIN department d ON s.department_id = d.id
LEFT JOIN uploads u ON s.id = u.summary_id
INNER JOIN mission_entries me ON s.id = me.summary_id
LEFT JOIN mission m ON me.mission_id = m.id
LEFT JOIN ilo_entries ie ON s.id = ie.summary_id
LEFT JOIN ilo i ON ie.ilo_id = i.id
INNER JOIN core_value_entries cve ON s.id = cve.summary_id
INNER JOIN core_value cv ON cve.core_value_id = cv.id
INNER JOIN executive_of_department eod ON s.department_id = eod.department_id
WHERE eod.executive_id = 3
GROUP BY s.id
我添加了其餘的主鍵。查詢從9秒變爲2秒。
然後我設置引用其他表的主鍵的字段作爲索引字段。查詢從2秒到20秒,我是否分配了太多索引?
有什麼方法可以加快速度?
什麼是索引情況?調整索引將是我的第一選擇。 – JohnFx 2011-04-19 18:33:57
+1 John - 索引是第一個嫌疑犯,尤其是。有這麼多'JOIN's。 – JNK 2011-04-19 18:35:20
此外@Brad,您可能會收到意想不到的結果,因爲您在某些字段上具有聚合函數,並且通過單個字段進行分組,甚至不在選擇列表中... – JNK 2011-04-19 18:36:19