当前位置:网站首页>The SQL response is slow. What are your troubleshooting ideas?
The SQL response is slow. What are your troubleshooting ideas?
2022-06-25 04:46:00 【Tom bomb architecture】
If you need a full version of the interview document, you can scan the QR code at the bottom of the article to get it !
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 .
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 , I hope I can help you . Pay attention to me , The interview is no longer difficult !
Pay attention to WeChat public number 『 Tom Bomb architecture 』 reply “666” Available 200 page pdf Format document ( Complimentary gift 10 Internal interview materials of Wanzi factory ). Thank you for your support !
You can also scan the QR code below +\/ Get the full version free of charge !
↓ ↓ ↓ ↓ ↓
边栏推荐
- Basic introduction of gbase 8s blocking technology
- 【Flink】RocksDB增量模式checkpoint大小持续增长的问题及解决
- Paper notes: multi label learning ESMC (I don't understand it, but I haven't written it yet, so I'll put it here for a place temporarily)
- Excel exports data to SQL and pictures to folder through macro | VBA
- 固態硬盤開盤數據恢複的方法
- 《牛客刷verilog》Part I Verilog快速入门
- js的sort()函数
- Immutable学习之路----告别传统拷贝
- 515. find the maximum value / Sword finger offer II 095 in each tree row Longest common subsequence
- Gbase 8s parallel operation problem scenario description
猜你喜欢
Heavy broadcast | phase shift method + mathematical principle derivation of multi frequency heterodyne + implementation
CTF_ Web: Advanced questions of attack and defense world expert zone WP (15-18)
深度学习——几种学习类型
Method of opening data recovery of solid state disk
Web3 DApp用户体验最佳实践
高效的NoSQL数据库服务Amozon DynamoDB体验分享
第九章 APP项目测试(2) 测试工具
小白一键重装官网下载使用方法
《牛客刷verilog》Part I Verilog快速入门
leetcode1221. 分割平衡字符串
随机推荐
js的sort()函数
Which programming language is the most cumbersome to implement Hello world?
Wechat likes to pay attention to the solution of invalid automatic reply
LabVIEW development gas regulator
[untitled]
js的arguments
leetcode1221. Split balance string
GBASE 8s中DELIMIDENT环境变量的使用
Classification of gbase 8s locks
Immutable学习之路----告别传统拷贝
SOC验证环境的启动方式
绝了!自动点赞,我用 PyAutoGUI!
Basic introduction of gbase 8s blocking technology
Solution of gbase 8s livelock and deadlock
Paper notes: multi label learning ESMC (I don't understand it, but I haven't written it yet, so I'll put it here for a place temporarily)
leetcode1221. 分割平衡字符串
The solution of wechat applet switchtab unable to take parameters
JS' sort() function
STM32的DMA双缓冲模式详解
Huawei Hongmeng development lesson 4