MySql ten million limit optimization

After practice, summarize the following page optimization better limit

1. imitation Baidu, Google program (front-end service control)

Similar segments. We can only turn to 100, more than one hundred of the need to reload the 100 back. This would solve the problem of data each time you load a large number of slow

2 takes out the maximum record id, and where id> Maximum id

select * from table_name Where id > 最大id limit 10000, 10;
This method is suitable: In addition to discrete primary key ID field and the like, are also suitable continuous datetime fields like
the maximum id calculated by the front end and tab pageNum pageIndex.

3. IN acquire id

select * from table_name where id in (select id from table_name where ( user = xxx )) limit 10000, 10;

4. join manner covering index + (recommended)

select * from table_name inner join ( select id from table_name where (user = xxx) limit 10000,10) b using (id)

For if there are conditions where, they want to go with the limit of the index, an index must be designed, will put the first one where the primary key limit used to put No. 2, and only select a primary key!

select id from test where pid = 1 limit 100000,10;
Create an index:alter table test add index idx_pid_id(pid, id)

Published 178 original articles · won praise 28 · views 80000 +

Guess you like

Origin blog.csdn.net/sunct/article/details/90441965