When SQL Server Books says that “Locked (S) resource locks are released as soon as the read operation completes , if the transaction isolation level is not set to repeat reading or higher, or the lock pointer is used to preserve the total (S) lock for the duration of the transaction.
Assuming we are talking about row level locking without an explicit transaction at the default isolation level (Read Committed), what does a read operation mean?
- Reading a single row of data?
- Reading one page of 8k IO?
- or until the complete Select statement in which the lock was created is completed, regardless of how many other rows are involved?
NOTE. The reason I need to know this is because we have several second read-only select statements created by a data-level web service that creates page-level shared read locks, creating a deadlock due to a row level conflict Exclusive update locks from prcoess replication that support server updates. The select statement is quite large, with many subselections, and one database administrator suggests rewriting it to break it into several smaller statements (shorter instances), "to reduce lock time." Since this assumes that the general read locks are maintained until the completed select statement completes, if this is not the case (if the locks are released while reading a line or page), then this approach will have no effect ...
sql-server locking isolation-level
Charles Bretana
source share