Analysis and method of pagination efficiency of tens of millions of SQL data

Source: Internet
Author: User
Top 500 SQL data Efficiency Analysis and Methods * from (selecttop500 * fromT1orderbyidasc) aorderbyiddesc first asc takes the first 100 and then reverse (desc) the result of the first results... MSSQL tests the ID field here. If the default ascending sequence is also the primary key column, the following statement can achieve the Efficiency Analysis and method of select * from SQL with tens of millions of data records.

Top 100 * from (select top 500 * from T1 order by id asc) a order by id desc

Asc first obtains the first 500 records and then returns the first 100 results of the result (desc...

MSSQL passed the test here

If the ID field is the default ascending sequence and the primary key column, the following sentence can be implemented.
Select * from t1 where id between 400 and 500

I know three methods: having in between and> = and <=
The efficiency of tested between and should be the highest among the three.


First: id> 400 and id <500 only 99
Id> = 401 and id <= 500 is 100

The best method: Use the FIRST_ROWS (n) optimizer to prompt: The purpose of this optimizer is to increase the SQL statement response time and quickly return n rows first

In addition, between and has the highest efficiency.

Select/* FIRST_ROWS (100 )*/
Id, username from t1
Where id between 401 and 500

Conclusion

From the query point, using between... and is more efficient than obtaining "<" and ">"
Select .*
From table1
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.