假设索引已经到位,并且绝对计数准确度不是必需的(可以偏离一两个也可以),是否可以使用:
选项 A
select count(*)
from Table
where Property = @Property
对比
选项 B
update PropertyCounters
SET PropertyCount = PropertyCount + 1
where Property = @Property
然后做:
select PropertyCount
from PropertyCounters
where Property = @Property
随着表增长到数千/数百万条记录,我可以合理地预期执行 select count(*) 会降低多少性能?