Why is limit slow?

Source: Internet
Author: User

For the question about why limit is slow in the future, we have used mysql paging, the implementation is generally select * from talbe_name limit pageSize * (pageNo-1), pageSize the first few pages of the statement is very fast, why does pageNo become slower? The principle of www.2cto.com is because the limit paging will mark the records before pageSize * (pageNo-1. This sentence may not be easy to understand. For example, the mail in the post office may be placed on different racks by region, which is equivalent to the database index. You can easily find which mails are from Xihu District, and the messages on each shelf are sorted by the receiving time. But now you need to find 10th to 15 letters from the 15th to 20th in Xihu District. In your practice, I think we should first find all the shelves in the West Lake District. You will be able to locate them soon. How can you locate the 15th shelf now, if there is a tag number on the shelf [time index], you can easily find it. But what about next? How do you locate the 10th mails? You will start from the 15th and check that the first letter is from the 15th, which is the first symbol condition, but it is not for me to find it. Well, write down the number, 2, 3, 4, 5, 6, until 10, now I need it. Take it out and keep getting 15th mails. The problem is here. If I need to find 10,000th to 10010 mails, you have to find them all. So it will be slow later. So how can we solve this problem? We only need to make the previous useless work a little less. For example, if I want to replace the above conditions with the one I want to find from to on the 18 th, will it be useless? Of course, how can we find 10,000th to 10010 mails? This requirement is converted to the scenario where you want to find the number from to on the 18 th to your business scenario.

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.