b_info表50万条记录
id为主键
cityid和b_classid为联合索引
为防止缓存,关闭查询缓存对比如下:
(1)
mysql> select sql_no_cache count(*) as num from b_info where cityid=1 and b_classid=79;
+-------+
| num |
+-------+
| 25822 |
+-------+
1 row in set (0.04 sec)
(2)
mysql> select sql_no_cache count(id) as num from b_info where cityid=1 and b_classid=79;
+-------+
| num |
+-------+
| 25822 |
+-------+
1 row in set (0.24 sec)
总结:
此时count(*) 比count(id)快多了,不知道有什么有count(id) 快于 count(*)的例子??