Articles → SQL SERVER → Index Scan And Index Seek In Sql Server

Index Scan And Index Seek In Sql Server






Software Requirement





Technical Knowledge




  1. What are tables?
  2. What is an index?
  3. What is the difference between clustered and non-clustered indexes?
  4. What is a primary key?
  5. What is an execution plan?

Scan And Seek




Picture showing the graphical representation of scan process
Click to Enlarge



Picture showing the graphical representation of seek process
Click to Enlarge




Types Of Scans And Seek In SQL Server




  1. Table scan
  2. Clustered index scan
  3. Clustered index seek



Table Scan






Picture showing the sample table with records
Click to Enlarge



SELECT 
  [PersonId], 
  [PersonName], 
  [Address] 
FROM 
  [Test].[dbo].[Person]






Picture showing the execution plan of the select query on the table
Click to Enlarge




Adding Primary Key And Clustered Index On The Table




  1. Set primary key for "PersonId"
  2. Add a non-clustered index on the "Address" column

Clustered Index Scan And Seek






Picture showing the execution plan of the select query with clustered index scan
Click to Enlarge





SELECT 
  [PersonId], 
  [PersonName], 
  [Address] 
FROM 
  [Test].[dbo].[Person] 
where 
  Personid = 1




Picture showing the execution plan of the select query with clustered index seek
Click to Enlarge


How ISNULL Functions Change The Behavior?




select 
  [Address] 
from 
  Person 
where 
  [Address] = 'Address 1'




Picture showing the execution plan of the select query with clustered index scan with isnull function
Click to Enlarge



select 
  [Address] 
from 
  Person 
where 
  Isnull([Address], '') = 'Address 1'




Picture showing the execution plan of the select query with clustered index seek with isnull function
Click to Enlarge




Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, October 1, 2014
 
Updated On  -  Thursday, September 29, 2022

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250