FIX: Rare possibility of incorrect results when you use Option(Recompile) for queries inside a procedure in SQL Server 2014 or SQL Server 2012

Applies to: SQL Server 2014 DeveloperSQL Server 2014 DeveloperSQL Server 2014 Enterprise More

Symptoms


Consider the following scenario:
  • You run a procedure in Microsoft SQL Server 2014 or SQL Server 2012.
  • The procedure contains a query has the following conditions:
    • It joins a table that is updated very frequently.
    • It has a WHERE clause that contains parameters.
    • It uses Option(Recompile).
  • This procedure is run on multiple concurrent connections that have different sets of parameter values.
  • Your server is under a heavy load that is causing each of these procedures to take more time than usual.
In this scenario, you may receive incorrect results from the procedure that is run on your connection if the following additional conditions are met during the time interval that occurs between the end of query compilation and the start of query execution on your connection:
  • Condition 1: Another concurrent connection makes updates to the joined table that are large enough to trigger another recompilation of the query on your connection.
  • Condition 2: The same query was recompiled from another connection and then put into cache.
Important This timing issue is extremely rare.

Cause


This problem occurs because the parameter values for the query are changed to incorrect values after you run the query on your connection. This occurs because of an extremely rare timing issue that exists between concurrent compilations.

Resolution


The issue was first fixed in the following cumulative update of SQL Server.

Cumulative Update 4 for SQL Server 2014

Cumulative Update 2 for SQL Server 2012 SP2

Cumulative Update 11 for SQL Server 2012 SP1

Status


Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.