這是我的Mysql數據庫視圖。如何減少查詢執行時間MySql
Create View viewschools As Select
school.*,
conference.conference_name,
conference.division_id,
division.division_level,
facility.facility_address,
GROUP_CONCAT(DISTINCT facility.facility_name) AS Athletic_Venue
FROM school
INNER JOIN conference
ON school.conference_id = conference.conference_id
INNER JOIN division
ON conference.division_id = division.division_id
LEFT OUTER JOIN schoolfacilitysport
ON school.school_id = schoolfacilitysport.school_id
LEFT OUTER JOIN facilitytosports
ON schoolfacilitysport.facilitytosports_id = facilitytosports.facilitytosports_id
LEFT OUTER JOIN facility
ON facilitytosports.facility_id = facility.facility_id
group by school.school_id
在數據庫表中20千條記錄現在查詢執行時間是13秒那麼我打開數據庫中的這個視圖。搜索任何學校名稱時,查詢執行時間會增加。請建議任何事情以減少查詢執行時間。
簡單規則:任何在'where或'join操作中使用的字段都應該有一個索引。 –