当前位置:网站首页>The SQL response is slow. What are your troubleshooting ideas?
The SQL response is slow. What are your troubleshooting ideas?
2022-07-06 22:21:00 【Tom bomb architecture】
If the interview asks you , perform SQL Slow response , What are your troubleshooting ideas and solutions ? This is a real interview question shared with me by a small partner who went to a certain place to try , Today, I would like to share my thoughts with you .
in addition , I spent it. 1 More than a week , Prepared a copy of 10W Word interview question analysis supporting documents , You can pay attention to my profile of boiling leaves if you want to get it .
1、 Investigation thought
If you execute SQL Slow response , I think there may be the following 4 One reason :
The first 1 One reason : No index or Cause index to fail .
The first 2 One reason : There are too many data in a single table , Cause query bottleneck
The first 3 One reason : Network reasons or the machine load is too high .
The first 4 One reason : Hot data causes single point load imbalance .
Next , I aim at the above situations , Let's talk about my solutions .
2、 Solution
The first 1 In this case : The index is invalid or there is no index
First , Can open MySQL Slow query log , Collect the contents of slow query logs for a period of time , Then find out what took the longest SQL sentence , For these SQL Statement analysis .
For example, you can use the execution plan explain To view the SQL Whether there is a hit index . If you find slow queries SQL No hit index , You can try to optimize these SQL sentence , Guarantee SQL Execute by index . If SQL If there is no way to optimize the structure , Consider adding the corresponding index to the table . We are optimizing SQL Or when adding an index , Must conform to the leftmost matching principle .
The first 2 In this case : There are too many data in a single table , Conditions that cause query bottlenecks . Even if SQL The statement is indexed , The performance is not particularly good . At this time, we need to consider table segmentation . Table segmentation rules are generally divided into two types , One is horizontal segmentation , One is vertical segmentation .
Horizontal segmentation means that a large table with tens of millions of data rows , Split into multiple small tables according to the business PK , These small watches may reach 100 Zhang even 1000 Zhang .
That vertical segmentation means , Combine multiple columns in a single table , According to the business logic, put the columns with high relevance into the same table .
In addition to this sub table , We can also divide the warehouse ,
For example, we have split up 1000 surface , then , Put the suffix 0-100 The tables of are placed in the same database instance , then ,100-200 Put the table of into another database instance , And so on 1000 Table storage 10 Database instances . In this case , We can route requests to different database instances according to the business primary key , Thus, the traffic borne by each database instance is relatively small , To achieve the purpose of improving database performance .
The first 3 In this case : Network reasons or excessive machine load , We can separate reading and writing .
such as MySQL Support the distributed deployment of one master and multiple slaves , We can use the main library only to handle the operation of writing data , Multiple slave libraries are only used to handle read operations . In scenarios with large traffic , You can increase the load capacity of the database by adding slave libraries , So as to improve the overall performance of the database .
The first 4 In this case : Hot data leads to unbalanced load at a single point .
In this case , In addition to adjusting the database itself , You can also increase the cache . Pre store the hot data with frequent queries into the cache , such as Redis、MongoDB、ES etc. , To relieve the pressure of data , So as to improve the response speed of the database .
The above is my view on the implementation SQL Slow response troubleshooting ideas and solution understanding ,
This paper is about “Tom Bomb architecture ” original , Reprint please indicate the source . Technology is about sharing , I share my happiness !
If this article helps you , Welcome to pay attention and like ; If you have any suggestions, you can also leave comments or private letters , Your support is the driving force for me to adhere to my creation . Pay attention to WeChat public number 『 Tom Bomb architecture 』 reply “666” Available 200 page PDF Interview document !
I was delayed by programming Tom
边栏推荐
- MariaDb数据库管理系统的学习(一)安装示意图
- 插入排序与希尔排序
- Xiaoman network model & http1-http2 & browser cache
- zabbix 代理服务器 与 zabbix-snmp 监控
- Hardware development notes (10): basic process of hardware development, making a USB to RS232 module (9): create ch340g/max232 package library sop-16 and associate principle primitive devices
- GPS从入门到放弃(十一)、差分GPS
- OpenCV VideoCapture. Get() parameter details
- 微信红包封面小程序源码-后台独立版-带测评积分功能源码
- 数据处理技巧(7):MATLAB 读取数字字符串混杂的文本文件txt中的数据
- 每日一题:力扣:225:用队列实现栈
猜你喜欢

Crawler obtains real estate data

LeetCode刷题(十一)——顺序刷题51至55
![[linear algebra] determinant of order 1.3 n](/img/6e/54f3a994fc4c2c10c1036bee6715e8.gif)
[linear algebra] determinant of order 1.3 n

基於 QEMUv8 搭建 OP-TEE 開發環境

GPS from entry to abandonment (XVII), tropospheric delay

Memorabilia of domestic database in June 2022 - ink Sky Wheel

2020 Bioinformatics | GraphDTA: predicting drug target binding affinity with graph neural networks

Unity3d Learning Notes 6 - GPU instantiation (1)

Management background --4, delete classification

重磅新闻 | Softing FG-200获得中国3C防爆认证 为客户现场测试提供安全保障
随机推荐
Maximum product of three numbers in question 628 of Li Kou
Leetcode question brushing (XI) -- sequential questions brushing 51 to 55
GPS从入门到放弃(十七) 、对流层延时
Spatial domain and frequency domain image compression of images
硬件開發筆記(十): 硬件開發基本流程,制作一個USB轉RS232的模塊(九):創建CH340G/MAX232封裝庫sop-16並關聯原理圖元器件
About the professional ethics of programmers, let's talk about it from the way of craftsmanship and neatness
Management background --5, sub classification
微信红包封面小程序源码-后台独立版-带测评积分功能源码
PVL EDI 项目案例
Notes de développement du matériel (10): flux de base du développement du matériel, fabrication d'un module USB à RS232 (9): création de la Bibliothèque d'emballage ch340g / max232 SOP - 16 et Associa
labelimg的安装与使用
小常识:保险中的“保全”是什么?
【sciter】: 基于 sciter 封装通知栏组件
Barcodex (ActiveX print control) v5.3.0.80 free version
GPS from getting started to giving up (XI), differential GPS
LeetCode刷题(十一)——顺序刷题51至55
Unity3d minigame-unity-webgl-transform插件转换微信小游戏报错To use dlopen, you need to use Emscripten‘s...问题
小程序系统更新提示,并强制小程序重启并使用新版本
Data processing skills (7): MATLAB reads the data in the text file TXT with mixed digital strings
2500 common Chinese characters + 130 common Chinese and English characters