MySQL query count (*), count (1), the difference count (field) collection

count (*) is calculated on the number of lines, comprising a NULL
COUNT (column) having a number of lines for a particular column value is calculated, it does not contain a NULL value.

count () there is a way to use the results count (1) and the usage count (*) is the same.

In any case select count (*) from tablename is the best choice;

Minimizing select count (*) from tablename where COL = 'value' Such a query;

Eliminate select count (COL) tablename where COL2 = 'value' emergence from.

If the table has no primary key, then count (1) (*) faster than the count.

If there is a primary key, then count (primary key, the primary key) (*) faster than the count.

If the table has only one field, count (*) the fastest.

count (1) Like count (primary key), only scans the primary key. count (*) with the same count (non-key), scan the entire table. The former obviously faster.

If the statement is contained where, in the conditions index takes precedence where.

Guess you like

Origin www.cnblogs.com/liuchunxiao83/p/11326348.html