0

Does having a filtered index on a column improve queries with a WHERE clause that is the opposite of the filter condition?

Since the filtered index specifies what not to return, does it reduce the number of records to search?

Example:

CREATE TABLE MyTable
(
  ColumnA INT PRIMARY KEY CLUSTERED,
  ColumnB INT NULL
)

CREATE NONCLUSTERED INDEX IX_MyTable_Filtered_ColumnB
  ON MyTable (ColumnB)
  WHERE ColumnB IS NOT NULL

The index should improve this query:

SELECT ColumnA
FROM MyTable
WHERE ColumnB IS NOT NULL

Will it make any difference to this one?

SELECT ColumnA
FROM MyTable
WHERE ColumnB IS NULL
4

nope. You'll probably even get an error if you try to force your 'IS NULL' query to use your filtered index with an index hint.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.