Digging Deeper Into the Procedure Cache - vConferenceOnline.com

5 downloads 203 Views 4MB Size Report
Procedure Cache. Microsoft SQL Server 2005/2008 ... Working with SQL Server since 1997 .... Pinal Dave (@pinaldave) - http://blog.sqlauthority.com/ ...
Digging Deeper Into the Procedure Cache Microsoft SQL Server 2005/2008

Who Am I? Jason Strate – SQL Server MVP – Enterprise Consultant with Digineer – Working with SQL Server since 1997

[email protected] – www.jasonstrate.com – twitter.com/StrateSQL

Session Agenda Session Goals

Session Refresher Showplan XML Structure Scenarios and Demos Wrap Up

Session Agenda Session Goals

Session Refresher Showplan XML Structure Scenarios and Demos Wrap Up

Session Goals 1. Discuss information available in an procedure cache 2. Demonstrate use of XQuery to query execution cache 3. Demonstrate methods to performance tune

Session Agenda Session Goals

Session Refresher Showplan XML Structure Scenarios and Demos Wrap Up

Last Time… • Cats were loving Dogs • Wal-Mart was setting fashion trends • Zombies stopped eating brains • DBAs were excited about XML

http://www.flickr.com/photos/evil_cheese_scientist/4670299206/sizes/m/in/photostream/

DMV Refresher • sys.dm_exec_query_plan(plan_handle) – Returns the Showplan in XML

• sys.dm_exec_cached_plans – Distinct list of plans – Stats on cached plans

• sys.dm_exec_query_stats – Stats on executed queries

• sys.dm_exec_requests – Stats on current connections

XML Refresher • Namespace – Defines XML of execution plan

• Nodes – Section of XML document

• Values – XML data into a column value

• Exists – Are there nodes/values like this?

• Query – Display XML fragment http://www.flickr.com/photos/doctabu/1429221641/

Queries From Last Time • • • • • • •

Plans for a stored procedure Plans that use Parallelism List SQL Statements for a Plan Parameters for a plan Plans using an index Plans improved with an index Plans with Implicit Conversion

Session Agenda Session Goals

Session Refresher Showplan XML Structure Scenarios and Demos Wrap Up

Showplan XML Structure You found the plan… • What is in it? ShowPlanXML BatchSequence Batch

Statements StmtSimple http://www.flickr.com/photos/etringita/854298772/

Going Below StmtSimple Type

Missing Indexes Parameter List RelOp Unmatched Indexes

• Query Plan • UDF • StoredProc

• Indexes that would improve plan performance

• Parameters passed into query

• EstimateRows, EstimateIO, PhysicalOp, • Hash, IndexScan, NestedLoops • OutputList

• Might be interesting

More Than StmtSimple • StmtUseDb – When database is changed

• StmtCond – When conditional logic is used

• StmtCursor – When CURSORs are used

• StmtReceive – When CURSORs are used

Session Agenda Session Goals

Session Refresher Showplan XML Structure Scenarios and Demos Wrap Up

Query Properties What queries have executed with… • ANSI_NULLS • QUOTED_IDENTIFIER

Statement Information What’s the parallelism trigger? • Parallelism is cost based • Query cost default 5

Query Tree Estimates What does SQL Server expect? • IO • CPU • Rows • Cost

Demo

PROPERTIES AND COSTS

Key Lookup • Find value in one index • Look up more columns in clustered index

Deeper For Included Indexes You found them… NOW fix them… The information is in the plan! • Investigate the nodes • Pull in the data!

Demo

BOOKMARK & INCLUDED COLUMNS

SCOPE_IDENTITY() The Problem • Multiple processors • Unexpected results Solution • Use OUTPUT clause

Scoping the Cache What’s the update strategy? • Large database platform • Many databases • Many, many more procedures Where is 80/80 reward?

Demo

SCOPE IDENTITY

Let’s Get Physical

Index Scans • What about large tables? – Scans? • Good? • Bad?

What do you do when you see large counts of scans on an index?

Demo

MORE OPERATIONS

Session Agenda Session Goals

Session Refresher Showplan XML Structure Scenarios and Demos Wrap Up

Keep On Shoveling http://schemas.microsoft.com/sqlserver/200 4/07/showplan/showplanxml.xsd

Execution Plans Find out more about execution plans… Download for FREE • http://www.sqlserver central.com/articles/ books/65831/

Resources • Troubleshooting Performance Problems in SQL Server 2008 - http://msdn.microsoft.com/enus/library/dd672789.aspx • Jonathan Kehayias (@SQLSarg) sqlblog.com/blogs/jonathan_kehayias • Grant Fritchey (@GFritchey) - scarydba.wordpress.com/ • Michelle Ufford (@SQLFool) – sqlfool.com • Jason Strate (@StrateSQL) – jasonstrate.com • Pinal Dave (@pinaldave) - http://blog.sqlauthority.com/

Questions?

Thank you!

Using XML to Query Execution Plans Microsoft SQL Server 2005/2008