<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Deepesh Dhake on Medium]]></title>
        <description><![CDATA[Stories by Deepesh Dhake on Medium]]></description>
        <link>https://medium.com/@deepeshdhake?source=rss-9eaa24f08bc4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Deepesh Dhake on Medium</title>
            <link>https://medium.com/@deepeshdhake?source=rss-9eaa24f08bc4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 20:45:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@deepeshdhake/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Detecting Plan Regression in SQL Server Using Query Store]]></title>
            <link>https://medium.com/@deepeshdhake/detecting-plan-regression-in-sql-server-using-query-store-6cc6cb5103e3?source=rss-9eaa24f08bc4------2</link>
            <guid isPermaLink="false">https://medium.com/p/6cc6cb5103e3</guid>
            <category><![CDATA[sql-server]]></category>
            <category><![CDATA[performance-tuning]]></category>
            <category><![CDATA[performance-monitoring]]></category>
            <category><![CDATA[query-store]]></category>
            <category><![CDATA[regression-analysis]]></category>
            <dc:creator><![CDATA[Deepesh Dhake]]></dc:creator>
            <pubDate>Fri, 08 May 2026 17:16:49 GMT</pubDate>
            <atom:updated>2026-05-12T18:54:10.303Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Weighted Baseline Regression Pattern for Query Store</strong></p><p>Plan regressions in SQL Server often appear without any obvious trigger. A query that was stable suddenly becomes slower even though there were no deployments or schema changes. Query Store usually contains the data needed to identify the issue, but simple average duration comparisons can be misleading because Query Store stores aggregated runtime statistics instead of raw executions.</p><p>This article walks through a practical weighted baseline approach for detecting regressions by comparing recent workload performance against historical execution patterns. It also covers filtering low-volume noise, validating execution plan changes, and identifying regressions tied to new execution plans using Query Store.</p><p><strong>Problem</strong></p><p>A common starting point is comparing “yesterday vs today” using average duration. While quick, this approach often does not reflect the full behavior of the workload</p><p>Query Store data is already summarized. By the time you hit sys.query_store_runtime_stats, SQL Server has grouped executions into time windows.</p><p>So a few things get lost pretty easily:</p><ul><li>a couple of bad executions don’t stand out</li><li>low traffic queries can look more important than they are</li><li>plan changes get mixed with normal variation</li></ul><p>There are cases where average duration appears stable, but individual executions show spikes of 20–30x. You won’t see that unless you dig deeper.</p><p>Another thing — multiple plans doesn’t automatically mean trouble. This is normal behavior in SQL Server. Statistics updates, parameter sniffing, and memory pressure can all introduce plan changes without indicating a regression. The key question is whether performance actually degraded after a plan change.</p><p><strong>Detection Pattern</strong></p><p>The approach is to compare recent performance against a historical baseline, while filtering out low-frequency noise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/248/1*3sc6xWCoCXkoKUN2wlhtZQ.png" /><figcaption><strong>Architecture View</strong></figcaption></figure><p>Start by looking at older data as your baseline:</p><pre>SELECT<br>    q.query_id,<br>    p.plan_id,<br>    SUM(rs.avg_duration * rs.count_executions) * 1.0<br>        / NULLIF(SUM(rs.count_executions), 0) AS baseline_duration<br>FROM sys.query_store_runtime_stats rs<br>JOIN sys.query_store_plan p ON rs.plan_id = p.plan_id<br>JOIN sys.query_store_query q ON p.query_id = q.query_id<br>WHERE rs.last_execution_time &gt;= DATEADD(day, -7, getdate())<br>  AND rs.last_execution_time &lt; DATEADD(day, -1, getdate())<br>GROUP BY q.query_id, p.plan_id;</pre><p>Then compare that with what’s happening now:</p><pre>SELECT<br>    q.query_id,<br>    p.plan_id,<br>    SUM(rs.avg_duration * rs.count_executions) * 1.0<br>        / NULLIF(SUM(rs.count_executions), 0) AS current_duration,<br>    SUM(rs.count_executions) AS exec_count<br>FROM sys.query_store_runtime_stats rs<br>JOIN sys.query_store_plan p ON rs.plan_id = p.plan_id<br>JOIN sys.query_store_query q ON p.query_id = q.query_id<br>WHERE rs.last_execution_time &gt;= DATEADD(day, -1, getdate())<br>GROUP BY q.query_id, p.plan_id;</pre><p>And then just combine the two queries and look for queries that got significantly slower:</p><pre>WITH baseline AS<br>(<br>    SELECT<br>        q.query_id,<br>        p.plan_id,<br>        SUM(rs.avg_duration * rs.count_executions) * 1.0<br>            / NULLIF(SUM(rs.count_executions), 0) AS baseline_duration,<br>        SUM(rs.count_executions) AS baseline_exec_count,<br>        SUM(rs.avg_duration * rs.count_executions) AS baseline_total_duration<br>    FROM sys.query_store_runtime_stats rs<br>    JOIN sys.query_store_plan p<br>        ON rs.plan_id = p.plan_id<br>    JOIN sys.query_store_query q<br>        ON p.query_id = q.query_id<br>    WHERE rs.last_execution_time &gt;= DATEADD(day, -7, getdate())<br>      AND rs.last_execution_time &lt; DATEADD(day, -1, getdate())<br>    GROUP BY q.query_id, p.plan_id<br>),<br>current AS<br>(<br>    SELECT<br>        q.query_id,<br>        p.plan_id,<br>        SUM(rs.avg_duration * rs.count_executions) * 1.0/ NULLIF(SUM(rs.count_executions), 0) AS current_duration,<br>        SUM(rs.count_executions) AS current_exec_count,<br>        SUM(rs.avg_duration * rs.count_executions) AS current_total_duration<br>    FROM sys.query_store_runtime_stats rs<br>    JOIN sys.query_store_plan p<br>        ON rs.plan_id = p.plan_id<br>    JOIN sys.query_store_query q<br>        ON p.query_id = q.query_id<br>    WHERE rs.last_execution_time &gt;= DATEADD(day, -1, getdate())<br>    GROUP BY q.query_id, p.plan_id<br>)<br>SELECT<br>    c.query_id,<br>    c.plan_id,<br>    b.baseline_duration,<br>    c.current_duration,<br>    CAST(<br>        c.current_duration * 1.0 / NULLIF(b.baseline_duration, 0) AS DECIMAL(10,2)<br>    ) AS slowdown_factor,<br>    b.baseline_exec_count,<br>    c.current_exec_count,<br>    b.baseline_total_duration,<br>    c.current_total_duration<br>FROM current c<br>JOIN baseline b<br>    ON c.query_id = b.query_id<br>   AND c.plan_id = b.plan_id<br>WHERE<br>    c.current_duration &gt; b.baseline_duration * 1.5<br>    AND c.current_exec_count &gt; 20<br>    AND c.current_total_duration &gt; 100000<br>ORDER BY slowdown_factor DESC;</pre><p><strong>Check the plans</strong></p><p>Once a query is identified, the next step is to verify whether the execution plan has changed.</p><pre>SELECT<br>    q.query_id,<br>    p.plan_id,<br>    p.last_execution_time<br>FROM sys.query_store_plan p<br>JOIN sys.query_store_query q<br>    ON p.query_id = q.query_id<br>ORDER BY p.last_execution_time DESC;</pre><p>If a new plan appears around the same time the performance degradation began, it is often the root cause.</p><p><strong>Real world example</strong></p><p>I’ve seen this in reporting systems. Query runs fine for weeks, around 150 ms. Statistics update happens, nothing else changes, and suddenly it’s over a second. Same query, just a different plan. Query Store showed a join strategy change and worse estimates.</p><p>Forcing the old plan fixed it immediately. Then we went back and checked why stats pushed the optimizer in that direction.</p><pre>EXEC sp_query_store_force_plan<br>    @query_id = 42,<br>    @plan_id = 10;</pre><p><strong>Conclusion</strong></p><p>You don’t really need a complex setup for this.</p><p>If you understand baseline vs current, and you actually look at execution plans instead of just averages, most regressions are pretty easy to spot.</p><p>Query Store already has everything. The key is to avoid overinterpreting simple averages and focus on meaningful workload changes.</p><p>GitHub Repository: <a href="https://github.com/deepeshd87/Performance-Monitoring-Suite">https://github.com/deepeshd87/Performance-Monitoring-Suite</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cc6cb5103e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>