• Revenant (2/13/2012)


    jascunce (2/13/2012)


    This is interesting. The actual execution plan from the Std instance with sp1 reports that the clustered index from the base table, not the view, was used in each of the 5 queries. Sorry I couldn't get that info from the RTM instance since it was just upgraded but I would think the results would still be the same :-).

    I compared that with the execution of the code in a SQL 2008 R2 Enterprise instance with sp1 and the results were like you had reported from the Developer edition; the clustered index from the view was used.

    The same for the DataCenter Edition.

    The plan is attached.

    All exactly as I expected. This confirms that on editions below Enterprise, the only way to get the optimizer to use an index on the view is to use the NOEXPAND hint; using an index hint will not work, as they are ignored on views.

    Remember, on Enterprise Edition (and hence also on the feature-equal Developer Edition and on DataCenter, which is essentially Enterprise++), the optimizer will automatically consider using indexes on views, regardless of whether the query references the view or the base tables. On lower editions (such as Standard, Workgroup, and Express), the optimizer will never consider using indexes on views, unless the NOEXPAND hint is used to force the use of an index on the view.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/