当前位置:网站首页>MySQL知识总结 (六) MySQL调优
MySQL知识总结 (六) MySQL调优
2022-08-02 14:05:00 【weixin_45773632】
MySQL调优金字塔理论
如下图所示:
如上图所示:
数据库优化维度有四个:硬件、系统配置、数据库表结构、SQL及索引优化成本:硬件>系统配置>数据库表结构>SQL及索引优化效果:硬件<系统配置<数据库表结构<SQL及索引
SQL优化工具
原文链接:大厂实践 - 美团: SQL优化工具SQLAdvisor开源
项目地址:https://github.com/Meituan-Dianping/SQLAdvisor/blob/master/doc/QUICK_START.md
常见调优技巧及面试
1. 实践中如何优化MySQL
最好是按照以下顺序优化:
- SQL 语句及索引的优化
- 数据库表结构的优化
- 系统配置的优化
- 硬件的优化
2. 百万条数据MySql分页问题
在开发过程中我们经常会使用分页,核心技术是使用limit进行数据的读取,在使用limit进行分页的测试过程中,得到以下数据:
select * from news order by id desc limit 0,10
耗时0.003秒
select * from news order by id desc limit 10000,10
耗时0.058秒
select * from news order by id desc limit 100000,10
耗时0.575秒
select * from news order by id desc limit 1000000,10
耗时7.28秒
我们惊讶的发现mysql在数据量大的情况下分页起点越大查询速度越慢,100万条起的查询速度已经需要7秒钟。这是一个我们无法接受的数值!
改进方案1:
SELECT * FROM news
WHERE id > (SELECT id FROM news ORDER BY id DESC LIMIT 1000000, 1)
ORDER BY id DESC
LIMIT 0,10
查询时间 0.365秒,提升效率是非常明显的!!原理是什么呢???
我们使用条件对id进行了筛选,在子查询 (select id from news order by id desc limit 1000000, 1) 中我们只查询了id这一个字段比起select * 或 select 多个字段 节省了大量的查询开销!
改进方案2:
适合id连续的系统,速度极快!
select * from news
where id between 1000000 and 1000010
order by id desc
边栏推荐
猜你喜欢
随机推荐
Raj delivery notes - separation 第08 speak, speaking, reading and writing
C语言日记 4 变量
Deep learning framework pytorch rapid development and actual combat chapter3
c语言三子棋详解!!! (电脑智能下棋)(附上完整代码)
A little thought about password encryption
verilog学习|《Verilog数字系统设计教程》夏宇闻 第三版思考题答案(第十章)
8576 Basic operations of sequential linear tables
Flask-RESTful request response and SQLAlchemy foundation
Hands-on OCR (1)
[ROS] (05) ROS Communication - Node, Nodes & Master
Linux: CentOS 7 install MySQL5.7
MongoDB安装流程心得:
C语言日记 5、7setprecision()问题
The specific operation process of cloud GPU (Hengyuan cloud) training
鼠标右键菜单栏太长如何减少
ng-style:动态控制样式
YOLOv7 uses cloud GPU to train its own dataset
[ROS] The difference between roscd and cd
uniapp小程序禁止遮罩弹窗下的页面滚动的完美解决办法
初识c语言指针




![[ROS] The difference between roscd and cd](/img/a8/a1347568170821e8f186091b93e52a.png)




