Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Records go missing with Nolock hint - results in deadlock if nolock hint taken out

$
0
0
I m currently doing my reads using the nolock hint, and updates using the rowlock hint. Here is the experiment setup:

Thread 1:
while (1 = 1)
begin
    -- Perform a read operation on row 101. Read query accesses a non-clustered index and then does a key lookup using PK
end

Thread 2:
while (1 = 1)
begin
    -- Perform update operation on row 101, note that both clustered index and non-clustered index both get updated (and many other indexes)
end

If I run the read operation without using the nolock hint, the read operation sometimes run into a deadlock.

If I run the read operation using the nolock hint, the read operation sometimes does not return any records.

Question: When I use the nolock hint, there are many instances of no record being returned at all. If I remove the nolock hint, it results in a deadlock. Why is this happening? i.e. no result-set being returned - nolock hint should ignore all locking and return dirty data (which I m ok with as long as some data is being returned), however, I dont understand why no record is being returned at all.

I donot think that the record not being returned when using the nolock hint is caused by page splits. Please correct me if I m wrong.

If I drop all the non-clustered indexes, there is no deadlock.

Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>