我们花了5秒来加载,但当我删除订单时,我们只花了0.4秒就可以改进这个查询了吗?
下面的查询也有更多的左连接,但不要认为这不是问题
SELECT b.id,
b.name,
b.start_date,
b.start_time,
at.filename,
at.width,
at.height,
at.id AS attachment_id,
ve.name AS venue_name,
ve.slug AS v_slug,
ve.address,
ci.name AS city_name,
st.code AS state_code
FROM events b
LEFT JOIN attachments at
ON at.foreign_id = b.id
LEFT JOIN venues ve
ON b.venue_id = ve.id
LEFT JOIN cities ci
ON ve.city_id = ci.id
LEFT JOIN states st
ON ci.state_id = st.id
WHERE 1 = 1
AND b.start_date >= '2016-10-06'
AND b.is_active = 1
AND b.virtual_delete = 0
AND ve.is_approved = 1
GROUP BY b.id
ORDER BY b.event_view_count DESC
LIMIT 30
1条答案
按热度按时间zzlelutf1#
请参考本文。
为了提高排序速度,请检查是否可以让mysql使用索引而不是额外的排序阶段。
所以首先检查一下
event_view_count
列索引。