When the amount of data in MySQL is large, limit paging is used. As the page number increases, the query efficiency decreases. experiment 1. Directly use the limit start, count paging statement: When the starting page is small, the query has no performance issues. Let's look at the execution time of paging from 10, 100, 1000, and 10000 (20 records per page), as follows: select * from order limit 10, 20 0.016 seconds select * from order limit 100, 20 0.016 seconds select * from order limit 1000, 20 0.047 seconds select * from order limit 10000, 20 0.094 seconds We have seen that as the number of starting records increases, the time also increases. This shows that the paging statement limit is closely related to the starting page number. So let's change the starting record to 40w and see. Let's look at the time when we took the last page of records. Obviously this time is unbearable. We can also conclude two things from this: 1) The query time of the limit statement is proportional to the position of the starting record 2) The MySQL limit statement is very convenient, but it is not suitable for direct use for tables with many records. 2. Performance optimization method for limit paging problem Use the table's covering index to speed up paging queries We all know that if the statement that uses an index query only contains that index column (covering index), the query will be very fast. Because index search has an optimized algorithm and the data is on the query index, there is no need to look for the relevant data address, which saves a lot of time. In addition, MySQL also has related index cache, and the effect will be better if the cache is used when the concurrency is high. In our example, we know that the id field is the primary key, so the default primary key index is included. Now let's see how the query using the covering index performs: This time we query the data of the last page (using a covering index, which only contains the id column), as follows: Compared to the 37.44 seconds it takes to query all columns, the speed is increased by more than 100 times. If we also want to query all columns, there are two ways, one is id>= form, the other is to use join, see the actual situation: The query time is 0.2 seconds, which is a qualitative leap, haha Another way to write The query time is also very short You may also be interested in:
|
<<: Detailed explanation of the adaptive adaptation problem of Vue mobile terminal
>>: Detailed explanation of system input and output management in Linux
1. Install MySQL: Use the following three command...
The overall architecture of NGINX is characterize...
This article describes the commonly used MySQL fu...
<br />When thoughts were divided into East a...
If you want to install multiple tomcats, you must...
The following three methods are commonly used to d...
This article shares the specific code of node+exp...
MySQL add, delete, modify and query statements 1....
1. There are many Python version management tools...
Table of contents Preface 1. The process of using...
Table of contents 1. Direct assignment 2. Shallow...
When a user registers, they will click on a label...
To put it simply, the IP of the virtual machine u...
These two attributes are often used, but their di...
We often need to summarize data without actually ...