• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Discovering the plan cache (sql sat175)
 

Discovering the plan cache (sql sat175)

on

  • 659 views

 

Statistics

Views

Total Views
659
Views on SlideShare
501
Embed Views
158

Actions

Likes
0
Downloads
5
Comments
0

6 Embeds 158

http://www.jasonstrate.com 102
http://sqlserverpedia.com 25
http://feeds.feedburner.com 13
http://www.sqlservercentral.com 9
http://www.newsblur.com 6
http://newsblur.com 3

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Discovering the plan cache (sql sat175) Discovering the plan cache (sql sat175) Presentation Transcript

    • Jason StrateDatabase ArchitectPragmatic Works, Inc.DISCOVERINGTHE PLAN CACHESQL SATURDAY 175FARGO
    • Session GoalsViewing The Plan CacheShowplan XML StructureScenarios and DemosWrap UpSESSION AGENDA
    • SESSION GOALSWrap UpScenariosandDemosShowplanXMLStructureViewingThe PlanCacheSessionGoals
    • 1. Discuss the plan cache2. Explore the plan cache3. Demonstrate methodsto query plan cache4. Demonstrateperformance tuningconceptsSESSION GOALS
    • SQL Server2012SQL Server2008 (R2)SQL Server2005CONTENT COMPATIBILITY
    • VIEWING THE PLANCACHEWrap UpScenariosandDemosShowplanXMLStructureViewingThe PlanCacheSessionGoals
    • 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
    • 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.
    •  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
    • 0x06000F001CF36A2640C1318A…Varbinary(64)Hash valueIdentifies planPLAN 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 plansWHERE IN THE WORLD IS PLAN_HANDLE?http://www.flickr.com/photos/fallentomato/3918329246/
    • SHOWPLAN XMLSTRUCTUREWrap UpScenariosandDemosShowplanXMLStructureViewingThe PlanCacheSessionGoals
    • DBA-409-SGETTING STARTED
    • DBA-409-SGETTING STARTED
    • DBA-409-SGETTING STARTED
    • DBA-409-SGETTING STARTED
    • DBA-409-SEXECUTION PLAN
    • DBA-409-SSHOWPLAN XML STRUCTURE
    • What is in it?SHOWPLAN XML STRUCTUREhttp://www.flickr.com/photos/etringita/854298772/ShowPlanXMLBatchSequenceBatchStatementsStmtSimple
    • GOING BELOW STMTSIMPLEMissingIndexes•Indexes thatwould improveplanperformanceParameterList•Parameterspassed intoqueryWarnings•Plan AffectingConvert•Columns withno Statistics•UnmatchedIndexesRelOp•EstimateRows,EstimateIO,PhysicalOp,•Hash,IndexScan,NestedLoops•OutputList
    • VolatileDataCacheIn UseUseXqueryBeMindfulCAUTION
    • • 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
    • SCENARIOS AND DEMOSWrap UpScenariosandDemosShowplanXMLStructureViewingThe PlanCacheSessionGoals
    • 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
    • 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?
    • Demo 1MISSING INDEXES
    • Data types matter?varchar vs. nvarcharscan vs. seekWhat plans have this issue?CONVERSION WARNINGSHere lies yourtransaction
    • Columnswith noStatisticsUnmatchedIndexesSpill toTempdb*OTHER WARNINGS
    • Demo 2IMPLICIT CONVERSIONSAND OTHER WARNINGS
    • 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
    • Demo 3PARAMETERSNIFFING
    • What’s the parallelism trigger?• Parallelism is cost based• Query cost default 5STATEMENT INFORMATION
    • What does SQL Server expect?• CPU• IO• Rows• CostQUERY TREE ESTIMATES
    • Demo 3QUERY PROPERTIES
    • LET’S GET PHYSICAL
    • Demo 5PHYSICAL OPERATIONS
    •  Access Methods:Full Scans/secINDEX OPERATIONS
    •  Access Methods:Full Scans/secINDEX OPERATIONS
    • What about large tables?Scans? Good? Bad?What do you do when yousee large counts of scanson an index?INDEX OPERATIONS
    • What plans are using that index?Should you drop it?What is the potential effect?INDEX OPERATIONShttp://www.flickr.com/photos/s3a/4436302537/
    • Demo 5INDEX OPERATIONS
    • Find value in one indexLook up more columns in clustered indexKEY LOOKUP
    • You found them…NOW fix them…The information is in the plan!• Investigate the nodes• Pull in the data!DEEPER FOR INCLUDED INDEXES
    • Demo 4KEY LOOKUPS &INCLUDED COLUMNS
    • WRAP UPWrap UpScenariosandDemosShowplanXMLStructureViewingThe PlanCacheSessionGoals
    •  http://schemas.microsoft.com/sqlserver /2004/07/showplan/showplanxml.xsdFIND YOUR OWN TREASURE
    • 1. Plan Cache IS yourperformance work load2. Information is readilyavailable3. Techniques to accessnot as complex asappearances4. Scale your performanceknowledge across theenvironmentSUMMARY
    •  www.operationsmile.org www.manning.com/delaneySQL SERVER MVP DEEP DIVES, VOLUME 2
    • JasonStratee: jstrate@pragmaticworks.come: jasonstrate@gmail.comb: www.jasonstrate.comt: StrateSQLResources jasonstrate.com/go/Cache2013RESOURCES