For count(primary key ID), the innoDB engine iterates through the table, fetching the ID value for each row and returning it to the server layer, which determines that the ID value is not empty and adds it up by row
For count(1), the innoDB engine iterates through the table, but does not value it and returns it to the server layer. For each row returned by InnoDB, the server puts a number 1 in the table and decides that it cannot be empty
For the count(field),
If the field is defined as not NULL, the column is read from the record line by line, and the value is accumulated
If the field definition is allowed to be NULL, then the value must be extracted to determine if it is not null
But count(*) is an exception
I’m not going to pull all the fields out, I’m going to optimize it, I’m not going to take the value, count(*) is definitely not null, I’m going to add it up
So in order of efficiency, count(field)<count(primary key ID)<count(1)≈count(*)
So, try to use count(*)