Execution efficiency

  1. Column name primary key, count(column name) and count(1) and count(*) perform the same efficiency: because the type in explain is index

  2. The column name is not a primary key, and no index is created for the column name. Count (1) = count(*) > count(column name); The type of count(column name) is all

  3. Column names are not primary keys, but column names create indexes: count(1) = count(*) = count(column name). Because the type in explain is index

  4. If the table has only one field, all three perform equally efficiently.

The main difference

  1. Count (1) counts all records in the table, including those with null fields.

  2. Count (field) counts the number of times the field appears in the table, ignoring the case of a null field. That is, records whose field is null are not counted.

  3. Count (*) counts all records in the table, including those with null fields.

perform

Count (*) includes all columns, which is equivalent to the number of rows. If the value of a column is NULL count(1), the value of a column is ignored. If the value of a column is NULL count(1), the value of a column is ignored. If the value of a field is NULL, statistics are not collected