Advertisement
Advanced SQL Server, Indexes

How do filtered indexes work, and what specific scenarios benefit most from using one?

Short answer

A filtered index only includes rows that match a specific WHERE condition defined when the index is created, making it smaller and more efficient than indexing the entire table, which is especially useful for tables where queries commonly filter on a small, well defined subset…

Save SQL Server mock interview
Advertisement
AModel answer
A filtered index only includes rows that match a specific WHERE condition defined when the index is created, making it smaller and more efficient than indexing the entire table, which is especially useful for tables where queries commonly filter on a small, well defined subset of data, such as only active or incomplete records.
CREATE NONCLUSTERED INDEX IX_Orders_Pending
ON Orders(OrderDate)
WHERE Status = 'Pending';
Real-world example
An order processing system creates a filtered index that only covers pending orders, since queries checking for pending orders run frequently, and the filtered index stays much smaller and faster than indexing every order regardless of status.
Likely follow-ups
  • How much smaller is a typical filtered index compared to indexing the whole table?
  • Can a filtered index be used for queries that do not include the same filter condition?
Related topics