Bug #96748 | deadlock when doing SELECT FOR UPDATE and INSERT | ||
---|---|---|---|
Submitted: | 4 Sep 2019 11:59 | Modified: | 4 Sep 2019 13:20 |
Reporter: | Antony Dovgal | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Locking | Severity: | S3 (Non-critical) |
Version: | 8.0.17 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | deadlock, insert, SELECT, UPDATE |
[4 Sep 2019 11:59]
Antony Dovgal
[4 Sep 2019 13:20]
MySQL Verification Team
Hello Mr. Dovgal, Thank you for your bug report. However, this is not a bug, but expected behaviour. InnoDB is an ACID, MVCC and transactional storage engine. All such storage engines have a check for deadlocks. The fact that you got the deadlock error is a proof that InnoDB SE is working perfectly. Deadlocks happen when, in the simplest case, transaction A locks row X1 and attempts to lock X2, while transaction B has locked row X2 and tries to get a lock on row X1. What you should do, is when you get this error, to resubmit each of the transactions that get this error. From your application side, to be clear. Not a bug.
[21 Mar 2023 18:24]
Jesse Russell
I'm experiencing the same issue and while I understand that deadlocks are expected, I don't understand how this scenario causes a deadlock. I would like to avoid failed queries so it would be nice to know what exactly I have to do to prevent this deadlock from happening. I don't see how the second transaction is preventing the first from completing and releasing its lock as the second transaction doesn't appear to have acquired any locks yet when it runs the first query (select ... for update).
[21 Mar 2023 18:28]
Jesse Russell
Hang on, I see now. I ran some tests and it looks like both transactions succeed on creating the lock at the same time because there's no rows to lock on. I kinda feel like that could be considered a bug, or at least unwanted behavior.
[22 Mar 2023 13:45]
MySQL Verification Team
Hi, We are happy that you have got it ..... Next, you should always use latest release, which is now 8.0.32. Last, but not least, P_S has a nice way of presenting InnoDB locks. Just read a manual on the tables that are available there in the latest releases. See for example, sub-paragraph 27.12.13.1.