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
First, download a series of things from the Alipa...
Table of contents 1. Create a Hadoop directory in...
It is often necessary to run commands with sudo i...
Installation of MySQL decompression version and N...
This article example shares the specific code of ...
1. Introduction Nginx is a free, open source, hig...
Table of contents Preface How to implement Vuex f...
Table of contents 01. Listener watch (1) Function...
The specific code is as follows: <div id="...
Table of contents 【Code background】 【Code Impleme...
Table of contents Problem 1: Destruction 1. How t...
On Linux, bash is adopted as the standard, which ...
Preface I have been working on some front-end pro...
Solve the problem of not being able to access the...
This tag is not part of HTML3.2 and only supports ...