SQL Server rownumber and table variable paging performance optimization Subtotal

Source: Internet
Author: User

Directly letCodeNow, let's take a look at the comparison.

Of course, this situation is suitable for extracting a large number of fields.

 

Poor performance:

 
With # temp as (select column1, column2, column3, column4, column5, column6, column7, column8, column8, column10, row_number () over (order by column100 DESC) as rownumber from tables1 where .....) select * from # temp where rownumber between 1601 and 1620 order by rownumber

 

Good performance after optimization

With # temp as (select column1, row_number () over (order by column100 DESC) as rownumber from tables1 where .....) select column1, column2, column3, column4, column5, column6, column7, column8, column10from tables1where column1 in (select column1 from # tempwhere rownumber between 1601 and 1620 order by rownumber)

 

RelatedArticle: SQL Server 2012 paging Method Analysis (offset and fetch)
Original article address: SQL Server rownumber and table variable paging performance optimization Subtotal

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.