【mysql优化】mysql count(*)、count(1)、count(主键字段)、count(非主键字段)哪个性能最佳

测试结果为:count(*)和count(1)基本相等,count(非主键字段)最耗性能

-- 数据量 708254
select count(*) from tmp_test1;-- avg 0.224
0.229  
0.219
0.227
0.222
0.215
0.224
0.225
0.221
0.240
0.219

select count(1) from tmp_test1;-- avg 0.226
0.230
0.217
0.217
0.233
0.225
0.220
0.235
0.232
0.233
0.219

select count(id) from tmp_test1;-- avg 0.238
0.240
0.242
0.230
0.250
0.234
0.233
0.240
0.242
0.231
0.239

select count(iccid) from tmp_test1;-- avg 0.268
0.288
0.269
0.255
0.255
0.295
0.262
0.274
0.265
0.256
0.260

posted @ 2017-10-10 14:35  __初  阅读(797)  评论(0编辑  收藏  举报