当前位置:网站首页>A troubleshooting process for database timeout caused by SQL misguided
A troubleshooting process for database timeout caused by SQL misguided
2022-06-13 07:36:00 【Fish is not fish】
The phenomenon
A project I just took over recently , At noon one day 12 spot 30 Receive more development feedback , When their business requests a database , There are a lot of request timeouts , Although there have been before , But this one lasted a long time , I recovered in about two minutes .
Database version 8.0.22. Isolation level RR.
Preliminary analysis
Receive questions , take it easy , Take a look at the surveillance :

From the monitoring diagram, it can be seen that the corresponding 12 spot 36 The number of connections began to soar around the minute , And there is a small amount of slowness at this point sql.
View the slow query log at the corresponding time point , The following slow queries are found at the corresponding time sql:
Here you can see the slow query from 12 spot 36 It's done 155s.
This SQL It's not supposed to be slow , because (uid,msg_id) It's a uk Indexes ,id It's the primary key .
And then because of the timeout , So guess it is the timeout caused by the lock ?
However, the new project does not have a very deep lock related monitoring , You can only query the storage engine information Show engine innodb status\G; You can only see the latest deadlock information . To see the complete deadlock information Suggest opening innodb_print_all_deadlocks, This parameter will output all deadlock information to MySQL Of error log among . In this way, the deadlock log at the corresponding time point will not be missed .
As a result, a deadlock message occurred at the corresponding time point , as follows :
From the latest deadlock log , We can see :
At that time, there was a lock waiting situation Here we need to declare the difference between lock waiting and deadlock
1. An error will be reported immediately when a deadlock occurs , And the rollback cost is small SQL. Lock waiting is based on innodb_lock_wait_timeout Default 50s, If in 50s Can't get the corresponding lock , An error will be reported try again. Therefore, the deadlock must be caused by the lock waiting first .
At that time, lock competition mainly focused on the primary key index record Lock contention leads to however , From two SQL Look at , these two items. SQL All have uk Indexed , Finally, the primary key cannot have lock contention .
Here we are. , I have no idea , Later, I thought I could only look back at the implementation plan , Whether the implementation plan has not reached ;

A magical scene happened , This SQL I went to the primary key index , Then there is a train of thought .
The data in the table is 2500w strip , It's almost like scanning the whole table ,
If it is a full table scan , Lock all primary keys , That makes sense .
summary
The process of the problem is as follows :
12 spot 36 branch , This is slow SQL Due to the wrong index , With all the primary key indexes gap and record lock
Then other requests come , because innodb_lock_wait_timeout=50s By default ,
So the following SQL Waiting when you can't get the lock 50s Later error reporting try again, The business response is timeout .
Thus, during the slow query execution , The corresponding in the back SQL Can't get the lock , All in 50s Time out after ,
Also because of waiting , So the connection stack , soar , Slow behind SQL 155s completion of enforcement , Back to normal .
边栏推荐
- Data desensitization tool advance tool Datamask
- Redis learning journey sentinel mode
- Pdf to word
- 11.29 Li Kou swipes questions every day
- c#高級編程-特性篇
- B. I hate 1111 (mnemonic search number theory
- Performance tuning can't just depend on tapping the brain
- redis-2. Redis string type & bitmap
- Upgrade the project of log4j to log4j2
- FTP_ Manipulate remote files
猜你喜欢

在排序数组中查找元素的第一个和最后一个位置

GCC compilation process, function library related compilation process

C#合并多个richtextbox内容时始终存在换行符的解决方法

关于#数据库#的问题:PGADMIN4 编辑sql窗口问题
![[log framework] add user-defined parameters to the MDC implementation log](/img/94/5c0c51663f6a26d2ccf4a81047060f.jpg)
[log framework] add user-defined parameters to the MDC implementation log

Redis underlying data structure -- listpack

The password does not take effect after redis is set

Simple understanding of basic language of C language

Make cer/pfx public and private key certificates and export CFCA application certificates

redis-0. Introduction to redis and NiO principle (random talk)
随机推荐
socket编程2:IO复用(select && poll && epoll)
What languages can be decompiled
P1434 [show2002] skiing (memory search
EF core execute SQL statement
论文笔记: 多标签学习 BP-MLL
[vivefocus uses the wavevr plug-in to obtain handle operation events]
B. I hate 1111 (mnemonic search number theory
About database: pgadmin4 editing SQL window
Find the first and last positions of elements in a sorted array
6. system call
c#高级编程-特性篇
Redis learning journey - transaction
How to solve the 404 problem
Nodejs file module FS
Logback log framework learning and problems
Paper notes: multi label learning bp-mll
理財產品連續幾天收益都是零是怎麼回事?
Awk use
平衡二叉树学习笔记------一二熊猫
Distributed database tidb