SlideShare une entreprise Scribd logo
1  sur  21
Understanding Query
Execution Plans
Richard Douglas
Agenda
• Introductions
• The Query Optimizer
• Commonly used operators
• Blocking and non-blocking operators
• Reading Query Execution Plans

2

Understanding Query Execution Plans

Global Marketing
Your host
• Richard Douglas
• Systems Consultant
• SQL Server MCITPro

• Maidenhead SQL User Group Leader
• Blog: http://SQL.RichardDouglas.co.uk
• Twitter: @SQLRich
• Email:
Richard.Douglas@Software.Dell.com

3

Understanding Query Execution Plans

Global Marketing
The Query Optimizer
Why do we need an optimizer?
• T-SQL is a “What” not “how” language.
• We write “logical” requests.
• SQL Optimizer Engine converts
logical requests into physical
plans.

4

Understanding Query Execution Plans

Global Marketing
The Query Optimizer
What is the goal of the Optimizer?

The job of the
SQL Optimizer is
to find “the best
plan possible”.

5

Understanding Query Execution Plans

Global Marketing
Query optimization explained simply

1.

Query submitted

2. Magic happens
3. Shedload of data returned

6

Understanding Query Execution Plans

Global Marketing
Query Optimization (in a bit more detail)
Optimizer steps
Parse

Bind

Optimize

Execute
7

Understanding Query Execution Plans

Global Marketing
Parse
Builds a tree structure based upon the logical operators in the query.
For example:

Logical Operations

SELECT
SSOD.[SalesOrderID],
PP.[Name],
PP.[Weight],
SSOD.[UnitPrice]
FROM [Sales].[SalesOrderDetail] SSOD
INNER JOIN [Production].[Product] PP
ON SSOD.ProductID = PP.ProductID
WHERE PP.Weight > 100

Nodes

Project

Filter

Join

8

Understanding Query Execution Plans

Sales
Order
Detail

Product

Global Marketing
Bind
• Series of validation steps
• Schema validation
• Table validation
• Attribute validation
• Permission validation
SELECT

SSOD.[SalesOrderID],
PP.[Name],
PP.[Weight],
SSOD.[UnitPrice]
FROM [Sales].[SalesOrderDetail] SSOD
INNER JOIN [Production].[Product] PP
ON SSOD.ProductID = PP.ProductID
WHERE PP.Weight > 100

9

Understanding Query Execution Plans

Global Marketing
Optimize
Works though many rules and heuristics.
These Include:
• Commutativity
• Substitution rules
• Exploration rules
• Implementation rules

10

Understanding Query Execution Plans

Global Marketing
Statistics
• SQL uses a cost based optimizer
• Costs influenced by statistics

12

Understanding Query Execution Plans

Global Marketing
Commonly used operators

SELECT

UPDATE

INSERT

DELETE

Table scan

Clustered
Index Scan

NonClustered
Index Scan

Clustered
Index Seek

NonClustered
Index Seek

Key Lookup

Nested Loop
Join

Merge Join

Hash Join
14

Understanding Query Execution Plans

Global Marketing
Blocking and Non-blocking Operators
• Operators / Iterators can be put in two categories:
1. Blocking
2. Non-blocking

• Having a blocking operator in your plan means other operators
further down the line are sitting idle.
This will reduce the overall performance of your query

• Some examples…

15

Understanding Query Execution Plans

Global Marketing
Blocking and Non-blocking operators
Non-blocking example
• An example using a Compute Scalar function

?

16

Understanding Query Execution Plans

Compute
Scalar
Function

Row 1
Row 2
Row 3
Row 4
Row 5

Global Marketing
Blocking and Non-blocking operators
Blocking example
• An example using the sort operator:

?
17

Understanding Query Execution Plans

Sort
Desc

Row 1
Row 2
Row 3
Row 4
Row 5

Global Marketing
Demo’s
Solution Area

Product

Description

Backup and
Recovery

Fast, flexible backup and
recovery with industry-leading
compression technology

Performance
& Operations

Discover and resolve
performance issues in production
before they impact end users and
service levels
Deepest possible understanding
of database performance and
norms

Performance
Tuning

Plan and develop applications
that deliver both functionality and

Development

optimal performance
Comprehensive schema, object,
security and change
management

Administration

Community,
Knowledge,
Training

Project
Lucy
© 2012 Quest Software Inc. All rights reserved.

Community crowdsourcing for
SQL Server tracing and
performance information!
Pg. 22
SQLRelay Dates











@SQLRelay2013

11/11/13 – Reading
12/11/13 – Southampton
13/11/13 – Cardiff
14/11/13 – Birmingham
15/11/13 – Hemel Hempstead
25/11/13 – Newcastle
26/11/13 – Manchester
27/11/13 – Norwich
28/11/13 – Bristol
29/11/13 – London
Any questions?

24

Understanding Query Execution Plans

Global Marketing
Thank you for attending
Richard Douglas
Richard.Douglas@Software.Dell.com
@SQLRich

Contenu connexe

En vedette (12)

Using grouping sets in sql server 2008 tech republic
Using grouping sets in sql server 2008   tech republicUsing grouping sets in sql server 2008   tech republic
Using grouping sets in sql server 2008 tech republic
 
Joins SQL Server
Joins SQL ServerJoins SQL Server
Joins SQL Server
 
Consultas en MS SQL Server 2012
Consultas en MS SQL Server 2012Consultas en MS SQL Server 2012
Consultas en MS SQL Server 2012
 
MS SQL SERVER: Creating Views
MS SQL SERVER: Creating ViewsMS SQL SERVER: Creating Views
MS SQL SERVER: Creating Views
 
Sql tuning guideline
Sql tuning guidelineSql tuning guideline
Sql tuning guideline
 
Sql xp 04
Sql xp 04Sql xp 04
Sql xp 04
 
Statistics
StatisticsStatistics
Statistics
 
e computer notes - Subqueries
e computer notes - Subqueriese computer notes - Subqueries
e computer notes - Subqueries
 
Sub-queries,Groupby and having in SQL
Sub-queries,Groupby and having in SQLSub-queries,Groupby and having in SQL
Sub-queries,Groupby and having in SQL
 
Locking in SQL Server
Locking in SQL ServerLocking in SQL Server
Locking in SQL Server
 
Review of SQL
Review of SQLReview of SQL
Review of SQL
 
Triggers-Sequences-SQL
Triggers-Sequences-SQLTriggers-Sequences-SQL
Triggers-Sequences-SQL
 

Plus de SQLDBApros

10 SQL Server Metrics to Monitor
10 SQL Server Metrics to Monitor10 SQL Server Metrics to Monitor
10 SQL Server Metrics to MonitorSQLDBApros
 
Achieving Gold Medal Performance From SQL Server
Achieving Gold Medal Performance From SQL ServerAchieving Gold Medal Performance From SQL Server
Achieving Gold Medal Performance From SQL ServerSQLDBApros
 
12 Days of Christmas for the SQL DBA
12 Days of Christmas for the SQL DBA12 Days of Christmas for the SQL DBA
12 Days of Christmas for the SQL DBASQLDBApros
 
What SQL Server Pros Can Get by Giving this Holiday Season
What SQL Server Pros Can Get by Giving this Holiday SeasonWhat SQL Server Pros Can Get by Giving this Holiday Season
What SQL Server Pros Can Get by Giving this Holiday SeasonSQLDBApros
 
What SQL Server Pros Can Get By Giving
What SQL Server Pros Can Get By GivingWhat SQL Server Pros Can Get By Giving
What SQL Server Pros Can Get By GivingSQLDBApros
 
SunBridge Ensures the Health of their SQL Server Database with Solutions from...
SunBridge Ensures the Health of their SQL Server Database with Solutions from...SunBridge Ensures the Health of their SQL Server Database with Solutions from...
SunBridge Ensures the Health of their SQL Server Database with Solutions from...SQLDBApros
 
DBA SQL Health Check-up
DBA SQL Health Check-upDBA SQL Health Check-up
DBA SQL Health Check-upSQLDBApros
 
SQL Server Backup and Recovery Challenges
SQL Server Backup and Recovery ChallengesSQL Server Backup and Recovery Challenges
SQL Server Backup and Recovery ChallengesSQLDBApros
 
Cache issues from T-SQL-generated Plans and How to Manage Them
Cache issues from T-SQL-generated Plans and How to Manage ThemCache issues from T-SQL-generated Plans and How to Manage Them
Cache issues from T-SQL-generated Plans and How to Manage ThemSQLDBApros
 
I got 99 Problems but my backup ain't one by Richard Douglas
I got 99 Problems but my backup ain't one by Richard DouglasI got 99 Problems but my backup ain't one by Richard Douglas
I got 99 Problems but my backup ain't one by Richard DouglasSQLDBApros
 
Are the Native SQL Server Backup Utilities Holding You Back?
Are the Native SQL Server Backup Utilities Holding You Back?Are the Native SQL Server Backup Utilities Holding You Back?
Are the Native SQL Server Backup Utilities Holding You Back?SQLDBApros
 

Plus de SQLDBApros (11)

10 SQL Server Metrics to Monitor
10 SQL Server Metrics to Monitor10 SQL Server Metrics to Monitor
10 SQL Server Metrics to Monitor
 
Achieving Gold Medal Performance From SQL Server
Achieving Gold Medal Performance From SQL ServerAchieving Gold Medal Performance From SQL Server
Achieving Gold Medal Performance From SQL Server
 
12 Days of Christmas for the SQL DBA
12 Days of Christmas for the SQL DBA12 Days of Christmas for the SQL DBA
12 Days of Christmas for the SQL DBA
 
What SQL Server Pros Can Get by Giving this Holiday Season
What SQL Server Pros Can Get by Giving this Holiday SeasonWhat SQL Server Pros Can Get by Giving this Holiday Season
What SQL Server Pros Can Get by Giving this Holiday Season
 
What SQL Server Pros Can Get By Giving
What SQL Server Pros Can Get By GivingWhat SQL Server Pros Can Get By Giving
What SQL Server Pros Can Get By Giving
 
SunBridge Ensures the Health of their SQL Server Database with Solutions from...
SunBridge Ensures the Health of their SQL Server Database with Solutions from...SunBridge Ensures the Health of their SQL Server Database with Solutions from...
SunBridge Ensures the Health of their SQL Server Database with Solutions from...
 
DBA SQL Health Check-up
DBA SQL Health Check-upDBA SQL Health Check-up
DBA SQL Health Check-up
 
SQL Server Backup and Recovery Challenges
SQL Server Backup and Recovery ChallengesSQL Server Backup and Recovery Challenges
SQL Server Backup and Recovery Challenges
 
Cache issues from T-SQL-generated Plans and How to Manage Them
Cache issues from T-SQL-generated Plans and How to Manage ThemCache issues from T-SQL-generated Plans and How to Manage Them
Cache issues from T-SQL-generated Plans and How to Manage Them
 
I got 99 Problems but my backup ain't one by Richard Douglas
I got 99 Problems but my backup ain't one by Richard DouglasI got 99 Problems but my backup ain't one by Richard Douglas
I got 99 Problems but my backup ain't one by Richard Douglas
 
Are the Native SQL Server Backup Utilities Holding You Back?
Are the Native SQL Server Backup Utilities Holding You Back?Are the Native SQL Server Backup Utilities Holding You Back?
Are the Native SQL Server Backup Utilities Holding You Back?
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
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
 
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
 
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...Drew Madelung
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
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
 
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 organizationRadu Cotescu
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
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 Takeoffsammart93
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
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...Neo4j
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
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
 
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
 

Dernier (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
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
 
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...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 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
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
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...
 
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
 

Understanding SQL Server's Query Execution Plans

  • 2. Agenda • Introductions • The Query Optimizer • Commonly used operators • Blocking and non-blocking operators • Reading Query Execution Plans 2 Understanding Query Execution Plans Global Marketing
  • 3. Your host • Richard Douglas • Systems Consultant • SQL Server MCITPro • Maidenhead SQL User Group Leader • Blog: http://SQL.RichardDouglas.co.uk • Twitter: @SQLRich • Email: Richard.Douglas@Software.Dell.com 3 Understanding Query Execution Plans Global Marketing
  • 4. The Query Optimizer Why do we need an optimizer? • T-SQL is a “What” not “how” language. • We write “logical” requests. • SQL Optimizer Engine converts logical requests into physical plans. 4 Understanding Query Execution Plans Global Marketing
  • 5. The Query Optimizer What is the goal of the Optimizer? The job of the SQL Optimizer is to find “the best plan possible”. 5 Understanding Query Execution Plans Global Marketing
  • 6. Query optimization explained simply 1. Query submitted 2. Magic happens 3. Shedload of data returned 6 Understanding Query Execution Plans Global Marketing
  • 7. Query Optimization (in a bit more detail) Optimizer steps Parse Bind Optimize Execute 7 Understanding Query Execution Plans Global Marketing
  • 8. Parse Builds a tree structure based upon the logical operators in the query. For example: Logical Operations SELECT SSOD.[SalesOrderID], PP.[Name], PP.[Weight], SSOD.[UnitPrice] FROM [Sales].[SalesOrderDetail] SSOD INNER JOIN [Production].[Product] PP ON SSOD.ProductID = PP.ProductID WHERE PP.Weight > 100 Nodes Project Filter Join 8 Understanding Query Execution Plans Sales Order Detail Product Global Marketing
  • 9. Bind • Series of validation steps • Schema validation • Table validation • Attribute validation • Permission validation SELECT SSOD.[SalesOrderID], PP.[Name], PP.[Weight], SSOD.[UnitPrice] FROM [Sales].[SalesOrderDetail] SSOD INNER JOIN [Production].[Product] PP ON SSOD.ProductID = PP.ProductID WHERE PP.Weight > 100 9 Understanding Query Execution Plans Global Marketing
  • 10. Optimize Works though many rules and heuristics. These Include: • Commutativity • Substitution rules • Exploration rules • Implementation rules 10 Understanding Query Execution Plans Global Marketing
  • 11.
  • 12. Statistics • SQL uses a cost based optimizer • Costs influenced by statistics 12 Understanding Query Execution Plans Global Marketing
  • 13. Commonly used operators SELECT UPDATE INSERT DELETE Table scan Clustered Index Scan NonClustered Index Scan Clustered Index Seek NonClustered Index Seek Key Lookup Nested Loop Join Merge Join Hash Join 14 Understanding Query Execution Plans Global Marketing
  • 14. Blocking and Non-blocking Operators • Operators / Iterators can be put in two categories: 1. Blocking 2. Non-blocking • Having a blocking operator in your plan means other operators further down the line are sitting idle. This will reduce the overall performance of your query • Some examples… 15 Understanding Query Execution Plans Global Marketing
  • 15. Blocking and Non-blocking operators Non-blocking example • An example using a Compute Scalar function ? 16 Understanding Query Execution Plans Compute Scalar Function Row 1 Row 2 Row 3 Row 4 Row 5 Global Marketing
  • 16. Blocking and Non-blocking operators Blocking example • An example using the sort operator: ? 17 Understanding Query Execution Plans Sort Desc Row 1 Row 2 Row 3 Row 4 Row 5 Global Marketing
  • 18. Solution Area Product Description Backup and Recovery Fast, flexible backup and recovery with industry-leading compression technology Performance & Operations Discover and resolve performance issues in production before they impact end users and service levels Deepest possible understanding of database performance and norms Performance Tuning Plan and develop applications that deliver both functionality and Development optimal performance Comprehensive schema, object, security and change management Administration Community, Knowledge, Training Project Lucy © 2012 Quest Software Inc. All rights reserved. Community crowdsourcing for SQL Server tracing and performance information! Pg. 22
  • 19. SQLRelay Dates           @SQLRelay2013 11/11/13 – Reading 12/11/13 – Southampton 13/11/13 – Cardiff 14/11/13 – Birmingham 15/11/13 – Hemel Hempstead 25/11/13 – Newcastle 26/11/13 – Manchester 27/11/13 – Norwich 28/11/13 – Bristol 29/11/13 – London
  • 20. Any questions? 24 Understanding Query Execution Plans Global Marketing
  • 21. Thank you for attending Richard Douglas Richard.Douglas@Software.Dell.com @SQLRich

Notes de l'éditeur

  1. Heuristics quote from WikiPedia - The objective of a heuristic is to produce quickly enough a solution that is good enough for solving the problem at hand. This solution may not be the best of all the actual solutions to this problem, or it may simply approximate the exact solution. But it is still valuable because finding it does not require a prohibitively long time.Commutativity – In mathematics Commutativity is where sums can be rewritten and still provide the same answer, 10+100=110 & 100+10=110.The optimizer knows that if you are asking for an inner join (that is a join where the same data must be found on either side) then it would be more efficient to join the large table to the smaller one. This would result in less work for the storage engine. Let’s take the figures 10 & 100 again Table A will be 100 records, table b will be 10.Join A to b would require 100 searches into table b. join b to a would require 10 searches into table a – quite a saving and still the same logical outcome.In other words this part helps to work out the most efficient join order for your query. It’s been some time since we have had to worry about the order of our joins, the optimizer now figures that out for us.Substitution rules &Exploration rules - Substitution &Exploration rules are rules that use heuristics or mathematic rules to generate new tree shapes, this may provide the opportunity for more optimization rules.Implementation rules - Implementation rules convert the logical trees into physical trees, at this point they can be optimized further and become the eventual execution plan.
  2. Physical OperatorsPhysical operators implement the operation described by logical operators. Each physical operator is an object or routine that performs an operation. For example, some physical operators access columns or rows from a table, index or view. Other physical operators perform other operations such as calculations, aggregations, data integrity checks or joins. Physical operators have costs associated with them.The physical operators initialize, collect data, and close. Specifically, the physical operator can answer the following three method calls:Init(): The Init() method causes a physical operator to initialize itself and set up any required data structures. The physical operator may receive many Init() calls, though typically a physical operator receives only one.GetNext(): The GetNext() method causes a physical operator to get the first, or subsequent row of data. The physical operator may receive zero or many GetNext() calls.Close(): The Close() method causes a physical operator to perform some clean-up operations and shut itself down. A physical operator only receives one Close() call.The GetNext() method returns one row of data, and the number of times it is called appears as ActualRows in the Showplan output that is produced by using SET STATISTICS PROFILE ON or SET STATISTICS XML ON. For more information about these SET options, see SET STATISTICS PROFILE (Transact-SQL) and SET STATISTICS XML (Transact-SQL).The ActualRebinds and ActualRewinds counts that appear in Showplan output refer to the number of times that the Init() method is called. Unless an operator is on the inner side of a loop join, ActualRebinds equals one and ActualRewinds equals zero. If an operator is on the inner side of a loop join, the sum of the number of rebinds and rewinds should equal the number of rows processed on the outer side of the join. A rebind means that one or more of the correlated parameters of the join changed and the inner side must be reevaluated. A rewind means that none of the correlated parameters changed and the prior inner result set may be reused.ActualRebinds and ActualRewinds are present in XML Showplan output produced by using SET STATISTICS XML ON. They are only populated for the Nonclustered Index Spool, Remote Query, Row Count Spool, Sort, Table Spool, and Table-valued Functionoperators. ActualRebinds and ActualRewinds may also be populated for the Assert and Filter operators when the StartupExpression attribute is set to TRUE.When ActualRebinds and ActualRewinds are present in an XML Showplan, they are comparable to EstimateRebinds and EstimateRewinds. When they are absent, the estimated number of rows (EstimateRows) is comparable to the actual number of rows (ActualRows). Note that actual graphical Showplan output displays zeros for the actual rebinds and actual rewinds when they are absent.A related counter, ActualEndOfScans, is available only when Showplan output is produced by using SET STATISTICS XML ON. Whenever a physical operator reaches the end of its data stream, this counter is incremented by one. A physical operator can reach the end of its data stream zero, one, or multiple times. As with rebinds and rewinds, the number of end of scans can be more than one only if the operator is on the inner side of a loop join. The number of end of scans should be less than or equal to the sum of the number of rebinds and rewinds.