日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
百萬數(shù)據(jù)下幾種SQL性能測試

測試環(huán)境:90W,單條記錄約3KB,數(shù)據(jù)庫:MSSQL2005

成都網(wǎng)絡(luò)公司-成都網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)建站10年經(jīng)驗成就非凡,專業(yè)從事網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè),成都網(wǎng)頁設(shè)計,成都網(wǎng)頁制作,軟文營銷一元廣告等。10年來已成功提供全面的成都網(wǎng)站建設(shè)方案,打造行業(yè)特色的成都網(wǎng)站建設(shè)案例,建站熱線:18982081108,我們期待您的來電!

測試前清除緩存

 
 
 
  1. DBCC FREEPROCCACHE
  2. DBCC DROPCLEANBUFFERS

一、翻頁性能測試

1、Top

 
 
 
  1. select top 10 * 
  2. from message where  id not in 
  3. (select top 20 id frommessage where classid=77 order by id desc )
  4.  and classid=77 order by id desc

2、Max/Top

 
 
 
  1. select top 10 * 
  2. from message where id <(select min(id) from messagewhere  id in(select top 20 id 
  3. from message where classid=77 order by iddesc) )
  4.  and classid=77 order by id desc

3、row_number

 
 
 
  1. select top 10 * from 
  2. (select row_number()over(order by id desc) rownumber,*from 
  3. 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

結(jié)論:

1)從以上測試結(jié)果可以看出,不論是否索引排序字段,也不管是何種索引,row_number都能得到最高的性能,其次Max/Top的方式測試性能也不錯。

2)在使用非聚焦索引的情況下,性能并無任何提示,甚至要慢于無索引的情況,可能是因為SQL先要去查找索引表,然后根據(jù)索引結(jié)果再去查找實體表,在這過程浪費了資源。

3)聚焦索引也的正確應(yīng)用才能發(fā)揮其該有的優(yōu)勢??!

綜合結(jié)果:row_number> max/top > top

二、in、or、union關(guān)鍵字性能測試

介于網(wǎng)上有很多關(guān)于in/or/union等關(guān)鍵字的性能討論,本人也小試了一把,測試結(jié)果如下。

 1、in

 select * from video where id in(100,101,102,103,104,105,106,107,108,109)

2、union

 
 
 
  1. select * from video where id =100
  2. union all select * from video where  id =101
  3. union all select * from video where  id =102
  4. union all select * from video where  id =103
  5. union all select * from video where  id =104
  6. union all select * from video where  id =105
  7. union all select * from video where  id =106
  8. union all select * from video where  id =107
  9. union all select * from video where  id =108
  10. union all select * from video where  id =109

3、or

select * from video where id=100 or id=101 or id=102 or id=103or id=104 or id=105 or id=106 or id=107 or id=108 or id=109

in PK or PK union

ID列索引

in

union

or

無索引

cpu

reads

duration

0

37

54

cpu

reads

duration

0

58

104

cpu

reads

duration

0

41

56

聚焦索引

cpu

reads

duration

0

44

54

cpu

reads

duration

0

54

58

cpu

reads

duration

0

40

54

非聚焦索引

cpu

reads

duration

0

43

53

cpu

reads

duration

16

61

62

cpu

reads

duration

0

43

54

結(jié)論:

1)  網(wǎng)上很多資料說union的性能要高于in/or,但從我這測試的結(jié)果來看,不論是有無索引,union的性能都是最低的?不知是何原因?

2)  網(wǎng)上流傳mssql會自己把in解析成or查詢,從這份測試結(jié)果來看,貌似不假!

3)  雖然in/or會引起全表掃描,但別無選擇的情況下也是是能勝任很多工作的。


網(wǎng)站名稱:百萬數(shù)據(jù)下幾種SQL性能測試
分享鏈接:http://www.dlmjj.cn/article/cddosoi.html