count(*) count(1) count(列名)那个更快
经验与学习 2012/1/5 18:14:44 点击:不统计
%77w%77%2Ef%6F%72p%73%70%2Ec%6E
sql的count查询,在做大数据量数量统计的时候用到了count()的sql方法,但是count的用法也有不同。耗时和效率也有不同
百万级数据量查询的时候
select count(*) from count_table;
select count(1) from count_table;
select count(列名) from count_table;
上面的三种count() 都可以查询出检索数量。但是三种那种更快,我在百万数据量上进行测试,测试环境是
mysql的Myisam数据表
(三种同时查询)
[SQL] select count(*) from log;
影响的数据栏: 0
时间: 0.031ms
[SQL]
select count(1) from log;
影响的数据栏: 0
时间: 0.031ms
[SQL]
select count(lid) from log;
影响的数据栏: 0
时间: 0.031ms
三者的数据查询时间相同。
(单条查询)
[SQL] select count(*) from log;
影响的数据栏: 0
时间: 0.015ms
[SQL] select count(1) from log;
影响的数据栏: 0
时间: 0.000ms
[SQL] select count(lid) from log;
影响的数据栏: 0
时间: 0.000ms
总结一下就是 count(索引列名)<count(1)<count(*),最终建议是使用count(索引列名)
http://www.forasp.cn/
·上一篇:replace替换\xef\xbb\xbf >> ·下一篇:HTML5平台的7大特点 >>