SQL Server Execution Plan – Simplifying : Part 2

Dear Friends,

In my previous post of Simplifying SQL Server Execution Plan: Part 1 I’ve discussed on Clustered Index Scan. On this blog post we will cover following operators one by one;

  • Clustered Index Seek
  • Non-Clustered Index Seek

We are set to go;

Clustered Index Seek

Let us introduce a WHERE clause to the query that we used during clustered index scan demo;

1_SQL_Server_Simplifying_execution_plans_Part2

2_SQL_Server_Simplifying_execution_plans_Part2

Index seek is different from index scans as the optimizer is able to locate the index that it can use to retrieve intended records. It instructs query engine to look up the values based on the keys in given index. To re-iterate, in a clustered index not only structure is stored but also it sorts and stores actual data. You can imagine the way when we look up any specific word in the index of a book, when index seek takes place the key values are used to quickly identify row or rows of data. This is faster and efficient way of data retrieval compared to scans as actual data stored in indexes mentioned above.

In our example, we observe Clustered Index Seek against Person.Person table on PK_Person_BusinessEntityID which is the clustered key. When we look at the ToolTip window carefully, it is observed that Ordered option is set to True here which wasn’t the case during scans (discussed on my previous blog post).

Non-Clustered Index Seek

   

Let us run a query on Sales.SalesOrderDetail table first;

3_SQL_Server_Simplifying_execution_plans_Part2

4_SQL_Server_Simplifying_execution_plans_Part2

A non-clustered index seek also uses an index to look up desired rows like clustered index seek. Difference is, a non clustered index key is used perform search operation. Based on the query i.e. how they are written, optimizer will be able to find required data in non-clustered index or may route through clustered key. Here in our example, non clustered key IX_SalesOrderDetail_ProductID used to retrieve data set. We will cover more on this latter part of this series.

Let us stop here today; I will be back with next part soon.

 

Regards

Kanchan Bhattacharyya

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

Follow me on TwitterFollow 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.