count(*)： All rows are counted , Include NULL That's ok count(1)： All rows are counted , Include NULL That's ok count(column)： Yes column Central African Null Make statistics
There will be some differences between them according to different situations ,MySQL Would be right count（*） Make optimization .
（1） If the column is the primary key ,count( Name ) Efficiency is better than count(1) （2） If the column is not a primary key ,count(1) Efficiency is better than count( Name ) （3） If there is a primary key in the table ,count( Primary key column name ) The efficiency is the best （4） If there is only one column in the table , be count(*) The efficiency is the best (5） If the table has multiple columns , And there is no primary key , be count(1) Efficiency is better than count(*)
count(1), In fact, it is to calculate the number of qualified lines .1 It doesn't mean the first field , It's a fixed value .
In fact, it can be thought that there is such a field in the table ： This field is a fixed value 1,count(1), That's how many in all 1.
count(*), During execution, the asterisk will be translated into the specific name of the field , The effect is the same .
But there is one more translation action , Slightly less efficient than the fixed value approach .