SQL Server Large Data volume paging proposal scenario

Source: Internet
Author: User

In short, that's it.

Select Top * FROM (

SELECT *, rowID = Row_number () over (order by XXX) from TB with (NOLOCK)

) data where rowID > 0

ORDER BY rowID

or write like this.

SELECT * FROM (

SELECT *, rowID = Row_number () over (order by XXX) from TB with (NOLOCK)

) data where rowID > 0 and rowID <= 20

Previously stressed, for such queries, must use the following way (or similar, mainly to first remove the primary key to meet the conditions), but from this message, we still use the previous old method

--Recommended method:

SELECT * from TB with (NOLOCK)

Where primary key in (

Select Primary Key from (

Select Primary KEY, rowID = Row_number () over (order by XXX) from TB with (NOLOCK)

) data where rowID > 0 and rowID <= 20

)

The previous emphasis on this is performance, because the old method, the data is taken at the same time in the Row_number, that is, before paging, actually take all the data, but eventually only return a part of it

Now the newly discovered problem is:

When the table contains some fields of a larger length, such as XML, Varchar/nvarchar (max), or thousands of of the length (such as the number of the table in the message is 8000)

Memory overhead evaluation can become very scary, the memory allocated for the query will reach a very large value, such as this query, the allocation of memory is 4.4G, our server is 64G memory, a few 10 of such queries will cause the server because there is no memory available to respond to subsequent requests

So please pay special attention to this attachment in the query, arrange the relevant personnel adjustment

The attachment has one that was previously adjusted, that's more scary, press 10G of memory

reducing the memory overhead is primarily ORDER by , including Row_number this has ORDER by when using the rank function of an operation, try to exclude irrelevant columns from the columns in the query, especially XML, Nvarchar/varchar This long column (whether or not the columns contain data, should be avoided as long as they are defined; Memory evaluation is based on the structure, not the actual stored data)

SQL Server Large Data volume paging proposal scenario

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.