问题
问题要从之前的统计 店铺数关注人数说起
SELECT shop_id, count(user_Id) as attentionNumber
FROM shop_attention
WHERE shop_id...阿里云对这个SQL的检测报告时
扫描行数和返回行数比例超过了100
使用了groupby函数,注意检查groupby是否用到了索引
分析
首先可以确定的是,group by 的 shop_id字段肯定是建了索引的...关联查询/范围排序查询时都会使得扫描行数大于返回行数。一般这个比例要控制在10以下,否则可能会有性能问题。
题外话,我一直觉得mysql explain的展示字段不如mongo的直观。...那么就explain 一下了
实验1
SELECT shop_id, count(user_Id) as attentionNumber
FROM shop_attention
WHERE shop_id...SELECT shop_id, count(user_Id) as attentionNumber
FROM shop_attention
WHERE shop_id IN(1,2,3,4,5,6,7,8,9