SA0164 : Consider adding WITH(NEXPAND) when querying an indexed view in order to enable query optimizer use view’s index |
![]() |
Improper use of indexed views in non-Enterprise or non-Developer editions of SQL Server can result in inefficient query performance.

In SQL Server, an indexed view can optimize query performance by storing precomputed results as an index. However, in editions other than Enterprise or Developer, the query optimizer will not automatically consider these indexed views unless explicitly instructed using the WITH(NOEXPAND) hint.
For example:
1-- Example of a problematic query in SQL Server Standard edition 2SELECT * FROM MyIndexedView; 3-- Without using WITH(NOEXPAND)
This query might not leverage the performance benefits of an indexed view because the optimizer in non-Enterprise editions overlooks the index unless WITH(NOEXPAND) is specified. As a result:
-
Query performance may degrade because the optimizer processes the view as if it were a regular table, re-evaluating the computations unnecessarily.
-
It negates the benefits of having an indexed view, particularly in high read scenarios where performance gains are critical.

This section provides guidance on optimizing the performance of queries using indexed views in SQL Server editions that are not Enterprise or Developer by employing the WITH(NOEXPAND) hint.
Follow these steps to address the issue:
-
Identify queries that reference indexed views in SQL Server Standard or Datacenter editions. These queries may not automatically benefit from the indexed view without further action.
-
Modify the query to include the WITH(NOEXPAND) hint. This ensures the query optimizer uses the index created for the view, enhancing performance.
-
Review and test the query to confirm performance improvements, especially in scenarios with high read operations, where the indexed view should offer significant benefits.
For example:
1-- Example of a corrected query in SQL Server Standard edition 2SELECT * FROM MyIndexedView WITH (NOEXPAND);

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

Name | Description | Default Value |
---|---|---|
SuppressInEditions |
Parameter specifies a comma separated list of SQL Sever editions, for which the rule not to be applied. |
Enterprise |

The rule requires Analysis Context. If context is missing, the rule will be skipped during analysis.


Performance Rules, Bugs


SQL
1SELECT * 2FROM Person.vStateProvinceCountryRegion 3 4SELECT * 5FROM Production.vProductAndDescription WITH ( NOEXPAND ) 6 7SELECT * 8FROM Person.vStateProvinceCountryRegion AS e WITH ( NOEXPAND ) 9 10SELECT * 11FROM Production.vProductAndDescription |

Message | Line | Column | |
---|---|---|---|
1 | SA0164 : Consider adding WITH(NEXPAND) when querying an indexed view in order to enable query optimizer use view’s index. | 2 | 13 |
2 | SA0164 : Consider adding WITH(NEXPAND) when querying an indexed view in order to enable query optimizer use view’s index. | 11 | 17 |
