Skip to content

Commit c7dfbbb

Browse files
committed
Now with more actually ignoring query hashes
There was some additional logic involved in skipping triggers and stored procedures. A comment Jeremiah left threw me off. It will not work unless it's handled the same way as @OnlyQueryHashes; those things have to be ignored, or there will be no query_hash column to check against.
1 parent 2d17b75 commit c7dfbbb

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

sp_BlitzCache.sql

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,8 @@ END
912912
values will be inserted into #ignore_query_hashes. This is used to
913913
exclude values from query results.
914914
915-
Stored procedures and triggers will still be queried.
915+
Just a reminder: Using @OnlyQueryHashes will ignore stored
916+
procedures and triggers.
916917
*/
917918
IF @IgnoreQueryHashes IS NOT NULL
918919
AND LEN(@IgnoreQueryHashes) > 0
@@ -1004,6 +1005,7 @@ FROM (SELECT TOP (@Top) x.*, xpa.*,
10041005

10051006
SET @body += N' WHERE 1 = 1 ' + @nl ;
10061007

1008+
10071009
IF @IgnoreSystemDBs = 1
10081010
SET @body += N' AND COALESCE(DB_NAME(CAST(xpa.value AS INT)), '''') NOT IN (''master'', ''model'', ''msdb'', ''tempdb'', ''32767'') AND COALESCE(DB_NAME(CAST(xpa.value AS INT)), '''') NOT IN (SELECT name FROM sys.databases WHERE is_distributor = 1)' + @nl ;
10091011

@@ -1024,6 +1026,15 @@ BEGIN
10241026
SET @body += N' AND EXISTS(SELECT 1/0 FROM #only_query_hashes q WHERE q.query_hash = x.query_hash) ' + @nl ;
10251027
END
10261028

1029+
/* filtering for query hashes */
1030+
IF (SELECT COUNT(*) FROM #ignore_query_hashes) > 0
1031+
AND (SELECT COUNT(*) FROM #only_query_hashes) = 0
1032+
BEGIN
1033+
SET @body += N' AND NOT EXISTS(SELECT 1/0 FROM #ignore_query_hashes iq WHERE iq.query_hash = x.query_hash) ' + @nl ;
1034+
END
1035+
/* end filtering for query hashes */
1036+
1037+
10271038
IF @DurationFilter IS NOT NULL
10281039
SET @body += N' AND (total_elapsed_time / 1000.0) / execution_count > @min_duration ' + @nl ;
10291040

@@ -1061,14 +1072,14 @@ SELECT @body += ' ORDER BY ' +
10611072

10621073

10631074

1064-
SET @body += N') AS qs
1065-
CROSS JOIN(SELECT SUM(execution_count) AS t_TotalExecs,
1075+
SET @body += N') AS qs
1076+
CROSS JOIN(SELECT SUM(execution_count) AS t_TotalExecs,
10661077
SUM(CAST(total_elapsed_time AS BIGINT) / 1000.0) AS t_TotalElapsed,
10671078
SUM(CAST(total_worker_time AS BIGINT) / 1000.0) AS t_TotalWorker,
10681079
SUM(CAST(total_logical_reads AS BIGINT)) AS t_TotalReads,
10691080
SUM(CAST(total_logical_writes AS BIGINT)) AS t_TotalWrites
10701081
FROM sys.#view#) AS t
1071-
CROSS APPLY sys.dm_exec_plan_attributes(qs.plan_handle) AS pa
1082+
CROSS APPLY sys.dm_exec_plan_attributes(qs.plan_handle) AS pa
10721083
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st
10731084
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) AS qp ' + @nl ;
10741085

@@ -1243,7 +1254,7 @@ BEGIN
12431254
END
12441255

12451256

1246-
IF (@QueryFilter = 'all' AND (SELECT COUNT(*) FROM #only_query_hashes) = 0)
1257+
IF (@QueryFilter = 'all' AND (SELECT COUNT(*) FROM #only_query_hashes) = 0 AND (SELECT COUNT(*) FROM #ignore_query_hashes) = 0)
12471258
OR (LEFT(@QueryFilter, 3) = 'pro')
12481259
BEGIN
12491260
SET @sql += @insert_list;
@@ -1273,6 +1284,7 @@ END
12731284
******************************************************************************/
12741285
IF (@UseTriggersAnyway = 1 OR @v >= 11)
12751286
AND (SELECT COUNT(*) FROM #only_query_hashes) = 0
1287+
AND (SELECT COUNT(*) FROM #ignore_query_hashes) = 0
12761288
AND (@QueryFilter = 'all')
12771289
BEGIN
12781290
RAISERROR (N'Adding SQL to collect trigger stats.',0,1) WITH NOWAIT;

0 commit comments

Comments
 (0)