美文网首页
MySQL排序优化

MySQL排序优化

作者: 养一只tom猫 | 来源:发表于2021-07-09 11:31 被阅读0次

最近在项目中有一个需求,将表中所有客户做出的数据查询出来并且统计每一个客户做的数量,数据量大概50W。
SQL大致如下

select
   a.relation_id,
   a.relation_name,
   count(a.id) as total
from
   table a
where
   a.group_id = 'xx'
   and a.org_id in('xx','xx')
group by a.relation_id
order by total
limit 0,40

在查询的时候,发现是排序太费时了
由于排序字段是count出来的,没办法使用索引进行优化

相关文章

网友评论

      本文标题:MySQL排序优化

      本文链接:https://www.haomeiwen.com/subject/ithfpltx.html