There is essentially no difference between the two.
InnoDB
handlesSELECT COUNT(*)
andSELECT COUNT(1)
operations in the same way. There is no performance difference.
1. Count situation
1. count(1): all data in the table can be counted, not all columns, 1 is used to represent the code row, and the column field is null data in the statistical result;
2. Count (field): a column that only contains the column name, counts the number of times the field appears in the table, and does not count the case where the field is null;
3. Count(*): Count all the columns, which is equivalent to the number of rows, and the statistical results will include columns whose field value is null;
Second, count execution efficiency
The column name is the primary key, count (column name) is faster than count(1); the column name is not the primary key, count(1) will be faster than count (column name);
If there are multiple columns in the table and there is no primary key, the execution efficiency of count(1) is better than count(*);
If there is a primary key, the execution efficiency of select count (primary key) is optimal; if there is only one field in the table, select count(*) is optimal.