1.  一般情况下,Select Count (*)和Select Count(1)两者的返回结果是一样的

   2.  假如表沒有主键(PK), 那么count(1)比count(*)快, 如果有主键PK的話,那count(主键)最快, 如果你的表只有一个字段的话那count(*)就是最快的

   3. count(*) 跟 count(1) 的结果一样,都包括对NULL的统计,而count(column) 是不包括NULL的统计

100多万条count(1)和count(*)查询速度对比

count(*)

select count(*) 和 select count(1) 以及 select count(column) 的区别_count

耗时:4.2s

count(1)

select count(*) 和 select count(1) 以及 select count(column) 的区别_主键_02

耗时:4.2s

时间差不多

优化

给主键添加索引,使用sum函数

select count(*) 和 select count(1) 以及 select count(column) 的区别_SQL优化_03

select count(*) 和 select count(1) 以及 select count(column) 的区别_count_04

耗时:0.33s

直接起飞,又一个sql优化小技巧!!!