MySQL Fastest paging method

Source: Internet
Author: User

It is always known that MySQL paging is written like this:

</pre><span style= "White-space:pre" ></span><p><pre name= "code" class= "SQL" >select * From ' yourtable ' limit start,rows


Now, I have a table with 9969W data in my database, and it's called Tweet_data.

Select COUNT (*) from Tweet_data

Execute the first SQL statement, look at the beginning of 6 million article 10, see Query time


58s how slow this must be!

Solution One,

someone immediately think of using the index to improve efficiency, then we use the primary key bar, so, the following SQL

SELECT * FROM  tweet_data where ID >= (select id from tweet_data limit 60000000,1) limit 10


Look at the effect

Really did not much promotion, but if the amount of data in the millions, the efficiency can be many times, but! It obviously didn't meet our requirements.


So here's the SQL statement

SELECT * from Tweet_data where id_auto_increase between 60000000 and 60000010




There is a picture for proof!


Here we only work on a table of data, and the amount of data is about 100 million, but what if our data is larger?

Then it will involve more knowledge! Little brother's humble opinion!







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.