Analysis and method of data paging efficiency in SQL tens

Source: Internet
Author: User

Analysis and method of data paging efficiency in SQL tens

Select Top * FROM (select top * to T1 ORDER by ID ASC) an ORDER by id DESC

First ASC to take the first 500 and then inverted (DESC) The results of the 100 ...

MSSQL tested it in me through

This ID field is also the primary key column if the default ascending sequence is the same as the following sentence can be achieved
SELECT * from t1 where ID between 500

I know three ways to have in between and and >= and <=
The efficiency of testing between and is the highest of 3.


First: id>400 and id<500 only 99
id>=401 and id<=500 are only 100.

The best way: With the First_rows (n) optimizer hint: The purpose is to improve the response time of SQL statements, quickly first return n rows

In addition, between and is the most efficient

Select/* FIRST_ROWS (100) * *
ID, username from t1
where ID between 401 and 500

Final summary

At the point of enquiry, it is more efficient to use between...and than to take "<" and ">" numbers.
Select A.*
From table1 A
where rownum between 10000001 and 10000101

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.