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.