mysql count(*) vs count(1)

perfer count(*)

  1. 官方文档:

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

  2. 阿里手册:

【强制】不要使用 count( 列名 ) 或 count( 常量 ) 来替代 count( * ) , count( * ) 是 SQL 92 定义的
标准统计行数的语法,跟数据库无关,跟 NULL 和非 NULL 无关。
说明: count( * ) 会统计值为 NULL 的行,而 count( 列名 ) 不会统计此列为 NULL 值的行。

猜你喜欢

转载自www.cnblogs.com/thinkam/p/10350406.html