order-by使mysql变慢

nmpmafwu  于 2021-06-25  发布在  Mysql
关注(0)|答案(1)|浏览(265)

我们花了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
zzlelutf

zzlelutf1#

请参考本文。
为了提高排序速度,请检查是否可以让mysql使用索引而不是额外的排序阶段。
所以首先检查一下 event_view_count 列索引。

相关问题