开发者

SELECT Blocking Update in DB with RCSI enabled

We have a database, tstERP. tstERP has RCSI enabled and that was verified via:

SELECT is_read_committed_snapshot_on, name from sys.databases WHERE name = 'TEST'

There are two connections. SPID 87 and 243. 87 is blocking 243. The detailed information is below. In summary, SPID 87, the "select on tbl1" has an exclusive lock on an index key. 243, an update, is waiting for an exclusive lock on that same key.

I have been told there are not hints of any type at play here, but have not seen all of the code myself.

So, right up front, I have two questions pertaining to SPID 87.

  1. With RCSI enabled, why is the select even taking locks?
  2. Lock taking or not aside, this is a very simple select statement which returns one row. Why is the transa开发者_开发百科ction staying open? Have some devs very fond of setting implicit trans on, which sometimes get them in trouble with leaving trans open. However this code is well past the point of design so that should not be an issue.

All insight is appreciated.

Thanks!


SPID 87 - Head of the blocking chain

Code: SELECT col1,col2,col3,col4,col5 FROM tbl1 WHERE col1 = @P1 AND col2 = @P2 AND col3 = @P3 AND col4 = @P4

Locks:

Object name="tbl1" schema_name="dbo"
    Locks
        Lock resource_type="KEY" index_name="ind1" request_mode="X" request_status="GRANT" request_count="1" 
        Lock resource_type="OBJECT" request_mode="IX" request_status="GRANT" request_count="1" 
        Lock resource_type="PAGE" page_type="*" index_name="ind1" request_mode="IX" request_status="GRANT" request_count="1"
    /Locks
/Object

Additional Info: transaction_isolation_level ReadCommitted /transaction_isolation_level


SPID 243 - Being Blocked

Code: update tbl1 set col5 = vol5 + 1 where col1 = @1 and col2 = @2 and col3 = @3 and col4 = @4

Locks:

Object name="tbl1" schema_name="dbo"
      Locks
        Lock resource_type="KEY" index_name="ind1" request_mode="X" request_status="WAIT" request_count="1"
        Lock resource_type="OBJECT" request_mode="IX" request_status="GRANT" request_count="1"
       Lock resource_type="PAGE" page_type="*" index_name="ind1" request_mode="IX" request_status="GRANT" request_count="1"
      /Locks
/Object

Additional Info: transaction_isolation_level ReadCommitted /transaction_isolation_level


0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜