Find the problem When we display the contents in a list, we will inevitably encounter paging problems, because the number of contents in the list may be large, but the size of the interface that the user can see at one time is limited. It is impossible to display all the contents in one interface. Fetching too much data from the backend at one time will also cause additional pressure on the backend. Usually the following statement is used for paging query: SELECT * FROM table where condition1 = 0 and condition2 = 0 and condition3 = -1 and condition4 = -1 order by id asc LIMIT 2000 OFFSET 50000 When the offset is particularly large, the execution efficiency of this statement will be significantly reduced, and the efficiency decreases as the offset increases. The reasons are: MySQL does not skip the offset row, but takes the offset+N rows, then returns the previous offset row and returns N rows. When the offset is particularly large and the single data is also large, the more data needs to be obtained each time the query is made, the slower it will be. Optimization plan: SELECT * FROM table JOIN (select id from table where condition1 = 0 and condition2 = 0 and condition3 = -1 and condition4 = -1 order by id asc LIMIT 2000 OFFSET 50000) as tmp using(id) or SELECT a.* FROM table a, (select id from table where condition1 = 0 and condition2 = 0 and condition3 = -1 and condition4 = -1 order by id asc LIMIT 2000 OFFSET 50000) b where a.id = b.id First obtain the primary key list, and then query the target data by the primary key. Even if the offset is large, many primary keys are obtained instead of all field data. Relatively speaking, the efficiency will be greatly improved. Summarize The above is the full content of this article. I hope that the content of this article can bring some help to your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support of 123WORDPRESS.COM. You may also be interested in:
|
<<: How to recover accidentally deleted messages files in Linux
>>: Detailed explanation of the pitfalls of add_header in nginx configuration tutorial
1. Inline style, placed in <body></body&g...
Table of contents Is setState synchronous or asyn...
In tomcat, jsp is not garbled, but html Chinese i...
This article mainly describes two kinds of underl...
Recently, I made a function similar to shake, usi...
Download mysql-5.7.19-winx64 from the official we...
Table of contents Overview Install Gulp.js Create...
Table of contents 1. Download steps 2. Configure ...
Sometimes we need to control whether HTML elements...
This article uses an example to describe how to c...
Table of contents 1. Comments on MySQL primary ke...
In the recent project, we need to create an effec...
Install zip decompression function under Linux Th...
Table of contents Introduction Architecture Advan...
Here we introduce the knowledge about form elemen...