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:

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

(and in addition complain missing index include deletiondate).
of course could
include (filename, deletiondate) instead, , work:

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
includecolumn 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
Post a Comment