Gail Shaw XpertEase DAT 305 Topics Background Information Query Hints Plan Cache Metadata Plan Guides Plan Freezing Monitoring Plan Guide Use.

Slides:



Advertisements
Similar presentations
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Advertisements

© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Shyam Pather Development Manager Microsoft Session Code: DTL402.
MIX 09 4/15/ :14 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Gavin Russell-Rockliff BI Technical Specialist Microsoft BIN305.
Windows 7 Training Microsoft Confidential. Windows ® 7 Compatibility Version Checking.
4/19/2017 7:23 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Session 1.
Built by Developers for Developers…. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Marcius Tribelhorn Premier Field Engineer Microsoft South Africa WCL401.
Marcius Tribelhorn Premier Field Engineer Microsoft South Africa WCL307.
Feature: Customer Combiner and Modifier © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
Tony Whitter Principal, Whitter Technology WMB401 Author Jeff Neafsey Mobility Architect Microsoft.

Siddharth Bhatia Senior Program Manager Microsoft Session Code: DTL301.
demo © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
demo Demo.
demo QueryForeign KeyInstance /sm:body()/x:Order/x:Delivery/y:TrackingId1Z
projekt202 © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Thavash Govender Senior BI Consultant iSolve Business Solutions BIN307.
Donald Farmer Microsoft Corporation BIN308.
Pieter Hancke Senior Consultant Microsoft Consulting Services Session Code: WCL303.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks.
Alyson Powell Erwin Sr. Program Manager Microsoft BIN307.
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
Arend-Jan Speksnijder Solutions Architect Microsoft Dynamics Lighthouse team Dynamics AX2009 Technical Overview and Demo (DYN301)
Dawie Human Infrastructure Architect Inobits Consulting VIR202.
Gavin Russell-Rockliff BI Technical Specialist Microsoft BIN202.
Tim Rains Group Product Manager Microsoft Session Code: SIA101.
Sara Ford Program Manager Microsoft Corporation DPR301.
Warren Stevens-Baytopp Director YoungBlood Consultants Session Code BIN303.

OFC308 Hilton Giesenow Development Manager - 3fifteen Host –
Luke Hoban Senior Program Manager Microsoft Session Code: DTL319.
Scott Morrison Program Manager Microsoft Corporation Session Code: WUX308.
Errol Schoenfish Director Product Management Microsoft Session Code: DYN304.
6/2/2018 3:37 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
6/23/2018 8:42 AM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
6/26/2018 9:02 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Tech·Ed North America /31/2018 4:35 PM
Microsoft Ajax Taking Ajax to the Next Level
9/11/2018 5:53 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Tech·Ed North America /14/2018 7:13 PM
Optimizing Microsoft SQL Server 2008 Applications Using Table Valued Parameters, XML, and MERGE
Peeking into the Plan Cache with SQL Server 2008
Sysinternals Tutorials
11/22/2018 8:05 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Jason Zander Unplugged
12/5/2018 3:24 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
12/27/ :01 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Tech·Ed North America /2/2019 4:47 PM
Peter Provost Sr. Program Manager Microsoft Session Code: DEV312
Building Silverlight Apps with RIA Services
Tech Ed North America /12/2019 6:45 AM Required Slide
8/04/2019 9:13 PM © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Windows 8 Security Internals
Виктор Хаджийски Катедра “Металургия на желязото и металолеене”
Tech·Ed North America /25/ :53 PM
Hack-proofing your Clients using Windows 7 Security!
Шитманов Дархан Қаражанұлы Тарих пәнінің
Lap Around the Windows Azure Platform
Code First Development in Microsoft ADO.NET Entity Framework 4.1
5/24/ :22 AM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Presentation transcript:

Gail Shaw XpertEase DAT 305

Topics Background Information Query Hints Plan Cache Metadata Plan Guides Plan Freezing Monitoring Plan Guide Use

Background information Optimal index usage Minimal sorting Appropriate joins What makes a good plan

Three different types of cached plan Procedure Ad-hoc Parameterised SQL tries as much as possible to reuse plans Plan reuse is not always good Many reasons for SQL to chose to recompile It is possible to force a recompile Background information Plan caching basics

Query Hints Hints can be use to override the Query Optimiser In most cases, the optimiser knows best When using hints Use the one that has the smallest effect Test, test, test, test and retest Hints do not reduce compile time Overview

Table hints Index hints Locking hints Join hints Query hints Recompile Optimise for MaxDop Use Plan Query Hints Types of hints

Plan Cache Metadata Four main DMVs Sys.dm_exec_cached_plans Sys.dm_exec_query_stats Sys.dm_exec_sql_text Sys.dm_exec_query_plan

Plan Cache Metadata Aggregate info is stored in sys.dm_exec_query_stats One row per statement in the batch/object Plan handle and sql handle are for entire batch New columns in SQL Server 2008 allow you to find ‘similar’ queries and ‘similar’ plans: query_hash query_plan_hash Plan Details

Example: Retrieve query text -- Retrieve the text of all queries in cache SELECT st.text FROM sys.dm_exec_cached_plans cp INNER JOIN sys.dm_exec_query_stats qs on cp.plan_handle = qs.plan_handle CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) st

Example: Retrieve query plan -- Retrieve the execution plans of all queries in cache SELECT qp.query_plan FROM sys.dm_exec_cached_plans cp INNER JOIN sys.dm_exec_query_stats qs on cp.plan_handle = qs.plan_handle CROSS APPLY sys.dm_exec_query_plan(qs.sql_handle) qp

Examining the plan cache

Plan Guides For when hints are needed, but the query cannot be modified Three types of guide SQL Object Template

Creating a Plan Guide = = N'SELECT * FROM Sales.Customer AS c INNER JOIN Sales.SalesTerritory t ON c.CustomerID = t.CustomerID WHERE = = = = N'OPTION ( OPTIMIZE FOR = N''US'') )'

Plan Guides Apply to individual T-SQL batches and statements Statement must match exactly. Whitespace and case must match SQL plan guides

For SQL statements that are part of T-SQL procedures, functions or triggers Text is parsed and normalised before matching Case for Keywords is not important Whitespace is ignored Plan Guides Object plan guides

Same text matching rules as the Object plan guide Only accepts the parameterisation hint Requires that the statement be a parameterised template Plan Guides Template plan guides

Creating a Template Plan Guide OUTPUT; EXEC = = = = N'OPTION(PARAMETERIZATION FORCED)'

Plan Guides Only query hints can be used in plan guides No table hints No join hints In SQL 2008, most of the table hints can be expressed as query hints The parameterisation hints can only be applied in a plan guide Query hints and plan guides

Creating and Using Plan guides

Plan Guide Metadata sp_create_plan_guide sp_control_plan_guide sys.plan_guides Script plan guide from SSMS (new in 2008)

Plan freezing New in SQL 2008 The ability to create a plan guide from an existing plan in cache

Plan Freezing SELECT City, StateProvinceID, PostalCode FROM Person.Address WHERE … ; SELECT plan_handle FROM sys.dm_exec_query_stats AS qs CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st WHERE st.text LIKE N'SELECT City,%' EXEC = = 0x F19B1E1FC0A14C0A

Freezing a plan

Monitoring Plan Guides SHOWPLAN_XML Validation Function Tracing Successful and Unsuccessful Plan Guide Use events Captured at Compile Time PerfMon Successful and Unsuccessful Plan Guide Use events Captured at Execution Time Tools

sys.fn_validate_plan_guide(Plan_guide_id) The statement or object associated with the plan is compiled with the plan hint If there are any errors, a resultset is returned with message and severity Monitoring Plan Guides Validation

Monitoring Plan Guides Profiler

Monitoring Plan Guides Performance Monitor

Validating and monitoring plan guides

Best Practices Let the optimizer do its job If the optimizer can’t find a good plan, try to figure out why not Use the least invasive hint possible Least invasive: RECOMPILE Most invasive: USE PLAN Consider implementing all hints through plan guides So they can be switched off and on as needed…

International Content & Community Resources for IT Professionals Resources for Developers Microsoft Certification & Training Resources Resources Required Slide Speakers, TechEd 2009 is not producing a DVD. Please announce that attendees can access session recordings from Tech-Ed website. These will only be available after the event. Required Slide Speakers, TechEd 2009 is not producing a DVD. Please announce that attendees can access session recordings from Tech-Ed website. These will only be available after the event. Tech ·Ed Africa 2009 sessions will be made available for download the week after the event from:

Related Content Microsoft SQL Server 2008: Performance Profiling and Troubleshooting with Extended Events (DAT401) Required Slide Speakers, please list the Breakout Sessions, TLC Interactive Theaters and Labs that are related to your session. Any queries, please check with your Track Owner. Required Slide Speakers, please list the Breakout Sessions, TLC Interactive Theaters and Labs that are related to your session. Any queries, please check with your Track Owner.

Track Resources Blog series on Execution Plans: "SQL Server Execution plans" by Grant Fritchey: “SQL Server 2008 Query Performance Tuning Distilled” by Grant Fritchey and Sajal Dam Required Slide Track Owners to provide guidance. Please address any queries to your track owners. Required Slide Track Owners to provide guidance. Please address any queries to your track owners.

South African SQL Server Usergroup Meet monthly, 3 rd Tuesday evening at Microsoft’s Offices in Bryanston Current leads: Paul Filmalter and Gail Shaw

Required Slide Complete a session evaluation and enter to win! 10 pairs of MP3 sunglasses to be won

© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. Required Slide