Mysql million-level paging optimization, mysql Paging

Source: Internet
Author: User
Tags time 0

Mysql million-level paging optimization, mysql Paging
Normal Paging

Data paging is very common in webpages. pages are generally limit start and offset, and start is calculated based on the page number.

Select * from user limit 1, 20

When the page size is several hundred thousand, the page efficiency will be relatively low. MySQL needs to calculate the page size from the beginning to the end, which greatly affects the efficiency.

SELECT * from user limit 0.151; // time sexplain SELECT * from user limit;

We can use the explain statement to analyze the statements without any indexes. The number of rows executed by MySQL is 16 W +, so we can use indexes to implement paging.

 

Optimize Paging

Use primary key index to optimize data Paging

Select * from user where id> (select id from user where id> = 100000 limit 1) limit 20; // time 0.003 s

Using the explain statement, the number of lines scanned by MySQL is more than, and the time is greatly shortened.

Explain select * from user where id> (select id from user where id> = 100000 limit 1) limit 20;

Summary

When the data volume is large, we try to optimize the statement by using indexes. If the id is not a primary key index, the query efficiency is lower than the first one. We can use the explain statement to analyze the statement execution sequence and performance.

 

 

 

Related Article

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.