Skip to content

Instantly share code, notes, and snippets.

@codethereforam
Last active February 1, 2019 01:48
Show Gist options
  • Save codethereforam/640bccfc718e6db9f37cc7a394b6c319 to your computer and use it in GitHub Desktop.
Save codethereforam/640bccfc718e6db9f37cc7a394b6c319 to your computer and use it in GitHub Desktop.
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.

  1. 阿里手册:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment