SQL Server Nested Loop Join Operator – Part1

Hi Geeks,

Let’s start with following query that uses SQL Server nested loop operator in the query plan.

USE [AdventureWorks2012]

SELECT EMP.BusinessEntityID
FROM HumanResources.Employee EMP
	INNER JOIN Sales.SalesPerson AS SLS
	ON EMP.BusinessEntityID = SLS.BusinessEntityID

NestedLoopGrphPlan

IndexScanOuterInputTTCISeekInnerInputTT

   

The input appears at top in SQL Server nested loop join plan is known as outer input and the one at the bottom is known as inner input. The algorithm for the nested loop join is easy, operator used to access the outer input is executed only once and the operator used to access inner input executed once for every records that qualify on the outer input.

In the example query, the plan is scanning a non-clustered index for the outer input and since there is not filter on SalesPerson table all records are being returned and as per nested loop join algorithm, the inner input i.e. clustered index seek is executed 17 times, one for each row from the outer table.

These details can be verified from the tooltips. Index scan tooltip shows actual number executions as 1 and actual number of rows as 17 and in index seek both actual number of executions and actual number of rows are 17.

Stay tuned, we will explore more on this operator tomorrow.

Regards,

Kanchan

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.