How to optimize query in MySQLlimit
This article shows you how to optimize the query in MySQLlimit, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
How to query Optimization in MySQLlimit
Also take 10 pieces of data.
Select*fromyanxue8_visitlimit10000,10select*fromyanxue8_visitlimit0,10
It's not a quantitative level.
On the Internet, there are also many of the five optimization guidelines for limit, which are translated from the MySQL manual, which are correct but not practical. Today, I found an article about limit optimization, which is very good.
In this paper, instead of using limit directly, we first get the id of offset and then directly use limitsize to get the data. According to his data, it is obviously better than using limit directly. Here I use the data to test in two cases. (test environment win2033+p4 dual core (3GHZ) + 4G memory MySQLlimit query)
How to query Optimization in MySQLlimit
1. When offset is relatively small
Select*fromyanxue8_visitlimit10,10
Run multiple times and keep the time between 0.0004 and 0.0005
Select*Fromyanxue8_visitWherevid > = (SelectvidFromyanxue8_visitOrderByvidlimit10,1) limit10
Multiple runs, the time is kept between 0.0005 and 0.0006, mainly 0.0006
Conclusion: when the offset offset is small, it is better to use limit directly. This is obviously the reason for the subquery.
2. When offset is big
Select*fromyanxue8_visitlimit10000,10
Run many times and keep the time at about 0.0187
Select*Fromyanxue8_visitWherevid > = (SelectvidFromyanxue8_visitOrderByvidlimit10000,1) limit10
Run many times, the time is kept at about 0.0061, only the former 1 / 3. It can be expected that the larger the offset, the better the latter.
In the future, you should pay attention to correct your own limit statement and optimize the MySQL.
The above is how to optimize queries in MySQLlimit. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.