count(*) count(1)哪个更快?

Views :
Update time : 2025-06-23 18:15:13

团队 code review 时,一位同事把 count(*)改成了 count(1),说这样性能更好。

真的是这样吗?今天通过源码和实测数据,把这个问题说透。

本文基于 MySQL 8.0.28 版本测试,不同版本的优化器行为可能有差异 三种 count 方式的本质区别先看看这三种写法在 MySQL 中到底做了什么: // 模拟MySQL处理count的伪代码 public class CountProcessor { // count(*) 的处理逻辑 public long countStar(Table table) { long count = 0; for …。

count(*)  count(1)哪个更快?
Related News
Read More >>
Blog Post With Youtube Video 我国的军工能力可以实现一天5000枚火箭弹连着炸三个月吗?
2025-06-26 03:25:09
我国的军工能力可以实现一天5000枚火箭弹连着炸三个月吗?...
Blog Post With Youtube Video 用PHP写了个小框架,怎么才能得到大佬们的指点?
2025-06-26 03:10:11
用PHP写了个小框架,怎么才能得到大佬们的指点?...
Blog Post With Youtube Video 做网页开发时,允许用户输入url图片地址来作为自己的头像有什么风险?
2025-06-26 03:25:09
做网页开发时,允许用户输入url图片地址来作为自己的头像有什么风险?...
Blog Post With Youtube Video 为什么师父不愿把真本事传给弟子?
2025-06-26 02:50:10
为什么师父不愿把真本事传给弟子?...

Leave Your Message