Paging optimization code for mysql massive data

Source: Internet
Author: User
Tags mysql tutorial

Mysql tutorial paging optimization code for massive data
Page indicates the page number.
Pagesize indicates the number of entries displayed on each page.
Conditon indicates some conditions view sourceprint? 1 select * from table where conditon order by id limit (page-1) * pagesize, pagesize;
In this way, there was no problem with paging in the early stage, but when the data in the table reached 100 million, the problem gradually occurred. When searching hundreds of pages, it often takes more than 2 seconds to search online. You can refer to the online Correction Method to Solve the Problem temporarily.
SELECT SQL _no_cache * FROM table WHERE id> = (SELECTsql_no_cache id FROM table where conditon ORDER BY id DESC LIMIT 126380,1) limit 20;


Cache. In this way, you can change the index id to 0.0 seconds. In fact, this is mainly because the index id is used.

Audit = 1 AND share = 1

In my table's index design, the primary key is id, and the audit and share are associated indexes.

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.