当前位置:网站首页>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
边栏推荐
- [ROS] (04) Detailed explanation of package.xml
- 初识c语言指针
- drf routing component Routers
- How does Apache, the world's largest open source foundation, work?
- A little thought about password encryption
- ThinkPHP5.0内置分页函数Paginate无法获取POST页数问题的解决办法
- [ROS] (05) ROS Communication - Node, Nodes & Master
- 数据的表示方法和转换(二进制、八进制、十进制、十六进制)
- 鼠标右键菜单栏太长如何减少
- 宏定义问题记录day2
猜你喜欢
随机推荐
MongoDB Compass 安装与使用
猜数字游戏,猜错10次关机(srand、rand、time)随机数生成三板斧(详细讲解!不懂问我!)
YOLOv7使用云GPU训练自己的数据集
Linux: CentOS 7 install MySQL5.7
Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id ‘c
PHP open source customer service system _ online customer service source code PHP
VS Code无法安装插件之Unable to install because, the extension '' compatible with current version
C语言一维数组练习——将m个元素移动到数组尾部
什么是 Web 3.0:面向未来的去中心化互联网
Steps to connect the virtual machine with xshell_establish a network connection between the host and the vm virtual machine
宝塔搭建PESCMS-Ticket开源客服工单系统源码实测
Deep learning framework pytorch rapid development and actual combat chapter4
函数递归和动态内存初识
[ROS]roscd和cd的区别
二级指针,数组指针,指针数组和函数指针
yolov5 improvement (1) Add attention focus mechanism
Flask framework
C语言初级—判断一个数是不是素数(函数封装)
华为路由交换
[ROS] The software package of the industrial computer does not compile