那夜我还很年幼~
我不去想身后会不会袭来寒风冷雨 既然目标是地平线 留给世界的只能是背影

测试环境:90W,单条记录约3KB,数据库:MSSQL2005

测试前清除缓存

DBCC FREEPROCCACHE DBCC DROPCLEANBUFFERS

 

一、翻页性能测试

1、Top select top 10 * from message where  id not in (select top 20 id frommessage where classid=77 order by id desc ) and classid=77 order by id desc 2、Max/Top select top 10 * from message where id <(select min(id) from messagewhere  id in(select top 20 id from message where classid=77 order by iddesc) ) and classid=77 order by id desc 3、row_number select top 10 * from (select row_number()over(order by id desc) rownumber,*from message where classid=77)a where classid=77 and rownumber>20

MsSql翻页性能测试

ID列索引

Top

Max/Top

row_number()

无索引

cpu

reads

duration

0

893

65

cpu

reads

duration

0

590

70

cpu

reads

duration

0

512

67

聚焦索引

cpu

reads

duration

0

37

66

cpu

reads

duration

0

98

64

cpu

reads

duration

0

28

67

非聚焦索引

cpu

reads

duration

0

895

63

cpu

reads

duration

0

592

66

cpu

reads

duration

0

514

66

 

 

 

 

 

 

 

 

 

 

 

 

结论:

1)从以上测试结果可以看出,不论是否索引排序字段,也不管是何种索引,row_number都能得到最高的性能,其次Max/Top的方式测试性能也不错。

2)在使用非聚焦索引的情况下,性能并无任何提示,甚至要慢于无索引的情况,可能是因为SQL先要去查找索引表,然后根据索引结果再去查找实体表,在这过程浪费了资源。

3)聚焦索引也的正确应用才能发挥其该有的优势啊!

综合结果:row_number> max/top > top

posted on 2012-11-22 23:00  那夜我还很年幼~  阅读(97)  评论(0)    收藏  举报