Filtered Index is a new feature in SQL SERVER. Filtered Index is used to index a portion of rows in a table that means it applies a filter on INDEX which improves query performance, reduces index maintenance costs, and reduce index storage costs compared with full-table indexes.
When we see an Index created with somewhere clause then that is actually a FILTERED.
If we want to get the Employees whose Title is “Marketing Manager”, for that let’s create an INDEX on EmployeeID whose Title is “Marketing Manager” and then write the SQL Statement to retrieve Employees who are “Marketing Manager”.
CREATE NONCLUSTERED INDEX NCI_Department ON HumanResources.Employee(EmployeeID) WHERE Title= 'Marketing Manager'
Points to remember when creating a Filtered Ix:
– They can be created only as Nonclustered Index
– They can be used on Views only if they are persisted views.
– They cannot be created on full-text Indexes.
Let us write a simple SELECT statement on the table where we created a Filtered Ix.
SELECT he.EmployeeID,he.LoginID,he.Title FROM HumanResources.Employee he WHERE he.Title = 'Marketing Manager'
Now we will see the Execution Plan and compare the performance before and after the Filtered Index was created on Employee table.
As we can see, in the first case the index scan in 100% done on the Clustered Index taking 24% of total cost of execution. Once the Filtered index was created on Employee table, the Index scan is 50% on Clustered Index and 50% on Nonclustered Index which retrieves the data faster taking 20% of total cost of execution compared to 24% on the table with no index.
If we have a table with thousands of records and we are only concern with very few rows in our query we should use Filtered Ix.
A Filtered Index is an optimized non clustered Index which is one of the great performance improvements in SQL SERVER reducing the Index storage cost and reduces maintenance cost.
Reference : Pinal Dave (https://blog.sqlauthority.com)