Designing Modular Indexed Views

Because of the many restrictions on indexed views (no unions, no outer joins, no aggregates other than SUM() and COUNT_BIG(), and so on), you won't find a lot of complex queries that you can cover completely with a single indexed view. However, you will likely find many simpler ones—aggregations and joins that your code repeats often—and this is where the best use of indexed views comes in: modular preprocessing. Indexed views are best suited to simpler queries that take a considerable amount of time to run because of the amount of data they traverse. By materializing the result sets that are produced by these queries, you create the possibility that the optimizer may use an indexed view to avoid having to reproduce ...

Get Guru's Guide to SQL Server™ Stored Procedures, XML, and HTML, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.