加入收藏 | 设为首页 | 会员中心 | 我要投稿 衡阳站长网 (https://www.0734zz.cn/)- 数据集成、设备管理、备份、数据加密、智能搜索!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql-server – 堆上的非聚簇索引与聚簇索引的性能

发布时间:2021-01-02 05:05:33 所属栏目:MsSql教程 来源:网络整理
导读:This 2007 White Paper比较了组织为聚簇索引的表上的单个select / insert / delete / update和range select语句的性能与组织为具有与CI表相同的键列上的非聚簇索引的堆的表的性能. 通常,聚簇索引选项在测试中表现更好,因为只需要维护一个结构,因为不需要书签

cmd.CommandText = "delete clust where group between @id and @id+1000";

  • 751 Rows have > 0 CPU and affect more than 0 rows
Counter   Minimum    Maximum Average  Weighted
--------- ------- ---------- ------- ---------
RowCounts     144      69788    4648         -
Cpu            15        764      56   0.01538
Reads         989     458467   30207   6.48490
Writes          2       1830     127   0.02694
Duration   0.2938  2512.1968 24.3714   0.00555

End of Update on 9 Mar 2011.

INSERT基准测试

基准测试的最后一部分是插入语句的执行.

插入堆/ clust(…)
值(…),
(…),
(……)

这个堆基准测试的结果:

rows  reads CPU   Elapsed 
----- ----- ----- -------- 
6     38    0ms   31ms

Update on 9 Mar 2011:

string str = @"insert into heap (group,currency,year,period,domain_id,mtdAmount,ytdAmount,amount,ytd_restated,restated,auditDate,auditUser)
                    values";

                    for (int x = 0; x < 999; x++)
                    {
                        str += string.Format(@"(@id + {0},'EUR',2012,2,100,1000 + @id,1000,current_timestamp,'test'),",x);
                    }
                    str += string.Format(@"(@id,'CAD','test') ",1000);

                    cmd.CommandText = str;
  • 912 statements have > 0 CPU
Counter   Minimum    Maximum Average  Weighted
--------- ------- ---------- ------- ---------
RowCounts    1000       1000    1000         -
Cpu            15       2138      25   0.02500
Reads        5212       7069    6328   6.32837
Writes         16         34      22   0.02222
Duration   1.6336   293.2132  4.4009   0.00440

End of Update on 9 Mar 2011.

这个clust基准的结果:

rows  reads CPU   Elapsed 
----- ----- ----- -------- 
6     50    0ms   18ms

Update on 9 Mar 2011:

string str = @"insert into clust (group,1000);

                    cmd.CommandText = str;
  • 946 statements have > 0 CPU
Counter   Minimum    Maximum Average  Weighted
--------- ------- ---------- ------- ---------
RowCounts    1000       1000    1000         -      
Cpu            15       2403      21   0.02157
Reads        6810       8997    8412   8.41223
Writes         16         25      19   0.01942
Duration   1.5375   268.2571  6.1463   0.00614

End of Update on 9 Mar 2011.

结论

虽然使用集群& amp;访问表时会有更多的逻辑读取.非聚集索引(使用非聚簇索引时)性能结果为:

> SELECT语句具有可比性
>使用聚簇索引时,UPDATE语句更快
>使用聚簇索引,DELETE语句更快
>使用聚簇索引时,INSERT语句更快

当然,我的基准测试对于特定类型的表以及非常有限的查询集非常有限,但我认为基于这些信息我们已经可以开始说,在表上创建聚簇索引几乎总是更好.

Update on 9 Mar 2011:

正如我们从增加的结果中看到的那样,有限测试的结论在每种情况下都不正确.

结果现在表明,受益于聚簇索引的唯一语句是update语句.使用聚簇索引的表上的其他语句约慢30%.

一些额外的图表,其中我绘制了堆与clust的每个查询的加权持续时间.

正如您所看到的,insert语句的性能配置文件非常有趣.尖峰是由一些数据点引起的,这些数据点需要更长的时间才能完成.

End of Update on 9 Mar 2011.

(编辑:衡阳站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读