Symptoms
Consider the following scenario:
-
You have a database that has the options ALLOW_SNAPSHOT_ISOLATION and READ_COMMITTED_SNAPSHOT enabled in Microsoft SQL Server 2008 R2.
-
You run a SELECT statement that contains TABLOCK and UPDLOCK hints against a table in the database.
-
The SELECT statement is wrapped in an explicit BEGIN TRAN, but COMMIT TRAN is not executed.
-
Two more of the same queries that are started with the same query hints are in the explicit transaction.
In this scenario, when the first query is committed, one of the other queries will be deadlock.
Cause
The issue occurs because SQL Server incorrectly reports deadlock in one of the following scenarios:
-
When ALLOW_SNAPSHOT_ISOLATION and READ_COMMITTED_SNAPSHOT are enabled for a database, multiple queries against the same transaction may be reported as deadlocked incorrectly when one of them is completed.
-
When ALLOW_SNAPSHOT_ISOTION is enabled and the hints TABLOCK and UPDLOCK are used, the second and third SELECT statement take IX locks with the intent to convert to X. The IX locks end up deadlocking when an attempt to convert to X is made.
-
When ALLOW_SNAPSHOT_ISOLATION is disabled, the second and third queries will obtain a SIX lock. In this situation, when the SIX lock is converted to X, it is just a blocking scenario, not a deadlock.
Resolution
The issue was first fixed in the following cumulative update of SQL Server.
After you apply the hotfix, SQL Server resolve the issue by recording if a READ COMMIT hint or NOLOCK hint is encountered for the database and query. This information is used to select the correct type of locks to handle the situation correctly, instead of incorrectly report deadlock.Cumulative Update 11 for SQL Server 2008 R2 SP2 /en-us/help/2926028
Each new cumulative update for SQL Server contains all the hotfixes and all the security fixes that were included with the previous cumulative update. Check out the latest cumulative updates for SQL Server:
Status
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.