Subject | how to resolve this deadlock |
---|---|
Author | Hamish Moffatt |
Post date | 2018-09-10T08:46:59Z |
I have a bunch of users logging in to my system at the same time, which
causes a simple query like this to run:
UPDATE OR INSERT INTO G_CLASS (CLASS_NUM, CLASS_NAME, USER_NUM,
SYLLABUS_NUM)
VALUES (1, 'Foo', 10000001, 43)
The field values are identical for each - it's exactly the same query.
There's multiple threads running.
I'm getting a deadlock. The transaction mode is read committed with
wait; when one transaction finishes the next one unblocks, but fails
with a deadlock error.
The real query during login is actually a MERGE INTO which achieves the
same thing except it doesn't update all the fields. This might be
another level of complexity again.
Where do I start on resolving this? The queries kind of don't actually
conflict... Is there a different isolation mode that makes it work, or
do I need a different approach, or to retry?
Hamish
causes a simple query like this to run:
UPDATE OR INSERT INTO G_CLASS (CLASS_NUM, CLASS_NAME, USER_NUM,
SYLLABUS_NUM)
VALUES (1, 'Foo', 10000001, 43)
The field values are identical for each - it's exactly the same query.
There's multiple threads running.
I'm getting a deadlock. The transaction mode is read committed with
wait; when one transaction finishes the next one unblocks, but fails
with a deadlock error.
The real query during login is actually a MERGE INTO which achieves the
same thing except it doesn't update all the fields. This might be
another level of complexity again.
Where do I start on resolving this? The queries kind of don't actually
conflict... Is there a different isolation mode that makes it work, or
do I need a different approach, or to retry?
Hamish