TOP N 和SET ROWCOUNT N 哪个更快

2016-01-29 17:03 5 1 收藏

TOP N 和SET ROWCOUNT N 哪个更快,TOP N 和SET ROWCOUNT N 哪个更快

【 tulaoshi.com - SQLServer 】

懒得翻译了,大意:
在有合适的索引的时候,Top n和set rowcount n是一样快的。但是对于一个无序堆来说,top n更快。
原理自己看英文去。

Q. Is using the TOP N clause faster than using SET ROWCOUNT N to return a specific number of rows from a query?

A. With proper indexes, the TOP N clause and SET ROWCOUNT N statement are equally fast, but with unsorted input from a heap, TOP N is faster. With unsorted input, the TOP N operator uses a small internal sorted temporary table in which it replaces only the last row. If the input is nearly sorted, the TOP N engine must delete or insert the last row only a few times. Nearly sorted means you're dealing with a heap with ordered inserts for the initial population and without many updates, deletes, forwarding pointers, and so on afterward.

A nearly sorted heap is more efficient to sort than sorting a huge table. In a test that used TOP N to sort a table with the same number of rows but with unordered inserts, TOP N was not as efficient anymore. Usually, the I/O time is the same both with an index and without; however, without an index SQL Server must do a complete table scan. Processor time and elapsed time show the efficiency of the nearly sorted heap. The I/O time is the same because SQL Server must read all the rows either way.

来源:http://www.tulaoshi.com/n/20160129/1500197.html

延伸阅读
佳能Powershot N评测   当我们从口袋里拿出PowerShot N的时候,第一反应都是:这货根本不是一个相机,它是一个玩具。实际上,这个小型的矩形相机的确背离佳能一贯的设计方式,至少近期是没有这种设计的款式出现。PowerShot N可以连接网络,趣味性强,市场定位为80后。在这里,我们通过更详细地评测来看看佳能PowerShot N到底如何...
标签: PS PS教程
本教程为 www.jcwcn.com 中国 a87818089、楚楚原创,如转载请保留这段话: screen.width-500)this.style.width=screen.width-500;" border=0 pop="按此在新窗口浏览图片"> screen.width-500)this.style.width=screen.width-500;" border=0 pop="按此在新窗口浏览图片"> 一图层样式 1.美女图复制一张, screen.width-500)this.style.wid...
当偶然的在网上发现这个装饰纸花的 手工教程 时,不由得对手工达人们的创意由衷的赞叹!作为一个办公室的达人,N字帖与图钉都是要频繁用到的东西,可是却从没想过它们也可以展示出如此美丽的一面,以至于觉得这些总是带来压力的便签竟然也是那么的可爱了。用手上的图钉和便签也diy一款美丽的装饰纸花吧,将它钉在工位中,元气满满的,就...
标签: 孕期 孕前
怀孕N种难事轻松搞掂 难事1:肤色——做个蜜色美人也不错 辛苦保养一年的白皙肤色可能受荷尔蒙的教唆而变黑。更恼人的是,这种变化不仅发生在脸上,你的乳晕、外阴及大腿内侧等隐私部位也都不能幸免。蝴蝶斑更是让女人们害怕的孕期馈赠之一。 不要放弃对皮肤的保养。 即使现在的你是个大腹便便的孕妈,也不能就此大大咧咧起来。 解决之道...

经验教程

528

收藏

79
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部