Willing to understand a scenario when deadlock is occurring in a table with 1 clustered and 1 non-clustered index due to multiple insert statements.
The solution was weird, where ignoreDuplicateKey
was set to False, which resolved the problem. It was TRUE
by mistake and deadlock occurred when it was true. I read a lot about index and locking, insert might cause the lock, but how come this property solved the problem?
Scenario - 1 table, 5 threads in parallel attempting to insert using Spring batch (5 multiple partitions), 1000 is the commit interval. 2 indexes - 1 primary key unique clustered index, 1 non-clustered unique index (with IgnoreDuplicateKey=True
).
No triggers on the table.
~150 inserts failed out of 40000 due to deadlock. Number of deadlock failures increased with increased volume.