Normal paging queryWhen we encounter big data queries in our daily work, our first reaction is to use paging queries. MySQL supports the limit statement to select a specified number of data, while Oracle can use rownum to select The mysql paging query statement is as follows: SELECT * FROM table LIMIT [offset,] rows | rows OFFSET offset
How to optimizeFrom the above summary, we can clearly see that when the offset is large and the amount of data is large, the query time is still quite long, so we will start to optimize these two types. Large offset Using subquery We can first locate the id of the offset position and then query the data select * from test limit 1000000,10 select id from test limit 1000000,1 select * from test where id>=(select id from test limit 1000000,1)limit 10 Through execution, we can find that the first one takes the longest time, the third one is slightly better than the first one, and the subquery is faster when using the index. But it only applies to cases where the id is incremented Use id limitationThis method has higher requirements. The ID must be continuously increasing, and the range of the ID must be calculated, and then between is used. The SQL is as follows: select * from test where id between 1000000 and 1000100 limit 100; select * from test where id>=1000000 limit 100 Results are fast Here, limit is used to limit the number of entries, and no offset is used. Optimizing the problem of large data volume
This is the end of this article about how to quickly query 10 million records in MySQL. For more information about MySQL quick query, please search previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of how Vue returns values to dynamically generate forms and submit data
>>: Summary of the use of CSS scope (style splitting)
1. concat() function Function: Concatenate multip...
Web Application Class 1. DownForEveryoneOrJustMe ...
Through the brief introduction in the previous tw...
The latest tutorial for installing MySQL 8.0.25 o...
Recently, due to work needs, I need to format num...
(1) Each HTML tag has an attribute style, which c...
<br />If only XHTML and CSS were object-orie...
Deployment environment: Installation version red ...
Pull the image docker pull mysql View the complet...
CSS3 syntax: (1rem = 100px for a 750px design) @m...
Docker Swarm is a container cluster management se...
Preparation 1. Check whether the GPU supports CUD...
Alibaba Cloud Server cannot connect to FTP FileZi...
Table of contents Error demonstration By computed...
In the past, when I needed the border length to b...