Fix deadlock on MySQL when updating MRs
What does this MR do?
Picks a fix from https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/13102 back to 9.4.
Are there points in the code the reviewer needs to double check?
Don't think so!
Why was this MR needed?
MySQL users were seeing an actual deadlock in 9.4: https://gitlab.com/gitlab-org/gitlab-ce/issues/36425.
What are the relevant issue numbers?
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/36425.