SQL Server Nested Loop Join Operator – Revisiting: Part2

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.

USE [AdventureWorks2012]

SELECT SD.SalesOrderID, 
FROM Production.Product PR
	JOIN Sales.SalesOrderDetail SD
	ON PR.ProductID = SD.ProductID
WHERE PR.ProductID = 875



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


About Kanchan Bhattacharyya

Kanchan is an astute IT professional, a seasoned SQL Database Administrator with 13+ years of industry experience. A calculated risk taker with deep technical knowledge and has gained proficiency in database consulting and solutions across different environments. Kanchan holds MBA degree in IT and an International Executive MBA in Project Management. He is very passionate about SQL Server and holds MCSE (Data Platform), MCSA – SQL 2012, MCITP – SQL 2008 certifications. Currently he is focusing on cloud and latest releases of SQL Server. When not working, Kanchan likes to spend his time reading on new technical developments specifically on SQL Server and other related technologies.

View all posts by Kanchan Bhattacharyya →

Leave a Reply

Your email address will not be published.