这是我的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秒然后我在数据库中打开这个视图。使用like运算符搜索任何学校名称时查询执行时间增加。请建议任何减少查询执行时间的事情。
答案 0 :(得分:1)
首先在conference_id,division_id,school_id,facilitytosports_id,facility_id上创建索引(如果还没有)。
见create index
答案 1 :(得分:0)
使用mysql索引。 以下链接可能有帮助。 http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html