count(*)和count(1)区别?
学习是最好的投资!
You can see how your sql will be translated by mysql using the following sql
EXPLAIN EXTENDED SELECT count(*) FROM `table`; SHOW WARNINGS;
My version is mysql 5.6.26, the following is the translated result:
/* select#1 */ select count(0) AS `count(*)` from `test`.`table`
So, in my opinion, newer versions of mysql no longer have this difference, but I still use count(1) as a habit.
When the data records are not empty, there will be no difference in the query results. But when the column queried by COUNT(1) is empty, the empty ones will be removed and not recorded in the statistics. The results of this query It’s different.
You can see how your sql will be translated by mysql using the following sql
My version is mysql 5.6.26, the following is the translated result:
So, in my opinion, newer versions of mysql no longer have this difference, but I still use count(1) as a habit.
When the data records are not empty, there will be no difference in the query results. But when the column queried by COUNT(1) is empty, the empty ones will be removed and not recorded in the statistics. The results of this query It’s different.