• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Discovering the Plan Cache (#SQLSat 206)
 

Discovering the Plan Cache (#SQLSat 206)

on

  • 481 views

 

Statistics

Views

Total Views
481
Views on SlideShare
407
Embed Views
74

Actions

Likes
0
Downloads
11
Comments
0

7 Embeds 74

http://www.jasonstrate.com 52
http://sqlserverpedia.com 8
http://feeds.feedburner.com 5
http://newsblur.com 5
http://feeds2.feedburner.com 2
http://www.newsblur.com 1
http://www.sqlservercentral.com 1
More...

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 (#SQLSat 206) Discovering the Plan Cache (#SQLSat 206) Presentation Transcript

    • 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 Cache Structure Demos
    • SESSION GOALS1. Discuss the plan cache2. Explore the plan cache3. Demonstrate methods to query plan cache4. Demonstrate performance tuning concepts
    • CONTENT COMPATIBILIT Y SQL Server 2012 SQL Server 2008 (R2) SQL Server 2005
    • VIEWING THE PLAN CACHE Viewing Showplan ScenariosSession The Plan XML and Wrap Up Goals Cache Structure Demos
    • 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.
    • 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
    • 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
    • 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_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/
    • SHOWPLAN XML STRUCTURE Viewing Showplan ScenariosSession The Plan XML and Wrap Up Goals Cache Structure Demos
    • 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 http://www.flickr.com/photos/etringita/854298772/
    • 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
    • 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• Important Functions • nodes() • value() • exist() • query()• Everything is case sensitive
    • SCENARIOS AND DEMOS Viewing Showplan Scenarios Session The Plan XML and Wrap Up Goals Cache Structure Demos
    • 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
    • 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/
    • MISSING INDEXES Demo 1
    • CONVERSION WARNINGSData types matter? Here lies your  varchar vs. nvarchar transaction  scan vs. seekWhat plans have this issue?
    • 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 using the wrong values?What parameters is theplan using?
    • 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 an index?
    • INDEX OPERATIONSWhat plans are using that index?  Should you drop it?  What is the potential effect? http://www.flickr.com/photos/s3a/4436302537/
    • 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 in the data!
    • KEY LOOKUPS & Demo 4INCLUDED COLUMNS
    • WRAP UP Viewing Showplan ScenariosSession The Plan XML and Wrap Up Goals Cache Structure Demos
    • 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 complex as appearances4. Scale your performance knowledge across the environment
    • 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.com t: StrateSQLResources jasonstrate.com/go/Cache2013