sql server 2008 - Filtered index condition is ignored by optimizer -


assume i'm running website shows funny cat pictures. have table called catpictures columns filename, awesomeness, , deletiondate, , following index:

create nonclustered index catsbyawesomeness on catpictures (awesomeness)  include (filename) deletiondate null 

my main query this:

select filename catpictures deletiondate null , awesomeness > 10 

i, human being, know above index sql server needs, because index filter condition ensures deletiondate null part.

sql server doesn't know this; execution plan query not use index:

query plan, doing table scan

even if adding index hint, still explicitly check deletiondate looking @ actual table data:

query plan uses index, still bookmark lookup

(and in addition complain missing index include deletiondate).

of course could

include (filename, deletiondate) 

instead, , work:

query plan index includes deletiondate; index used

but seems waste include column, since uses space without adding new information.

is there way make sql server aware filter condition doing job of checking deletiondate?

no, not currently.

see connect item. closed won't fix. (or this one is null case specifically)

the connect item provide workaround shown below.

posted richardb cfcu on 29/09/2011 @ 9:15

a workaround include column being filtered on.

example:

create nonclustered index [idx_filteredkey1] on [dbo].[table]  (     [table_id] asc,     [table_id2] asc ) include ( [removal_timestamp]) --explicitly include column here ([removal_timestamp] null) 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -