Your SlideShare is downloading. ×
0
DISCOVERING   Jason Strate                 Database ArchitectTHE PLAN CACHE   Pragmatic Works, Inc.
SESSION AGENDASession GoalsViewing The Plan CacheShowplan XML StructureScenarios and DemosWrap Up
SESSION GOALS          Viewing    Showplan    ScenariosSession          The Plan     XML         and       Wrap Up Goals  ...
SESSION GOALS1. Discuss the plan cache2. Explore the plan cache3. Demonstrate methods   to query plan cache4. Demonstrate ...
CONTENT COMPATIBILIT Y SQL Server   2012 SQL Server 2008 (R2) SQL Server   2005
VIEWING THE PLAN                    CACHE          Viewing    Showplan    ScenariosSession          The Plan     XML      ...
PLAN CACHEPortion of SQL Server memory that stores execution plansthat have been prepared by the Query Optimizer. Executio...
PLAN CACHEPortion of SQL Server memory that stores execution plansthat have been prepared by the Query Optimizer. Executio...
PLAN CACHE  sys.dm_exec_cached_plans• All Plans• Size• Use count  sys.dm_exec_query_plan   (plan_handle)• Table Valued F...
PLAN HANDLE0x06000F001CF36A2640C1318A… Varbinary(64) Hash value Identifies plan
WHERE IN THE WORLD IS PLAN_HANDLE?sys.dm_exec_requests  Current connection  Vaguely similar to sp_whosys.dm_exec_query...
SHOWPLAN XML                  STRUCTURE          Viewing    Showplan    ScenariosSession          The Plan     XML        ...
GETTING STARTED      DBA-409-S
GETTING STARTED      DBA-409-S
GETTING STARTED      DBA-409-S
GETTING STARTED      DBA-409-S
EXECUTION PLAN      DBA-409-S
SHOWPLAN XML STRUCTURE          DBA-409-S
SHOWPLAN XML STRUCTUREWhat is in it?  ShowPlanXML    BatchSequence      Batch       Statements         StmtSimple        ...
GOING BELOW STMTSIMPLEMissing          Parameter      Warnings          RelOpIndexes          List           •Plan Affecti...
CAUTION      Volatile   Cache       Data      In Use       Use         Be      Xquery     Mindful
XQUERY FUNCTIONS• Forward slashes   / means to find the specific location   // means find any from the current location•...
SCENARIOS AND DEMOS           Viewing    Showplan    Scenarios Session           The Plan     XML         and       Wrap U...
MISSING INDEXESWhat plans would benefit from indexes?  DMVs    sys.dm_db_missing_index_columns    sys.dm_db_missing_in...
MISSING INDEXESWhat plans would benefit from indexes?  DMVs    sys.dm_db_missing_index_columns    sys.dm_db_missing_in...
MISSING INDEXES   Demo 1
CONVERSION WARNINGSData types matter?       Here lies your  varchar vs. nvarchar    transaction  scan vs. seekWhat pla...
OTHER WARNINGSColumns         Unmatched      Spill to with no         Indexes      Tempdb*Statistics
IMPLICIT CONVERSIONS   Demo 2 AND OTHER WARNINGS
POOR PARAMETER SNIFFINGThink about the plans you find example…   What has changed in the    environments?   Is the plan...
PARAMETER    Demo 3  SNIFFING
STATEMENT INFORMATIONWhat’s the parallelism trigger?• Parallelism is cost based• Query cost default 5
QUERY TREE ESTIMATESWhat does SQL Server expect?• CPU• IO• Rows• Cost
QUERY PROPERTIES   Demo 3
LET’S GET PHYSICAL
PHYSICAL OPERATIONS   Demo 5
INDEX OPERATIONS Access Methods:Full Scans/sec
INDEX OPERATIONS Access Methods:Full Scans/sec
INDEX OPERATIONSWhat about large tables?   Scans?    Good?    Bad?What do you do when yousee large counts of scanson a...
INDEX OPERATIONSWhat plans are using that index?  Should you drop it?  What is the potential effect?                   ...
INDEX OPERATIONS   Demo 5
KEY LOOKUPFind value in one indexLook up more columns in clustered index
DEEPER FOR INCLUDED INDEXESYou found them…     NOW fix them…The information is in the plan!• Investigate the nodes• Pull i...
KEY LOOKUPS &   Demo 4INCLUDED COLUMNS
WRAP UP          Viewing    Showplan    ScenariosSession          The Plan     XML         and       Wrap Up Goals        ...
FIND YOUR OWN TREASURE http://schemas.microsoft.com/sqlserver  /2004/07/showplan/showplanxml.xsd
SUMMARY1. Plan Cache IS your   performance work load2. Information is readily   available3. Techniques to access   not as ...
SQL SERVER MVP DEEP DIVES, VOLUME 2                  www.operationsmile.org                  www.manning.com/delaney
RESOURCESJason      e: jstrate@pragmaticworks.comStrate           e: jasonstrate@gmail.com           b: www.jasonstrate.co...
Upcoming SlideShare
Loading in...5
×

Discovering the Plan Cache (#SQLSat 206)

355

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
355
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Discovering the Plan Cache (#SQLSat 206)"

  1. 1. DISCOVERING Jason Strate Database ArchitectTHE PLAN CACHE Pragmatic Works, Inc.
  2. 2. SESSION AGENDASession GoalsViewing The Plan CacheShowplan XML StructureScenarios and DemosWrap Up
  3. 3. SESSION GOALS Viewing Showplan ScenariosSession The Plan XML and Wrap Up Goals Cache Structure Demos
  4. 4. SESSION GOALS1. Discuss the plan cache2. Explore the plan cache3. Demonstrate methods to query plan cache4. Demonstrate performance tuning concepts
  5. 5. CONTENT COMPATIBILIT Y SQL Server 2012 SQL Server 2008 (R2) SQL Server 2005
  6. 6. VIEWING THE PLAN CACHE Viewing Showplan ScenariosSession The Plan XML and Wrap Up Goals Cache Structure Demos
  7. 7. PLAN CACHEPortion of SQL Server memory that stores execution plansthat have been prepared by the Query Optimizer. Executionplans are used to by SQL Server to execute SQL statements.
  8. 8. PLAN CACHEPortion of SQL Server memory that stores execution plansthat have been prepared by the Query Optimizer. Executionplans 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. 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
  10. 10. PLAN HANDLE0x06000F001CF36A2640C1318A… Varbinary(64) Hash value Identifies plan
  11. 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. 12. SHOWPLAN XML STRUCTURE Viewing Showplan ScenariosSession The Plan XML and Wrap Up Goals Cache Structure Demos
  13. 13. GETTING STARTED DBA-409-S
  14. 14. GETTING STARTED DBA-409-S
  15. 15. GETTING STARTED DBA-409-S
  16. 16. GETTING STARTED DBA-409-S
  17. 17. EXECUTION PLAN DBA-409-S
  18. 18. SHOWPLAN XML STRUCTURE DBA-409-S
  19. 19. SHOWPLAN XML STRUCTUREWhat is in it? ShowPlanXML BatchSequence Batch Statements StmtSimple http://www.flickr.com/photos/etringita/854298772/
  20. 20. GOING BELOW STMTSIMPLEMissing Parameter Warnings RelOpIndexes 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. 21. CAUTION Volatile Cache Data In Use Use Be Xquery Mindful
  22. 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. 23. SCENARIOS AND DEMOS Viewing Showplan Scenarios Session The Plan XML and Wrap Up Goals Cache Structure Demos
  24. 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. 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/
  26. 26. MISSING INDEXES Demo 1
  27. 27. CONVERSION WARNINGSData types matter? Here lies your  varchar vs. nvarchar transaction  scan vs. seekWhat plans have this issue?
  28. 28. OTHER WARNINGSColumns Unmatched Spill to with no Indexes Tempdb*Statistics
  29. 29. IMPLICIT CONVERSIONS Demo 2 AND OTHER WARNINGS
  30. 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 theplan using?
  31. 31. PARAMETER Demo 3 SNIFFING
  32. 32. STATEMENT INFORMATIONWhat’s the parallelism trigger?• Parallelism is cost based• Query cost default 5
  33. 33. QUERY TREE ESTIMATESWhat does SQL Server expect?• CPU• IO• Rows• Cost
  34. 34. QUERY PROPERTIES Demo 3
  35. 35. LET’S GET PHYSICAL
  36. 36. PHYSICAL OPERATIONS Demo 5
  37. 37. INDEX OPERATIONS Access Methods:Full Scans/sec
  38. 38. INDEX OPERATIONS Access Methods:Full Scans/sec
  39. 39. INDEX OPERATIONSWhat about large tables?  Scans?  Good?  Bad?What do you do when yousee large counts of scanson an index?
  40. 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/
  41. 41. INDEX OPERATIONS Demo 5
  42. 42. KEY LOOKUPFind value in one indexLook up more columns in clustered index
  43. 43. DEEPER FOR INCLUDED INDEXESYou found them… NOW fix them…The information is in the plan!• Investigate the nodes• Pull in the data!
  44. 44. KEY LOOKUPS & Demo 4INCLUDED COLUMNS
  45. 45. WRAP UP Viewing Showplan ScenariosSession The Plan XML and Wrap Up Goals Cache Structure Demos
  46. 46. FIND YOUR OWN TREASURE http://schemas.microsoft.com/sqlserver  /2004/07/showplan/showplanxml.xsd
  47. 47. SUMMARY1. Plan Cache IS your performance work load2. Information is readily available3. Techniques to access not as complex as appearances4. Scale your performance knowledge across the environment
  48. 48. SQL SERVER MVP DEEP DIVES, VOLUME 2  www.operationsmile.org  www.manning.com/delaney
  49. 49. RESOURCESJason e: jstrate@pragmaticworks.comStrate e: jasonstrate@gmail.com b: www.jasonstrate.com t: StrateSQLResources jasonstrate.com/go/Cache2013
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×