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
If a parent proc has children in the list, only call it for the statements, not the parent. Added prompt context for AI to focus it on the specific statements. Working on #3669.
Copy file name to clipboardExpand all lines: sp_BlitzCache.sql
+33-5Lines changed: 33 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -5111,7 +5111,7 @@ BEGIN
5111
5111
RAISERROR('Building AI prompts for query plans', 0, 1) WITHNOWAIT;
5112
5112
5113
5113
/* Update ai_prompt column with query metrics for rows that have query plans */
5114
-
UPDATE##BlitzCacheProcs
5114
+
UPDATEp
5115
5115
SET ai_prompt = N'Here are the performance metrics we are seeing in production, as measured by the plan cache:
5116
5116
5117
5117
Database: '+ISNULL(DatabaseName, N'Unknown') + N'
@@ -5172,16 +5172,45 @@ Here are the warnings that popular query analysis tool sp_BlitzCache detected an
5172
5172
Query Text (which is cut off for long queries):
5173
5173
'+ISNULL(LEFT(QueryText, 4000), N'N/A') + N'
5174
5174
5175
+
'+CASEWHEN QueryType LIKEN'Statement (parent%'THENN' The above query is part of a batch, stored procedure, or function, so other queries may show up in the query plan. However, those other queries are irrelevant here. Focus on this specific query above, because it is one of the most resource-intensive queries in the batch. The execution plan below includes other statements in the batch, but ignore those and focus only the query above and its specific plan in the batch below. 'ELSEN' 'END+ N'
5176
+
5175
5177
XML Execution Plan:
5176
5178
'+ISNULL(CAST(QueryPlan ASNVARCHAR(MAX)), N'N/A') + N'
5177
5179
5178
5180
Thank you.'
5179
-
WHERE SPID =@@SPID
5180
-
AND QueryPlan ISNOTNULL
5181
+
FROM ##BlitzCacheProcs p
5182
+
WHEREp.SPID=@@SPID
5183
+
ANDp.QueryPlanISNOTNULL
5184
+
ANDNOT (p.QueryTypeLIKE'Procedure or Function:%'/* This and the below exists query makes sure that we don't get advice for parent procs, only their statements, if the statements are in our result set. */
5185
+
ANDEXISTS
5186
+
(
5187
+
SELECT1
5188
+
FROM ##BlitzCacheProcs AS S
5189
+
WHERE
5190
+
S.SPID=p.SPID
5191
+
ANDS.DatabaseName=p.DatabaseName
5192
+
ANDS.PlanHandle=p.PlanHandle
5193
+
ANDS.QueryTypeLIKE'Statement (parent %'
5194
+
AND
5195
+
/* Procedure name from "Procedure or Function: [dbo].[usp_X]" */
5196
+
LTRIM(RTRIM(SUBSTRING(
5197
+
p.QueryType,
5198
+
CHARINDEX(':', p.QueryType) +1,
5199
+
8000
5200
+
))) =
5201
+
/* Procedure name from "Statement (parent [dbo].[usp_X])" */
0 commit comments