For 'large' tables, is there any reason not to put a filter on indexes for optional columns?
So for an index on column AAA (because people can search on AAA),
I can set the filter to ([AAA] IS NOT NULL)
.
This saves storage, so it saves money.
Some more advantages from technet:
People say that it's good to put a filter on an index for columns that are mostly empty. But why wouldn't I put a filter on indexes for columns that are empty for like 1%? Is there any reason not to do it if it only has advantages?
This is usually a good idea with two gotchas:
select distinct col from T
will not use the index because a null value might be found. Use this: select distinct col from T where col is not null
.Filtered indexes are vastly underused. They can even be used to make a nullable column unique.
My practical recommendation: Just try it for a few month and learn for yourself if there are additional unforseen problems.
If you are into advanced SQL Server query techniques, also look ad indexed views. THey are a super set of filtered indexes (at least on Enterprise).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With