假设已放置索引,并且绝对计数精度不是必需的(可以将其减少一到两个),则可以使用:
select count(*)
from Table
where Property = @Property
Run Code Online (Sandbox Code Playgroud)
与
update PropertyCounters
SET PropertyCount = PropertyCount + 1
where Property = @Property
Run Code Online (Sandbox Code Playgroud)
然后做:
select PropertyCount
from PropertyCounters
where Property = @Property
Run Code Online (Sandbox Code Playgroud)
当表增长到成千上万的记录时,我合理地期望通过执行select count(*)会导致多少性能下降?