Filtered index with IS NULL predicate

  • GilaMonster (11/8/2011)


    Time to reopen the item I think.

    It'll be interesting to see if you can - I know Aaron has had trouble re-opening things recently.

    Anyway, yes this needs clarifying - at the moment it says Won't Fix, fixed in SP2, and fixed in a future version. Add your email to that and I think they've made very decision possible at one stage or another 🙂

  • I ran into the same problem today, and tried to see if this has been fixed in SQL 2014. I'm a bit disappointed to see that this is not the case. SQL will still perform the lookup.

    Robert van den Berg

    Freelance DBA
    Author of:

  • Also just hit this (SQL 2012). Put in the "INCLUDE" workaround, but went digging as it felt grubby and came across this post 🙂

  • If you do many lookups by ManagerID, you'd likely be able to avoid messing with all this by clustering the table differently:

    CREATE TABLE Employees (

    ID INT NOT NULL IDENTITY,

    ManagerID INT NULL,

    Department VARCHAR(2) NOT NULL

    )

    GO

    CREATE CLUSTERED INDEX Employees__CL ON Employees ( ManagerID ) WITH ( FILLFACTOR = 99, SORT_IN_TEMPDB = ON ) ON [<filegroup>] --<< adjust FILL if/as needed

    --or, if you prefer only explicitly unique clustered indexes:

    --CREATE UNIQUE CLUSTERED INDEX Employees__CL ON Employees ( ManagerID, ID )

    GO

    CREATE UNIQUE NONCLUSTERED INDEX Employees__IX_ID ON Employees ( ID ) ON [<filegroup>]

    A single lookup by ID will be extremely efficient either way. The huge gain comes when you need to process all/some employees for a specific manager(s).

    You might end up having to rebuild the table slightly more often, but it could be well worth it in terms of overall performance, esp. if you can use ONLINE rebuild.

    SQL DBA,SQL Server MVP(07, 08, 09) "Money can't buy you happiness." Maybe so, but it can make your unhappiness a LOT more comfortable!

Viewing 4 posts - 31 through 33 (of 33 total)

You must be logged in to reply to this topic. Login to reply