Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Discovering the plan cache (sql sat175)

1,045 views

Published on

  • Be the first to comment

  • Be the first to like this

Discovering the plan cache (sql sat175)

  1. 1. Jason StrateDatabase ArchitectPragmatic Works, Inc.DISCOVERINGTHE PLAN CACHESQL SATURDAY 175FARGO
  2. 2. Session GoalsViewing The Plan CacheShowplan XML StructureScenarios and DemosWrap UpSESSION AGENDA
  3. 3. SESSION GOALSWrap UpScenariosandDemosShowplanXMLStructureViewingThe PlanCacheSessionGoals
  4. 4. 1. Discuss the plan cache2. Explore the plan cache3. Demonstrate methodsto query plan cache4. Demonstrateperformance tuningconceptsSESSION GOALS
  5. 5. SQL Server2012SQL Server2008 (R2)SQL Server2005CONTENT COMPATIBILITY
  6. 6. VIEWING THE PLANCACHEWrap UpScenariosandDemosShowplanXMLStructureViewingThe PlanCacheSessionGoals
  7. 7. Portion 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.PLAN CACHE
  8. 8. ProsNo setupQuery-ableActionableReal WorldConsReset with serviceActivity flushPlans miss cacheIn UsePLAN 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.
  9. 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 textPLAN CACHE
  10. 10. 0x06000F001CF36A2640C1318A…Varbinary(64)Hash valueIdentifies planPLAN HANDLE
  11. 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 plansWHERE IN THE WORLD IS PLAN_HANDLE?http://www.flickr.com/photos/fallentomato/3918329246/
  12. 12. SHOWPLAN XMLSTRUCTUREWrap UpScenariosandDemosShowplanXMLStructureViewingThe PlanCacheSessionGoals
  13. 13. DBA-409-SGETTING STARTED
  14. 14. DBA-409-SGETTING STARTED
  15. 15. DBA-409-SGETTING STARTED
  16. 16. DBA-409-SGETTING STARTED
  17. 17. DBA-409-SEXECUTION PLAN
  18. 18. DBA-409-SSHOWPLAN XML STRUCTURE
  19. 19. What is in it?SHOWPLAN XML STRUCTUREhttp://www.flickr.com/photos/etringita/854298772/ShowPlanXMLBatchSequenceBatchStatementsStmtSimple
  20. 20. GOING BELOW STMTSIMPLEMissingIndexes•Indexes thatwould improveplanperformanceParameterList•Parameterspassed intoqueryWarnings•Plan AffectingConvert•Columns withno Statistics•UnmatchedIndexesRelOp•EstimateRows,EstimateIO,PhysicalOp,•Hash,IndexScan,NestedLoops•OutputList
  21. 21. VolatileDataCacheIn UseUseXqueryBeMindfulCAUTION
  22. 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 sensitiveXQUERY FUNCTIONS
  23. 23. SCENARIOS AND DEMOSWrap UpScenariosandDemosShowplanXMLStructureViewingThe PlanCacheSessionGoals
  24. 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_groupsDBA-409-SMISSING INDEXES
  25. 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_groupsMISSING INDEXEShttp://www.flickr.com/photos/fallentomato/3918329246/What QueriesShould I Test?
  26. 26. Demo 1MISSING INDEXES
  27. 27. Data types matter?varchar vs. nvarcharscan vs. seekWhat plans have this issue?CONVERSION WARNINGSHere lies yourtransaction
  28. 28. Columnswith noStatisticsUnmatchedIndexesSpill toTempdb*OTHER WARNINGS
  29. 29. Demo 2IMPLICIT CONVERSIONSAND OTHER WARNINGS
  30. 30. Think about the plans youfind example…What has changed in theenvironments?Is the plan using the wrongvalues?What parameters is theplan using?POOR PARAMETER SNIFFING
  31. 31. Demo 3PARAMETERSNIFFING
  32. 32. What’s the parallelism trigger?• Parallelism is cost based• Query cost default 5STATEMENT INFORMATION
  33. 33. What does SQL Server expect?• CPU• IO• Rows• CostQUERY TREE ESTIMATES
  34. 34. Demo 3QUERY PROPERTIES
  35. 35. LET’S GET PHYSICAL
  36. 36. Demo 5PHYSICAL OPERATIONS
  37. 37.  Access Methods:Full Scans/secINDEX OPERATIONS
  38. 38.  Access Methods:Full Scans/secINDEX OPERATIONS
  39. 39. What about large tables?Scans? Good? Bad?What do you do when yousee large counts of scanson an index?INDEX OPERATIONS
  40. 40. What plans are using that index?Should you drop it?What is the potential effect?INDEX OPERATIONShttp://www.flickr.com/photos/s3a/4436302537/
  41. 41. Demo 5INDEX OPERATIONS
  42. 42. Find value in one indexLook up more columns in clustered indexKEY LOOKUP
  43. 43. You found them…NOW fix them…The information is in the plan!• Investigate the nodes• Pull in the data!DEEPER FOR INCLUDED INDEXES
  44. 44. Demo 4KEY LOOKUPS &INCLUDED COLUMNS
  45. 45. WRAP UPWrap UpScenariosandDemosShowplanXMLStructureViewingThe PlanCacheSessionGoals
  46. 46.  http://schemas.microsoft.com/sqlserver /2004/07/showplan/showplanxml.xsdFIND YOUR OWN TREASURE
  47. 47. 1. Plan Cache IS yourperformance work load2. Information is readilyavailable3. Techniques to accessnot as complex asappearances4. Scale your performanceknowledge across theenvironmentSUMMARY
  48. 48.  www.operationsmile.org www.manning.com/delaneySQL SERVER MVP DEEP DIVES, VOLUME 2
  49. 49. JasonStratee: jstrate@pragmaticworks.come: jasonstrate@gmail.comb: www.jasonstrate.comt: StrateSQLResources jasonstrate.com/go/Cache2013RESOURCES

×