Can read-only strings trigger database locks?

Follow the https://stackoverflow.com/a/318677/

I understand that it is important to maintain the lock order for tables in order to reduce the frequency of locks, and that this affects the UPDATE and SELECT [1]. But, does the same holds true for read-only strings?

If a line is filled once during initialization, and no one has modified it yet, does it really matter what order we turn to?

Given two transactions: T1, T2 and two lines of read-only R1, R2

T1 reads R1, then R2 T2 reads R2, then R1

Can transactions come to a standstill even if I use SERIALIZABLE transaction isolation?

[1] If transaction isolation REPEATABLE_READ , T1 SELECT R1, R2, and T2 UPDATE R2, R1, a deadlock may occur.

CLARIFICATION . This issue is not specific to an RDBMS. My impression is that no implementation can block read-only strings. If you have a counter example (for a specific provider), send an answer showing the same amount, and I will accept it. In addition, publishing a list of all the specific implementations that you can prove will not be inhibited (and the most complete list will be accepted).

+1
source share
1 answer

This question cannot be answered for all possible DBMSs, since the locking strategy is an implementation detail. At the same time, a useful DBMS will have common characteristics:

For SELECT without hints ( FOR UPDATE , WITH (UPDLOCK) , ...) any sensible RDBMS will not use write locks. These may be read locks. Indeed, at least SQL Server does this for SERIALIZABLE , with the exception of Hekaton tables.

Read-locks never conflict. No deadlock is possible if only reads are performed.

Read-only lines can cause deadlocks, even if they are never written. In SQL Server

 UPDATE T SET SomeCol = 1 WHERE ID = 10 AND SomeCol = 0 

will take a U-lock of the row with id 10. If SomeCol is not 0, the lock will be released immediately and nothing will be written. But U-lock is a type of lock that can conflict and lead to a deadlock. If the line with ID 10 were not present, a dead end would have been possible.

0
source

All Articles