网站性能优化实践-for循环中的数据库操作
来源:互联网 发布:计算机算法流程图 编辑:程序博客网 时间:2024/05/01 14:28
<!-- /* Font Definitions */ @font-face{font-family:宋体;panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-alt:SimSun;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;}@font-face{font-family:"/@宋体";panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:inter-ideograph;mso-pagination:none;font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;}h3{mso-margin-top-alt:auto;margin-right:0cm;mso-margin-bottom-alt:auto;margin-left:0cm;mso-pagination:widow-orphan;mso-outline-level:3;font-size:13.5pt;font-family:宋体;mso-bidi-font-family:宋体;font-weight:bold;}a:link, span.MsoHyperlink{color:blue;text-decoration:underline;text-underline:single;}a:visited, span.MsoHyperlinkFollowed{color:purple;text-decoration:underline;text-underline:single;}p{mso-margin-top-alt:auto;margin-right:0cm;mso-margin-bottom-alt:auto;margin-left:0cm;mso-pagination:widow-orphan;font-size:12.0pt;font-family:宋体;mso-bidi-font-family:宋体;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;}-->
从核桃博客转载,http://www.hetaoblog.com/?p=42
网站性能优化实践-for循环中的数据库操作
在网站性能优化实践-数据库分页和轻量级Session提到,数据库操作是较为耗时的IO操作,
在某企业级应用项目中,某用户操作后台可能对应N条数据库记录,在原有业务下,通常N<200,后来,随着业务扩展,出现了N>1000甚至更多的情况,原有代码的一段大概逻辑是
for(int i =0; i <n;++i)
{
select …. from tableA where id = id[i];
}
虽然sql很简单直接,一个主键的where条件,可是当N较大时,数据库操作的影响实在太大了,虽然在oracle9i下,这样一条sql不过5毫秒左右,可是for循环一下,5秒时间就浪费在这里了。类似这样的代码段还有一些,极大的影响了该操作的时间,
将代码改成如下
select … from tableA where id in (id0,id1,id2,id3…,id999);
这里,由于oracle的in语句有限制,不能超过1000个,所以如果N较大,仍然需要将N拆成N/1000,然后循环调用;通过这样的改进,
节省了(N/1000+1) * 5秒时间,效果是较为可观的;
- 网站性能优化实践-for循环中的数据库操作
- zz网站性能优化实践-数据库分页和轻量级Session
- 如何优化网站性能实践
- 网站性能优化实践总结
- 嵌套For循环性能优化
- 系统性能优化之如何查找循环操作数据库
- 嵌套for循环优化最佳实践
- 嵌套For循环性能优化案例
- 嵌套For循环性能优化案例
- 嵌套For循环性能优化案例
- 嵌套For循环性能优化案例
- 嵌套For循环性能优化案例
- 嵌套For循环性能优化案例
- 嵌套For循环性能优化案例
- 嵌套For循环性能优化案例
- 嵌套For循环性能优化案例
- 嵌套For循环性能优化分析
- java性能优化之for循环
- zz网站性能优化实践-数据库分页和轻量级Session
- 当他不爱你的时候
- 基于java技术的搜索引擎的实现-2
- [zz]单片机入门的几点建议
- Pascal实现Byte型转BIN字符串格式
- 网站性能优化实践-for循环中的数据库操作
- ASP.NET页面间值传递的几种方法
- 网站性能优化实践-cms性能优化之动态页面静态化、减少http请求和js压缩
- OutputDebugString的用法
- 如何写综述
- mysql在ubuntu下的使用
- 转:研究人员发现:手机辐射或可治疗老年痴呆症
- 最近一直困扰我的问题
- 使用性能监控工具-Perfmon监控windows服务器性能