You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sp_BlitzCache: return oversized plans inline instead of manual query fallback
Fixes#3868 — when a plan exceeds 128 levels of XML nesting, populate
the QueryPlan column with the text plan wrapped in an XML processing
instruction (same technique as sp_QuickieStore) instead of leaving it
NULL and telling the user to run dm_exec_text_query_plan manually.
Also uses StatementStartOffset/StatementEndOffset for statement-level
plan retrieval, and separates truly missing plans into their own UPDATE.
Tested on SQL2016, SQL2017, SQL2019, SQL2022, SQL2025.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
SET Warnings =ISNULL('Your query plan is >128 levels of nested nodes, and can''t be converted to XML. Use SELECT * FROM sys.dm_exec_text_query_plan('+CONVERT(VARCHAR(128), ph.PlanHandle, 1) +', 0, -1) to get more information'
5093
-
, 'We couldn''t find a plan for this query. More info on possible reasons: https://www.brentozar.com/go/noplans')
5094
-
FROM ##BlitzCacheProcs b
5095
-
LEFT JOIN plan_handle ph ON
5096
-
b.PlanHandle=ph.PlanHandle
5080
+
/* Populate oversized plans as processing instructions so they're clickable in SSMS */
5081
+
RAISERROR('Checking for plans with >128 levels of nesting', 0, 1) WITHNOWAIT;
5082
+
UPDATE
5083
+
b
5084
+
SET
5085
+
b.QueryPlan=
5086
+
(
5087
+
SELECT
5088
+
[processing-instruction(query_plan)] =
5089
+
N'-- '+NCHAR(13) +NCHAR(10) +
5090
+
N'-- This is a huge query plan.'+NCHAR(13) +NCHAR(10) +
5091
+
N'-- Remove the headers and footers, save it as a .sqlplan file, and re-open it.'+NCHAR(13) +NCHAR(10) +
b.Warnings='This is a huge query plan (>128 levels of nesting). Click the plan link, remove the headers and footers, and save it as a .sqlplan file to view it.'
5101
+
FROM ##BlitzCacheProcs AS b
5102
+
CROSSAPPLYsys.dm_exec_text_query_plan(b.PlanHandle, b.StatementStartOffset, b.StatementEndOffset) AS tqp
5103
+
CROSSAPPLYsys.dm_exec_query_plan(b.PlanHandle) AS qp
0 commit comments