FIX: Assertion failure when you execute a query specifying TOP N and ORDER BY in SQL Server

Applies to: SQL Server 2008 R2 Service Pack 2SQL Server 2008 R2 DeveloperSQL Server 2008 R2 Enterprise

Symptoms


Assume that you use Microsoft SQL Server 2008 R2, SQL Server 2012, or SQL Server 2014. When you execute a query by using TOP N and ORDER BY, the query hits an assert failure similar to the following:
Location: "qstopsrt.cpp":384
Expression: fFalse
SPID: <SPID>
Process ID: <ProcessID>
Location: qxcntxt.cpp:1052
Expression: cref == 0
SPID: <SPID>
Process ID: <ProcessID>
Msg 3624, Level 20, State 1, Line 2
A system assertion check has failed. Check the SQL Server error log for details. Typically, an assertion failure is caused by a software bug or data corruption. To check for database corruption, consider running DBCC CHECKDB. If you agreed to send dumps to Microsoft during setup, a mini dump will be sent to Microsoft. An update might be available from Microsoft in the latest Service Pack or in a QFE from Technical Support.
Msg 0, Level 20, State 0, Line 0
A severe error occurred on the current command. The results, if any, should be discarded.

Note
The fix may also apply to that the query plan contains "Sort (Top N Sort)."

Cause


The issue occurs because an internal error in the query execution engine.

Resolution


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

Cumulative Update 1 for SQL Server 2012 SP2

Cumulative Update 2 for SQL Server 2014

Cumulative Update 10 for SQL Server 2012 SP1

Cumulative Update 12 for SQL Server 2008 R2 SP2

Status


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