SlideShare una empresa de Scribd logo
1 de 16
SQL Query Performance Analysis
What is an index ?
• Index is a way to organize data to make
  searching, sorting and grouping fasters
• we need indexing when :

1. WHERE, ON, HAVING clause (Searching)
2. ORDER BY clause (Sorting)
3. GROUP BY clause (Grouping) etc.
Table scan:
SELECT * FROM Student WHERE RollNo = 111


Time complexity of table scan is : O(n)
RollNo          Name              Country     Age
101             Greg              UK          23
102             Sachin            India       21
103             Akaram            Pakistan    22
107             Miyabi            China       18
108             Marry             Russia      27
109             Scott             USA         31
110             Benazir           Banglades   17
111             Miyabi            Japan       24
112             Rahul             India       27
113             Nicolus           France      19
Types of Index
• Table without any index is called Heap

• There are two type of index:

1. Clustered index
2. Non-Clustered index
Clustered index
• When we create a clustered index on any
  table physical organization of table is changed.
• Now data of table is stored as binary search
  tree(B tree).

CREATE UNIQUE [CLUSTERED] INDEX <Name>
  ON <ObjectName>(
  <ColumnName> [ASC | DESC ] [ ,...n ]
 )
Types of scanning
• Table scan: It is very slow can and it is used only if table has
  not any clustered index.

• Index scan: It is also slow scan. It is used when table has
  clustered index and either in WHERE clause non-key columns
  are present or query has not been covered (will discuss later)
  or both.

• Index Seek: It is very fast. Our goal is to achieve this.
Clustered index
• If we create table with primary key, sql server
  automatically creates clustered index on that
  table
• A table can have only one clustered index .
• Physical order of rows of table is same as
  logical order of key columns of clustered
  index.
Terms of execution plan
• Predicate: It is condition in WHERE clause which is either non-
  key column or column which has not been covered.

• Object: It is name of source from where it getting the data. It
  can be name of table, Clustered index or non-clustered index

• Output list: It is name of the columns which is getting from
  object.

• Seek Predicate: It is condition in WHERE clause which is either
  key column or fully covered.
Non-clustered index
• It is logical organization of data of table. A non-clustered index
  can be of two types.

1. Heap
2. Based on clustered index.

• If table has clustered index then leaf node of non-clustered
  index keeps the key columns of clustered index.

• If the table has not any clustered index then leaf node of non-
  clustered index keeps RID which unique of each row of table.
Based on clustered Index
Based on heap
Covering of queries
• We can specify maximum 16 column names.

•   Sum of size of the columns cannot be more than 900 bytes.

• All columns must belong to same table.

• Data     type    of    columns      cannot     be     ntext,  text,
  varchar (max), nvarchar (max), varbinary (max), xml, or image

• It cannot be non-deterministic computed column.
Statistics Analysis
• The query optimizer uses statistics to create query plans that
  improve query performance

• A correct statistics will lead to high-quality query plan.

• Auto create and updates applies strictly to single-column
  statistics.

• The query optimizer determines when statistics might be out-
  of-date by counting the number of data modifications since
  the last statistics update and comparing the number of
  modifications to a threshold.
Goal
• Should we use sub query or inner join?
• Should we use temp table or table variable?

Other tools:

•   Sql query profiler
•   Database Tuning Advisor
•   Resource Governor
THANK YOU

Más contenido relacionado

Destacado

跑酷网
跑酷网跑酷网
跑酷网Paoku
 
Photo Competition 2011
Photo Competition 2011Photo Competition 2011
Photo Competition 2011Bschneid
 
Каталог Енчо Енчев ЕТЕ
Каталог Енчо Енчев ЕТЕКаталог Енчо Енчев ЕТЕ
Каталог Енчо Енчев ЕТЕMaterial_bg
 
LocalEqual: Crowdsource your international growth
LocalEqual: Crowdsource your international growthLocalEqual: Crowdsource your international growth
LocalEqual: Crowdsource your international growthGuillaume Ang
 
Database design
Database designDatabase design
Database designRiteshkiit
 
Каталог Техносим 2010 бетонови паважи
Каталог Техносим 2010 бетонови паважиКаталог Техносим 2010 бетонови паважи
Каталог Техносим 2010 бетонови паважиMaterial_bg
 
Order by and join
Order by and joinOrder by and join
Order by and joinRiteshkiit
 
Backup and restore
Backup and restoreBackup and restore
Backup and restoreRiteshkiit
 
How is WordPress.com made?
How is WordPress.com made?How is WordPress.com made?
How is WordPress.com made?hugobaeta
 
Adult learning 1_m_knowles
Adult learning 1_m_knowlesAdult learning 1_m_knowles
Adult learning 1_m_knowlesgonofre
 
Database index
Database indexDatabase index
Database indexRiteshkiit
 

Destacado (14)

跑酷网
跑酷网跑酷网
跑酷网
 
Photo Competition 2011
Photo Competition 2011Photo Competition 2011
Photo Competition 2011
 
Каталог Енчо Енчев ЕТЕ
Каталог Енчо Енчев ЕТЕКаталог Енчо Енчев ЕТЕ
Каталог Енчо Енчев ЕТЕ
 
LocalEqual: Crowdsource your international growth
LocalEqual: Crowdsource your international growthLocalEqual: Crowdsource your international growth
LocalEqual: Crowdsource your international growth
 
Database design
Database designDatabase design
Database design
 
Каталог Техносим 2010 бетонови паважи
Каталог Техносим 2010 бетонови паважиКаталог Техносим 2010 бетонови паважи
Каталог Техносим 2010 бетонови паважи
 
Order by and join
Order by and joinOrder by and join
Order by and join
 
Backup and restore
Backup and restoreBackup and restore
Backup and restore
 
How is WordPress.com made?
How is WordPress.com made?How is WordPress.com made?
How is WordPress.com made?
 
Statistics
StatisticsStatistics
Statistics
 
Korean culture
Korean cultureKorean culture
Korean culture
 
English today 1 book
English today 1 bookEnglish today 1 book
English today 1 book
 
Adult learning 1_m_knowles
Adult learning 1_m_knowlesAdult learning 1_m_knowles
Adult learning 1_m_knowles
 
Database index
Database indexDatabase index
Database index
 

Similar a SQL Query Performance Analysis Through Indexing and Statistics

Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysisRiteshkiit
 
Introduction of sql server indexing
Introduction of sql server indexingIntroduction of sql server indexing
Introduction of sql server indexingMahabubur Rahaman
 
Query parameterization
Query parameterizationQuery parameterization
Query parameterizationRiteshkiit
 
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
SQLDay2013_Denny Cherry - Table indexing for the .NET DeveloperSQLDay2013_Denny Cherry - Table indexing for the .NET Developer
SQLDay2013_Denny Cherry - Table indexing for the .NET DeveloperPolish SQL Server User Group
 
SAG_Indexing and Query Optimization
SAG_Indexing and Query OptimizationSAG_Indexing and Query Optimization
SAG_Indexing and Query OptimizationVaibhav Jain
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL ServerRajesh Gunasundaram
 
Lec 1 = introduction to structured query language (sql)
Lec 1 = introduction to structured query language (sql)Lec 1 = introduction to structured query language (sql)
Lec 1 = introduction to structured query language (sql)Faisal Anwar
 
Introduction to Structured Query Language (SQL) (1).ppt
Introduction to Structured Query Language (SQL) (1).pptIntroduction to Structured Query Language (SQL) (1).ppt
Introduction to Structured Query Language (SQL) (1).pptComputerScienceDepar6
 
02 database oprimization - improving sql performance - ent-db
02  database oprimization - improving sql performance - ent-db02  database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-dbuncleRhyme
 
Data Never Lies Presentation for beginners in data field.pptx
Data Never Lies Presentation for beginners in data field.pptxData Never Lies Presentation for beginners in data field.pptx
Data Never Lies Presentation for beginners in data field.pptxTusharAgarwal49094
 
How oracle query works (The SQL Optimizers)
How oracle query works (The SQL Optimizers)How oracle query works (The SQL Optimizers)
How oracle query works (The SQL Optimizers)Hosein Zare
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server DatabasesColdFusionConference
 
How nebula graph index works
How nebula graph index worksHow nebula graph index works
How nebula graph index worksNebula Graph
 

Similar a SQL Query Performance Analysis Through Indexing and Statistics (20)

Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysis
 
Introduction of sql server indexing
Introduction of sql server indexingIntroduction of sql server indexing
Introduction of sql server indexing
 
Query parameterization
Query parameterizationQuery parameterization
Query parameterization
 
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
SQLDay2013_Denny Cherry - Table indexing for the .NET DeveloperSQLDay2013_Denny Cherry - Table indexing for the .NET Developer
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
 
SAG_Indexing and Query Optimization
SAG_Indexing and Query OptimizationSAG_Indexing and Query Optimization
SAG_Indexing and Query Optimization
 
Tunning overview
Tunning overviewTunning overview
Tunning overview
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL Server
 
15925 structured query
15925 structured query15925 structured query
15925 structured query
 
Lec 1 = introduction to structured query language (sql)
Lec 1 = introduction to structured query language (sql)Lec 1 = introduction to structured query language (sql)
Lec 1 = introduction to structured query language (sql)
 
Introduction to Structured Query Language (SQL) (1).ppt
Introduction to Structured Query Language (SQL) (1).pptIntroduction to Structured Query Language (SQL) (1).ppt
Introduction to Structured Query Language (SQL) (1).ppt
 
Statistics and Indexes Internals
Statistics and Indexes InternalsStatistics and Indexes Internals
Statistics and Indexes Internals
 
02 database oprimization - improving sql performance - ent-db
02  database oprimization - improving sql performance - ent-db02  database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-db
 
Data Never Lies Presentation for beginners in data field.pptx
Data Never Lies Presentation for beginners in data field.pptxData Never Lies Presentation for beginners in data field.pptx
Data Never Lies Presentation for beginners in data field.pptx
 
How oracle query works (The SQL Optimizers)
How oracle query works (The SQL Optimizers)How oracle query works (The SQL Optimizers)
How oracle query works (The SQL Optimizers)
 
Sql performance tuning
Sql performance tuningSql performance tuning
Sql performance tuning
 
Optimizing MySQL queries
Optimizing MySQL queriesOptimizing MySQL queries
Optimizing MySQL queries
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
 
SQL.pptx
SQL.pptxSQL.pptx
SQL.pptx
 
02222016
0222201602222016
02222016
 
How nebula graph index works
How nebula graph index worksHow nebula graph index works
How nebula graph index works
 

Más de Riteshkiit

Sql server introduction fundamental
Sql server introduction fundamentalSql server introduction fundamental
Sql server introduction fundamentalRiteshkiit
 
Sql server introduction
Sql server introductionSql server introduction
Sql server introductionRiteshkiit
 
Sql server JOIN
Sql server JOINSql server JOIN
Sql server JOINRiteshkiit
 

Más de Riteshkiit (6)

Sql server introduction fundamental
Sql server introduction fundamentalSql server introduction fundamental
Sql server introduction fundamental
 
Sql server introduction
Sql server introductionSql server introduction
Sql server introduction
 
Addhoc query
Addhoc queryAddhoc query
Addhoc query
 
Sql server JOIN
Sql server JOINSql server JOIN
Sql server JOIN
 
Sql server 2
Sql server 2Sql server 2
Sql server 2
 
Topics
TopicsTopics
Topics
 

Último

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Último (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

SQL Query Performance Analysis Through Indexing and Statistics

  • 2. What is an index ? • Index is a way to organize data to make searching, sorting and grouping fasters • we need indexing when : 1. WHERE, ON, HAVING clause (Searching) 2. ORDER BY clause (Sorting) 3. GROUP BY clause (Grouping) etc.
  • 3. Table scan: SELECT * FROM Student WHERE RollNo = 111 Time complexity of table scan is : O(n) RollNo Name Country Age 101 Greg UK 23 102 Sachin India 21 103 Akaram Pakistan 22 107 Miyabi China 18 108 Marry Russia 27 109 Scott USA 31 110 Benazir Banglades 17 111 Miyabi Japan 24 112 Rahul India 27 113 Nicolus France 19
  • 4. Types of Index • Table without any index is called Heap • There are two type of index: 1. Clustered index 2. Non-Clustered index
  • 5. Clustered index • When we create a clustered index on any table physical organization of table is changed. • Now data of table is stored as binary search tree(B tree). CREATE UNIQUE [CLUSTERED] INDEX <Name> ON <ObjectName>( <ColumnName> [ASC | DESC ] [ ,...n ] )
  • 6.
  • 7. Types of scanning • Table scan: It is very slow can and it is used only if table has not any clustered index. • Index scan: It is also slow scan. It is used when table has clustered index and either in WHERE clause non-key columns are present or query has not been covered (will discuss later) or both. • Index Seek: It is very fast. Our goal is to achieve this.
  • 8. Clustered index • If we create table with primary key, sql server automatically creates clustered index on that table • A table can have only one clustered index . • Physical order of rows of table is same as logical order of key columns of clustered index.
  • 9. Terms of execution plan • Predicate: It is condition in WHERE clause which is either non- key column or column which has not been covered. • Object: It is name of source from where it getting the data. It can be name of table, Clustered index or non-clustered index • Output list: It is name of the columns which is getting from object. • Seek Predicate: It is condition in WHERE clause which is either key column or fully covered.
  • 10. Non-clustered index • It is logical organization of data of table. A non-clustered index can be of two types. 1. Heap 2. Based on clustered index. • If table has clustered index then leaf node of non-clustered index keeps the key columns of clustered index. • If the table has not any clustered index then leaf node of non- clustered index keeps RID which unique of each row of table.
  • 13. Covering of queries • We can specify maximum 16 column names. • Sum of size of the columns cannot be more than 900 bytes. • All columns must belong to same table. • Data type of columns cannot be ntext, text, varchar (max), nvarchar (max), varbinary (max), xml, or image • It cannot be non-deterministic computed column.
  • 14. Statistics Analysis • The query optimizer uses statistics to create query plans that improve query performance • A correct statistics will lead to high-quality query plan. • Auto create and updates applies strictly to single-column statistics. • The query optimizer determines when statistics might be out- of-date by counting the number of data modifications since the last statistics update and comparing the number of modifications to a threshold.
  • 15. Goal • Should we use sub query or inner join? • Should we use temp table or table variable? Other tools: • Sql query profiler • Database Tuning Advisor • Resource Governor