@JohnSterrett
Troubleshooting Plan Changes with
Query Store in SQL Server 2016
www.linchpinpeople.com 2
John Sterrett
@johnsterrett
John.Sterrett@linchpinpeople.com
Johnsterrett.com
linked.com/in/johnsterrett
google.com/+johnsterrett
Specialties / Focus Areas / Passions:
• Performance Tuning &
Troubleshooting
• Virtualization
• Infrastructure
• Architecture
• High Availability
• Disaster Recovery
• Health Monitoring
• Capacity Management
• License Efficiency
Linchpin People Group Principle
Leader Austin SQL
Server User Group
Leader Virtual Chapter
“High Availability and
Disaster Recovery”
PASS Regional Mentor
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
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
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
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
References
• Plan Guides (plan freezing) in SQL Server 2005/2008
• Plan Guides on Books Online
• Execution Plan Caching and Reuse
The SQL Server 2016 Solution….
8
Query Store!
9
DEMO!
• Query Store in SQL Server 2016
• Find Top Offenders
• Identify Changing Execution Plans
• Easily Freeze an Execution Plan
• Internal DMVs
10
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)

Troubleshooting Plan Changes with Query Store in SQL Server 2016

  • 1.
    @JohnSterrett Troubleshooting Plan Changeswith Query Store in SQL Server 2016
  • 2.
    www.linchpinpeople.com 2 John Sterrett @johnsterrett John.Sterrett@linchpinpeople.com Johnsterrett.com linked.com/in/johnsterrett google.com/+johnsterrett Specialties/ Focus Areas / Passions: • Performance Tuning & Troubleshooting • Virtualization • Infrastructure • Architecture • High Availability • Disaster Recovery • Health Monitoring • Capacity Management • License Efficiency Linchpin People Group Principle Leader Austin SQL Server User Group Leader Virtual Chapter “High Availability and Disaster Recovery” PASS Regional Mentor
  • 3.
    Life of anExecution 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 IDetect 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 ExecutionPlan 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 ExecutionPlan 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
  • 8.
    The SQL Server2016 Solution…. 8
  • 9.
  • 10.
    DEMO! • Query Storein 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)