create table #aa(f int)
insert #aa(f) select 1 union all select 2 union all select 2 union all select 3 union all select 3 union all select 3 union all select 4 union all select 4 union all select 4 union all select 4 union all select null
select count(*) from #aa
select count(f) from #aa
go
select getdate()
select Count(*) from t_info group by batch
select getdate()
select Count(batch) from t_info group by batch
select getdate()
select Count(*) from t_info group by batch
select getdate()
这个是非主键的查询结果
-----
2006-01-24 16:41:59.083
-----
2006-01-24 16:43:02.810
-----
2006-01-24 16:44:28.600
---
2006-01-24 16:45:57.173
测试数据49690000行,表结构:t(id int,a int),id上建有索引,a上无索引
SELECT count(*) FROM t--1分三十几秒
SELECT count(id) FROM t--1分十几秒,有时1分几秒
SELECT count(a) FROM t--与count(id)差不多