views:

62

answers:

2

Hi !

I'd like to understand the SQL Server 2008 Filtered Index Feature.

How does the Database Engine deal wih this concept ? And how is it going to help me get faster results than standard indexes while querying large tables ?

Can anybody help me on this ?

Thanks.

+3  A: 

The easiest way I find to conceptualise the filtered index is an index with a constraint upon it, which only allows certain values into the index.

If your query is asking for values which all fall within the constraint then the engine knows it can use the filtered index instead of reverting to another index / underlying table. If you ask for values outside of the constraint, the filtered index will not be used.

In terms of how it makes your system faster, the index can be very targetted and will occupy less pages overall than an equivalent NC index on the same values. this basically gives you less I/O and results in a speed increase. Even index seeking the Filtered index, you are more likely to get a page cache hit for the index, since the filtered index is only including rows that you were interested in (in theory) due to the constraint.

If your data distributions and queries do not follow defined usage patterns it will be harder to make these work for you, but in scenarios where you have lots of null values which you are never interested in, then the filtered index can be set up to only include non-null values for example.

Andrew
+3  A: 

It's WHERE clause on your index.

My real life plans for a million row table:

  • I need an index on a column in a table, but 90% of the values are NULL. I need the index for the 10% non-null, but the index is bloated with the 90% NULL. So I add filter and save space.

  • I want to unique the same column (eq unique on NON-null value only). Pre SQL Server 2008, I had to use an indexed view or code. Now, the "WHERE" allows me to enforce unique via the index

gbn