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