The count () function uses count (*) to return the number of rows to be retrieved, whether or not it contains NULL values. When SELECT is retrieved from a table, but no other columns are retrieved, and there is no WHERE clause, COUNT (*) is optimized to the fastest return speed. For example, mysqlSELECTCOUNT (*) FROMstudent; this optimization only applies to MyISAM
The count () function uses count (*) to return the number of rows to be retrieved, whether or not it contains NULL values. When SELECT is retrieved from a table, but no other columns are retrieved, and there is no WHERE clause, COUNT (*) is optimized to the fastest return speed. For example, mysql select count (*) FROM student; this optimization only applies to MyISAM
Count () function usage
Count (*) returns the number of rows to be retrieved, whether or not it contains a NULL value.
When SELECT is retrieved from a table, but no other columns are retrieved, and there is no WHERE clause, COUNT (*) is optimized to the fastest return speed. For example:
Mysql> select count (*) FROM student;
This optimization only applies to MyISAM tables because these table types store the exact number of records returned by a function and are very easy to access.
For transaction-type storage engines (InnoDB and BDB), there are many problems with storing a precise number of rows because multiple transactions may occur,
However, each row may have an impact on the number of rows.
COUNT (DISTINCT field)
Returns the number of non-NULL values.
If no matching item is found, COUNT (DISTINCT) returns 0.