快上网建站品牌

13518219792
  • 首页
  • 关于我们
    • 如何选择
    • 选择理由
  • 案例作品
    • 网站建设
    • 优化推广
    • 微信开发
    • 电商托管
  • 服务项目
    • 网站建设
    • 移动端/APP
    • 微信/小程序
    • 技术支持
    • 其它服务
  • 建站知识
    • 成都网站建设
    • 成都做网站
    • 成都网站设计
  • 网站售后
    • 成都网站运营
    • 成都网站维护
    • 成都网站推广
  • 客服中心
  • 全国分站

百万数据下几种SQL性能测试

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

成都网络公司-成都网站建设公司创新互联建站10年经验成就非凡,专业从事网站设计、成都网站建设,成都网页设计,成都网页制作,软文营销,一元广告等。10年来已成功提供全面的成都网站建设方案,打造行业特色的成都网站建设案例,建站热线: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

结论:

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

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

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

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

二、in、or、union关键字性能测试

介于网上有很多关于in/or/union等关键字的性能讨论,本人也小试了一把,测试结果如下。

 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

结论:

1)  网上很多资料说union的性能要高于in/or,但从我这测试的结果来看,不论是有无索引,union的性能都是最低的?不知是何原因?

2)  网上流传mssql会自己把in解析成or查询,从这份测试结果来看,貌似不假!

3)  虽然in/or会引起全表扫描,但别无选择的情况下也是是能胜任很多工作的。


新闻标题:百万数据下几种SQL性能测试
URL标题:http://gydahua.com/article/cddosoi.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流

其他资讯

  • php数据表行数,mysql查询数据表行数
  • mysql怎么进入数据库 怎样进入数据库
  • 阶乘函数c语言编程 求阶乘函数c语言
  • 程序员表白java代码 程序员表白代码大全
  • 关于sap系统se01传输的信息
  • 用java程序代码来聊天 用java编写聊天程序
  • linux命令基础 Linux命令基础题目
  • 创新互联Python教程:python怎么判断字符串开头
  • 怎么拍延时摄影?(手机怎么拍延时摄影)
  • xp系统电脑快速锁屏快捷键是什么?windowsxp锁屏快捷键

行业动态

企业网站建设的重要性!

现在虽然是移动互联网时代,但企业网站依然重要,包含PC站点,移动站。可以说企业网站关系企业的未来发展和前途,尤其对中小企业更是如此,一些中小企业老板,对自己的名片很在乎,因为这是个门面。...

服务项目

  • 网站建设

    查看详情
  • 移动端/APP

    查看详情
  • 微信/小程序

    查看详情
  • 技术支持

    查看详情
  • 其它服务

    查看详情
  • 更多服务项目

    用我们的专业和诚信赢得您的信赖,从PC到移动互联网均有您想要的服务!

    获取更多

联系吧 在百度地图上找到我们

电话:13518219792

如遇占线或暂未接听请拨:136xxx98888

业务咨询 技术咨询 售后服务
网站设计
高端网站设计推广
成都网站设计
高端网站设计
盐亭网站设计
网站制作
成都营销网站制作
成都网站制作
手机网站制作
网站制作价格
联系我们
电话:13518219792
邮箱:631063699@qq.com
地址:成都青羊区锦天国际1002号
网址:www.gydahua.com
网站建设
网站建设开发
成都定制网站建设
响应式网站建设
定制网站建设

微信二维码

  • 友情链接
  • 成都景观雕塑
  • 成都水电改造服务
  • 子晨包装
  • 浴室清洁用品
  • 门头广告公司
  • 成都网站建设
  • 湖北防潮卫浴洁具
  • 成都网站制作
  • 活动板房
  • 电气五防系统

Copyright © 2002-2023 www.gydahua.com 快上网建站品牌 QQ:244261566 版权所有 备案号:蜀ICP备19037934号

  • 在线咨询
  • 13518219792
  • 微信二维码

  • 移动版官网