当前位置:网站首页>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
边栏推荐
- Resolution and size of mainstream mobile phones
- Constraintlayout layout
- VScode
- 使用zerotier让异地设备组局域网
- The courses bought at a high price are open! PHPer data sharing
- 面向全球市场,PlatoFarm今日登录HUOBI等全球四大平台
- Visual common drawing (V) scatter diagram
- Cumcm 2021 - B: préparation d'oléfines C4 par couplage éthanol (2)
- MySQL对数据表已有表进行分区表的实现
- Excel·VBA自定义函数获取单元格多数值
猜你喜欢
第六站神京门户-------手机号码的转换
MySQL Router重装后重新连接集群进行引导出现的——此主机中之前已配置过的问题
数据库管理软件SQLPro for SQLite for Mac 2022.30
VIM + ctags + cscope development environment construction guide
Solutions to common problems in visualization (IX) background color
Constraintlayout layout
C语言之结构体(进阶篇)
Mysql8.0安装指南
Notes on concurrent programming of vegetables (IX) asynchronous IO to realize concurrent crawler acceleration
使用 PHP PDO ODBC 示例的 Microsoft Access 数据库
随机推荐
Learning Notes 6 - Summary of several deep learning convolutional neural networks
一道有趣的阿里面试题
Visualization Road (10) detailed explanation of segmentation canvas function
Solutions to common problems in visualization (VIII) solutions to problems in shared drawing area
Mba-day5 Mathematics - application problems - engineering problems
Anaconda3 installation
Visualized common drawing (II) line chart
Esp32 learning - use and configuration of GPIO
A diary of dishes | 238 Product of arrays other than itself
Precautions for latex formula
Chapter 1 of technical Xiaobai (express yourself)
Intuitive understanding entropy
Learning notes 7-depth neural network optimization
Mba-day5 Mathematics - application problems - engineering problems
CUMCM 2021-B:乙醇偶合制備C4烯烴(2)
Full stack cross compilation x86 completion process experience sharing
MySQL Router重装后重新连接集群进行引导出现的——此主机中之前已配置过的问题
Common parameters of ffmpeg command line
闹钟场景识别
关于JUC三大常用辅助类