4. 1. Discuss the plan cache
2. Explore the plan cache
3. Demonstrate methods
to query plan cache
4. Demonstrate
performance tuning
concepts
SESSION GOALS
6. VIEWING THE PLAN
CACHE
Wrap Up
Scenarios
and
Demos
Showplan
XML
Structure
Viewing
The Plan
Cache
Session
Goals
7. Portion of SQL Server memory that stores execution plans
that have been prepared by the Query Optimizer. Execution
plans are used to by SQL Server to execute SQL statements.
PLAN CACHE
8. Pros
No setup
Query-able
Actionable
Real World
Cons
Reset with service
Activity flush
Plans miss cache
In Use
PLAN CACHE
Portion of SQL Server memory that stores execution plans
that have been prepared by the Query Optimizer. Execution
plans are used to by SQL Server to execute SQL statements.
9. sys.dm_exec_cached_plans
• All Plans
• Size
• Use count
sys.dm_exec_query_plan
(plan_handle)
• Table Valued Function
• SHOWPLAN XML as XML
sys.dm_exec_text_query_plan
(plan_handle,0,-1)
• Table Valued Function
• SHOWPLAN XML as text
PLAN CACHE
11. sys.dm_exec_requests
Current connection
Vaguely similar to sp_who
sys.dm_exec_query_stats
Stats on executed queries
Contains SQL_Handle
sys.dm_exec_cached_plans
Stats on cached plans
Distinct list of plans
WHERE IN THE WORLD IS PLAN_HANDLE?
http://www.flickr.com/photos/fallentomato/3918329246/
22. • Forward slashes
/ means to find the specific location
// means find any from the current location
• Important Functions
• nodes()
• value()
• exist()
• query()
• Everything is case sensitive
XQUERY FUNCTIONS
23. SCENARIOS AND DEMOS
Wrap Up
Scenarios
and
Demos
Showplan
XML
Structure
Viewing
The Plan
Cache
Session
Goals
24. What plans would benefit from indexes?
DMVs
sys.dm_db_missing_index_columns
sys.dm_db_missing_index_details
sys.dm_db_missing_index_group_stats
sys.dm_db_missing_index_groups
DBA-409-S
MISSING INDEXES
25. What plans would benefit from indexes?
DMVs
sys.dm_db_missing_index_columns
sys.dm_db_missing_index_details
sys.dm_db_missing_index_group_stats
sys.dm_db_missing_index_groups
MISSING INDEXES
http://www.flickr.com/photos/fallentomato/3918329246/
What Queries
Should I Test?
30. Think about the plans you
find example…
What has changed in the
environments?
Is the plan using the wrong
values?
What parameters is the
plan using?
POOR PARAMETER SNIFFING
39. What about large tables?
Scans?
Good?
Bad?
What do you do when you
see large counts of scans
on an index?
INDEX OPERATIONS
40. What plans are using that index?
Should you drop it?
What is the potential effect?
INDEX OPERATIONS
http://www.flickr.com/photos/s3a/4436302537/
47. 1. Plan Cache IS your
performance work load
2. Information is readily
available
3. Techniques to access
not as complex as
appearances
4. Scale your performance
knowledge across the
environment
SUMMARY