Skip to content

Commit 90c2c69

Browse files
BrentOzarclaude
andcommitted
sp_BlitzWho/sp_BlitzFirst: address review feedback + wire @expertmode = 3
sp_BlitzWho: - Move @onlyproblems to the end of the parameter list so positional callers aren't shifted (Copilot review). - Use s.open_transaction_count first in the sleeping-with-open-tran branch so idle sessions (no active request, not in @Blocked) are correctly included (Copilot review). sp_BlitzFirst: - Run sp_BlitzWho at start/end when @expertmode IN (1, 3), matching the existing @expertmode = 1 behavior. - When @expertmode = 3, pass @onlyproblems = 1 so only problem sessions appear in the first/last result sets. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 99e82ab commit 90c2c69

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

sp_BlitzFirst.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ DECLARE @StringToExecute NVARCHAR(MAX),
134134
@OutputTableNameWaitStats_Categories NVARCHAR(256),
135135
@OutputTableCleanupDate DATE,
136136
@ObjectFullName NVARCHAR(2000),
137-
@BlitzWho NVARCHAR(MAX) = N'EXEC dbo.sp_BlitzWho @ShowSleepingSPIDs = ' + CONVERT(NVARCHAR(1), @ShowSleepingSPIDs) + N';',
137+
@BlitzWho NVARCHAR(MAX) = N'EXEC dbo.sp_BlitzWho @ShowSleepingSPIDs = ' + CONVERT(NVARCHAR(1), @ShowSleepingSPIDs) + CASE WHEN @ExpertMode = 3 THEN N', @OnlyProblems = 1' ELSE N'' END + N';',
138138
@BlitzCacheMinutesBack INT,
139139
@UnquotedOutputServerName NVARCHAR(256) = @OutputServerName ,
140140
@UnquotedOutputDatabaseName NVARCHAR(256) = @OutputDatabaseName ,
@@ -280,7 +280,7 @@ END; /* IF @AsOf IS NOT NULL AND @OutputDatabaseName IS NOT NULL AND @OutputSche
280280
ELSE IF @LogMessage IS NULL /* IF @OutputType = 'SCHEMA' */
281281
BEGIN
282282
/* What's running right now? This is the first and last result set. */
283-
IF @SinceStartup = 0 AND @Seconds > 0 AND @ExpertMode = 1 AND @OutputType <> 'NONE' AND @OutputResultSets LIKE N'%BlitzWho_Start%'
283+
IF @SinceStartup = 0 AND @Seconds > 0 AND @ExpertMode IN (1, 3) AND @OutputType <> 'NONE' AND @OutputResultSets LIKE N'%BlitzWho_Start%'
284284
BEGIN
285285
IF OBJECT_ID('master.dbo.sp_BlitzWho') IS NULL AND OBJECT_ID('dbo.sp_BlitzWho') IS NULL
286286
BEGIN
@@ -290,7 +290,7 @@ BEGIN
290290
BEGIN
291291
EXEC (@BlitzWho);
292292
END;
293-
END; /* IF @SinceStartup = 0 AND @Seconds > 0 AND @ExpertMode = 1 AND @OutputType <> 'NONE' - What's running right now? This is the first and last result set. */
293+
END; /* IF @SinceStartup = 0 AND @Seconds > 0 AND @ExpertMode IN (1, 3) AND @OutputType <> 'NONE' - What's running right now? This is the first and last result set. */
294294

295295
/* Set start/finish times AFTER sp_BlitzWho runs. For more info: https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/issues/2244 */
296296
IF @Seconds = 0 AND SERVERPROPERTY('EngineEdition') = 5 /*SERVERPROPERTY('Edition') = 'SQL Azure'*/
@@ -5372,7 +5372,7 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
53725372
DROP TABLE #BlitzFirstResults;
53735373

53745374
/* What's running right now? This is the first and last result set. */
5375-
IF @SinceStartup = 0 AND @Seconds > 0 AND @ExpertMode = 1 AND @OutputType <> 'NONE' AND @OutputResultSets LIKE N'%BlitzWho_End%'
5375+
IF @SinceStartup = 0 AND @Seconds > 0 AND @ExpertMode IN (1, 3) AND @OutputType <> 'NONE' AND @OutputResultSets LIKE N'%BlitzWho_End%'
53765376
BEGIN
53775377
IF OBJECT_ID('master.dbo.sp_BlitzWho') IS NULL AND OBJECT_ID('dbo.sp_BlitzWho') IS NULL
53785378
BEGIN
@@ -5382,7 +5382,7 @@ If one of them is a lead blocker, consider killing that query.'' AS HowToStopit,
53825382
BEGIN
53835383
EXEC (@BlitzWho);
53845384
END;
5385-
END; /* IF @SinceStartup = 0 AND @Seconds > 0 AND @ExpertMode = 1 AND @OutputType <> 'NONE' - What's running right now? This is the first and last result set. */
5385+
END; /* IF @SinceStartup = 0 AND @Seconds > 0 AND @ExpertMode IN (1, 3) AND @OutputType <> 'NONE' - What's running right now? This is the first and last result set. */
53865386

53875387
END; /* IF @LogMessage IS NULL */
53885388
END; /* ELSE IF @OutputType = 'SCHEMA' */

sp_BlitzWho.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ ALTER PROCEDURE dbo.sp_BlitzWho
5050
@MinTempdbMB INT = 0 ,
5151
@MinRequestedMemoryKB INT = 0 ,
5252
@MinBlockingSeconds INT = 0 ,
53-
@OnlyProblems BIT = 0 ,
5453
@CheckDateOverride DATETIMEOFFSET = NULL,
5554
@ShowActualParameters BIT = 0,
5655
@GetOuterCommand BIT = 0,
5756
@GetLiveQueryPlan BIT = NULL,
5857
@Version VARCHAR(30) = NULL OUTPUT,
5958
@VersionDate DATETIME = NULL OUTPUT,
6059
@VersionCheckMode BIT = 0,
61-
@SortOrder NVARCHAR(256) = N'elapsed time'
60+
@SortOrder NVARCHAR(256) = N'elapsed time',
61+
@OnlyProblems BIT = 0
6262
AS
6363
BEGIN
6464
SET NOCOUNT ON;
@@ -949,7 +949,7 @@ IF @OnlyProblems = 1
949949
r.blocking_session_id <> 0
950950
OR blocked.session_id IS NOT NULL
951951
OR wt.wait_info IS NOT NULL
952-
OR (s.status = ''sleeping'' AND COALESCE(r.open_transaction_count, blocked.open_tran, 0) >= 1)
952+
OR (s.status = ''sleeping'' AND COALESCE(s.open_transaction_count, r.open_transaction_count, blocked.open_tran, 0) >= 1)
953953
OR ABS(COALESCE(r.total_elapsed_time, 0)) / 1000 >= 30
954954
) ';
955955
END

0 commit comments

Comments
 (0)