Sometimes it is considered that count (*) is slower than count (1) or count (column name) and is actually handled in a sub-case.
Like what:
---initialization statements
Create a table and insert the data:
Create table test2 (id BIGINT PRIMARY key, name varchar)engine=innodb;
insert Into Test2 (id,name) values (1, NULL);
insert into test2 (id,name) values ( Span class= "Hljs-number" >2, ' name1 ');
insert Into Test2 (id,name) values (3, " Name2 ')
Execute the following SELECT statement:
select count (*) from test2; //Result: 3
select count (ID) from test2;//Result: 3
select count (name) from test2;//Result: 2
select count (name) from test2 where name is null; Result: 0
count (1) refers to the first field of the table rather than the count of 1. If the first field does not have an index, his efficiency is very low;
), in the above count (column name)
in query mode, if the specified column is limited to non-null, MySQL then converts the above expression to count () for querying. So if you want
to query the size of the data, it is recommended that count (*) be used in MySQL to execute, meaning and fast.
The count () function in MySQL uses