当前位置:网站首页>Mysql中一千万条数据怎么快速查询
Mysql中一千万条数据怎么快速查询
2022-04-23 11:02:00 【liming89】
文章来源: 学习通http://www.bdgxy.com/
普通分页查询
当我们在日常工作中遇到大数据查询的时候,第一反应就是使用分页查询。
mysql支持limit语句来选取指定的条数数据,而oracle可以使用rownum来选取
mysql分页查询语句如下:
SELECT * FROM table LIMIT [offset,] rows | rows OFFSET offset
- 第一个参数用来指定第一个返回记录行的偏移量
- 第二个参数指定返回记录行的最大数目
- 当相同的偏移量时,数据量越大,花费时间越长
- 当相同的数据量时,偏移量越大,花费时间越长
如何优化
经过上面的总结,我们可以很清晰的看到当偏移量大,数据量大的时候,查询的时间还是挺多的,所以我们就针对这两种来着手优化
偏移量大
采用子查询方式
我们可以先定位偏移位置的id,然后再查询数据
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
?通过执行我们可以发现,第一条花费时间最大,第三条比第一条稍微好一点,而且子查询使用索引速度更快。
但是只是适用于id递增的情况
采用id限定方式
这种方法要求更高,id必须是连续递增,而且还得计算id的范围,然后使用between,sql如下:
select * from test where id between 1000000 and 1000100 limit 100;
select * from test where id>=1000000 limit 100
结果很快
这里limit是限制了条数,没有采用偏移量
优化数据量大问题
- 返回结果的数据量也会直接影响速度
- 减少不需要的列,查询效率会明显提升
到此这篇关于Mysql中一千万条数据怎么快速查询的文章就介绍到这了,更多相关Mysql 快速查询内容请搜索菜鸟教程www.piaodoo.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持菜鸟教程www.piaodoo.com!
版权声明
本文为[liming89]所创,转载请带上原文链接,感谢
https://blog.csdn.net/liming89/article/details/124333744
边栏推荐
- A diary of dishes | 238 Product of arrays other than itself
- Notes on concurrent programming of vegetables (IX) asynchronous IO to realize concurrent crawler acceleration
- Go interface usage
- Google Earth Engine(GEE)——将原始影像进行升尺度计算(以海南市为例)
- Gets the current time in character format
- 【leetcode】199. Right view of binary tree
- Excel·VBA自定义函数获取单元格多数值
- MIT:用无监督为世界上每个像素都打上标签!人类:再也不用为1小时视频花800个小时了
- @valid,@Validated 的学习笔记
- Understand the key points of complement
猜你喜欢

数据库管理软件SQLPro for SQLite for Mac 2022.30

MySQL how to merge the same data in the same table

Promise详解

Mysql8.0安装指南

Google Earth engine (GEE) - scale up the original image (taking Hainan as an example)

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

UEditor之——图片上传组件大小4M的限制

Cumcm 2021 - B: préparation d'oléfines C4 par couplage éthanol (2)

一道有趣的阿里面试题

语雀文档编辑器将开源:始于但不止于Markdown
随机推荐
SQL Server recursive query of superior and subordinate
Ueditor -- limitation of 4m size of image upload component
使用 PHP PDO ODBC 示例的 Microsoft Access 数据库
Jupyter lab top ten high productivity plug-ins
全栈交叉编译X86完成过程经验分享
JVM - common parameters
Mysql8.0安装指南
Promise详解
Esp32 learning - use and configuration of GPIO
Simple thoughts on the design of a microblog database
The songbird document editor will be open source: starting with but not limited to markdown
Learning notes 7-depth neural network optimization
VScode
活动进行时! 点击链接加入直播间参与“AI真的能节能吗?”的讨论吧!
Cygwin 中的 rename 用法
学习 Go 语言 0x03:理解变量之间的依赖以及初始化顺序
Visual common drawing (I) stacking diagram
Pycharm
web三大组件(Servlet,Filter,Listener)
Read integrity monitoring techniques for vision navigation systems