Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top