From 9d03cc9a0b2200b3fe51acca041c627de12a7665 Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Mon, 6 Apr 2026 08:12:48 -0400 Subject: [PATCH] sp_QuickieCache: add CPU tie-breaker to duplicate plans sort order Within the same plan_count, sort by total_worker_time DESC so the most expensive query hash surfaces first. Co-Authored-By: Claude Opus 4.6 (1M context) --- sp_QuickieCache/sp_QuickieCache.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sp_QuickieCache/sp_QuickieCache.sql b/sp_QuickieCache/sp_QuickieCache.sql index 9335bd95..490f3042 100644 --- a/sp_QuickieCache/sp_QuickieCache.sql +++ b/sp_QuickieCache/sp_QuickieCache.sql @@ -498,7 +498,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. HAVING COUNT_BIG(DISTINCT qs.plan_handle) > 1 ORDER BY - COUNT_BIG(DISTINCT qs.plan_handle) DESC + COUNT_BIG(DISTINCT qs.plan_handle) DESC, + SUM(qs.total_worker_time) DESC OPTION(RECOMPILE, MAXDOP 1); RETURN;