Hi Geeks,

Before moving ahead with something new on One operator a day series, I wanted discuss another scenario on SQL Server Nested Loop Join Operator. I recommend you to read my earlier posts on the same topic by clicking Part1, Part2 and SQL Server Nested Loop Join Operator – Revisiting: Part1 before reading today’s post.

Let me modify our query from yesterday as following which generates a different execution plan.


As we see from the above figure, by adding OrderQty column in SELECT statement, index on ProductId is not sufficient to cover the query results. In other words, index does not include all the details to fetch required data.

The query optimizer may either choose a Lookup or to scan SalesOrderDetail table. In our example, there is only one Product row as such the table needs to be scanned once. This is much better than performing number of lookups i.e. use a pointer from the index then select rows and query optimizer is smart enough to select the optimum plan.

You can click on Clustered Index Scan, Clustered Index Seek and SQL Server Key Lookup Operator Part1, Part2, Part3 and Part4 to read more on them.

That’s it for today, see you tomorrow.

Happy Learning!



Like us on FaceBook | Join the fastest growing SQL Server group on FaceBook | Follow me on Twitter | Follow me on FaceBook