mysql count(*) vs count(1)

perfer count(*)html

  1. 官方文檔:mysql

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

  2. 阿里手冊:數據庫

【強制】不要使用 count( 列名 ) 或 count( 常量 ) 來替代 count( * ) , count( * ) 是 SQL 92 定義的
標準統計行數的語法,跟數據庫無關,跟 NULL 和非 NULL 無關。
說明: count( * ) 會統計值爲 NULL 的行,而 count( 列名 ) 不會統計此列爲 NULL 值的行。orm

相關文章
相關標籤/搜索