标签:
mysql> select 1 from t; +---+ | 1 | +---+ | 1 | | 1 | | 1 | | 1 | +---+ 4 rows in set (0.00 sec)
mysql> select count(1) from t; +----------+ | count(1) | +----------+ | 4 | +----------+ 1 row in set (0.00 sec)
mysql> select count(*) from t; +----------+ | count(*) | +----------+ | 4 | +----------+ 1 row in set (0.00 sec)
mysql> select count(a) from t; +----------+ | count(a) | +----------+ | 4 | +----------+ 1 row in set (0.00 sec)
如果表中没有主键,那么count(1)比count(*)快
如果有主键,那么count(主键,联合主键)比count(*)快
如果表中只有一个字段,count(*)最快
标签:
原文地址:http://www.cnblogs.com/zengkefu/p/5635908.html