• Thanks for a great question, Jeff!

    I had it wrong, for two reasons:

    1. Not knowing that the optimizer is smart enough to rewrite an ISNULL of this form to a SARGable equivalent, and

    2. Being too stupid to really check out the indexes given in the question to check if "doesn't include EventID" is a bluff.

    So this question learned me one thing I didn't know yet, and attempted to learn me something I should know for a long time already. 😀

    EDIT: After looking at the question in yet a bit more detail, I realise that the ability to rewrite the ISNULL is completely irrelevant to the question. The index seek uses StartDate, not EndDate. I'm not saying that the optimizer will not rewrite an ISNULL in some cases, but it doesn't in this case! The seek includes only the StartDate in the Seek Predicate; the predicate on the EndDate is in the (non-seek) predicate of the operator.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/