当前位置:网站首页>MySQL limit usage and large paging problem solving
MySQL limit usage and large paging problem solving
2022-07-28 00:46:00 【LV Er Meng Da】
limit grammar
limit The syntax supports two parameters ,offset and limit, The former represents the offset , The latter means taking the former limit Data .
for example :
## Return to the qualified former 10 statement
select * from user limit 10
## Return the qualified number 11-20 Data
select * from user limit 10,20
It can also be seen from above ,limit n Equivalent to limit 0,n.
Performance analysis
In actual use, we will find , Some pages after paging , Loading will slow down , in other words :
select * from user limit 1000000,10
Statement execution is slow . So let's test it first .
The first is offset In smaller cases, take 100 Data .( The total amount of data is 200 about ). Then gradually increase offset.
select * from user limit 0,100 --------- Time consuming 0.03s
select * from user limit 10000,100 --------- Time consuming 0.05s
select * from user limit 100000,100 --------- Time consuming 0.13s
select * from user limit 500000,100 --------- Time consuming 0.23s
select * from user limit 1000000,100 --------- Time consuming 0.50s
select * from user limit 1800000,100 --------- Time consuming 0.98s
You can see that with offset The increase of , Performance is getting worse .
Why is that ? because limit 10000,10 The grammar of is actually mysql Before finding 10010 Data , Then discard the front 10000 That's ok , This step is actually wasted .
Optimize
1. use id Optimize
First find the largest page number of the last page ID, And then use it id To query , Be similar to
select * from user where id>1000000 limit 100.
It's very fast , Because the primary key is indexed , But there's a drawback to that , Namely ID It has to be continuous Of , also Query cannot have where sentence ,
because where Statements cause filtered data .
2. Optimizing with overlay index
mysql When the query completely hits the index , Called overlay index , It's very fast , Because the query only needs to look up on the index , Then you can go straight back to , Instead of going back to the data table to get the data . So we can look up the index first ID, And then according to Id Get data .
select * from (select id from job limit 1000000,100) a left join job b on a.id = b.id;
Time consuming 0.2 second .
summary
use mysql Paging a lot of data is really difficult , But there are also some ways to optimize , It needs to be tested more in combination with business scenarios .
When the user turns to 10000 Page time , Why don't we just return to empty , So boring …
边栏推荐
- The second uncle cured my spiritual internal friction and made me angry out of station B
- Matlab | those matlab tips you have to know (3)
- LeetCode 415. 字符串相加 和 43. 字符串相乘
- Set data constructor
- 蓝桥杯单片机第十一届国赛程序设计试题
- 强强协同,共拓发展!英特尔与太一物联举办 AI 计算盒聚合服务研讨会
- Buildforge materials
- 从第二层到第三层
- "Digital economy, science and technology for the good" talk about dry goods
- mysql分表之后怎么平滑上线?
猜你喜欢

Read cmake in one article

Analysis and solution of errors in symbols uploading when baget manages packages

Intel releases open source AI Reference Suite

【打新必读】魅视科技估值分析,分布式视听产品及解决方案

The second uncle cured my spiritual internal friction and made me angry out of station B

Basic operations of MySQL database (2) --- Based on data table

公司7月来了个软件测试工程师,一副毛头小子的样儿,哪想到是新一代卷王...
![[bre] software build release automation](/img/c6/daead474a64a9a3c86dd140c097be0.jpg)
[bre] software build release automation

Recurrence of fastjson historical vulnerabilities

mysql数据库的基本操作(三)-——基于字段
随机推荐
[book club issue 13] packaging format of audio and video files
迷惑的单片机矩阵按键
Analysis and solution of errors in symbols uploading when baget manages packages
҈ straight ҈ Broadcast ҈ Pre ҈ Report ҈ |҈ In hot summer, let's cross the high temperature and "bake" with nono!
【Meetup预告】OpenMLDB+OneFlow:链接特征工程到模型训练,加速机器学习模型开发
MATLAB如何将k线图设置为经典红绿配色?
OpenVINO整合TensorFlow实现推理加速
[bre] software build release automation
强强协同,共拓发展!英特尔与太一物联举办 AI 计算盒聚合服务研讨会
The construction of Yongzhou entry exit inspection laboratory
阿里二面:为什么要分库分表?
永州水质检测实验室建设:家具说明
这种动态规划你见过吗——状态机动态规划之股票问题(中)
How does JMeter solve the problem of garbled code?
Overview of construction site selection of Yongzhou analytical laboratory
【打新必读】魅视科技估值分析,分布式视听产品及解决方案
Arm发布全新A78/G78/N78内核!还有支持自定义的Cortex-X系列CPU
Yongzhou plant cell laboratory construction layout plan
[21 day learning challenge] classmate K invites you to participate in the in-depth learning seminar
Threejs personal notes