[私] mysql 慢查询优化

订单根据游戏来统计

1
2
3
select count(id) as co, game_id from `mk_game_order` 
where `order_status` = 'publish'
group by `game_id`

这里优化的方式是给 order_statusgame_id 两个都加入了索引,根据游戏还有订单状态来统计网站的订单数量.

公有/私有订单的查询

1
2
3
4
5
6
7
8
select count(*) as aggregate from `mk_game_order` 
where
`order_status` = 'publish'
and (
(`is_public` = 'Y' and `account_id` != '58567')
or
(`is_public` = 'N' and match (push_to) against (",_58567_," IN BOOLEAN MODE)))
order by `created_at` desc;

优化项目:

  1. 区分公有和私有, 因为私有的加载项目太缓慢, 全文检索太缓慢, 同时查询量也很少
  2. 排序, 使用 id 排序比创建时间排序速度要快

语雀镜像 : [私] mysql 慢查询优化 ,点此 提问

作者

Duoli

发布于

2021-06-26

更新于

2022-12-08

许可协议

评论