当前位置:网站首页>How to quickly query 10 million pieces of data in MySQL
How to quickly query 10 million pieces of data in MySQL
2022-04-23 11:06:00 【liming89】
Source of the article : Learn through http://www.bdgxy.com/
General paging query
When we encounter big data query in our daily work , The first reaction is to use paging queries .
mysql Support limit Statement to select the specified number of data , and oracle have access to rownum To select
mysql The paging query statement is as follows :
SELECT * FROM table LIMIT [offset,] rows | rows OFFSET offset
- The first parameter is used to specify the offset of the first return record line
- The second parameter specifies the maximum number of rows to return records
- When the same offset , More data , The longer it takes
- When the same amount of data , The greater the offset , The longer it takes
How to optimize
After the summary above , We can clearly see that when the offset is large , When there's a lot of data , There is still a lot of time to query , So we will optimize these two methods
Large offset
Adopt sub query method
We can locate the offset position first id, 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 , The first one takes the most time , The third one is a little better than the first one , And subqueries use indexes faster .
But it only applies to id Incremental situation
use id Limiting mode
This method is more demanding ,id Must be continuously increasing , And it has to be calculated id The scope of the , And then use between,sql as follows :
select * from test where id between 1000000 and 1000100 limit 100;
select * from test where id>=1000000 limit 100
The results are quick
here limit Yes, the number is limited , No offset is used
Optimize the problem of large amount of data
- The amount of data returned will also directly affect the speed
- Reduce unnecessary columns , Query efficiency will be significantly improved
This is about Mysql This is the article on how to quickly query 10 million pieces of data in , More about Mysql For quick query, please search rookie tutorial www.piaodoo.com Previous articles or continue to browse the relevant articles below. I hope you can support rookie tutorials in the future www.piaodoo.com!
版权声明
本文为[liming89]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231102124752.html
边栏推荐
- Detailed explanation of typora Grammar (I)
- 如何使用JDBC CallableStatement.wasNull()方法调用来查看最后一个OUT参数的值是否为 SQL NULL
- 活动进行时! 点击链接加入直播间参与“AI真的能节能吗?”的讨论吧!
- CUMCM 2021-B:乙醇偶合制備C4烯烴(2)
- Strongest date regular expression
- Is the pointer symbol of C language close to variable type or variable name?
- 我的创作纪念日
- MBA - day5 mathématiques - Questions d'application - Questions d'ingénierie
- Mysql8. 0 installation guide
- Visualization Road (10) detailed explanation of segmentation canvas function
猜你喜欢

Ueditor -- limitation of 4m size of image upload component

Visualized common drawing (II) line chart

Solutions to common problems in visualization (IX) background color

《Neo4j权威指南》简介,求伯君、周鸿袆、胡晓峰、周涛等大咖隆重推荐

关于JUC三大常用辅助类

STM32接电机驱动,杜邦线供电,然后反烧问题

Visual common drawing (III) area map

Solutions to common problems in visualization (VIII) solutions to problems in shared drawing area

Introduction to data analysis 𞓜 kaggle Titanic mission (III) - > explore data analysis

Detailed explanation of typora Grammar (I)
随机推荐
SWAT - Introduction to Samba web management tool
学习网站资料
MySQL面试题讲解之如何设置Hash索引
防止web项目中的SQL注入
Detailed explanation of typora Grammar (I)
ID number verification system based on visual structure - Raspberry implementation
Restful、SOAP、RPC、SOA、微服务之间的区别
CUMCM 2021-B:乙醇偶合制備C4烯烴(2)
C语言之结构体(进阶篇)
Esp32 learning - use and configuration of GPIO
Kaggle - real battle of house price prediction
Learning website materials
软件测试人员,如何优秀的提Bug?
More reliable model art than deep learning
Special members and magic methods
Simple thoughts on the design of a microblog database
JDBC – PreparedStatement – 如何设置 Null 值?
HuggingFace
UDP basic learning
Notes on concurrent programming of vegetables (IX) asynchronous IO to realize concurrent crawler acceleration