<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Force Last Good Plan on SQL Server Scripts</title><link>https://www.sqlserver70.com/tags/force-last-good-plan/</link><description>Recent content in Force Last Good Plan on SQL Server Scripts</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>SQLServer70.com</copyright><lastBuildDate>Sun, 08 Nov 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://www.sqlserver70.com/tags/force-last-good-plan/index.xml" rel="self" type="application/rss+xml"/><item><title>Log Forced Plans That Automatic Tuning Reverts with XEvents</title><link>https://www.sqlserver70.com/post/log-forced-plans-that-automatic-tuning-reverts-with-xevents/</link><pubDate>Sun, 08 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/log-forced-plans-that-automatic-tuning-reverts-with-xevents/</guid><description>
&lt;p&gt;When a query regresses, automatic plan correction forces the last known good plan and then keeps checking it. The script below creates an Extended Events session that writes each check ending in an unforced plan to an XEL file on disk, one event per reverted correction.&lt;/p&gt;
&lt;script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1012089347386563"
crossorigin="anonymous"&gt;&lt;/script&gt;
&lt;ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1012089347386563"
data-ad-slot="8593449130"&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&gt;
&lt;p&gt;A plan that automatic plan correction (APC) forces is not a final decision. After forcing a plan, automatic tuning &lt;a href="https://learn.microsoft.com/en-us/archive/blogs/sqlserverstorageengine/monitoring-automatic-tuning-actions-using-xevents"&gt;keeps monitoring the forced plan and verifies that its performance does not degrade&lt;/a&gt;. APC forces a recommendation on its own when &lt;a href="https://learn.microsoft.com/en-us/sql/relational-databases/automatic-tuning/automatic-tuning?view=sql-server-ver17"&gt;the estimated CPU gain is higher than 10 seconds, or the new plan has more errors than the recommended plan&lt;/a&gt;. If the forced plan is not better than the regressed plan, the Database Engine unforces it and compiles a new plan.&lt;/p&gt;</description></item></channel></rss>