慢查询经常性出现这个sql

2016-07-07 15:00 来源:www.chinab4c.com 作者:ecshop专家

  1. SELECT ad.*, COUNT(o.order_id) AS ad_stats, p.position_name FROM `mydb`.`ecs_ad`AS ad LEFT JOIN `mydb`.`ecs_ad_position` AS p
  2. ON p.position_id = ad.position_id LEFT JOIN `mydb`.`ecs_order_info` AS o ON o.from_ad = ad.ad_id WHERE 1
  3. GROUP BY ad.ad_id ORDER by ad.ad_name DESC
复制代码



请问应该如何优化呢?

回答:


先把from_ad count出来做成数组,放到缓存中1天更新1次,然后改写sql用in($from_ads)

可以用子查询的写法试试