TOP N and set ROWCOUNT n which is faster? _php Tutorials

Source: Internet
Author: User
Tags rowcount
Too lazy to translate, to the effect:
Top N and SET rowcount n are the same fast when there is a suitable index. But for an unordered heap, top n is faster.
The principle of looking at English to go.
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 is equally fast, but with unsorted input from a hea P, 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 RO W. If the input is nearly sorted, the TOP N engine must delete or inserts 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, D Eletes, 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 is not as Effici ENT anymore. Usually, the I/O time is the same both with an index and without; However, without an index SQL Server must does 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.

http://www.bkjia.com/PHPjc/631148.html www.bkjia.com true http://www.bkjia.com/PHPjc/631148.html techarticle lazy Translation, the main idea: when the appropriate index, Top N and SET rowcount n is the same fast. But for an unordered heap, top n is faster. The principle of looking at English to go. Q ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.