Watch the companion webinar at:
Join John Sterrett, Senior Advisor at Linchpin People and Scott Walz, Director of Software Consultants, to learn how execution plans get invalidated and why data skew could be the root cause to seeing different execution plans for the same query. We will look at options for forcing a query to use a particular execution plan. Finally, you will learn how this complex problem can be identified and resolved simply using a new feature in SQL Server 2016 called Query Store.
3. Life of an Execution Plan
Execute T-SQL
Does A Execution
Plan Exist?
Use The Execution Plan
in Cache
Yes, It Exists
Build Execution Plan
with Variables Used at
Runtime
No, Plan Doesn t Exist
Put Execution Plan in
Cache
11/12/2015 www.linchpinpeople.com 3
4. How Do I Detect Plan Recompile?
• Profiler
• Extended Events
• Dynamic Management Views (DMVs)
• Query Store (SQL Server 2016)
• TechNet – Execution Plan Caching and Reuse
11/12/2015 www.linchpinpeople.com 4
5. Reasons for Execution Plan Recompiles
• Changes made to a table or view referenced by the query (ALTER TABLE and ALTER VIEW).
• Changes made to a single procedure, which would drop all plans for that procedure from the
cache (ALTER PROCEDURE).
• Changes to any indexes used by the execution plan.
• Updates on statistics used by the execution plan, generated either explicitly from a statement,
such as UPDATE STATISTICS, or generated automatically.
• Dropping an index used by the execution plan.
• An explicit call to sp_recompile.
• Large numbers of changes to keys (generated by INSERT or DELETE statements from other users
that modify a table referenced by the query).
• For tables with triggers, if the number of rows in the inserted or deleted tables grows
significantly.
• Executing a stored procedure using the WITH RECOMPILE option.
11/12/2015 www.linchpinpeople.com 5
6. DEMO!
• Capture Execution Plan information
• Identify Queries with Changing Plans
• Learn how to freeze a plan with Plan Guides
11/12/2015 www.linchpinpeople.com 6
7. References
• Plan Guides (plan freezing) in SQL Server 2005/2008
• Plan Guides on Books Online
• Execution Plan Caching and Reuse
10. DEMO!
• Query Store in SQL Server 2016
• Find Top Offenders
• Identify Changing Execution Plans
• Easily Freeze an Execution Plan
• Internal DMVs
10
11. References
• Plan Guides (plan freezing) in SQL Server 2005/2008
• Plan Guides on Books Online
• Execution Plan Caching and Reuse
• Monitor Performance With Query Store (SQL 2016)