SlideShare a Scribd company logo
Performance Tuning: Intro to
  Execution Plan Analysis
    Presented by Kon Melamud
About me
• SQL Server Team Lead for RDX
• Lead code tuning team within RDX
• RDX works with over 200 customers on
  solutions within the SQL Server environment
  world wide.
Divide and conquer approach
• Eliminating non-problem areas
  –   Hardware - memory, CPU
  –   Disk/SAN performance
  –   Maintenance Tasks - index/statistics maintenance
  –   Other Applications on server causing performance bottleneck

      For more information on tools and techniques used to identify
      problem areas check out John Sterrett’s presentation, Performance
      tuning for Pirates, http://bit.ly/P3h5Hf
Objectives
• Execution plans
  – Additional tools
  – Things to check before start of analysis
• Indexes used by the SQL optimizer
  – Different type of index operations
  – Best practices
  – Determine what indexes are the optimal ones and the exceptions to
    the rules
• Join operations
  – Different join type and how they work
  – Exceptions to the general best practices
Execution Plans in a glance
• How to view an execution plan
  –   Profiler
  –   DMVs
  –   Extended Events (SQL2008+ only)
  –   Ad hoc queries

• Different views of execution plans
  – Graphical view
  – XML view
  – Text view
Before we begin…
• Additional query options (STATISTICS IO/TIME)
• Check optimization levels
• Check if optimizer timed out during plan
  generation
• How to regenerate a plan
• Right-to-left approach
Index Operations
• Four different base table operations
  –   Table Scan
  –   Index Scan - clustered/non-clustered
  –   Index Seek - clustered/non-clustered
  –   Lookups - RID/Key
Index Operations – Table Scans
• Table Scan – Heap (no clustered index)
    –   Generally not a best practice for data retrieval

• When Table Scans Are Acceptable
    –   Small tables
    –   Table variables
    –   CTE functionality
    –   Heavily inserted tables, minimal selects/updates/deletes
Index Operations – Index Scans
• Clustered Index Scans
    –   Same as a table scan but table is sorted on disk
    –   Generally slightly better than heap operations for CPU usage
    –   Query could most likely benefit from different index
    –   Could also mean the large range of data is been selected
Index Operations – Index Scans
• Non-Clustered Index Scan
   –   Less data scanned than a clustered index
   –   Causes for non-clustered index scan
          • Not an optimal index for the query
          • Seek predicate is not SARGable
          • Dataset returned represents most of the table
Index Operations – Index Seeks
• Clustered Index Seek
    –   Most preferred method for data retrieval
    –   Downside, only one clustered index can exist on the table
Index Operations – Index Seeks
• Non-Clustered Index Seek
   –   As good as clustered index seek
   –   Upside, can have multiple non-clustered indexes
   –   Downside, over indexing tables can cause slowdowns on
       writes
Index Operations - Lookups
• Lookups – What are they?
  – Only on non-clustered index operations
  – RID Lookup (Heap) - no clustered index present
  – Key Lookup (Clustered) - clustered key lookup

• Eliminating lookups
  – Pre SQL2005, create covering indexes
  – SQL2005 and later, INCLUDED columns option

• Exceptions to eliminating lookups
  – Select every column from the table
Index Operations - Lookups
RID Lookup      Key Lookup
Join Operations
• Three main logical join operators
  – Hash join
  – Nested Loop join
  – Merge join
Join Operations – Hash Join
• Hash joins - How it works…
  – Two phases - build phase, probe phase
      • Build phase - Scans or computes build input and builds hash table in memory (if
        possible)
      • Probe phase - For each row of probe input hash value is build or computed than
        compared against hash bucket of the build input, either producing matches or not
  – Requires at least one equality statement
  – Performed when at least one side of the join is not properly indexed
    (index scan/table scan)
  – Most common join operation
Join Operations – Hash Join
Graphic Look:
Join Operation – Nested Loop
• Nested loop join – How it works
  – Also called nested iteration, builds two inputs - inner and outer input
     • Outer input (displayed on top in the execution plan)
           – Processes row by row against inner output
           – A smaller table in the join predicate
      • Inner input (on the bottom of the execution plan)
           – Scanned for every row of the outer input to produce matches
           – A larger table of the two participating in the join
           – Has to be properly indexed ( index seeks)
  – Usually used when one table in the join is relatively small and the
    other is rather large, and at least one table (larger) is properly indexed.
     • If those conditions are met generally outperforms hash join
       operations
Join Operation – Nested Loop

 Graphic Look:
Join Operations - Merge
• Merge join – How it works
  – Both tables participated in the join must be sorted on the join
    columns. If that condition is not met, merge join operation would
    require an explicit sort which could be very costly.
  – Both inputs are scanned once at the same time, one row at a time,
    and if the rows are not matched, the row is discarded. Since both
    inputs are sorted, we can guarantee we will not see another possible
    match.
Join Operations - Merge Join
Graphic Look:
Parallelism – Good or Bad?
• SQL Server Optimizer determines when to use
  – Can be seen in execution plan as one of three exchange operators
      • Distribute Streams
      • Repartition Streams
      • Gather Streams
  – When parallel execution is not an option
      • The query contains scalar or relational operators that cannot be run in parallel
      • Sequential cost of the query is not high enough
      • Sequential execution is faster than parallel
  – Cost threshold of parallelism and MAXDOP options
Parallelism -
Graphical View:
Putting it all Together
•   Again Right-to-left approach
•   Index operation priorities Seek-> Scan-> Heap
•   Join operation priorities Merge->NL-> Hash
•   Advanced options
    – MAXDOP
    – INDEX HINTS
    – OPTIMIZE FOR
    – JOIN HINTS
Q/A Time
• Any questions regarding what we have
  covered?
We are done 
Thanks for attending.

More Related Content

Similar to Introduction to execution plan analysis

Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL ServerRajesh Gunasundaram
 
SAG_Indexing and Query Optimization
SAG_Indexing and Query OptimizationSAG_Indexing and Query Optimization
SAG_Indexing and Query OptimizationVaibhav Jain
 
Optimizing Application Performance - 2022.pptx
Optimizing Application Performance - 2022.pptxOptimizing Application Performance - 2022.pptx
Optimizing Application Performance - 2022.pptxJasonTuran2
 
Shard-Query, an MPP database for the cloud using the LAMP stack
Shard-Query, an MPP database for the cloud using the LAMP stackShard-Query, an MPP database for the cloud using the LAMP stack
Shard-Query, an MPP database for the cloud using the LAMP stackJustin Swanhart
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09guest9d79e073
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Mark Ginnebaugh
 
My Query is slow, now what?
My Query is slow, now what?My Query is slow, now what?
My Query is slow, now what?Gianluca Sartori
 
Experiences Migrating Hive Workload to SparkSQL with Jie Xiong and Zhan Zhang
Experiences Migrating Hive Workload to SparkSQL with Jie Xiong and Zhan ZhangExperiences Migrating Hive Workload to SparkSQL with Jie Xiong and Zhan Zhang
Experiences Migrating Hive Workload to SparkSQL with Jie Xiong and Zhan ZhangDatabricks
 
SqlDay 2018 - Brief introduction into SQL Server Execution Plans
SqlDay 2018 - Brief introduction into SQL Server Execution PlansSqlDay 2018 - Brief introduction into SQL Server Execution Plans
SqlDay 2018 - Brief introduction into SQL Server Execution PlansMarek Maśko
 
Columnar Table Performance Enhancements Of Greenplum Database with Block Meta...
Columnar Table Performance Enhancements Of Greenplum Database with Block Meta...Columnar Table Performance Enhancements Of Greenplum Database with Block Meta...
Columnar Table Performance Enhancements Of Greenplum Database with Block Meta...Ontico
 
5 ways to improve performance through indexing
5 ways to improve performance through indexing5 ways to improve performance through indexing
5 ways to improve performance through indexingJason Strate
 
Main MeMory Data Base
Main MeMory Data BaseMain MeMory Data Base
Main MeMory Data BaseSiva Rushi
 
AWS Redshift Introduction - Big Data Analytics
AWS Redshift Introduction - Big Data AnalyticsAWS Redshift Introduction - Big Data Analytics
AWS Redshift Introduction - Big Data AnalyticsKeeyong Han
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysisRiteshkiit
 
Hive Evolution: ApacheCon NA 2010
Hive Evolution:  ApacheCon NA 2010Hive Evolution:  ApacheCon NA 2010
Hive Evolution: ApacheCon NA 2010John Sichi
 
Query Tuning for Database Pros & Developers
Query Tuning for Database Pros & DevelopersQuery Tuning for Database Pros & Developers
Query Tuning for Database Pros & DevelopersCode Mastery
 

Similar to Introduction to execution plan analysis (20)

Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL Server
 
SAG_Indexing and Query Optimization
SAG_Indexing and Query OptimizationSAG_Indexing and Query Optimization
SAG_Indexing and Query Optimization
 
Cheetah:Data Warehouse on Top of MapReduce
Cheetah:Data Warehouse on Top of MapReduceCheetah:Data Warehouse on Top of MapReduce
Cheetah:Data Warehouse on Top of MapReduce
 
Optimizing Application Performance - 2022.pptx
Optimizing Application Performance - 2022.pptxOptimizing Application Performance - 2022.pptx
Optimizing Application Performance - 2022.pptx
 
Shard-Query, an MPP database for the cloud using the LAMP stack
Shard-Query, an MPP database for the cloud using the LAMP stackShard-Query, an MPP database for the cloud using the LAMP stack
Shard-Query, an MPP database for the cloud using the LAMP stack
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
 
My Query is slow, now what?
My Query is slow, now what?My Query is slow, now what?
My Query is slow, now what?
 
Experiences Migrating Hive Workload to SparkSQL with Jie Xiong and Zhan Zhang
Experiences Migrating Hive Workload to SparkSQL with Jie Xiong and Zhan ZhangExperiences Migrating Hive Workload to SparkSQL with Jie Xiong and Zhan Zhang
Experiences Migrating Hive Workload to SparkSQL with Jie Xiong and Zhan Zhang
 
SqlDay 2018 - Brief introduction into SQL Server Execution Plans
SqlDay 2018 - Brief introduction into SQL Server Execution PlansSqlDay 2018 - Brief introduction into SQL Server Execution Plans
SqlDay 2018 - Brief introduction into SQL Server Execution Plans
 
Columnar Table Performance Enhancements Of Greenplum Database with Block Meta...
Columnar Table Performance Enhancements Of Greenplum Database with Block Meta...Columnar Table Performance Enhancements Of Greenplum Database with Block Meta...
Columnar Table Performance Enhancements Of Greenplum Database with Block Meta...
 
Statistics and Indexes Internals
Statistics and Indexes InternalsStatistics and Indexes Internals
Statistics and Indexes Internals
 
5 ways to improve performance through indexing
5 ways to improve performance through indexing5 ways to improve performance through indexing
5 ways to improve performance through indexing
 
Main MeMory Data Base
Main MeMory Data BaseMain MeMory Data Base
Main MeMory Data Base
 
AWS Redshift Introduction - Big Data Analytics
AWS Redshift Introduction - Big Data AnalyticsAWS Redshift Introduction - Big Data Analytics
AWS Redshift Introduction - Big Data Analytics
 
San diegophp
San diegophpSan diegophp
San diegophp
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysis
 
Hive Evolution: ApacheCon NA 2010
Hive Evolution:  ApacheCon NA 2010Hive Evolution:  ApacheCon NA 2010
Hive Evolution: ApacheCon NA 2010
 
Tunning overview
Tunning overviewTunning overview
Tunning overview
 
Query Tuning for Database Pros & Developers
Query Tuning for Database Pros & DevelopersQuery Tuning for Database Pros & Developers
Query Tuning for Database Pros & Developers
 

More from John Sterrett

DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfJohn Sterrett
 
Getting Started with SQL Server Performance Tuning.pdf
Getting Started with SQL Server Performance Tuning.pdfGetting Started with SQL Server Performance Tuning.pdf
Getting Started with SQL Server Performance Tuning.pdfJohn Sterrett
 
Workload Replay in the Cloud: Secret Weapon for Cloud Migrations
Workload Replay in the Cloud: Secret Weapon for Cloud MigrationsWorkload Replay in the Cloud: Secret Weapon for Cloud Migrations
Workload Replay in the Cloud: Secret Weapon for Cloud MigrationsJohn Sterrett
 
Introduction to High Availability with SQL Server
Introduction to High Availability with SQL ServerIntroduction to High Availability with SQL Server
Introduction to High Availability with SQL ServerJohn Sterrett
 
Introduction to PowerShell for DBA's
Introduction to PowerShell for DBA'sIntroduction to PowerShell for DBA's
Introduction to PowerShell for DBA'sJohn Sterrett
 
SQL Server Performance Root Cause Analysis in 10 Minutes
SQL Server Performance Root Cause Analysis in 10 MinutesSQL Server Performance Root Cause Analysis in 10 Minutes
SQL Server Performance Root Cause Analysis in 10 MinutesJohn Sterrett
 
12 Steps to Workload Tuning
12 Steps to Workload Tuning12 Steps to Workload Tuning
12 Steps to Workload TuningJohn Sterrett
 
Performance Tuning for Pirates!
Performance Tuning for Pirates!Performance Tuning for Pirates!
Performance Tuning for Pirates!John Sterrett
 
Can You Host a SQL Saturday?
Can You Host a SQL Saturday?Can You Host a SQL Saturday?
Can You Host a SQL Saturday?John Sterrett
 
Evaluating Daily Checklist Against 1000 Servers using Policy Based Management
Evaluating Daily Checklist Against 1000 Servers using Policy Based ManagementEvaluating Daily Checklist Against 1000 Servers using Policy Based Management
Evaluating Daily Checklist Against 1000 Servers using Policy Based ManagementJohn Sterrett
 
SQL Server 2008 For Developers
SQL Server 2008 For DevelopersSQL Server 2008 For Developers
SQL Server 2008 For DevelopersJohn Sterrett
 
Evaluate Daily Checklist with PBM and CMS
Evaluate Daily Checklist with PBM and CMSEvaluate Daily Checklist with PBM and CMS
Evaluate Daily Checklist with PBM and CMSJohn Sterrett
 

More from John Sterrett (13)

DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdf
 
Getting Started with SQL Server Performance Tuning.pdf
Getting Started with SQL Server Performance Tuning.pdfGetting Started with SQL Server Performance Tuning.pdf
Getting Started with SQL Server Performance Tuning.pdf
 
Workload Replay in the Cloud: Secret Weapon for Cloud Migrations
Workload Replay in the Cloud: Secret Weapon for Cloud MigrationsWorkload Replay in the Cloud: Secret Weapon for Cloud Migrations
Workload Replay in the Cloud: Secret Weapon for Cloud Migrations
 
PowerPivot for DBAs
PowerPivot for DBAsPowerPivot for DBAs
PowerPivot for DBAs
 
Introduction to High Availability with SQL Server
Introduction to High Availability with SQL ServerIntroduction to High Availability with SQL Server
Introduction to High Availability with SQL Server
 
Introduction to PowerShell for DBA's
Introduction to PowerShell for DBA'sIntroduction to PowerShell for DBA's
Introduction to PowerShell for DBA's
 
SQL Server Performance Root Cause Analysis in 10 Minutes
SQL Server Performance Root Cause Analysis in 10 MinutesSQL Server Performance Root Cause Analysis in 10 Minutes
SQL Server Performance Root Cause Analysis in 10 Minutes
 
12 Steps to Workload Tuning
12 Steps to Workload Tuning12 Steps to Workload Tuning
12 Steps to Workload Tuning
 
Performance Tuning for Pirates!
Performance Tuning for Pirates!Performance Tuning for Pirates!
Performance Tuning for Pirates!
 
Can You Host a SQL Saturday?
Can You Host a SQL Saturday?Can You Host a SQL Saturday?
Can You Host a SQL Saturday?
 
Evaluating Daily Checklist Against 1000 Servers using Policy Based Management
Evaluating Daily Checklist Against 1000 Servers using Policy Based ManagementEvaluating Daily Checklist Against 1000 Servers using Policy Based Management
Evaluating Daily Checklist Against 1000 Servers using Policy Based Management
 
SQL Server 2008 For Developers
SQL Server 2008 For DevelopersSQL Server 2008 For Developers
SQL Server 2008 For Developers
 
Evaluate Daily Checklist with PBM and CMS
Evaluate Daily Checklist with PBM and CMSEvaluate Daily Checklist with PBM and CMS
Evaluate Daily Checklist with PBM and CMS
 

Recently uploaded

Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...Dirk Spencer Corporate Recruiter LION
 
太阳城娱乐-太阳城娱乐推荐-太阳城娱乐官方网站| 立即访问【ac123.net】
太阳城娱乐-太阳城娱乐推荐-太阳城娱乐官方网站| 立即访问【ac123.net】太阳城娱乐-太阳城娱乐推荐-太阳城娱乐官方网站| 立即访问【ac123.net】
太阳城娱乐-太阳城娱乐推荐-太阳城娱乐官方网站| 立即访问【ac123.net】foismail170
 
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】foismail170
 
Day care leadership document it helps to a person who needs caring children
Day care leadership document it helps to a person who needs caring childrenDay care leadership document it helps to a person who needs caring children
Day care leadership document it helps to a person who needs caring childrenMeleseWolde3
 
Luke Royak's Personal Brand Exploration!
Luke Royak's Personal Brand Exploration!Luke Royak's Personal Brand Exploration!
Luke Royak's Personal Brand Exploration!LukeRoyak
 
DIGITAL MARKETING COURSE IN CHENNAI.pptx
DIGITAL MARKETING COURSE IN CHENNAI.pptxDIGITAL MARKETING COURSE IN CHENNAI.pptx
DIGITAL MARKETING COURSE IN CHENNAI.pptxFarzanaRbcomcs
 
0524.THOMASGIRARD_SINGLEPAGERESUME-01.pdf
0524.THOMASGIRARD_SINGLEPAGERESUME-01.pdf0524.THOMASGIRARD_SINGLEPAGERESUME-01.pdf
0524.THOMASGIRARD_SINGLEPAGERESUME-01.pdfThomas GIRARD BDes
 
0524.THOMASGIRARD_CURRICULUMVITAE-01.pdf
0524.THOMASGIRARD_CURRICULUMVITAE-01.pdf0524.THOMASGIRARD_CURRICULUMVITAE-01.pdf
0524.THOMASGIRARD_CURRICULUMVITAE-01.pdfThomas GIRARD BDes
 
Heidi Livengood Resume Senior Technical Recruiter / HR Generalist
Heidi Livengood Resume Senior Technical Recruiter / HR GeneralistHeidi Livengood Resume Senior Technical Recruiter / HR Generalist
Heidi Livengood Resume Senior Technical Recruiter / HR GeneralistHeidiLivengood
 
Operating system. short answes and Interview questions .pdf
Operating system. short answes and Interview questions .pdfOperating system. short answes and Interview questions .pdf
Operating system. short answes and Interview questions .pdfharikrishnahari6276
 
0524.priorspeakingengagementslist-01.pdf
0524.priorspeakingengagementslist-01.pdf0524.priorspeakingengagementslist-01.pdf
0524.priorspeakingengagementslist-01.pdfThomas GIRARD BDes
 
133. Reviewer Certificate in Advances in Research
133. Reviewer Certificate in Advances in Research133. Reviewer Certificate in Advances in Research
133. Reviewer Certificate in Advances in ResearchManu Mitra
 
Biography and career history of Chad Henson.pdf
Biography and career history of Chad Henson.pdfBiography and career history of Chad Henson.pdf
Biography and career history of Chad Henson.pdfChad Henson
 
D.El.Ed. College List -Session 2024-26.pdf
D.El.Ed. College List -Session 2024-26.pdfD.El.Ed. College List -Session 2024-26.pdf
D.El.Ed. College List -Session 2024-26.pdfbipedoy339
 
129. Reviewer Certificate in BioNature [2024]
129. Reviewer Certificate in BioNature [2024]129. Reviewer Certificate in BioNature [2024]
129. Reviewer Certificate in BioNature [2024]Manu Mitra
 
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】larisashrestha558
 
135. Reviewer Certificate in Journal of Engineering
135. Reviewer Certificate in Journal of Engineering135. Reviewer Certificate in Journal of Engineering
135. Reviewer Certificate in Journal of EngineeringManu Mitra
 
欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】
欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】
欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】foismail170
 
134. Reviewer Certificate in Computer Science
134. Reviewer Certificate in Computer Science134. Reviewer Certificate in Computer Science
134. Reviewer Certificate in Computer ScienceManu Mitra
 
Widal Agglutination Test: A rapid serological diagnosis of typhoid fever
Widal Agglutination Test: A rapid serological diagnosis of typhoid feverWidal Agglutination Test: A rapid serological diagnosis of typhoid fever
Widal Agglutination Test: A rapid serological diagnosis of typhoid fevertaexnic
 

Recently uploaded (20)

Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
Transferable Skills - Your Roadmap - Part 1 and 2 - Dirk Spencer Senior Recru...
 
太阳城娱乐-太阳城娱乐推荐-太阳城娱乐官方网站| 立即访问【ac123.net】
太阳城娱乐-太阳城娱乐推荐-太阳城娱乐官方网站| 立即访问【ac123.net】太阳城娱乐-太阳城娱乐推荐-太阳城娱乐官方网站| 立即访问【ac123.net】
太阳城娱乐-太阳城娱乐推荐-太阳城娱乐官方网站| 立即访问【ac123.net】
 
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
欧洲杯买球平台-欧洲杯买球平台推荐-欧洲杯买球平台| 立即访问【ac123.net】
 
Day care leadership document it helps to a person who needs caring children
Day care leadership document it helps to a person who needs caring childrenDay care leadership document it helps to a person who needs caring children
Day care leadership document it helps to a person who needs caring children
 
Luke Royak's Personal Brand Exploration!
Luke Royak's Personal Brand Exploration!Luke Royak's Personal Brand Exploration!
Luke Royak's Personal Brand Exploration!
 
DIGITAL MARKETING COURSE IN CHENNAI.pptx
DIGITAL MARKETING COURSE IN CHENNAI.pptxDIGITAL MARKETING COURSE IN CHENNAI.pptx
DIGITAL MARKETING COURSE IN CHENNAI.pptx
 
0524.THOMASGIRARD_SINGLEPAGERESUME-01.pdf
0524.THOMASGIRARD_SINGLEPAGERESUME-01.pdf0524.THOMASGIRARD_SINGLEPAGERESUME-01.pdf
0524.THOMASGIRARD_SINGLEPAGERESUME-01.pdf
 
0524.THOMASGIRARD_CURRICULUMVITAE-01.pdf
0524.THOMASGIRARD_CURRICULUMVITAE-01.pdf0524.THOMASGIRARD_CURRICULUMVITAE-01.pdf
0524.THOMASGIRARD_CURRICULUMVITAE-01.pdf
 
Heidi Livengood Resume Senior Technical Recruiter / HR Generalist
Heidi Livengood Resume Senior Technical Recruiter / HR GeneralistHeidi Livengood Resume Senior Technical Recruiter / HR Generalist
Heidi Livengood Resume Senior Technical Recruiter / HR Generalist
 
Operating system. short answes and Interview questions .pdf
Operating system. short answes and Interview questions .pdfOperating system. short answes and Interview questions .pdf
Operating system. short answes and Interview questions .pdf
 
0524.priorspeakingengagementslist-01.pdf
0524.priorspeakingengagementslist-01.pdf0524.priorspeakingengagementslist-01.pdf
0524.priorspeakingengagementslist-01.pdf
 
133. Reviewer Certificate in Advances in Research
133. Reviewer Certificate in Advances in Research133. Reviewer Certificate in Advances in Research
133. Reviewer Certificate in Advances in Research
 
Biography and career history of Chad Henson.pdf
Biography and career history of Chad Henson.pdfBiography and career history of Chad Henson.pdf
Biography and career history of Chad Henson.pdf
 
D.El.Ed. College List -Session 2024-26.pdf
D.El.Ed. College List -Session 2024-26.pdfD.El.Ed. College List -Session 2024-26.pdf
D.El.Ed. College List -Session 2024-26.pdf
 
129. Reviewer Certificate in BioNature [2024]
129. Reviewer Certificate in BioNature [2024]129. Reviewer Certificate in BioNature [2024]
129. Reviewer Certificate in BioNature [2024]
 
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
皇冠体育- 皇冠体育官方网站- CROWN SPORTS| 立即访问【ac123.net】
 
135. Reviewer Certificate in Journal of Engineering
135. Reviewer Certificate in Journal of Engineering135. Reviewer Certificate in Journal of Engineering
135. Reviewer Certificate in Journal of Engineering
 
欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】
欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】
欧洲杯投注app-欧洲杯投注app推荐-欧洲杯投注app| 立即访问【ac123.net】
 
134. Reviewer Certificate in Computer Science
134. Reviewer Certificate in Computer Science134. Reviewer Certificate in Computer Science
134. Reviewer Certificate in Computer Science
 
Widal Agglutination Test: A rapid serological diagnosis of typhoid fever
Widal Agglutination Test: A rapid serological diagnosis of typhoid feverWidal Agglutination Test: A rapid serological diagnosis of typhoid fever
Widal Agglutination Test: A rapid serological diagnosis of typhoid fever
 

Introduction to execution plan analysis

  • 1. Performance Tuning: Intro to Execution Plan Analysis Presented by Kon Melamud
  • 2. About me • SQL Server Team Lead for RDX • Lead code tuning team within RDX • RDX works with over 200 customers on solutions within the SQL Server environment world wide.
  • 3.
  • 4.
  • 5. Divide and conquer approach • Eliminating non-problem areas – Hardware - memory, CPU – Disk/SAN performance – Maintenance Tasks - index/statistics maintenance – Other Applications on server causing performance bottleneck For more information on tools and techniques used to identify problem areas check out John Sterrett’s presentation, Performance tuning for Pirates, http://bit.ly/P3h5Hf
  • 6. Objectives • Execution plans – Additional tools – Things to check before start of analysis • Indexes used by the SQL optimizer – Different type of index operations – Best practices – Determine what indexes are the optimal ones and the exceptions to the rules • Join operations – Different join type and how they work – Exceptions to the general best practices
  • 7. Execution Plans in a glance • How to view an execution plan – Profiler – DMVs – Extended Events (SQL2008+ only) – Ad hoc queries • Different views of execution plans – Graphical view – XML view – Text view
  • 8. Before we begin… • Additional query options (STATISTICS IO/TIME) • Check optimization levels • Check if optimizer timed out during plan generation • How to regenerate a plan • Right-to-left approach
  • 9. Index Operations • Four different base table operations – Table Scan – Index Scan - clustered/non-clustered – Index Seek - clustered/non-clustered – Lookups - RID/Key
  • 10. Index Operations – Table Scans • Table Scan – Heap (no clustered index) – Generally not a best practice for data retrieval • When Table Scans Are Acceptable – Small tables – Table variables – CTE functionality – Heavily inserted tables, minimal selects/updates/deletes
  • 11. Index Operations – Index Scans • Clustered Index Scans – Same as a table scan but table is sorted on disk – Generally slightly better than heap operations for CPU usage – Query could most likely benefit from different index – Could also mean the large range of data is been selected
  • 12. Index Operations – Index Scans • Non-Clustered Index Scan – Less data scanned than a clustered index – Causes for non-clustered index scan • Not an optimal index for the query • Seek predicate is not SARGable • Dataset returned represents most of the table
  • 13. Index Operations – Index Seeks • Clustered Index Seek – Most preferred method for data retrieval – Downside, only one clustered index can exist on the table
  • 14. Index Operations – Index Seeks • Non-Clustered Index Seek – As good as clustered index seek – Upside, can have multiple non-clustered indexes – Downside, over indexing tables can cause slowdowns on writes
  • 15. Index Operations - Lookups • Lookups – What are they? – Only on non-clustered index operations – RID Lookup (Heap) - no clustered index present – Key Lookup (Clustered) - clustered key lookup • Eliminating lookups – Pre SQL2005, create covering indexes – SQL2005 and later, INCLUDED columns option • Exceptions to eliminating lookups – Select every column from the table
  • 16. Index Operations - Lookups RID Lookup Key Lookup
  • 17. Join Operations • Three main logical join operators – Hash join – Nested Loop join – Merge join
  • 18. Join Operations – Hash Join • Hash joins - How it works… – Two phases - build phase, probe phase • Build phase - Scans or computes build input and builds hash table in memory (if possible) • Probe phase - For each row of probe input hash value is build or computed than compared against hash bucket of the build input, either producing matches or not – Requires at least one equality statement – Performed when at least one side of the join is not properly indexed (index scan/table scan) – Most common join operation
  • 19. Join Operations – Hash Join Graphic Look:
  • 20. Join Operation – Nested Loop • Nested loop join – How it works – Also called nested iteration, builds two inputs - inner and outer input • Outer input (displayed on top in the execution plan) – Processes row by row against inner output – A smaller table in the join predicate • Inner input (on the bottom of the execution plan) – Scanned for every row of the outer input to produce matches – A larger table of the two participating in the join – Has to be properly indexed ( index seeks) – Usually used when one table in the join is relatively small and the other is rather large, and at least one table (larger) is properly indexed. • If those conditions are met generally outperforms hash join operations
  • 21. Join Operation – Nested Loop Graphic Look:
  • 22. Join Operations - Merge • Merge join – How it works – Both tables participated in the join must be sorted on the join columns. If that condition is not met, merge join operation would require an explicit sort which could be very costly. – Both inputs are scanned once at the same time, one row at a time, and if the rows are not matched, the row is discarded. Since both inputs are sorted, we can guarantee we will not see another possible match.
  • 23. Join Operations - Merge Join Graphic Look:
  • 24. Parallelism – Good or Bad? • SQL Server Optimizer determines when to use – Can be seen in execution plan as one of three exchange operators • Distribute Streams • Repartition Streams • Gather Streams – When parallel execution is not an option • The query contains scalar or relational operators that cannot be run in parallel • Sequential cost of the query is not high enough • Sequential execution is faster than parallel – Cost threshold of parallelism and MAXDOP options
  • 26. Putting it all Together • Again Right-to-left approach • Index operation priorities Seek-> Scan-> Heap • Join operation priorities Merge->NL-> Hash • Advanced options – MAXDOP – INDEX HINTS – OPTIMIZE FOR – JOIN HINTS
  • 27. Q/A Time • Any questions regarding what we have covered?
  • 28. We are done  Thanks for attending.