Would partitioning prevent database deadlocks, when they are caused by rows that would otherwise be into two partitions?

StackOverflow https://stackoverflow.com/questions/7381548

Question

I am struggling with deadlocks that should not even be, as I am running bulk delete and inserts on mutually exclusive subsets of a table. Yet deadlocks seem unavoidable when running the queries on multiple threads (each of which accessing data that could be on separate partitions).

See also this question for more details on the issue, but I am wondering more generally speaking if partitioning is recommended to deal with deadlocks.

Was it helpful?

Solution

IMHO partioning would not solve anything. The chain of events for a deadlock situation is basically:

T1: get lock L1;
    get lock L2;

T2: get lock L2;
    get lock L1;

Deadlock occurs if T1 and t2 are both halfway, each owning one lock. Nothing will change if the L1 and L2 locks refer to objects in different tables; it is only the ordering of events that causes the deadlock.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top