mysql 的诡异现象,CPU 100%,order by 主键提示 sending data

mysql 单表数据量 50万,执行查询一直CPU爆表,按照hash(id) 分表 partitions 10份。
问题依旧出现,新问题出现了 select * from tb where status in(1,2) and type=1 order by id desc limit 1 提示sending data

诡异

MariaDB [db2_zz]> select count(tid) from zz_info where status in(1,2) and c2=12176;
+------------+
| count(tid) |
+------------+
|       4167 |
+------------+
1 row in set (0.01 sec)

MariaDB [db2_zz]> select max(uptime) from zz_info where status in(1,2) and c2=12176;
+-------------+
| max(uptime) |
+-------------+
|  1498126645 |
+-------------+
1 row in set (4.80 sec)

MariaDB [db2_zz]> select max(tid) from zz_info where status in (1,2) and c2=12176;
+----------+
| max(tid) |
+----------+
|  1364323 |
+----------+
1 row in set (0.00 sec)

MariaDB [db2_zz]> SELECT max(tid) FROM `zz_info` WHERE (`status` IN (1, 2)) AND (`d1`='25') LIMIT 1;
+----------+
| max(tid) |
+----------+
|  1636927 |
+----------+
1 row in set (1.59 sec)

字段statusd1 都有加单独索引,给 status d1 加复合索引之后,问题改善,但是一用上 order by 主键就不行,sending data

MariaDB [db2_zz]>  SELECT max(id) FROM `zz_info` WHERE (`status` IN (1, 2)) AND (`d1`='25') LIMIT 1;
+----------+
| max(tid) |
+----------+
|  1636927 |
+----------+
1 row in set (0.11 sec)

猜想

mysql 分表 partition by hash(id) partitions 10 之后用主键排序性能更差,还不如使用索引来排序快,最后只能改为 select max(主键) 加上 符合索引来解决问题。

有更好的方法吗?欢迎探讨 coconets@163.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值