The document discusses viewing and analyzing the plan cache in SQL Server. It covers viewing the plan cache, exploring the structure of showplan XML, and demonstrating methods to query the plan cache through demos. The goals are to discuss the plan cache, explore it, demonstrate querying methods, and demonstrate performance tuning concepts.
3. SESSION GOALS
Viewing Showplan Scenarios
Session
The Plan XML and Wrap Up
Goals
Cache Structure Demos
4. SESSION GOALS
1. Discuss the plan cache
2. Explore the plan cache
3. Demonstrate methods
to query plan cache
4. Demonstrate
performance tuning
concepts
6. VIEWING THE PLAN
CACHE
Viewing Showplan Scenarios
Session
The Plan XML and Wrap Up
Goals
Cache Structure Demos
7. 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.
8. 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.
Pros Cons
No setup Reset with service
Query-able Activity flush
Actionable Plans miss cache
Real World In Use
9. PLAN CACHE
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
11. WHERE IN THE WORLD IS PLAN_HANDLE?
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
http://www.flickr.com/photos/fallentomato/3918329246/
12. SHOWPLAN XML
STRUCTURE
Viewing Showplan Scenarios
Session
The Plan XML and Wrap Up
Goals
Cache Structure Demos
19. SHOWPLAN XML STRUCTURE
What is in it?
ShowPlanXML
BatchSequence
Batch
Statements
StmtSimple
http://www.flickr.com/photos/etringita/854298772/
20. GOING BELOW STMTSIMPLE
Missing Parameter Warnings RelOp
Indexes List •Plan Affecting •EstimateRows,
•Indexes that •Parameters Convert EstimateIO,
would improve passed into •Columns with PhysicalOp,
plan query no Statistics •Hash,
performance •Unmatched IndexScan,
Indexes NestedLoops
•OutputList
21. CAUTION
Volatile Cache
Data In Use
Use Be
Xquery Mindful
22. XQUERY FUNCTIONS
• 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
23. SCENARIOS AND DEMOS
Viewing Showplan Scenarios
Session
The Plan XML and Wrap Up
Goals
Cache Structure Demos
24. MISSING INDEXES
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
25. MISSING INDEXES
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
What Queries
Should I Test?
http://www.flickr.com/photos/fallentomato/3918329246/
30. POOR PARAMETER SNIFFING
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?
39. INDEX OPERATIONS
What about large tables?
Scans?
Good?
Bad?
What do you do when you
see large counts of scans
on an index?
40. INDEX OPERATIONS
What plans are using that index?
Should you drop it?
What is the potential effect?
http://www.flickr.com/photos/s3a/4436302537/
45. WRAP UP
Viewing Showplan Scenarios
Session
The Plan XML and Wrap Up
Goals
Cache Structure Demos
46. FIND YOUR OWN TREASURE
http://schemas.microsoft.com/sqlserver
/2004/07/showplan/showplanxml.xsd
47. SUMMARY
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
48. SQL SERVER MVP DEEP DIVES, VOLUME 2
www.operationsmile.org
www.manning.com/delaney