count(*)和count(1)的区别---InnoDB 没区别

Wrong

  1. 通常,count(*)和count(1)的计算结果一致。
  2. 若有主键,count(主键)的运行效率最快;若无主键,count(1)比count(*)运行效率要快。
  3. 若整个表只有一个行,count()的运行效率最快;若多于一个行时,count(1)要比count()运行效率快。因为count(*)会扫描整个表。

https://www.jianshu.com/p/84379d16e9b2

 

Right to MySQL8.x

InnoDB handles SELECT COUNT(*) and SELECT COUNT(1) operations in the same way. There is
no performance difference.


For MyISAM tables, COUNT(*) is optimized to return very quickly if the SELECT retrieves from one
table, no other columns are retrieved, and there is no WHERE clause.

This optimization only applies to MyISAM tables, because an exact row count is stored for
this storage engine and can be accessed very quickly. COUNT(1) is only subject to the same
optimization if the first column is defined as NOT NULL.

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值