TOPN和SETROWCOUNTN哪个更快
来源:互联网 发布:伴游网站 源码 编辑:程序博客网 时间:2024/06/10 07:52
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
在有合适的索引的时候,TOPN和setrowcountn是一样快的。但是对于一个无序堆来说,TOPN更快。
原理自己看英文去。
Q.IsusingtheTOPNclausefasterthanusingSETROWCOUNTNtoreturnaspecificnumberofrowsfromaquery?
A.Withproperindexes,theTOPNclauseandSETROWCOUNTNstatementareequallyfast,butwithunsortedinputfromaheap,TOPNisfaster.Withunsortedinput,theTOPNoperatorusesasmallinternalsortedtemporarytableinwhichitreplacesonlythelastrow.Iftheinputisnearlysorted,theTOPNenginemustdeleteorinsertthelastrowonlyafewtimes.Nearlysortedmeansyou'redealingwithaheapwithorderedinsertsfortheinitialpopulationandwithoutmanyupdates,deletes,forwardingpointers,andsoonafterward.
Anearlysortedheapismoreefficienttosortthansortingahugetable.InatestthatusedTOPNtosortatablewiththesamenumberofrowsbutwithunorderedinserts,TOPNwasnotasefficientanymore.Usually,theI/Otimeisthesamebothwithanindexandwithout;however,withoutanindexmustdoacompletetablescan.Processortimeandelapsedtimeshowtheefficiencyofthenearlysortedheap.TheI/OtimeisthesamebecauseSQLServermustreadalltherowseitherway.<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
懒得翻译了,大意:在有合适的索引的时候,TOPN和setrowcountn是一样快的。但是对于一个无序堆来说,TOPN更快。
原理自己看英文去。
Q.IsusingtheTOPNclausefasterthanusingSETROWCOUNTNtoreturnaspecificnumberofrowsfromaquery?
A.Withproperindexes,theTOPNclauseandSETROWCOUNTNstatementareequallyfast,butwithunsortedinputfromaheap,TOPNisfaster.Withunsortedinput,theTOPNoperatorusesasmallinternalsortedtemporarytableinwhichitreplacesonlythelastrow.Iftheinputisnearlysorted,theTOPNenginemustdeleteorinsertthelastrowonlyafewtimes.Nearlysortedmeansyou'redealingwithaheapwithorderedinsertsfortheinitialpopulationandwithoutmanyupdates,deletes,forwardingpointers,andsoonafterward.
Anearlysortedheapismoreefficienttosortthansortingahugetable.InatestthatusedTOPNtosortatablewiththesamenumberofrowsbutwithunorderedinserts,TOPNwasnotasefficientanymore.Usually,theI/Otimeisthesamebothwithanindexandwithout;however,withoutanindexmustdoacompletetablescan.Processortimeandelapsedtimeshowtheefficiencyofthenearlysortedheap.TheI/OtimeisthesamebecauseSQLServermustreadalltherowseitherway.
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- TOPN和SETROWCOUNTN哪个更快
- Java和C语言哪个更快?
- 复制和剪切, 哪个速度更快?
- C和C++哪个更快?
- NSSArray和NSSet遍历哪个更快
- insert和update哪个更执行更快
- 关于Java和C++哪个更快的问题
- 线程同步问题,CRITICAL_SECTION和Mutex哪个更快
- fwrite和ofstream文件输出效率上哪个更快?
- 内存画图和屏幕画图哪个更快?
- 遍历ArrayList,Iterator和for循环哪个更快?
- 移动文件时,复制和剪切哪个更快?
- 遍历ArrayList,Iterator和for循环哪个更快? (转载)
- java堆和内存的区别,哪个更快?
- ++num和num++哪个执行速度更快,++num为什么会比num++速度快
- 存储过程与Insert哪个更快
- ASP.NET vs. PHP,哪个更快?
- 串行, 并行,速度哪个更快。
- 正规化和技巧
- IDENTITY列的一个有用操作
- 当崩溃时如何恢复?
- 正确配置和使用SQLmail
- 关于DTS导入导出丢失默认值等对象
- TOPN和SETROWCOUNTN哪个更快
- 如何在视图中使用ORDERBY短语
- 如何区分大小写比较?
- 如何将作为字符串保存的IP地址变为二进制数值?
- 如何使Microsoft的日志文件不会增大?
- 关于占用过多内存的问题
- 非正常删除日志文件(ldf)恢复方法
- 处理孤立用户的存储过程
- 1069错误(由于登录失败而无法启动服务)解决方法