小编Lou*_*Lou的帖子

选择count(*)vs保留一个计数器

假设已放置索引,并且绝对计数精度不是必需的(可以将其减少一到两个),则可以使用:

选项A

select count(*) 
  from Table 
 where Property = @Property
Run Code Online (Sandbox Code Playgroud)

选项B

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(*)会导致多少性能下降?

sql performance counting

5
推荐指数
1
解决办法
1954
查看次数

标签 统计

counting ×1

performance ×1

sql ×1