SlideShare a Scribd company logo
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 ]
 )
Index
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

More Related Content

Viewers also liked

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

Viewers also liked (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 to Index

Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysis
Riteshkiit
 
Introduction of sql server indexing
Introduction of sql server indexingIntroduction of sql server indexing
Introduction of sql server indexing
Mahabubur Rahaman
 
Query parameterization
Query parameterizationQuery parameterization
Query parameterization
Riteshkiit
 
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
Polish SQL Server User Group
 
SAG_Indexing and Query Optimization
SAG_Indexing and Query OptimizationSAG_Indexing and Query Optimization
SAG_Indexing and Query Optimization
Vaibhav Jain
 
Tunning overview
Tunning overviewTunning overview
Tunning overview
Hitesh Kumar Markam
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL Server
Rajesh 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
 
15925 structured query
15925 structured query15925 structured query
15925 structured query
Universitas Bina Darma Palembang
 
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
ComputerScienceDepar6
 
Statistics and Indexes Internals
Statistics and Indexes InternalsStatistics and Indexes Internals
Statistics and Indexes Internals
Antonios Chatzipavlis
 
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
uncleRhyme
 
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
TusharAgarwal49094
 
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
 
Sql performance tuning
Sql performance tuningSql performance tuning
Sql performance tuning
Leo Mark Villar
 
Optimizing MySQL queries
Optimizing MySQL queriesOptimizing MySQL queries
Optimizing MySQL queries
GMO-Z.com Vietnam Lab Center
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
ColdFusionConference
 
SQL.pptx
SQL.pptxSQL.pptx
SQL.pptx
Satyam Sharma
 
02222016
0222201602222016
How nebula graph index works
How nebula graph index worksHow nebula graph index works
How nebula graph index works
Nebula Graph
 

Similar to Index (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
 
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)
 
15925 structured query
15925 structured query15925 structured query
15925 structured query
 
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
 

More from Riteshkiit

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

More from 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
 

Recently uploaded

History and Introduction for Generative AI ( GenAI )
History and Introduction for Generative AI ( GenAI )History and Introduction for Generative AI ( GenAI )
History and Introduction for Generative AI ( GenAI )
Badri_Bady
 
Retrieval Augmented Generation Evaluation with Ragas
Retrieval Augmented Generation Evaluation with RagasRetrieval Augmented Generation Evaluation with Ragas
Retrieval Augmented Generation Evaluation with Ragas
Zilliz
 
Indian Privacy law & Infosec for Startups
Indian Privacy law & Infosec for StartupsIndian Privacy law & Infosec for Startups
Indian Privacy law & Infosec for Startups
AMol NAik
 
Self-Healing Test Automation Framework - Healenium
Self-Healing Test Automation Framework - HealeniumSelf-Healing Test Automation Framework - Healenium
Self-Healing Test Automation Framework - Healenium
Knoldus Inc.
 
What's New in Teams Calling, Meetings, Devices June 2024
What's New in Teams Calling, Meetings, Devices June 2024What's New in Teams Calling, Meetings, Devices June 2024
What's New in Teams Calling, Meetings, Devices June 2024
Stephanie Beckett
 
Choosing the Best Outlook OST to PST Converter: Key Features and Considerations
Choosing the Best Outlook OST to PST Converter: Key Features and ConsiderationsChoosing the Best Outlook OST to PST Converter: Key Features and Considerations
Choosing the Best Outlook OST to PST Converter: Key Features and Considerations
webbyacad software
 
Mastering Board Best Practices: Essential Skills for Effective Non-profit Lea...
Mastering Board Best Practices: Essential Skills for Effective Non-profit Lea...Mastering Board Best Practices: Essential Skills for Effective Non-profit Lea...
Mastering Board Best Practices: Essential Skills for Effective Non-profit Lea...
OnBoard
 
Generative AI technology is a fascinating field that focuses on creating comp...
Generative AI technology is a fascinating field that focuses on creating comp...Generative AI technology is a fascinating field that focuses on creating comp...
Generative AI technology is a fascinating field that focuses on creating comp...
Nohoax Kanont
 
How UiPath Discovery Suite supports identification of Agentic Process Automat...
How UiPath Discovery Suite supports identification of Agentic Process Automat...How UiPath Discovery Suite supports identification of Agentic Process Automat...
How UiPath Discovery Suite supports identification of Agentic Process Automat...
DianaGray10
 
Keynote : AI & Future Of Offensive Security
Keynote : AI & Future Of Offensive SecurityKeynote : AI & Future Of Offensive Security
Keynote : AI & Future Of Offensive Security
Priyanka Aash
 
FIDO Munich Seminar: Securing Smart Car.pptx
FIDO Munich Seminar: Securing Smart Car.pptxFIDO Munich Seminar: Securing Smart Car.pptx
FIDO Munich Seminar: Securing Smart Car.pptx
FIDO Alliance
 
Top 12 AI Technology Trends For 2024.pdf
Top 12 AI Technology Trends For 2024.pdfTop 12 AI Technology Trends For 2024.pdf
Top 12 AI Technology Trends For 2024.pdf
Marrie Morris
 
"Hands-on development experience using wasm Blazor", Furdak Vladyslav.pptx
"Hands-on development experience using wasm Blazor", Furdak Vladyslav.pptx"Hands-on development experience using wasm Blazor", Furdak Vladyslav.pptx
"Hands-on development experience using wasm Blazor", Furdak Vladyslav.pptx
Fwdays
 
FIDO Munich Seminar In-Vehicle Payment Trends.pptx
FIDO Munich Seminar In-Vehicle Payment Trends.pptxFIDO Munich Seminar In-Vehicle Payment Trends.pptx
FIDO Munich Seminar In-Vehicle Payment Trends.pptx
FIDO Alliance
 
Mule Experience Hub and Release Channel with Java 17
Mule Experience Hub and Release Channel with Java 17Mule Experience Hub and Release Channel with Java 17
Mule Experience Hub and Release Channel with Java 17
Bhajan Mehta
 
The Challenge of Interpretability in Generative AI Models.pdf
The Challenge of Interpretability in Generative AI Models.pdfThe Challenge of Interpretability in Generative AI Models.pdf
The Challenge of Interpretability in Generative AI Models.pdf
Sara Kroft
 
FIDO Munich Seminar Blueprint for In-Vehicle Payment Standard.pptx
FIDO Munich Seminar Blueprint for In-Vehicle Payment Standard.pptxFIDO Munich Seminar Blueprint for In-Vehicle Payment Standard.pptx
FIDO Munich Seminar Blueprint for In-Vehicle Payment Standard.pptx
FIDO Alliance
 
Generative AI Reasoning Tech Talk - July 2024
Generative AI Reasoning Tech Talk - July 2024Generative AI Reasoning Tech Talk - July 2024
Generative AI Reasoning Tech Talk - July 2024
siddu769252
 
The History of Embeddings & Multimodal Embeddings
The History of Embeddings & Multimodal EmbeddingsThe History of Embeddings & Multimodal Embeddings
The History of Embeddings & Multimodal Embeddings
Zilliz
 
It's your unstructured data: How to get your GenAI app to production (and spe...
It's your unstructured data: How to get your GenAI app to production (and spe...It's your unstructured data: How to get your GenAI app to production (and spe...
It's your unstructured data: How to get your GenAI app to production (and spe...
Zilliz
 

Recently uploaded (20)

History and Introduction for Generative AI ( GenAI )
History and Introduction for Generative AI ( GenAI )History and Introduction for Generative AI ( GenAI )
History and Introduction for Generative AI ( GenAI )
 
Retrieval Augmented Generation Evaluation with Ragas
Retrieval Augmented Generation Evaluation with RagasRetrieval Augmented Generation Evaluation with Ragas
Retrieval Augmented Generation Evaluation with Ragas
 
Indian Privacy law & Infosec for Startups
Indian Privacy law & Infosec for StartupsIndian Privacy law & Infosec for Startups
Indian Privacy law & Infosec for Startups
 
Self-Healing Test Automation Framework - Healenium
Self-Healing Test Automation Framework - HealeniumSelf-Healing Test Automation Framework - Healenium
Self-Healing Test Automation Framework - Healenium
 
What's New in Teams Calling, Meetings, Devices June 2024
What's New in Teams Calling, Meetings, Devices June 2024What's New in Teams Calling, Meetings, Devices June 2024
What's New in Teams Calling, Meetings, Devices June 2024
 
Choosing the Best Outlook OST to PST Converter: Key Features and Considerations
Choosing the Best Outlook OST to PST Converter: Key Features and ConsiderationsChoosing the Best Outlook OST to PST Converter: Key Features and Considerations
Choosing the Best Outlook OST to PST Converter: Key Features and Considerations
 
Mastering Board Best Practices: Essential Skills for Effective Non-profit Lea...
Mastering Board Best Practices: Essential Skills for Effective Non-profit Lea...Mastering Board Best Practices: Essential Skills for Effective Non-profit Lea...
Mastering Board Best Practices: Essential Skills for Effective Non-profit Lea...
 
Generative AI technology is a fascinating field that focuses on creating comp...
Generative AI technology is a fascinating field that focuses on creating comp...Generative AI technology is a fascinating field that focuses on creating comp...
Generative AI technology is a fascinating field that focuses on creating comp...
 
How UiPath Discovery Suite supports identification of Agentic Process Automat...
How UiPath Discovery Suite supports identification of Agentic Process Automat...How UiPath Discovery Suite supports identification of Agentic Process Automat...
How UiPath Discovery Suite supports identification of Agentic Process Automat...
 
Keynote : AI & Future Of Offensive Security
Keynote : AI & Future Of Offensive SecurityKeynote : AI & Future Of Offensive Security
Keynote : AI & Future Of Offensive Security
 
FIDO Munich Seminar: Securing Smart Car.pptx
FIDO Munich Seminar: Securing Smart Car.pptxFIDO Munich Seminar: Securing Smart Car.pptx
FIDO Munich Seminar: Securing Smart Car.pptx
 
Top 12 AI Technology Trends For 2024.pdf
Top 12 AI Technology Trends For 2024.pdfTop 12 AI Technology Trends For 2024.pdf
Top 12 AI Technology Trends For 2024.pdf
 
"Hands-on development experience using wasm Blazor", Furdak Vladyslav.pptx
"Hands-on development experience using wasm Blazor", Furdak Vladyslav.pptx"Hands-on development experience using wasm Blazor", Furdak Vladyslav.pptx
"Hands-on development experience using wasm Blazor", Furdak Vladyslav.pptx
 
FIDO Munich Seminar In-Vehicle Payment Trends.pptx
FIDO Munich Seminar In-Vehicle Payment Trends.pptxFIDO Munich Seminar In-Vehicle Payment Trends.pptx
FIDO Munich Seminar In-Vehicle Payment Trends.pptx
 
Mule Experience Hub and Release Channel with Java 17
Mule Experience Hub and Release Channel with Java 17Mule Experience Hub and Release Channel with Java 17
Mule Experience Hub and Release Channel with Java 17
 
The Challenge of Interpretability in Generative AI Models.pdf
The Challenge of Interpretability in Generative AI Models.pdfThe Challenge of Interpretability in Generative AI Models.pdf
The Challenge of Interpretability in Generative AI Models.pdf
 
FIDO Munich Seminar Blueprint for In-Vehicle Payment Standard.pptx
FIDO Munich Seminar Blueprint for In-Vehicle Payment Standard.pptxFIDO Munich Seminar Blueprint for In-Vehicle Payment Standard.pptx
FIDO Munich Seminar Blueprint for In-Vehicle Payment Standard.pptx
 
Generative AI Reasoning Tech Talk - July 2024
Generative AI Reasoning Tech Talk - July 2024Generative AI Reasoning Tech Talk - July 2024
Generative AI Reasoning Tech Talk - July 2024
 
The History of Embeddings & Multimodal Embeddings
The History of Embeddings & Multimodal EmbeddingsThe History of Embeddings & Multimodal Embeddings
The History of Embeddings & Multimodal Embeddings
 
It's your unstructured data: How to get your GenAI app to production (and spe...
It's your unstructured data: How to get your GenAI app to production (and spe...It's your unstructured data: How to get your GenAI app to production (and spe...
It's your unstructured data: How to get your GenAI app to production (and spe...
 

Index

  • 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 ] )
  • 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