This document discusses various SQL Server tools for query tuning. It begins by outlining the goals of understanding available native tools, applying the right tools for situations, and learning how to use the tools. The document then covers tools for identifying issues, investigating queries, modifying queries, and measuring performance. These include extended events, Query Store, dynamic management views, execution plans, and automation features. It provides examples of how each tool can be used and concludes with documentation resources.
2. GOALS
• Understand the native tools available to aid in query tuning.
• Know how to apply which tools in a given situation in order to
better aid query tuning.
• Learn how to use various tools in aid of performance tuning.
23. YOU CONTROL…
23
Turn it on or Off
Time to flush to disk
Size of storage
Days in storage
Plans per query limit
Automatic cleanup
Capture Mode
Aggregation Interval Length
27. QUERY TUNING OPPORTUNITIES
27
Changes in how you monitor
New information available
Bad parameter sniffing
Cardinality estimation issues
Structural problems leading to plan differences
28. UPGRADE OPPORTUNITIES
28
Restore your older database, leave compatibility level
in place
Turn on query store
Run your load
Switch compatibility level
Identify regressions & force plans as needed
39. SSMS TOOLS
Stuff we are not talking
about
Data Collection
Database
Engine Tuning
Advisor
3rd Party
Profiler
40. SSMS TOOLS
Stuff we could talk about but
won’t
Statistics
Database
Objects
3rd Party
Fragmentation
41. SSMS TOOLS
Include Client Statistics
Positives
History Comparisons
Consistent
across edits
Negatives
Inaccurate
Inconsistent
with other
data
Difficult to
capture
42. SSMS TOOLS
SET STATISTICS TIME
Positives
Easy Immediate Persistent Flexible
Negatives
Creates
load
Inconsistent
with other
data
43. SSMS TOOLS
SET STATISTICS IO
Positives
Easy Immediate Persistent Flexible
Negatives
Creates
HUGE load
Inconsistent
with other
data
48. WHAT IS AN EXECUTION PLAN
• An execution plan describes the set of operations that the
execution engine within SQL Server needs to perform in
order to return the data or perform the action required by a
query.
54. PLAN METRICS
Degree of Parallelism
Memory Grant
Wait Statistics
Query Time Statistics
Memory Grant Info
Parameter Runtime Value
55. OPERATOR METRICS
Counts Per Thread
Actual Rebinds
Actual Rewinds
Actual Rows
Batches
Actual CPU MS
Actual End of Scans
Actual Executions
Actual Logical Reads
Actual Physical Reads
Actual Read Aheads
Actual Elapsed DMS
Actual Lob Logical Reads
Actual Lob Physical Reads
Actual Lob Read Aheads
Input Memory Grant
Output Memory Grant
Used Memory Grant
58. FIRST OPERATOR
Plan size Compile time
Missing
Indexes
Optimization
level
Parameter
• Compiled value
• Runtime Value
Query hash
Reason for
early
termination
ANSI settings
59. WHERE TO GO, WHAT TO READ
It’s all in the
Properties
Identify Node
ID
Combine plans
and metrics
Every operator
is unique (to a
degree)
Track output
from each
operator
60. LIVE QUERY STATISTICS
Living Query Plan
2014+
Data only in 2012
Must activate with query
Can’t run on
executing query
No recording
61. COMPARING EXECUTION PLANS
SSMS 17.4+
2016+
Hilight
differences
One plan must be file
Identify
similarities
Includes
properties
64. ADAPTIVE QUERY PROCESSING
Multi-Statement Table-
Valued Functions
Interleaved execution
No data modification
No CROSS APPLY
Marked in execution plan
Tracking through extended events
Batch Mode Memory
Grants
Literally revises memory grant
Batch Mode processing only
2x or greater on memory over 1mb
No RECOMPILE
Tracking through extended events
Batch Mode Adaptive
Joins
Defers join choice
Batch Mode processing only
Hash or loop joins only
Tracking through Query Store
69. DOCUMENTATION
• Introducing SQL Server Extended Events
• Plan Regressions in SQL Server 2017
• https://docs.microsoft.com/en-us/sql/relational-
databases/automatic-tuning/automatic-tuning
• https://docs.microsoft.com/en-us/azure/sql-database/sql-
database-automatic-tuning
70. GOALS
• Understand the native tools available to aid in query tuning.
• Know how to apply which tools in a given situation in order to
better aid query tuning.
• Learn how to use various tools in aid of performance tuning.