成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

百萬(wàn)數(shù)據(jù)下幾種SQL性能測(cè)試

數(shù)據(jù)庫(kù) SQL Server 數(shù)據(jù)庫(kù)運(yùn)維
今天閑來(lái)學(xué)習(xí)了一下SQL性能優(yōu)化方面的知識(shí),有以下學(xué)習(xí)收獲,歡迎大家指點(diǎn)。

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

測(cè)試前清除緩存

  1. DBCC FREEPROCCACHE 
  2. DBCC DROPCLEANBUFFERS 

一、翻頁(yè)性能測(cè)試

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翻頁(yè)性能測(cè)試

ID列索引

Top

Max/Top

row_number()

無(wú)索引

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)從以上測(cè)試結(jié)果可以看出,不論是否索引排序字段,也不管是何種索引,row_number都能得到最高的性能,其次Max/Top的方式測(cè)試性能也不錯(cuò)。

2)在使用非聚焦索引的情況下,性能并無(wú)任何提示,甚至要慢于無(wú)索引的情況,可能是因?yàn)镾QL先要去查找索引表,然后根據(jù)索引結(jié)果再去查找實(shí)體表,在這過(guò)程浪費(fèi)了資源。

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

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

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

介于網(wǎng)上有很多關(guān)于in/or/union等關(guān)鍵字的性能討論,本人也小試了一把,測(cè)試結(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

無(wú)索引

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)上很多資料說(shuō)union的性能要高于in/or,但從我這測(cè)試的結(jié)果來(lái)看,不論是有無(wú)索引,union的性能都是最低的?不知是何原因?

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

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

原文鏈接:http://www.cnblogs.com/shaocan/archive/2012/11/22/2783116.html

責(zé)任編輯:彭凡 來(lái)源: 博客園
相關(guān)推薦

2011-11-04 14:09:34

Google Clou

2025-05-12 00:00:00

2018-03-30 14:30:10

數(shù)據(jù)庫(kù)SQL語(yǔ)句性能優(yōu)化

2011-04-20 14:28:38

SQL優(yōu)化

2025-04-07 03:00:00

SpringBoot數(shù)據(jù)庫(kù)

2013-05-13 13:52:51

MariaDB 5.5

2013-06-27 10:34:08

準(zhǔn)備性能測(cè)試數(shù)據(jù)

2021-02-18 22:18:50

TCP 服務(wù)器源碼

2009-03-19 09:51:00

2017-08-24 18:22:25

公有云私有云混合云

2024-12-26 09:15:28

2012-06-28 10:18:01

數(shù)據(jù)庫(kù)

2022-10-14 17:24:35

MySQLSQL優(yōu)化

2019-03-25 12:20:29

數(shù)據(jù)MySQL性能測(cè)試

2023-11-28 07:48:23

SQL Server數(shù)據(jù)庫(kù)

2019-09-29 17:48:42

數(shù)據(jù)庫(kù)SQLMySQL

2011-03-15 16:34:36

Iptables性能

2024-10-29 08:21:05

2010-09-25 14:48:55

SQL連接

2011-06-08 16:59:04

性能測(cè)試載測(cè)試壓力測(cè)試
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 四虎午夜剧场 | 欧美网站一区二区 | 久久一区二区三区四区 | 欧美 日韩 国产 一区 | av在线免费观看不卡 | 欧美电影网 | 中文字幕1区 | 久久国产视频一区 | 国产精品99久久久久久宅男 | 亚洲一区二区三区免费视频 | 污视频免费在线观看 | 国产伊人精品 | 成人av在线播放 | 成人av一区二区三区 | 欧美国产亚洲一区二区 | 亚洲精品国产电影 | 精品亚洲二区 | 亚洲欧美一区二区三区情侣bbw | 精品美女视频在线观看免费软件 | 亚洲成人三区 | 在线看亚洲 | 性色视频 | 亚洲三级在线观看 | 欧美亚洲日本 | 亚洲国产成人精品女人 | 国产一区2区 | 久久久国产精品一区 | 国产日韩欧美在线一区 | 蜜臀av日日欢夜夜爽一区 | 狠狠做六月爱婷婷综合aⅴ 国产精品视频网 | 农夫在线精品视频免费观看 | 久久国产精品视频免费看 | 国产97视频在线观看 | 亚洲欧美综合 | 亚洲欧美在线观看 | 1000部精品久久久久久久久 | 成年人网站国产 | 成年人网站在线观看视频 | 欧美精品在线免费观看 | 黄色大片毛片 | 99精品一区 |