SlideShare a Scribd company logo
1 of 21
SQL Query Performance Analysis
Topics To Cover
• Query Optimizer

• Addhoc queries

• Execution Plan

• Statistics Analysis
Query Optimizer
The query optimizer in SQL Server is cost-based. It includes:

1. Cost for using different resources (CPU and IO)
2. Total execution time

It determines the cost by using:

• Cardinality: The total number of rows processed at each level
  of a query plan with the help of histograms , predicates and
  constraint

• Cost model of the algorithm: To perform various operations
  like sorting, searching, comparisons etc.
Addhoc queries
Any non-Parameterized quires are called addhoc queries. For
example :

SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = 100

In sql server if we execute a sql query it goes through two steps
just like any other programming languages:

• 1. Compilation
• 2. Execution
Properties of addhoc query
• Case sensitive
• Space sensitive
• Parameter sensitive

Sql severs treats two same sql query but of different parameters
as different sql statements. For example:

• SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = 1
• SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = 2
Effect of faulty C# code
• Sql server has took extra n * (Compilation time) ms to display
  records

• Extra time to insert records in cached plans.

• Sql server has to frequently fire a job to delete the cached
  plan since it will reach the max limit very soon.

• It will not only decrease the performance of this sql query but
  all sql queries of other application since this faulty code will
  force to delete cached query plans of other sql statement.
Prepared queries
Example:

(@Msgid int)SELECT MsgID, Severity FROM SqlMessage WHERE
  MsgID = @Msgid

• It is not case, space and parameter sensitive and it is our goal.

Stored procedure :

• It is precompiled sql queries which follow a common
  execution plan.
Execution Plan
• What is an index in sql server?

  Index is a way to organize data in a table to make some
  operations like searching, sorting, grouping etc faster. So, in
  other word we need indexing when sql query has:

• WHERE clause (That is searching)
• ORDER BY clause (That is sorting)
• GROUP BY clause (This is 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
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).
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.
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.
To improve cardinality
• If possible, simplify expressions with constants in them.

• If there is cross relation between column use computed
  column.

• Rewriting the query to use a parameter instead of a local
  variable.

• Avoid changing the parameter value within the stored
  procedure before using it in the query.
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

What's hot

Indexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuningIndexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuning
OSSCube
 
8 query processing and optimization
8 query processing and optimization8 query processing and optimization
8 query processing and optimization
Kumar
 
Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008
paulguerin
 
Sharding Overview
Sharding OverviewSharding Overview
Sharding Overview
MongoDB
 

What's hot (20)

Do IT with SQL
Do IT with SQLDo IT with SQL
Do IT with SQL
 
How nebula graph index works
How nebula graph index worksHow nebula graph index works
How nebula graph index works
 
Indexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuningIndexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuning
 
8 query processing and optimization
8 query processing and optimization8 query processing and optimization
8 query processing and optimization
 
R- Introduction
R- IntroductionR- Introduction
R- Introduction
 
Query processing-and-optimization
Query processing-and-optimizationQuery processing-and-optimization
Query processing-and-optimization
 
Elasticsearch 101 - Cluster setup and tuning
Elasticsearch 101 - Cluster setup and tuningElasticsearch 101 - Cluster setup and tuning
Elasticsearch 101 - Cluster setup and tuning
 
Query evaluation and optimization
Query evaluation and optimizationQuery evaluation and optimization
Query evaluation and optimization
 
New T-SQL Features in SQL Server 2012
New T-SQL Features in SQL Server 2012 New T-SQL Features in SQL Server 2012
New T-SQL Features in SQL Server 2012
 
Jdbc
JdbcJdbc
Jdbc
 
Step By Step Guide to Learn R
Step By Step Guide to Learn RStep By Step Guide to Learn R
Step By Step Guide to Learn R
 
InfiniFlux Minmax Cache
InfiniFlux Minmax CacheInfiniFlux Minmax Cache
InfiniFlux Minmax Cache
 
Executing Queries on a Sharded Database
Executing Queries on a Sharded DatabaseExecuting Queries on a Sharded Database
Executing Queries on a Sharded Database
 
B+Tree Indexes and InnoDB
B+Tree Indexes and InnoDBB+Tree Indexes and InnoDB
B+Tree Indexes and InnoDB
 
Chapter15
Chapter15Chapter15
Chapter15
 
The No SQL Principles and Basic Application Of Casandra Model
The No SQL Principles and Basic Application Of Casandra ModelThe No SQL Principles and Basic Application Of Casandra Model
The No SQL Principles and Basic Application Of Casandra Model
 
Synapseindia dot net development chapter 8 asp dot net
Synapseindia dot net development  chapter 8 asp dot netSynapseindia dot net development  chapter 8 asp dot net
Synapseindia dot net development chapter 8 asp dot net
 
Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008Myth busters - performance tuning 102 2008
Myth busters - performance tuning 102 2008
 
Advanced data structures vol. 1
Advanced data structures   vol. 1Advanced data structures   vol. 1
Advanced data structures vol. 1
 
Sharding Overview
Sharding OverviewSharding Overview
Sharding Overview
 

Viewers also liked (8)

E government 2012 Colombia
E government 2012 ColombiaE government 2012 Colombia
E government 2012 Colombia
 
Estudio benchmark publicidad digital mayor rendimiento por media mind
Estudio benchmark publicidad digital mayor rendimiento por media mindEstudio benchmark publicidad digital mayor rendimiento por media mind
Estudio benchmark publicidad digital mayor rendimiento por media mind
 
Query parameterization
Query parameterizationQuery parameterization
Query parameterization
 
You are all dead to me
You are all dead to meYou are all dead to me
You are all dead to me
 
Google Analytics Bootcamp Bogota Junio 28 2012 Dia 4
Google Analytics Bootcamp Bogota Junio 28 2012 Dia 4Google Analytics Bootcamp Bogota Junio 28 2012 Dia 4
Google Analytics Bootcamp Bogota Junio 28 2012 Dia 4
 
Sql server 2
Sql server 2Sql server 2
Sql server 2
 
Sql server introduction fundamental
Sql server introduction fundamentalSql server introduction fundamental
Sql server introduction fundamental
 
Reporte Cámara Colombiana de Comercio Electrónico Retail, Banking y Travel
Reporte Cámara Colombiana de Comercio Electrónico Retail, Banking y TravelReporte Cámara Colombiana de Comercio Electrónico Retail, Banking y Travel
Reporte Cámara Colombiana de Comercio Electrónico Retail, Banking y Travel
 

Similar to Sql query performance analysis

AWS (Amazon Redshift) presentation
AWS (Amazon Redshift) presentationAWS (Amazon Redshift) presentation
AWS (Amazon Redshift) presentation
Volodymyr Rovetskiy
 
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
 
PostgreSQL 9.0 & The Future
PostgreSQL 9.0 & The FuturePostgreSQL 9.0 & The Future
PostgreSQL 9.0 & The Future
Aaron Thul
 

Similar to Sql query performance analysis (20)

Index_2
Index_2Index_2
Index_2
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL Server
 
Sql Server Query Parameterization
Sql Server Query ParameterizationSql Server Query Parameterization
Sql Server Query Parameterization
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
 
AWS (Amazon Redshift) presentation
AWS (Amazon Redshift) presentationAWS (Amazon Redshift) presentation
AWS (Amazon Redshift) presentation
 
L6.sp17.pptx
L6.sp17.pptxL6.sp17.pptx
L6.sp17.pptx
 
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
 
MySQL performance tuning
MySQL performance tuningMySQL performance tuning
MySQL performance tuning
 
Statistics and Indexes Internals
Statistics and Indexes InternalsStatistics and Indexes Internals
Statistics and Indexes Internals
 
Cassandra training
Cassandra trainingCassandra training
Cassandra training
 
AWS June 2016 Webinar Series - Amazon Redshift or Big Data Analytics
AWS June 2016 Webinar Series - Amazon Redshift or Big Data AnalyticsAWS June 2016 Webinar Series - Amazon Redshift or Big Data Analytics
AWS June 2016 Webinar Series - Amazon Redshift or Big Data Analytics
 
Amazon Redshift: Performance Tuning and Optimization
Amazon Redshift: Performance Tuning and OptimizationAmazon Redshift: Performance Tuning and Optimization
Amazon Redshift: Performance Tuning and Optimization
 
In memory databases presentation
In memory databases presentationIn memory databases presentation
In memory databases presentation
 
JSSUG: SQL Sever Index Tuning
JSSUG: SQL Sever Index TuningJSSUG: SQL Sever Index Tuning
JSSUG: SQL Sever Index Tuning
 
POLARDB for MySQL - Parallel Query
POLARDB for MySQL - Parallel QueryPOLARDB for MySQL - Parallel Query
POLARDB for MySQL - Parallel Query
 
Statistics
StatisticsStatistics
Statistics
 
30334823 my sql-cluster-performance-tuning-best-practices
30334823 my sql-cluster-performance-tuning-best-practices30334823 my sql-cluster-performance-tuning-best-practices
30334823 my sql-cluster-performance-tuning-best-practices
 
10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQL10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQL
 
PostgreSQL 9.0 & The Future
PostgreSQL 9.0 & The FuturePostgreSQL 9.0 & The Future
PostgreSQL 9.0 & The Future
 

More from Riteshkiit (7)

Backup and restore
Backup and restoreBackup and restore
Backup and restore
 
Database index
Database indexDatabase index
Database index
 
Order by and join
Order by and joinOrder by and join
Order by and join
 
Database design
Database designDatabase design
Database design
 
Addhoc query
Addhoc queryAddhoc query
Addhoc query
 
Sql server JOIN
Sql server JOINSql server JOIN
Sql server JOIN
 
Topics
TopicsTopics
Topics
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Sql query performance analysis

  • 2. Topics To Cover • Query Optimizer • Addhoc queries • Execution Plan • Statistics Analysis
  • 3. Query Optimizer The query optimizer in SQL Server is cost-based. It includes: 1. Cost for using different resources (CPU and IO) 2. Total execution time It determines the cost by using: • Cardinality: The total number of rows processed at each level of a query plan with the help of histograms , predicates and constraint • Cost model of the algorithm: To perform various operations like sorting, searching, comparisons etc.
  • 4. Addhoc queries Any non-Parameterized quires are called addhoc queries. For example : SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = 100 In sql server if we execute a sql query it goes through two steps just like any other programming languages: • 1. Compilation • 2. Execution
  • 5. Properties of addhoc query • Case sensitive • Space sensitive • Parameter sensitive Sql severs treats two same sql query but of different parameters as different sql statements. For example: • SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = 1 • SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = 2
  • 6. Effect of faulty C# code • Sql server has took extra n * (Compilation time) ms to display records • Extra time to insert records in cached plans. • Sql server has to frequently fire a job to delete the cached plan since it will reach the max limit very soon. • It will not only decrease the performance of this sql query but all sql queries of other application since this faulty code will force to delete cached query plans of other sql statement.
  • 7. Prepared queries Example: (@Msgid int)SELECT MsgID, Severity FROM SqlMessage WHERE MsgID = @Msgid • It is not case, space and parameter sensitive and it is our goal. Stored procedure : • It is precompiled sql queries which follow a common execution plan.
  • 8. Execution Plan • What is an index in sql server? Index is a way to organize data in a table to make some operations like searching, sorting, grouping etc faster. So, in other word we need indexing when sql query has: • WHERE clause (That is searching) • ORDER BY clause (That is sorting) • GROUP BY clause (This is grouping) etc.
  • 9. 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
  • 10. 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).
  • 11.
  • 12. 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.
  • 13. 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.
  • 14. 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.
  • 17. 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.
  • 18. 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.
  • 19. To improve cardinality • If possible, simplify expressions with constants in them. • If there is cross relation between column use computed column. • Rewriting the query to use a parameter instead of a local variable. • Avoid changing the parameter value within the stored procedure before using it in the query.
  • 20. 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