MySQL optimized limit Paging

Source: Internet
Author: User
Many times, we need to select the specified number of rows starting from the specified position. At this time, limit laughed.
Limit is defined as follows:
Limit X, Y
Indicates selecting y records from row X.

When the business requires paging operations, we usually use limit + order by, which is a combination of washing, cutting, and blowing, and a high-end foreign gas.
However, when turning to a very backward page, MySQL takes a lot of time to scan the data to be discarded.

In this case, the better strategy is to use Latency Association:
Return the required primary key by overwriting the index query, and then associate the primary key with the original table to obtain the required rows.
For more information, see the following example.

Suppose there is such a query:

select film_id,actor,description from film where actor='WaterBin' order by title limit 100000,5

We can transform it like this:

select film.film_id,film.actor,film.description  from filminner join (select film_id from film where f.actor='WaterBin' order by title limit 100000,5           )as f using(film_id);

By dba_waterbin

2013-08-02

Good luck

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.