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