• GilaMonster (5/14/2015)


    Alan.B (5/14/2015)


    Add a the following WHERE clause to your Query after that and you get a non-clustered index seek (the plan has a slightly lower subtree cost on the SELECT statement.

    WHERE SESSION_SRNO >= 0

    Edit That's WHERE SESSION >= 0 (I don't know why SSC sometimes does that to my query code when posted)

    But will have the same performance. Don't look at costs, they're estimates, not actual measures of performance. Adding a where clause that will have no effect just to turn a scan into a seek doesn't improve performance.

    The index scan of the index on Session_SRNO will, in fact, read a single row because that's all it needs to do to get the highest value.

    Noted. Thanks Gail.

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001