SA0197 : The deprecated FASTFIRSTROW hint was encountered

The use of deprecated hints like FASTFIRSTROW in T-SQL queries can cause compatibility issues and is no longer recommended in newer versions of SQL Server.

Description

In SQL Server, the FASTFIRSTROW hint was originally intended to optimize query execution by fetching the first few rows quickly. However, with advancements in the query optimizer, this hint has been deprecated, and its use can lead to inefficient and unpredictable query behavior.

For example:

SQL
1-- Example of query using deprecated hint
2SELECT * FROM Customers OPTION(FASTFIRSTROW);

This example is problematic because the use of FASTFIRSTROW can cause SQL Server to generate suboptimal execution plans, which might degrade performance instead of improving it. Modern query optimizers automatically handle such scenarios more efficiently.

  • Using deprecated hints can result in less efficient query plans, negatively affecting performance.

  • Deprecated features may not be supported in future SQL Server releases, posing maintenance challenges.

How to fix

Replace deprecated FASTFIRSTROW hints with alternative options, like OPTION (FAST n), to enhance query efficiency and maintain compatibility with future SQL Server versions.

Follow these steps to address the issue:

  1. Identify queries using the deprecated FASTFIRSTROW hint. Search for SQL statements in your database scripts or stored procedures that include OPTION(FASTFIRSTROW).

  2. Replace the FASTFIRSTROW hint with the recommended OPTION (FAST n) syntax. Choose an appropriate value for n based on your specific query needs to optimize for the first n rows.

  3. Test the modified query to ensure performance improvements and validate the execution plan using SQL Server Management Studio (SSMS). Adjust the value of n if necessary to achieve optimal performance.

For example:

SQL
1-- Example of corrected query
2SELECT * FROM Customers OPTION (FAST 1);

Scope

The rule has a Batch scope and is applied only on the SQL script.

Parameters

Rule has no parameters.

Remarks

The rule does not need Analysis Context or SQL Connection.

Effort To Fix
8 minutes per issue.
Categories

Design Rules, Deprecated Features, Bugs

Additional Information

There is no additional info for this rule.

Example Test SQL
SQL
 1--- Table Hints ---
 2SELECT StartDate, ComponentID FROM Production.BillOfMaterials
 3    WITH( INDEX (FIBillOfMaterialsWithComponentID), FASTFIRSTROW /*IGNORE:SA0197*/ )
 4    WHERE ComponentID in (533, 324, 753, 855, 924);
 5
 6SELECT * FROM Sales.SalesOrderHeader  (FASTFIRSTROW)  AS h 
 7
 8SELECT * FROM Sales.SalesOrderHeader AS h (FASTFIRSTROW) 
 9
10SELECT * FROM Sales.SalesOrderHeader AS h
11OPTION (FAST 1)

Analysis Results
  Message Line Column
1 SA0197 : The deprecated FASTFIRSTROW hint was encountered. 6 39
2 SA0197 : The deprecated FASTFIRSTROW hint was encountered. 8 43
See Also

Other Resources