Subscribe in a reader" />
Welcome to TechNet Blogs Sign in | Join | Help

Andrew Fryer's Blog

Insufficient Data

News

SQL Server 2008 Filtered Indexes vs Index Views

SQL Server 2008 has a new feature called filtered indexes which are like normal table indexes only they have a simple where clause,  meaning that the index will only cover rows specified in the where clause. As I have mentioned before an obvious example is where you can filter out nulls and still create a unique index.

So how do filter indexes compare with index views, well index views are more complex , you can index across a view containing multiple tables for a start and the where and case clauses can be very sophisticated.  This sophistication comes at a price as the index can be larger (and the B+ Trees will be deeper)  and is will be updated during an insert whereas a filtered index will only be updated during insert if the new row meets the where clause in the filter.

So when to use what?

  • The where clause in a filtered indexes has be pretty simple – i.e. it has to conform to these this format:

<filter_predicate> ::=

    <conjunct> [ AND <conjunct> ]

<conjunct> ::=

    <disjunct> | <comparison>

<disjunct> ::=

        column_name IN (constant ,…)

<comparison> ::=

        column_name <comparison_op> constant

<comparison_op> ::=

    { IS | IS NOT | = | <> | != | > | >= | !> | < | <= | !< }

For more information on the rules check SQL Server 2008 books online here 

  • The rule eliminates a good portion of the table from being covered by the index, I would caveat this by reiterating the benefits of a unique index on a column with nulls in.
  • The  rest of the time use a regular index or in indexed view.
Technorati Tags: ,
Posted: Thursday, May 22, 2008 11:22 AM by Andrew_Fryer

Comments

Andrew_Fryer said:

I have had to amend this post as the orignal version had a link to an internal Microsoft site. Thanks to Bob Beachemin (http://sqlskills.com/blogs/bobb/) for pointing this out and Srini Acharya on the relational product team for pointing me in the right direction.

# May 23, 2008 11:49 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker