SlideShare a Scribd company logo
1 of 45
Execution Plans for Mere Mortals
A beginners overview of execution
plans and what to look for.
Who Am I?
Mike Lawell
Mike Lawell
Principal Consultant
Twitter: @SQLDiver
Blog: SQLServerAssociates.com
LinkedIn: LinkedIn.com/in/MikeLawell
EXECUTION STEPS
On The Inside
Relational Engine
Optimizer
Command
Parser
Query
Executor
SNI
User
Storage Engine
Buffer
Manager
Access
Methods
Transaction
Manager
SQL OS
Buffer Pool
Borrowed from Bradley Ball’s “SQL Internals, Recovery Models, & Backups” presentation
Plan Cache
Data
Cache
Data
Query Parsing
Relation Engine
1. Is the query syntactically correct?
SELECT [Nmae], [Number] FROM [Production].[Product]
Msg 207, Level 16, State 1, Line 3
Invalid column name 'Nmae'.
SELCT [Name], [Number] FROM [Production].[Product]
Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'FROM'.
2. No Errors Output as Parse Tree to Algebrizer
Query Parsing
SELECT [Nmae], [Number] FROM [Production].[Product]
Msg 207, Level 16, State 1, Line 3
Invalid column name 'Nmae'.
Query Parsing
SELECT [Name], [Number] FROM [Production].[Product]
Algebrizer
1. Resolve the Names of the objects (tables, columns, etc.)
2. Resolve the data types for the objects being accessed.
3. Finds aggregate operations (min, max, group by) and performs an operation
called aggregate binding.
If the names of the objects, columns aren’t found an error is output and the process
halts.
If it is successful the algebrizer outputs the query processor tree to the query
optimizer. The query hash is generated and passed with the query processor tree.
Query Optimizer
1. The query optimizer checks the hash against the plan cache. If it exists use it and
the optimization step is skipped and plan is passed to query execution.
2. The query optimizer uses the query processor tree and the statistics to determine
an estimated execution plan.
3. The optimizer goes through a process of using different types of joins and indexes
and assigns a cost to each step by CPU and I/O and determines a cost for each
possible estimated plan it generates.
4. Once an acceptable estimated plan is found it is stored in the plan cache then sent
to the query execution.
Query Execution
Storage Engine
1. The storage engine determines if a recompile was triggered causing a change in
the estimated execution plan.
2. SQL Server determines based upon cost whether it exceeds the threshold for
parallelism changing the estimated plan for parallelism.
3. Statistics that have changed causing a change in the estimated plan.
SQL Server returns the results.
Cardinality Estimation
The optimization process depends on a cost estimation of each physical operator and the
estimated number of records (cardinality estimation) to be processed.
DBCC SHOW_STATISTICS ("[Sales].[SalesOrderDetailEnlarged]", [_WA_Sys_00000003_3D7E1B63]);
The accuracy of the cardinality estimation depends upon the distribution of values in one or
more columns of a table (statistics).
Name Updated Rows Rows Sampled Steps Average key length String Index Filter Expression Unfiltered Rows
_WA_Sys_00000003_3D7E1B63 Nov 26 2014 11:26AM 1000 1000 196 24 YES NULL 1000
RANGE_HI_KEY RANGE_ROWS EQ_ROWS DISTINCT_RANGE_ROWS AVG_RANGE_ROWS
002EE045-E30 0 1 0 1
0169388E-8EC 6 1 6 1
031622B3-B68 3 1 3 1
0424F840-4C2 3 1 3 1
04C4FEAC-7C1 3 1 3 1
Swag Question
Name
_WA_Sys_00000003_3D7E1B63
Cardinality Estimation
There are multiple factors that can negatively impact the cardinality estimation process:
1. Out of date Statistics
SELECT object_name(object_id) as TableName, name AS stats_name,
STATS_DATE(object_id, stats_id) AS statistics_update_date
FROM sys.stats
WHERE object_id = OBJECT_ID('[Sales].[SalesOrderDetailEnlarged]');
2. Cardinality Estimation Errors
https://www.sqlskills.com/blogs/joe/cardinality-estimation-model-version/
Swag Question
Why 70 vs 120?
EXECUTION PLAN BASICS
Required Permissions
Server or database roles with permissions:
sysadmin, dbcreator or db_owner or showplan
To give showplan rights to the database:
GRANT SHOWPLAN TO [username];
How to Read
BASIC OPERATORS
Basic Operators
JOIN OPERATORS
Nested LoopNon-blocking
Description
For each row in the top (outer) input, scan the
bottom (inner) input, and output matching rows.
Where does it happen: Joins with
indexes on join columns.
Nested Loop
SELECT [sod].[CarrierTrackingNumber], [sod].[OrderQty], [soh].[RevisionNumber], [soh].[Ord
FROM [Sales].[SalesOrderHeader] soh
JOIN [Sales].[SalesOrderDetail] sod
ON sod.[SalesOrderID] = soh.[SalesOrderID]
WHERE soh.[OrderDate] = '2013-08-30 00:00:00.000'
Non-blocking
Outer
Inner
Nested Loop
SalesOrderID RevisionNumber OrderDate
55233 8 2013-08-30 00:00:00.000
55234 8 2013-08-30 00:00:00.000
55235 8 2013-08-30 00:00:00.000
55236 8 2013-08-30 00:00:00.000
55237 8 2013-08-30 00:00:00.000
55238 8 2013-08-30 00:00:00.000
55239 8 2013-08-30 00:00:00.000
55240 8 2013-08-30 00:00:00.000
55241 8 2013-08-30 00:00:00.000
55242 8 2013-08-30 00:00:00.000
55243 8 2013-08-30 00:00:00.000
55244 8 2013-08-30 00:00:00.000
55245 8 2013-08-30 00:00:00.000
55246 8 2013-08-30 00:00:00.000
55247 8 2013-08-30 00:00:00.000
55248 8 2013-08-30 00:00:00.000
55249 8 2013-08-30 00:00:00.000
55250 8 2013-08-30 00:00:00.000
55251 8 2013-08-30 00:00:00.000
55252 8 2013-08-30 00:00:00.000
55253 8 2013-08-30 00:00:00.000
SalesOrderID ProductID CarrierTrackingNumber OrderQt
55233 738 1590-499E-95 5
55233 792 1590-499E-95 5
55233 793 1590-499E-95 4
55233 794 1590-499E-95 4
55233 795 1590-499E-95 4
55233 796 1590-499E-95 5
55233 797 1590-499E-95 6
55233 798 1590-499E-95 2
55233 799 1590-499E-95 1
55233 800 1590-499E-95 1
55233 801 1590-499E-95 6
55233 835 1590-499E-95 6
55233 874 1590-499E-95 8
55233 875 1590-499E-95 8
55233 938 1590-499E-95 5
55233 939 1590-499E-95 5
55233 940 1590-499E-95 4
55233 973 1590-499E-95 5
55233 974 1590-499E-95 1
55233 975 1590-499E-95 1
Non-blocking
Description
Match rows from two suitably sorted input tables
exploiting their sort order.
Where does it happen: Joins with
indexes on join columns sorted in an
appropriate sort order.
MergeNon-blocking
MergeNon-blocking
SELECT [sod].[CarrierTrackingNumber], [sod].[OrderQty], [soh].[RevisionNumber], [soh].[OrderDate]
FROM [Sales].[SalesOrderHeader] soh
JOIN [Sales].[SalesOrderDetail] sod
ON sod.[SalesOrderID] = soh.[SalesOrderID]
MergeNon-blocking
SalesOrderID RevisionNumber OrderDate
55233 8 2013-08-30 00:00:00.000
55234 8 2013-08-30 00:00:00.000
55235 8 2013-08-30 00:00:00.000
55236 8 2013-08-30 00:00:00.000
55237 8 2013-08-30 00:00:00.000
55238 8 2013-08-30 00:00:00.000
55239 8 2013-08-30 00:00:00.000
55240 8 2013-08-30 00:00:00.000
55241 8 2013-08-30 00:00:00.000
55242 8 2013-08-30 00:00:00.000
55243 8 2013-08-30 00:00:00.000
55244 8 2013-08-30 00:00:00.000
55245 8 2013-08-30 00:00:00.000
55246 8 2013-08-30 00:00:00.000
55247 8 2013-08-30 00:00:00.000
55248 8 2013-08-30 00:00:00.000
55249 8 2013-08-30 00:00:00.000
55250 8 2013-08-30 00:00:00.000
55251 8 2013-08-30 00:00:00.000
55252 8 2013-08-30 00:00:00.000
55253 8 2013-08-30 00:00:00.000
SalesOrderID ProductID CarrierTrackingNumber OrderQt
55233 738 1590-499E-95 5
55233 792 1590-499E-95 5
55233 793 1590-499E-95 4
55233 794 1590-499E-95 4
55233 795 1590-499E-95 4
55233 796 1590-499E-95 5
55233 797 1590-499E-95 6
55233 798 1590-499E-95 2
55233 799 1590-499E-95 1
55233 800 1590-499E-95 1
55233 801 1590-499E-95 6
55233 835 1590-499E-95 6
55233 874 1590-499E-95 8
55233 875 1590-499E-95 8
55233 938 1590-499E-95 5
55233 939 1590-499E-95 5
55233 940 1590-499E-95 4
55233 973 1590-499E-95 5
55233 974 1590-499E-95 1
55233 975 1590-499E-95 1
Hash Match
Description
Use each row from the top input to build a hash
table, and each row from the bottom input to probe
into the hash table, outputting all matching rows.
Where does it happen: Missing Index,
Missing Where Clause, Where Clause
that is non-sargable.
Hash MatchBlocking
SELECT [sod1].[ProductID], [sod1].[CarrierTrackingNumber], [sod1].[UnitPrice], [sod1].[OrderQty]
FROM [Sales].[SalesOrderDetail] sod1
JOIN [Sales].[SalesOrderDetail] sod2
ON [sod1].[ProductID] = [sod2].[ProductID]
AND [sod1].[CarrierTrackingNumber] = [sod2].[CarrierTrackingNumber]
AND [sod1].[OrderQty] > 5
Hash MatchBlocking
ProductID CarrierTrackingNumber Hash
707 4BC2-4C6D-83 -767544381
711 2AA4-4D12-9F -767515863
715 C811-4D40-80 -767499885
715 8FCD-4D55-8F -767496256
714 CC2F-4D47-8C -767488607
712 BE3B-4D30-A7 -767488106
707 9EBF-4C7E-82 -767471833
716 F78B-4D68-8E -767470049
712 8EBE-4D2C-AB -767459569
716 7DE5-4D74-A7 -767455808
715 46EF-4D44-A9 -767449380
711 9FC2-4D08-A7 -767447057
ProductID CarrierTrackingNumbe
736 2554-4F68-AB -767556491
717 9526-4D73-83 -767556433
715 CC2F-4D47-8C -767554143
715 2960-4D59-96 -767553412
722 9708-4E22-A4 -767551834
722 6F5C-4E3C-B5 -767549829
717 7E0A-4D6E-9E -767545458
707 4BC2-4C6D-83 -767544381
716 F108-4D76-8A -767543168
711 B900-4D0D-AF -767541067
711 67A0-4D10-87 -767539667
707 8441-4C6F-89 -767535798
Hash Table 1 Hash Table 2
Fixed Hash Match
OTHER OPERATORS
Parallelism
SELECT [sod1].[ProductID], [sod1].[CarrierTrackingNumber], [sod1].[UnitPrice], [sod1].[OrderQty]
FROM [Sales].[SalesOrderDetail] sod1
JOIN [Sales].[SalesOrderDetail] sod2
ON [sod1].[ProductID] = [sod2].[ProductID]
AND [sod1].[CarrierTrackingNumber] = [sod2].[CarrierTrackingNumber]
Parallelism
SET STATISTICS IO ON
SET STATISTICS TIME ON
SELECT [sod1].[ProductID], [sod1].[CarrierTrackingNumber], [sod1].[UnitPrice], [sod1].[OrderQty]
FROM [Sales].[SalesOrderDetail] sod1
JOIN [Sales].[SalesOrderDetail] sod2
ON [sod1].[ProductID] = [sod2].[ProductID]
AND [sod1].[CarrierTrackingNumber] = [sod2].[CarrierTrackingNumber]
SELECT [sod1].[ProductID], [sod1].[CarrierTrackingNumber], [sod1].[UnitPrice], [sod1].[OrderQty]
FROM [Sales].[SalesOrderDetail] sod1
JOIN [Sales].[SalesOrderDetail] sod2
ON [sod1].[ProductID] = [sod2].[ProductID]
AND [sod1].[CarrierTrackingNumber] = [sod2].[CarrierTrackingNumber]
OPTION(MAXDOP 1)
Parallelism
Table 'SalesOrderDetail'. Scan count 18, logical reads 2490, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob
read-ahead reads 0.
Table 'Workfile'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads
0.
Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead
reads 0.
SQL Server Execution Times:
CPU time = 9593 ms, elapsed time = 2381 ms.
Table 'Workfile'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads
0.
Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead
reads 0.
Table 'SalesOrderDetail'. Scan count 2, logical reads 2490, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-
ahead reads 0.
SQL Server Execution Times:
CPU time = 7941 ms, elapsed time = 8372 ms.
Parallelism
Hash Aggregate
SELECT [sod1].[CarrierTrackingNumber], sum([sod1].[UnitPrice]) UnitPriceTotal,
sum([sod1].[OrderQty]) as OrderQtyTotal
FROM [Sales].[SalesOrderDetail] sod1
JOIN [Sales].[SalesOrderDetail] sod2
ON [sod1].[ProductID] = [sod2].[ProductID]
AND [sod1].[CarrierTrackingNumber] = [sod2].[CarrierTrackingNumber]
AND [sod1].[OrderQty] > 5
GROUP BY [sod1].[CarrierTrackingNumber]
Stream Aggregate
SELECT [sod1].[CarrierTrackingNumber], sum([sod1].[UnitPrice]) UnitPriceTotal,
sum([sod1].[OrderQty]) as OrderQtyTotal
FROM [Sales].[SalesOrderDetail] sod1
JOIN [Sales].[SalesOrderDetail] sod2
ON [sod1].[ProductID] = [sod2].[ProductID]
AND [sod1].[CarrierTrackingNumber] = [sod2].[CarrierTrackingNumber]
AND [sod1].[OrderQty] > 5
GROUP BY [sod1].[CarrierTrackingNumber]
Sort (spill)
Operator used tempdb to spill data during execution with spill level 1
SELECT [sod].[CarrierTrackingNumber], [sod].[OrderQty], [soh].[RevisionNumber], [soh].[OrderDate]
FROM [Sales].[SalesOrderHeader] soh
JOIN [Sales].[SalesOrderDetailEnlarged] sod
ON sod.[SalesOrderID] = soh.[SalesOrderID]
WHERE [sod].[CarrierTrackingNumber] > '41D0-42A8-A5'
ORDER BY [soh].[RevisionNumber], [soh].[OrderDate]
Sort Spill
SELECT TOP 1 [sod].[CarrierTrackingNumber], [sod].[OrderQty], [soh].[RevisionNumber], [soh].[OrderDate]
FROM [Sales].[SalesOrderHeader] soh
JOIN [Sales].[SalesOrderDetailEnlarged] sod
ON sod.[SalesOrderID] = soh.[SalesOrderID]
WHERE [sod].[CarrierTrackingNumber] > '41D0-42A8-A5'
ORDER BY [soh].[RevisionNumber], [soh].[OrderDate]
Implicit Conversion
SELECT [sod].[ProductID], [sod].[CarrierTrackingNumber], [sod].[UnitPrice], [sod].[OrderQty], [rowguid]
FROM [Sales].[SalesOrderDetail] sod
WHERE LEFT([sod].[rowguid],4) = N'FE10'
Properties
Cool Tools/Products
SQL Server Query Plan Analysis by Joe Sack
Resources
http://www.red-gate.com/community/books/
Downloadable
FREE!
Thank You!
Mike Lawell
Principal Consultant
Twitter: @SQLDiver
Blog: SQLServerAssociates.com
LinkedIn: LinkedIn.com/in/MikeLawell
Email: mike@sqlserverassociates.com
Who Am I?
Mike Lawell
Mike Lawell
Principal Consultant
Twitter: @SQLDiver
Blog: SQLServerAssociates.com
LinkedIn: LinkedIn.com/in/MikeLawell

More Related Content

Viewers also liked

Deepam annual report 2013-14
Deepam annual report 2013-14Deepam annual report 2013-14
Deepam annual report 2013-14Janavi Shyam
 
Mise en-scene/hospital scene
Mise en-scene/hospital sceneMise en-scene/hospital scene
Mise en-scene/hospital scenejessellie
 
Advertising Site Is Helping Us Have Our Dream Child
Advertising Site Is Helping Us Have Our Dream ChildAdvertising Site Is Helping Us Have Our Dream Child
Advertising Site Is Helping Us Have Our Dream Childtouchdown777a
 
Marketing via E-mail for Search Engines
Marketing via E-mail for Search EnginesMarketing via E-mail for Search Engines
Marketing via E-mail for Search Enginestouchdown777a
 
Distributed marketing marketing automation summit - artoos
Distributed marketing   marketing automation summit - artoosDistributed marketing   marketing automation summit - artoos
Distributed marketing marketing automation summit - artoosARTOOS|HAYEZ
 
Discount drug card association ny
Discount drug card association nyDiscount drug card association ny
Discount drug card association nyvidyasagar555
 

Viewers also liked (10)

Deepam annual report 2013-14
Deepam annual report 2013-14Deepam annual report 2013-14
Deepam annual report 2013-14
 
Film Trailer Analysis
Film Trailer AnalysisFilm Trailer Analysis
Film Trailer Analysis
 
Legge stabilità 2015
Legge stabilità 2015Legge stabilità 2015
Legge stabilità 2015
 
Mise en-scene/hospital scene
Mise en-scene/hospital sceneMise en-scene/hospital scene
Mise en-scene/hospital scene
 
Advertising Site Is Helping Us Have Our Dream Child
Advertising Site Is Helping Us Have Our Dream ChildAdvertising Site Is Helping Us Have Our Dream Child
Advertising Site Is Helping Us Have Our Dream Child
 
Marketing via E-mail for Search Engines
Marketing via E-mail for Search EnginesMarketing via E-mail for Search Engines
Marketing via E-mail for Search Engines
 
Distributed marketing marketing automation summit - artoos
Distributed marketing   marketing automation summit - artoosDistributed marketing   marketing automation summit - artoos
Distributed marketing marketing automation summit - artoos
 
Mood board
Mood boardMood board
Mood board
 
Discount drug card association ny
Discount drug card association nyDiscount drug card association ny
Discount drug card association ny
 
Audience Theory
Audience TheoryAudience Theory
Audience Theory
 

Similar to Execution plans for mere mortals

Writing efficient sql
Writing efficient sqlWriting efficient sql
Writing efficient sqlj9soto
 
Database Development Replication Security Maintenance Report
Database Development Replication Security Maintenance ReportDatabase Development Replication Security Maintenance Report
Database Development Replication Security Maintenance Reportnyin27
 
The ultimate-guide-to-sql
The ultimate-guide-to-sqlThe ultimate-guide-to-sql
The ultimate-guide-to-sqlMcNamaraChiwaye
 
Oracle 12c Application development
Oracle 12c Application developmentOracle 12c Application development
Oracle 12c Application developmentpasalapudi123
 
Kevin Bengtson Portfolio
Kevin Bengtson PortfolioKevin Bengtson Portfolio
Kevin Bengtson PortfolioKbengt521
 
How to Realize an Additional 270% ROI on Snowflake
How to Realize an Additional 270% ROI on SnowflakeHow to Realize an Additional 270% ROI on Snowflake
How to Realize an Additional 270% ROI on SnowflakeAtScale
 
Top 10 tips for Oracle performance
Top 10 tips for Oracle performanceTop 10 tips for Oracle performance
Top 10 tips for Oracle performanceGuy Harrison
 
Scaling AutoML-Driven Anomaly Detection With Luminaire
Scaling AutoML-Driven Anomaly Detection With LuminaireScaling AutoML-Driven Anomaly Detection With Luminaire
Scaling AutoML-Driven Anomaly Detection With LuminaireDatabricks
 
IBM Insight 2015 - 1824 - Using Bluemix and dashDB for Twitter Analysis
IBM Insight 2015 - 1824 - Using Bluemix and dashDB for Twitter AnalysisIBM Insight 2015 - 1824 - Using Bluemix and dashDB for Twitter Analysis
IBM Insight 2015 - 1824 - Using Bluemix and dashDB for Twitter AnalysisTorsten Steinbach
 
解决Ora 14098分区交换索引不匹配错误
解决Ora 14098分区交换索引不匹配错误解决Ora 14098分区交换索引不匹配错误
解决Ora 14098分区交换索引不匹配错误maclean liu
 
Enhancements that will make your sql database roar sp1 edition sql bits 2017
Enhancements that will make your sql database roar sp1 edition sql bits 2017Enhancements that will make your sql database roar sp1 edition sql bits 2017
Enhancements that will make your sql database roar sp1 edition sql bits 2017Bob Ward
 
Performance Tuning for Visualforce and Apex
Performance Tuning for Visualforce and ApexPerformance Tuning for Visualforce and Apex
Performance Tuning for Visualforce and ApexSalesforce Developers
 
EvolveExecutionPlans.pdf
EvolveExecutionPlans.pdfEvolveExecutionPlans.pdf
EvolveExecutionPlans.pdfPraveenPolu1
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?Andrej Pashchenko
 
Easy migration to a new Chart of Accounts
Easy migration to a new Chart of AccountsEasy migration to a new Chart of Accounts
Easy migration to a new Chart of AccountsChitra Kanakaraj
 
Kafka Streams State Stores Being Persistent
Kafka Streams State Stores Being PersistentKafka Streams State Stores Being Persistent
Kafka Streams State Stores Being Persistentconfluent
 

Similar to Execution plans for mere mortals (20)

Writing efficient sql
Writing efficient sqlWriting efficient sql
Writing efficient sql
 
Database Development Replication Security Maintenance Report
Database Development Replication Security Maintenance ReportDatabase Development Replication Security Maintenance Report
Database Development Replication Security Maintenance Report
 
Oracle SQL Basics
Oracle SQL BasicsOracle SQL Basics
Oracle SQL Basics
 
The ultimate-guide-to-sql
The ultimate-guide-to-sqlThe ultimate-guide-to-sql
The ultimate-guide-to-sql
 
Oracle 12c Application development
Oracle 12c Application developmentOracle 12c Application development
Oracle 12c Application development
 
Kevin Bengtson Portfolio
Kevin Bengtson PortfolioKevin Bengtson Portfolio
Kevin Bengtson Portfolio
 
How to Realize an Additional 270% ROI on Snowflake
How to Realize an Additional 270% ROI on SnowflakeHow to Realize an Additional 270% ROI on Snowflake
How to Realize an Additional 270% ROI on Snowflake
 
Top 10 tips for Oracle performance
Top 10 tips for Oracle performanceTop 10 tips for Oracle performance
Top 10 tips for Oracle performance
 
samsung engineering 028050 Algorithm Investment Report
samsung engineering 028050 Algorithm Investment Reportsamsung engineering 028050 Algorithm Investment Report
samsung engineering 028050 Algorithm Investment Report
 
Scaling AutoML-Driven Anomaly Detection With Luminaire
Scaling AutoML-Driven Anomaly Detection With LuminaireScaling AutoML-Driven Anomaly Detection With Luminaire
Scaling AutoML-Driven Anomaly Detection With Luminaire
 
IBM Insight 2015 - 1824 - Using Bluemix and dashDB for Twitter Analysis
IBM Insight 2015 - 1824 - Using Bluemix and dashDB for Twitter AnalysisIBM Insight 2015 - 1824 - Using Bluemix and dashDB for Twitter Analysis
IBM Insight 2015 - 1824 - Using Bluemix and dashDB for Twitter Analysis
 
5 Cool Things About SQL
5 Cool Things About SQL5 Cool Things About SQL
5 Cool Things About SQL
 
解决Ora 14098分区交换索引不匹配错误
解决Ora 14098分区交换索引不匹配错误解决Ora 14098分区交换索引不匹配错误
解决Ora 14098分区交换索引不匹配错误
 
Enhancements that will make your sql database roar sp1 edition sql bits 2017
Enhancements that will make your sql database roar sp1 edition sql bits 2017Enhancements that will make your sql database roar sp1 edition sql bits 2017
Enhancements that will make your sql database roar sp1 edition sql bits 2017
 
Performance Tuning for Visualforce and Apex
Performance Tuning for Visualforce and ApexPerformance Tuning for Visualforce and Apex
Performance Tuning for Visualforce and Apex
 
Dmaic
DmaicDmaic
Dmaic
 
EvolveExecutionPlans.pdf
EvolveExecutionPlans.pdfEvolveExecutionPlans.pdf
EvolveExecutionPlans.pdf
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?
 
Easy migration to a new Chart of Accounts
Easy migration to a new Chart of AccountsEasy migration to a new Chart of Accounts
Easy migration to a new Chart of Accounts
 
Kafka Streams State Stores Being Persistent
Kafka Streams State Stores Being PersistentKafka Streams State Stores Being Persistent
Kafka Streams State Stores Being Persistent
 

Recently uploaded

Digital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham WareDigital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham WareGraham Ware
 
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...kumargunjan9515
 
Giridih Escorts Service Girl ^ 9332606886, WhatsApp Anytime Giridih
Giridih Escorts Service Girl ^ 9332606886, WhatsApp Anytime GiridihGiridih Escorts Service Girl ^ 9332606886, WhatsApp Anytime Giridih
Giridih Escorts Service Girl ^ 9332606886, WhatsApp Anytime Giridihmeghakumariji156
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteedamy56318795
 
Vastral Call Girls Book Now 7737669865 Top Class Escort Service Available
Vastral Call Girls Book Now 7737669865 Top Class Escort Service AvailableVastral Call Girls Book Now 7737669865 Top Class Escort Service Available
Vastral Call Girls Book Now 7737669865 Top Class Escort Service Availablegargpaaro
 
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Klinik kandungan
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...Elaine Werffeli
 
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi ArabiaIn Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabiaahmedjiabur940
 
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...HyderabadDolls
 
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...SOFTTECHHUB
 
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book nowVadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book nowgargpaaro
 
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...nirzagarg
 
Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...
Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...
Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...HyderabadDolls
 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...nirzagarg
 
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...nirzagarg
 
💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...
💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...
💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...vershagrag
 
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...gajnagarg
 
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24  Building Real-Time Pipelines With FLaNKDATA SUMMIT 24  Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNKTimothy Spann
 
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...nirzagarg
 

Recently uploaded (20)

Digital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham WareDigital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham Ware
 
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
 
Giridih Escorts Service Girl ^ 9332606886, WhatsApp Anytime Giridih
Giridih Escorts Service Girl ^ 9332606886, WhatsApp Anytime GiridihGiridih Escorts Service Girl ^ 9332606886, WhatsApp Anytime Giridih
Giridih Escorts Service Girl ^ 9332606886, WhatsApp Anytime Giridih
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
 
Vastral Call Girls Book Now 7737669865 Top Class Escort Service Available
Vastral Call Girls Book Now 7737669865 Top Class Escort Service AvailableVastral Call Girls Book Now 7737669865 Top Class Escort Service Available
Vastral Call Girls Book Now 7737669865 Top Class Escort Service Available
 
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
 
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi ArabiaIn Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
 
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
 
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
 
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book nowVadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
 
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
 
Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...
Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...
Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...
 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
 
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Tumkur [ 7014168258 ] Call Me For Genuine Models We...
 
💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...
💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...
💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...
 
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
 
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24  Building Real-Time Pipelines With FLaNKDATA SUMMIT 24  Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
 
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
 

Execution plans for mere mortals

  • 1. Execution Plans for Mere Mortals A beginners overview of execution plans and what to look for.
  • 2. Who Am I? Mike Lawell Mike Lawell Principal Consultant Twitter: @SQLDiver Blog: SQLServerAssociates.com LinkedIn: LinkedIn.com/in/MikeLawell
  • 4. On The Inside Relational Engine Optimizer Command Parser Query Executor SNI User Storage Engine Buffer Manager Access Methods Transaction Manager SQL OS Buffer Pool Borrowed from Bradley Ball’s “SQL Internals, Recovery Models, & Backups” presentation Plan Cache Data Cache Data
  • 5. Query Parsing Relation Engine 1. Is the query syntactically correct? SELECT [Nmae], [Number] FROM [Production].[Product] Msg 207, Level 16, State 1, Line 3 Invalid column name 'Nmae'. SELCT [Name], [Number] FROM [Production].[Product] Msg 156, Level 15, State 1, Line 3 Incorrect syntax near the keyword 'FROM'. 2. No Errors Output as Parse Tree to Algebrizer
  • 6. Query Parsing SELECT [Nmae], [Number] FROM [Production].[Product] Msg 207, Level 16, State 1, Line 3 Invalid column name 'Nmae'.
  • 7. Query Parsing SELECT [Name], [Number] FROM [Production].[Product]
  • 8. Algebrizer 1. Resolve the Names of the objects (tables, columns, etc.) 2. Resolve the data types for the objects being accessed. 3. Finds aggregate operations (min, max, group by) and performs an operation called aggregate binding. If the names of the objects, columns aren’t found an error is output and the process halts. If it is successful the algebrizer outputs the query processor tree to the query optimizer. The query hash is generated and passed with the query processor tree.
  • 9. Query Optimizer 1. The query optimizer checks the hash against the plan cache. If it exists use it and the optimization step is skipped and plan is passed to query execution. 2. The query optimizer uses the query processor tree and the statistics to determine an estimated execution plan. 3. The optimizer goes through a process of using different types of joins and indexes and assigns a cost to each step by CPU and I/O and determines a cost for each possible estimated plan it generates. 4. Once an acceptable estimated plan is found it is stored in the plan cache then sent to the query execution.
  • 10. Query Execution Storage Engine 1. The storage engine determines if a recompile was triggered causing a change in the estimated execution plan. 2. SQL Server determines based upon cost whether it exceeds the threshold for parallelism changing the estimated plan for parallelism. 3. Statistics that have changed causing a change in the estimated plan. SQL Server returns the results.
  • 11. Cardinality Estimation The optimization process depends on a cost estimation of each physical operator and the estimated number of records (cardinality estimation) to be processed. DBCC SHOW_STATISTICS ("[Sales].[SalesOrderDetailEnlarged]", [_WA_Sys_00000003_3D7E1B63]); The accuracy of the cardinality estimation depends upon the distribution of values in one or more columns of a table (statistics). Name Updated Rows Rows Sampled Steps Average key length String Index Filter Expression Unfiltered Rows _WA_Sys_00000003_3D7E1B63 Nov 26 2014 11:26AM 1000 1000 196 24 YES NULL 1000 RANGE_HI_KEY RANGE_ROWS EQ_ROWS DISTINCT_RANGE_ROWS AVG_RANGE_ROWS 002EE045-E30 0 1 0 1 0169388E-8EC 6 1 6 1 031622B3-B68 3 1 3 1 0424F840-4C2 3 1 3 1 04C4FEAC-7C1 3 1 3 1
  • 13. Cardinality Estimation There are multiple factors that can negatively impact the cardinality estimation process: 1. Out of date Statistics SELECT object_name(object_id) as TableName, name AS stats_name, STATS_DATE(object_id, stats_id) AS statistics_update_date FROM sys.stats WHERE object_id = OBJECT_ID('[Sales].[SalesOrderDetailEnlarged]'); 2. Cardinality Estimation Errors https://www.sqlskills.com/blogs/joe/cardinality-estimation-model-version/
  • 16. Required Permissions Server or database roles with permissions: sysadmin, dbcreator or db_owner or showplan To give showplan rights to the database: GRANT SHOWPLAN TO [username];
  • 21. Nested LoopNon-blocking Description For each row in the top (outer) input, scan the bottom (inner) input, and output matching rows. Where does it happen: Joins with indexes on join columns.
  • 22. Nested Loop SELECT [sod].[CarrierTrackingNumber], [sod].[OrderQty], [soh].[RevisionNumber], [soh].[Ord FROM [Sales].[SalesOrderHeader] soh JOIN [Sales].[SalesOrderDetail] sod ON sod.[SalesOrderID] = soh.[SalesOrderID] WHERE soh.[OrderDate] = '2013-08-30 00:00:00.000' Non-blocking Outer Inner
  • 23. Nested Loop SalesOrderID RevisionNumber OrderDate 55233 8 2013-08-30 00:00:00.000 55234 8 2013-08-30 00:00:00.000 55235 8 2013-08-30 00:00:00.000 55236 8 2013-08-30 00:00:00.000 55237 8 2013-08-30 00:00:00.000 55238 8 2013-08-30 00:00:00.000 55239 8 2013-08-30 00:00:00.000 55240 8 2013-08-30 00:00:00.000 55241 8 2013-08-30 00:00:00.000 55242 8 2013-08-30 00:00:00.000 55243 8 2013-08-30 00:00:00.000 55244 8 2013-08-30 00:00:00.000 55245 8 2013-08-30 00:00:00.000 55246 8 2013-08-30 00:00:00.000 55247 8 2013-08-30 00:00:00.000 55248 8 2013-08-30 00:00:00.000 55249 8 2013-08-30 00:00:00.000 55250 8 2013-08-30 00:00:00.000 55251 8 2013-08-30 00:00:00.000 55252 8 2013-08-30 00:00:00.000 55253 8 2013-08-30 00:00:00.000 SalesOrderID ProductID CarrierTrackingNumber OrderQt 55233 738 1590-499E-95 5 55233 792 1590-499E-95 5 55233 793 1590-499E-95 4 55233 794 1590-499E-95 4 55233 795 1590-499E-95 4 55233 796 1590-499E-95 5 55233 797 1590-499E-95 6 55233 798 1590-499E-95 2 55233 799 1590-499E-95 1 55233 800 1590-499E-95 1 55233 801 1590-499E-95 6 55233 835 1590-499E-95 6 55233 874 1590-499E-95 8 55233 875 1590-499E-95 8 55233 938 1590-499E-95 5 55233 939 1590-499E-95 5 55233 940 1590-499E-95 4 55233 973 1590-499E-95 5 55233 974 1590-499E-95 1 55233 975 1590-499E-95 1 Non-blocking
  • 24. Description Match rows from two suitably sorted input tables exploiting their sort order. Where does it happen: Joins with indexes on join columns sorted in an appropriate sort order. MergeNon-blocking
  • 25. MergeNon-blocking SELECT [sod].[CarrierTrackingNumber], [sod].[OrderQty], [soh].[RevisionNumber], [soh].[OrderDate] FROM [Sales].[SalesOrderHeader] soh JOIN [Sales].[SalesOrderDetail] sod ON sod.[SalesOrderID] = soh.[SalesOrderID]
  • 26. MergeNon-blocking SalesOrderID RevisionNumber OrderDate 55233 8 2013-08-30 00:00:00.000 55234 8 2013-08-30 00:00:00.000 55235 8 2013-08-30 00:00:00.000 55236 8 2013-08-30 00:00:00.000 55237 8 2013-08-30 00:00:00.000 55238 8 2013-08-30 00:00:00.000 55239 8 2013-08-30 00:00:00.000 55240 8 2013-08-30 00:00:00.000 55241 8 2013-08-30 00:00:00.000 55242 8 2013-08-30 00:00:00.000 55243 8 2013-08-30 00:00:00.000 55244 8 2013-08-30 00:00:00.000 55245 8 2013-08-30 00:00:00.000 55246 8 2013-08-30 00:00:00.000 55247 8 2013-08-30 00:00:00.000 55248 8 2013-08-30 00:00:00.000 55249 8 2013-08-30 00:00:00.000 55250 8 2013-08-30 00:00:00.000 55251 8 2013-08-30 00:00:00.000 55252 8 2013-08-30 00:00:00.000 55253 8 2013-08-30 00:00:00.000 SalesOrderID ProductID CarrierTrackingNumber OrderQt 55233 738 1590-499E-95 5 55233 792 1590-499E-95 5 55233 793 1590-499E-95 4 55233 794 1590-499E-95 4 55233 795 1590-499E-95 4 55233 796 1590-499E-95 5 55233 797 1590-499E-95 6 55233 798 1590-499E-95 2 55233 799 1590-499E-95 1 55233 800 1590-499E-95 1 55233 801 1590-499E-95 6 55233 835 1590-499E-95 6 55233 874 1590-499E-95 8 55233 875 1590-499E-95 8 55233 938 1590-499E-95 5 55233 939 1590-499E-95 5 55233 940 1590-499E-95 4 55233 973 1590-499E-95 5 55233 974 1590-499E-95 1 55233 975 1590-499E-95 1
  • 27. Hash Match Description Use each row from the top input to build a hash table, and each row from the bottom input to probe into the hash table, outputting all matching rows. Where does it happen: Missing Index, Missing Where Clause, Where Clause that is non-sargable.
  • 28. Hash MatchBlocking SELECT [sod1].[ProductID], [sod1].[CarrierTrackingNumber], [sod1].[UnitPrice], [sod1].[OrderQty] FROM [Sales].[SalesOrderDetail] sod1 JOIN [Sales].[SalesOrderDetail] sod2 ON [sod1].[ProductID] = [sod2].[ProductID] AND [sod1].[CarrierTrackingNumber] = [sod2].[CarrierTrackingNumber] AND [sod1].[OrderQty] > 5
  • 29. Hash MatchBlocking ProductID CarrierTrackingNumber Hash 707 4BC2-4C6D-83 -767544381 711 2AA4-4D12-9F -767515863 715 C811-4D40-80 -767499885 715 8FCD-4D55-8F -767496256 714 CC2F-4D47-8C -767488607 712 BE3B-4D30-A7 -767488106 707 9EBF-4C7E-82 -767471833 716 F78B-4D68-8E -767470049 712 8EBE-4D2C-AB -767459569 716 7DE5-4D74-A7 -767455808 715 46EF-4D44-A9 -767449380 711 9FC2-4D08-A7 -767447057 ProductID CarrierTrackingNumbe 736 2554-4F68-AB -767556491 717 9526-4D73-83 -767556433 715 CC2F-4D47-8C -767554143 715 2960-4D59-96 -767553412 722 9708-4E22-A4 -767551834 722 6F5C-4E3C-B5 -767549829 717 7E0A-4D6E-9E -767545458 707 4BC2-4C6D-83 -767544381 716 F108-4D76-8A -767543168 711 B900-4D0D-AF -767541067 711 67A0-4D10-87 -767539667 707 8441-4C6F-89 -767535798 Hash Table 1 Hash Table 2
  • 32. Parallelism SELECT [sod1].[ProductID], [sod1].[CarrierTrackingNumber], [sod1].[UnitPrice], [sod1].[OrderQty] FROM [Sales].[SalesOrderDetail] sod1 JOIN [Sales].[SalesOrderDetail] sod2 ON [sod1].[ProductID] = [sod2].[ProductID] AND [sod1].[CarrierTrackingNumber] = [sod2].[CarrierTrackingNumber]
  • 33. Parallelism SET STATISTICS IO ON SET STATISTICS TIME ON SELECT [sod1].[ProductID], [sod1].[CarrierTrackingNumber], [sod1].[UnitPrice], [sod1].[OrderQty] FROM [Sales].[SalesOrderDetail] sod1 JOIN [Sales].[SalesOrderDetail] sod2 ON [sod1].[ProductID] = [sod2].[ProductID] AND [sod1].[CarrierTrackingNumber] = [sod2].[CarrierTrackingNumber] SELECT [sod1].[ProductID], [sod1].[CarrierTrackingNumber], [sod1].[UnitPrice], [sod1].[OrderQty] FROM [Sales].[SalesOrderDetail] sod1 JOIN [Sales].[SalesOrderDetail] sod2 ON [sod1].[ProductID] = [sod2].[ProductID] AND [sod1].[CarrierTrackingNumber] = [sod2].[CarrierTrackingNumber] OPTION(MAXDOP 1)
  • 34. Parallelism Table 'SalesOrderDetail'. Scan count 18, logical reads 2490, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. Table 'Workfile'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. SQL Server Execution Times: CPU time = 9593 ms, elapsed time = 2381 ms. Table 'Workfile'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. Table 'SalesOrderDetail'. Scan count 2, logical reads 2490, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read- ahead reads 0. SQL Server Execution Times: CPU time = 7941 ms, elapsed time = 8372 ms.
  • 36. Hash Aggregate SELECT [sod1].[CarrierTrackingNumber], sum([sod1].[UnitPrice]) UnitPriceTotal, sum([sod1].[OrderQty]) as OrderQtyTotal FROM [Sales].[SalesOrderDetail] sod1 JOIN [Sales].[SalesOrderDetail] sod2 ON [sod1].[ProductID] = [sod2].[ProductID] AND [sod1].[CarrierTrackingNumber] = [sod2].[CarrierTrackingNumber] AND [sod1].[OrderQty] > 5 GROUP BY [sod1].[CarrierTrackingNumber]
  • 37. Stream Aggregate SELECT [sod1].[CarrierTrackingNumber], sum([sod1].[UnitPrice]) UnitPriceTotal, sum([sod1].[OrderQty]) as OrderQtyTotal FROM [Sales].[SalesOrderDetail] sod1 JOIN [Sales].[SalesOrderDetail] sod2 ON [sod1].[ProductID] = [sod2].[ProductID] AND [sod1].[CarrierTrackingNumber] = [sod2].[CarrierTrackingNumber] AND [sod1].[OrderQty] > 5 GROUP BY [sod1].[CarrierTrackingNumber]
  • 38. Sort (spill) Operator used tempdb to spill data during execution with spill level 1 SELECT [sod].[CarrierTrackingNumber], [sod].[OrderQty], [soh].[RevisionNumber], [soh].[OrderDate] FROM [Sales].[SalesOrderHeader] soh JOIN [Sales].[SalesOrderDetailEnlarged] sod ON sod.[SalesOrderID] = soh.[SalesOrderID] WHERE [sod].[CarrierTrackingNumber] > '41D0-42A8-A5' ORDER BY [soh].[RevisionNumber], [soh].[OrderDate]
  • 39. Sort Spill SELECT TOP 1 [sod].[CarrierTrackingNumber], [sod].[OrderQty], [soh].[RevisionNumber], [soh].[OrderDate] FROM [Sales].[SalesOrderHeader] soh JOIN [Sales].[SalesOrderDetailEnlarged] sod ON sod.[SalesOrderID] = soh.[SalesOrderID] WHERE [sod].[CarrierTrackingNumber] > '41D0-42A8-A5' ORDER BY [soh].[RevisionNumber], [soh].[OrderDate]
  • 40. Implicit Conversion SELECT [sod].[ProductID], [sod].[CarrierTrackingNumber], [sod].[UnitPrice], [sod].[OrderQty], [rowguid] FROM [Sales].[SalesOrderDetail] sod WHERE LEFT([sod].[rowguid],4) = N'FE10'
  • 42. Cool Tools/Products SQL Server Query Plan Analysis by Joe Sack
  • 44. Thank You! Mike Lawell Principal Consultant Twitter: @SQLDiver Blog: SQLServerAssociates.com LinkedIn: LinkedIn.com/in/MikeLawell Email: mike@sqlserverassociates.com
  • 45. Who Am I? Mike Lawell Mike Lawell Principal Consultant Twitter: @SQLDiver Blog: SQLServerAssociates.com LinkedIn: LinkedIn.com/in/MikeLawell

Editor's Notes

  1. Object Names, Data types, Aggregate Binding
  2. Is it in plan cache? Estimated plan(s) Costs per plan? Sent to Storage Engine for execution.
  3. Is did recompile get triggered? Over cost threshold for parallelism?
  4. Cardinality Estimation Model Version 120 (new model) 70 old model.
  5. Cardinality Estimation Model Version 120 (new model) 70 old model.
  6. Physical order of process is SELECT pulls data from the next operator left to right top to bottom. Easier to understand from right to left top to bottom.
  7. Seeing a hash match is a good indication of an opportunity for tuning by adding an index, improving the join or where clause. If that isn’t possible, the hash match is the most efficient option you have.
  8. Table results are inserted into a temporary table and columns hashed for each table then matched from the temporary table. It is a blocking process as it must populate the hash tables completely before it can match the hash values for output.
  9. Average is a count and sum
  10. Disabled statistics, loaded table with