• In the first execution plan on the Operator Index Seek QueryId_nc you can see that the Estimated Number of Rows is about 4 and Actual Number of Rows is 34Mio! SQL Server Optimizer has choosen an Index Seek followed by Lookup because it expected only 4 rows to be returned and that's the reason why you have a lot of logical reads.

    In the second case ISNULL operator disallowed the optimizer to choosing Index Seek and in this case this desicion was better.

    The reason why the optimizer had a bad estimation in first case is usage of local variable. When you use local variables the optimizerhas to generate the plan for an unknown value and the real value has been evaluated at the run-time and this is too late for the exeution plan. The plan has been already created.

    You can use OPTION (RECOMPILE) hint at the end of the first query to force generating the plan at the statement level which allows the optimizer a better estimation and finally to generate an optimal execution plan.

    ___________________________
    Do Not Optimize for Exceptions!