SQL SERVER – Introduction to Filtered Index – Improve performance with Filtered Index

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.

For Example,

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:

Solarwinds

–          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'

SQL SERVER - Introduction to Filtered Index - Improve performance with Filtered Index 1_Index

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.

SQL SERVER - Introduction to Filtered Index - Improve performance with Filtered Index 2_ExecutionPlan

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.

Conclusion:

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)

Solarwinds
, ,
Previous Post
SQL SERVER – 2008 – Introduction to Table-Valued Parameters with Example
Next Post
SQL SERVER – 2008 – Hardware and Software Requirements for Installing SQL Server 2008

Related Posts

29 Comments. Leave new

Leave a Reply

Menu