Skip to content

Commit 9781676

Browse files
committed
#3670 sp_BlitzIndex AI prompt honing
More honing of the prompt. Working on #3670.
1 parent bcbc45e commit 9781676

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

sp_BlitzIndex.sql

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,9 +1115,13 @@ IF @AI > 0
11151115

11161116
IF @AISystemPrompt IS NULL OR @AISystemPrompt = N''
11171117
BEGIN
1118-
SET @AISystemPrompt = N'You are a very senior database developer working with Microsoft SQL Server and Azure SQL DB. You focus on real-world, actionable advice that will make a big difference, quickly. You value everyone''s time, and while you are friendly and courteous, you do not waste time with pleasantries or emoji because you work in a fast-paced corporate environment.
1118+
SET @AISystemPrompt = N'You are a very senior database developer working with Microsoft SQL Server and Azure SQL DB. You focus on real-world, actionable advice that will make a big difference, quickly. You value everyone''s time, and while you are friendly and courteous, you do not waste time with pleasantries or emoji because you work in a fast-paced corporate environment. Do not describe the table: you are working with other very senior database developers who understand SQL Server deeply, so get straight to the point with your recommendations and scripts.
11191119
1120-
You have been given the existing indexes, missing index suggestions from SQL Server, column data types, and foreign keys for a table. Your job is to recommend index changes: which indexes to add, which to remove as redundant or harmful, and which to modify. Focus on practical changes that will improve the most common query patterns shown by the usage statistics. If indexes can be dropped or merged together with minimal impact to performance, suggest that. Include CREATE INDEX and DROP INDEX scripts where appropriate. Include undo scripts in comments to back out your work if something goes wrong.
1120+
You have been given the existing indexes, missing index suggestions from SQL Server, column data types, and foreign keys for a table. Your job is to recommend index changes: which indexes to add, which to remove as redundant or harmful, and which to modify. Focus on practical changes that will improve the most common query patterns shown by the usage statistics.
1121+
1122+
If indexes are not being used, drop them. If duplicate or near-duplicate indexes exist, merge them together or keep the widest ones. Existing indexes that start with different leading columns should not be considered duplicates.
1123+
1124+
Include CREATE INDEX and DROP INDEX scripts. Include undo scripts in comments to back out your work if something goes wrong. Use the /* */ style for comments, not --, to make it easier for the customer to copy and paste your scripts without accidentally missing a line.
11211125
11221126
When working with missing index suggestions from SQL Server, keep in mind that they are ordered equality vs inequality search in the query, then by the column order of the table. The column order is nowhere near scientific, and can be rearranged if necessary for performance.
11231127
@@ -3790,22 +3794,25 @@ BEGIN
37903794

37913795
RAISERROR(N'Returning AI results', 0, 1) WITH NOWAIT;
37923796

3793-
/* Return the AI prompt (always when @AI >= 1) */
3794-
SELECT [AI Prompt] = (
3795-
SELECT (@AISystemPrompt + NCHAR(13) + NCHAR(10) + NCHAR(13) + NCHAR(10) + @CurrentAIPrompt)
3796-
AS [text()] FOR XML PATH('ai_prompt'), TYPE);
3797-
37983797
/* Return advice, payload, and raw response when @AI = 1 */
37993798
IF @AI = 1
38003799
BEGIN
38013800
SELECT
38023801
[AI Advice] = CASE WHEN @AIAdviceText IS NULL THEN NULL ELSE (
38033802
SELECT @AIAdviceText AS [text()] FOR XML PATH('ai_advice'), TYPE) END,
3803+
[AI Prompt] = (SELECT (@AISystemPrompt + NCHAR(13) + NCHAR(10) + NCHAR(13) + NCHAR(10) + @CurrentAIPrompt)
3804+
AS [text()] FOR XML PATH('ai_prompt'), TYPE),
38043805
[AI Payload] = CASE WHEN @AIPayload IS NULL THEN NULL ELSE (
38053806
SELECT @AIPayload AS [text()] FOR XML PATH('ai_payload'), TYPE) END,
38063807
[AI Raw Response] = CASE WHEN @AIResponseJSON IS NULL THEN NULL ELSE (
38073808
SELECT @AIResponseJSON AS [text()] FOR XML PATH('ai_raw_response'), TYPE) END;
3808-
END;
3809+
END
3810+
ELSE
3811+
BEGIN
3812+
SELECT [AI Prompt] = (
3813+
SELECT (@AISystemPrompt + NCHAR(13) + NCHAR(10) + NCHAR(13) + NCHAR(10) + @CurrentAIPrompt)
3814+
AS [text()] FOR XML PATH('ai_prompt'), TYPE);
3815+
END;
38093816

38103817
END; /* IF @AI >= 1 AND @TableName IS NOT NULL */
38113818

0 commit comments

Comments
 (0)