• dev.tridib (8/24/2012)


    If both update and select are part of the same transaction. and update is having a X lock on the data rows, IX lock on the index page and table. Then when select requires a shared lock on the data row will it be able to acquire?

    Yes, absolutely. Locks are to prevent other sessions from accessing data that's changed. You can always read changes that you yourself have made in the current session

    What i have understood (or misunderstood :doze:) from the topic is select will not be able to acquire the shared lock if the data row is protected by an X lock from the Update statement neither can have a IS on clustered index pages nor on table as those are already protected by IX locks.

    The select will not be able to get a shared lock if the row is protected by an X lock taken by another session. You never block yourself (could you imagine selecting rows but then not being able to update them because of the lock that the select took? Doesn't make sense does it?)

    Now the statement which says if the select statement acquires enough locks to trigger lock escalation and the escalation succeeds the IX lock on the table is converted to X lock. Now if the table is protected by X lock how select will succeed?

    Because they're on the same connection. A select that someone else runs (or you run from a different session) will be blocked. The select you run on the current session must succeed.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass