diff --git a/sp_HealthParser/sp_HealthParser.sql b/sp_HealthParser/sp_HealthParser.sql index 132ef48..ff3c5fe 100644 --- a/sp_HealthParser/sp_HealthParser.sql +++ b/sp_HealthParser/sp_HealthParser.sql @@ -4,6 +4,7 @@ SET ANSI_WARNINGS ON; SET ARITHABORT ON; SET CONCAT_NULL_YIELDS_NULL ON; SET QUOTED_IDENTIFIER ON; +SET IMPLICIT_TRANSACTIONS OFF; SET STATISTICS TIME, IO OFF; GO @@ -86,7 +87,7 @@ BEGIN WHEN N'@database_name' THEN N'database name to show blocking events for' WHEN N'@wait_duration_ms' THEN N'minimum wait duration' WHEN N'@wait_round_interval_minutes' THEN N'interval to round minutes to for wait stats' - WHEN N'@skip_locks' THEN N'skip the blocking and deadlocking section' + WHEN N'@skip_locks' THEN N'skip the blocking and deadlocking section' WHEN N'@version' THEN N'OUTPUT; for support' WHEN N'@version_date' THEN N'OUTPUT; for support' WHEN N'@help' THEN N'how you got here' @@ -271,7 +272,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. THEN 1 ELSE @wait_round_interval_minutes END; - + CREATE TABLE #ignore ( @@ -310,8 +311,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /*The more you ignore waits, the worser they get*/ IF @what_to_check IN ('all', 'waits') - BEGIN - INSERT + BEGIN + INSERT #ignore WITH(TABLOCKX) ( wait_type @@ -507,7 +508,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. CROSS APPLY (SELECT x.value( ''(@timestamp)[1]'', ''datetimeoffset'' )) ca ([utc_timestamp]) WHERE ca.utc_timestamp >= @start_date AND ca.utc_timestamp < @end_date OPTION(RECOMPILE, USE HINT(''ENABLE_PARALLEL_PLAN_PREFERENCE''));'; - + IF @debug = 1 BEGIN SET STATISTICS XML ON; PRINT @sql; END; INSERT INTO @@ -978,7 +979,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. WHERE w.x.exist('(data[@name="component"]/text[.="IO_SUBSYSTEM"])') = 1 AND (w.x.exist('(data[@name="state"]/text[.="WARNING"])') = @warnings_only OR @warnings_only IS NULL) OPTION(RECOMPILE); - + IF @debug = 1 BEGIN SELECT TOP (100) table_name = '#io, top 100 rows', x.* FROM #io AS x ORDER BY x.event_time DESC; @@ -1043,7 +1044,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. WHERE w.x.exist('(data[@name="component"]/text[.="QUERY_PROCESSING"])') = 1 AND (w.x.exist('(data[@name="state"]/text[.="WARNING"])') = @warnings_only OR @warnings_only IS NULL) OPTION(RECOMPILE); - + IF @debug = 1 BEGIN SELECT TOP (100) table_name = '#scheduler_details, top 100 rows', x.* FROM #scheduler_details AS x ORDER BY x.event_time DESC; @@ -1121,7 +1122,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. CROSS APPLY s.sp_server_diagnostics_component_result.nodes('/event/data/value/resource') AS r(c) WHERE (r.c.exist('@lastNotification[.= "RESOURCE_MEMPHYSICAL_LOW"]') = @warnings_only OR @warnings_only IS NULL) OPTION(RECOMPILE); - + IF @debug = 1 BEGIN SELECT TOP (100) table_name = '#memory, top 100 rows', x.* FROM #memory AS x ORDER BY x.event_time DESC; @@ -1210,7 +1211,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. BEGIN SELECT TOP (100) table_name = '#health, top 100 rows', x.* FROM #health AS x ORDER BY x.event_time DESC; END; - + SELECT finding = 'overall system health', h.event_time, @@ -1236,7 +1237,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. END; /*Grab useless stuff*/ - + /* I'm pulling this out for now, until I find a good use for it. SELECT @@ -1333,7 +1334,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. AND w.x.exist('//data[@name="data"]/value/queryProcessing/blockingTasks/blocked-process-report') = 1 AND (w.x.exist('(data[@name="state"]/text[.="WARNING"])') = @warnings_only OR @warnings_only IS NULL) OPTION(RECOMPILE); - + IF @debug = 1 BEGIN SELECT TOP (100) table_name = '#blocking_xml, top 100 rows', x.* FROM #blocking_xml AS x ORDER BY x.event_time DESC; @@ -1379,7 +1380,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. NCHAR(21),N'?'),NCHAR(20),N'?'),NCHAR(19),N'?'),NCHAR(18),N'?'),NCHAR(17),N'?'),NCHAR(16),N'?'),NCHAR(15),N'?'),NCHAR(14),N'?'),NCHAR(12),N'?'), NCHAR(11),N'?'),NCHAR(8),N'?'),NCHAR(7),N'?'),NCHAR(6),N'?'),NCHAR(5),N'?'),NCHAR(4),N'?'),NCHAR(3),N'?'),NCHAR(2),N'?'),NCHAR(1),N'?'),NCHAR(0),N'?') PERSISTED; - + IF @debug = 1 BEGIN SELECT TOP (100) table_name = '#blocked, top 100 rows', x.* FROM #blocked AS x ORDER BY x.event_time DESC; @@ -1425,7 +1426,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. NCHAR(21),N'?'),NCHAR(20),N'?'),NCHAR(19),N'?'),NCHAR(18),N'?'),NCHAR(17),N'?'),NCHAR(16),N'?'),NCHAR(15),N'?'),NCHAR(14),N'?'),NCHAR(12),N'?'), NCHAR(11),N'?'),NCHAR(8),N'?'),NCHAR(7),N'?'),NCHAR(6),N'?'),NCHAR(5),N'?'),NCHAR(4),N'?'),NCHAR(3),N'?'),NCHAR(2),N'?'),NCHAR(1),N'?'),NCHAR(0),N'?') PERSISTED; - + IF @debug = 1 BEGIN SELECT TOP (100) table_name = '#blocking, top 100 rows', x.* FROM #blocking AS x ORDER BY x.event_time DESC; @@ -1568,7 +1569,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. OR @database_name IS NULL) ) AS kheb OPTION(RECOMPILE); - + IF @debug = 1 BEGIN SELECT TOP (100) table_name = '#blocks, top 100 rows', x.* FROM #blocks AS x ORDER BY x.event_time DESC; @@ -1650,7 +1651,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. OR @database_name IS NULL) ) AS b OPTION(RECOMPILE); - + SELECT x.xml_deadlock_report, event_date = x.xml_deadlock_report.value('(event/@timestamp)[1]', 'datetime2'), @@ -1659,12 +1660,12 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. INTO #deadlocks FROM #xml_deadlock_report AS x OPTION(RECOMPILE); - + IF @debug = 1 BEGIN SELECT TOP (100) table_name = '#deadlocks, top 100 rows', x.* FROM #deadlocks AS x; END; - + SELECT x.event_date, x.id, @@ -1783,7 +1784,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. WHERE (x.database_id = @dbid OR @dbid IS NULL) OR (x.current_database_name = @database_name OR @database_name IS NULL) OPTION(RECOMPILE); - + ALTER TABLE #deadlocks_parsed ADD query_text AS REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( @@ -1794,12 +1795,12 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. NCHAR(21),N'?'),NCHAR(20),N'?'),NCHAR(19),N'?'),NCHAR(18),N'?'),NCHAR(17),N'?'),NCHAR(16),N'?'),NCHAR(15),N'?'),NCHAR(14),N'?'),NCHAR(12),N'?'), NCHAR(11),N'?'),NCHAR(8),N'?'),NCHAR(7),N'?'),NCHAR(6),N'?'),NCHAR(5),N'?'),NCHAR(4),N'?'),NCHAR(3),N'?'),NCHAR(2),N'?'),NCHAR(1),N'?'),NCHAR(0),N'?') PERSISTED; - + IF @debug = 1 BEGIN SELECT TOP (100) table_name = '#deadlocks_parsed, top 100 rows', x.* FROM #deadlocks_parsed AS x; END; - + SELECT finding = 'xml deadlock report', dp.event_date, @@ -1889,7 +1890,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. dp.event_date, is_victim OPTION(RECOMPILE); - + INSERT #available_plans WITH (TABLOCKX) ( @@ -1914,7 +1915,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. FROM #deadlocks_parsed AS dp CROSS APPLY dp.process_xml.nodes('//executionStack/frame[not(@sqlhandle = "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")]') AS e(x) OPTION(RECOMPILE); - + IF @debug = 1 BEGIN SELECT TOP (100) table_name = '#available_plans, top 100 rows', x.* FROM #available_plans AS x; @@ -1946,7 +1947,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ( SECOND, deqs.creation_time, - deqs.last_execution_time + NULLIF(deqs.last_execution_time, '1900-01-01 00:00:00.000') ), 0 ), @@ -1975,13 +1976,13 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. FROM sys.dm_exec_query_stats AS deqs WHERE EXISTS ( - SELECT - 1/0 - FROM #available_plans AS ap - WHERE ap.sql_handle = deqs.sql_handle + SELECT + 1/0 + FROM #available_plans AS ap + WHERE ap.sql_handle = deqs.sql_handle ) AND deqs.query_hash IS NOT NULL; - + CREATE CLUSTERED INDEX deqs_sh ON #dm_exec_query_stats_sh @@ -2068,7 +2069,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ORDER BY ap.avg_worker_time_ms DESC OPTION(RECOMPILE); - + SELECT aap.* FROM #all_avalable_plans AS aap @@ -2076,7 +2077,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ORDER BY aap.avg_worker_time_ms DESC OPTION(RECOMPILE); - + SELECT aap.* FROM #all_avalable_plans AS aap @@ -2085,4 +2086,5 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. aap.avg_worker_time_ms DESC OPTION(RECOMPILE); END; -END; /*Final End*/ \ No newline at end of file +END; /*Final End*/ +GO diff --git a/sp_HumanEvents/sp_HumanEvents.sql b/sp_HumanEvents/sp_HumanEvents.sql index 5d2e0b2..08c37a4 100644 --- a/sp_HumanEvents/sp_HumanEvents.sql +++ b/sp_HumanEvents/sp_HumanEvents.sql @@ -1,9 +1,10 @@ -SET ANSI_NULLS ON; +SET ANSI_NULLS ON; SET ANSI_PADDING ON; SET ANSI_WARNINGS ON; SET ARITHABORT ON; SET CONCAT_NULL_YIELDS_NULL ON; SET QUOTED_IDENTIFIER ON; +SET IMPLICIT_TRANSACTIONS OFF; SET STATISTICS TIME, IO OFF; GO @@ -3263,7 +3264,7 @@ BEGIN ( SECOND, deqs.creation_time, - deqs.last_execution_time + NULLIF(deqs.last_execution_time, '1900-01-01 00:00:00.000') ), 0 ), @@ -3292,10 +3293,10 @@ BEGIN FROM sys.dm_exec_query_stats AS deqs WHERE EXISTS ( - SELECT - 1/0 - FROM #available_plans AS ap - WHERE ap.sql_handle = deqs.sql_handle + SELECT + 1/0 + FROM #available_plans AS ap + WHERE ap.sql_handle = deqs.sql_handle ) AND deqs.query_hash IS NOT NULL; @@ -4697,9 +4698,7 @@ BEGIN EXEC @executer @drop_holder; RETURN; -END; - - +END; END TRY /*Very professional error handling*/ @@ -4725,7 +4724,6 @@ BEGIN CATCH RETURN -138; END; -END CATCH; - +END CATCH; END; -GO \ No newline at end of file +GO diff --git a/sp_HumanEvents/sp_HumanEventsBlockViewer.sql b/sp_HumanEvents/sp_HumanEventsBlockViewer.sql index 2f8a600..aad3f04 100644 --- a/sp_HumanEvents/sp_HumanEventsBlockViewer.sql +++ b/sp_HumanEvents/sp_HumanEventsBlockViewer.sql @@ -1,20 +1,21 @@ -SET ANSI_NULLS ON; +SET ANSI_NULLS ON; SET ANSI_PADDING ON; SET ANSI_WARNINGS ON; SET ARITHABORT ON; SET CONCAT_NULL_YIELDS_NULL ON; SET QUOTED_IDENTIFIER ON; +SET IMPLICIT_TRANSACTIONS OFF; SET STATISTICS TIME, IO OFF; GO /* -██╗ ██╗██╗ ██╗███╗ ███╗ █████╗ ███╗ ██╗ -██║ ██║██║ ██║████╗ ████║██╔══██╗████╗ ██║ -███████║██║ ██║██╔████╔██║███████║██╔██╗ ██║ -██╔══██║██║ ██║██║╚██╔╝██║██╔══██║██║╚██╗██║ -██║ ██║╚██████╔╝██║ ╚═╝ ██║██║ ██║██║ ╚████║ -╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝ - +██╗ ██╗██╗ ██╗███╗ ███╗ █████╗ ███╗ ██╗ +██║ ██║██║ ██║████╗ ████║██╔══██╗████╗ ██║ +███████║██║ ██║██╔████╔██║███████║██╔██╗ ██║ +██╔══██║██║ ██║██║╚██╔╝██║██╔══██║██║╚██╗██║ +██║ ██║╚██████╔╝██║ ╚═╝ ██║██║ ██║██║ ╚████║ +╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝ + ███████╗██╗ ██╗███████╗███╗ ██╗████████╗███████╗ ██╔════╝██║ ██║██╔════╝████╗ ██║╚══██╔══╝██╔════╝ █████╗ ██║ ██║█████╗ ██╔██╗ ██║ ██║ ███████╗ @@ -28,7 +29,7 @@ GO ██╔══██╗██║ ██║ ██║██║ ██╔═██╗ ██████╔╝███████╗╚██████╔╝╚██████╗██║ ██╗ ╚═════╝ ╚══════╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝ - + ██╗ ██╗██╗███████╗██╗ ██╗███████╗██████╗ ██║ ██║██║██╔════╝██║ ██║██╔════╝██╔══██╗ ██║ ██║██║█████╗ ██║ █╗ ██║█████╗ ██████╔╝ @@ -147,12 +148,12 @@ BEGIN SELECT mit_license_yo = 'i am MIT licensed, so like, do whatever' - + UNION ALL - + SELECT mit_license_yo = 'see printed messages for full license'; - + RAISERROR(' MIT License @@ -344,7 +345,7 @@ BEGIN ORDER BY t.target_name OPTION(RECOMPILE); END; - + IF @azure = 1 BEGIN SELECT TOP (1) @@ -363,7 +364,7 @@ END; IF @target_type = N'ring_buffer' AND @is_system_health = 0 BEGIN IF @azure = 0 - BEGIN + BEGIN INSERT #x WITH(TABLOCKX) ( @@ -378,7 +379,7 @@ BEGIN AND t.target_name = N'ring_buffer' OPTION(RECOMPILE); END; - + IF @azure = 1 BEGIN INSERT @@ -398,7 +399,7 @@ BEGIN END; IF @target_type = N'event_file' AND @is_system_health = 0 -BEGIN +BEGIN IF @azure = 0 BEGIN SELECT @@ -436,7 +437,7 @@ BEGIN ) AS f OPTION(RECOMPILE); END; - + IF @azure = 1 BEGIN SELECT @@ -479,7 +480,7 @@ BEGIN #x WITH(TABLOCKX) ( x - ) + ) SELECT x = TRY_CAST(f.event_data AS xml) FROM sys.fn_xe_file_target_read_file @@ -550,17 +551,17 @@ BEGIN IF @debug = 1 BEGIN SELECT * FROM #sp_server_diagnostics_component_result AS ssdcr; END; SELECT - event_time = - DATEADD - ( - MINUTE, - DATEDIFF - ( - MINUTE, - GETUTCDATE(), - SYSDATETIME() - ), - w.x.value('(//@timestamp)[1]', 'datetime2') + event_time = + DATEADD + ( + MINUTE, + DATEDIFF + ( + MINUTE, + GETUTCDATE(), + SYSDATETIME() + ), + w.x.value('(//@timestamp)[1]', 'datetime2') ), human_events_xml = w.x.query('//data[@name="data"]/value/queryProcessing/blockingTasks/blocked-process-report') INTO #blocking_xml_sh @@ -572,9 +573,9 @@ BEGIN SELECT bx.event_time, - currentdbname = bd.value('(process/@currentdbname)[1]', 'nvarchar(128)'), + currentdbname = bd.value('(process/@currentdbname)[1]', 'nvarchar(128)'), spid = bd.value('(process/@spid)[1]', 'int'), - ecid = bd.value('(process/@ecid)[1]', 'int'), + ecid = bd.value('(process/@ecid)[1]', 'int'), query_text_pre = bd.value('(process/inputbuf/text())[1]', 'nvarchar(MAX)'), wait_time = bd.value('(process/@waittime)[1]', 'bigint'), lastbatchstarted = bd.value('(process/@lastbatchstarted)[1]', 'datetime2'), @@ -598,7 +599,7 @@ BEGIN OUTER APPLY oa.c.nodes('//blocked-process-report/blocked-process') AS bd(bd) WHERE bd.exist('process/@spid') = 1 OPTION(RECOMPILE); - + ALTER TABLE #blocked_sh ADD query_text AS REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( @@ -611,7 +612,7 @@ BEGIN PERSISTED; IF @debug = 1 BEGIN SELECT * FROM #blocking_xml_sh AS bxs; END; - + /*Blocking queries*/ SELECT bx.event_time, @@ -641,7 +642,7 @@ BEGIN OUTER APPLY oa.c.nodes('//blocked-process-report/blocking-process') AS bg(bg) WHERE bg.exist('process/@spid') = 1 OPTION(RECOMPILE); - + ALTER TABLE #blocking_sh ADD query_text AS REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( @@ -669,7 +670,7 @@ BEGIN THEN ( SELECT - [processing-instruction(query)] = + [processing-instruction(query)] = OBJECT_SCHEMA_NAME ( SUBSTRING @@ -726,7 +727,7 @@ BEGIN kheb.last_transaction_completed, client_option_1 = SUBSTRING - ( + ( CASE WHEN kheb.clientoption1 & 1 = 1 THEN ', DISABLE_DEF_CNST_CHECK' ELSE '' END + CASE WHEN kheb.clientoption1 & 2 = 2 THEN ', IMPLICIT_TRANSACTIONS' ELSE '' END + CASE WHEN kheb.clientoption1 & 4 = 4 THEN ', CURSOR_CLOSE_ON_COMMIT' ELSE '' END + @@ -776,18 +777,18 @@ BEGIN kheb.blocked_process_report INTO #blocks_sh FROM - ( + ( SELECT bg.* FROM #blocking_sh AS bg WHERE (bg.currentdbname = @database_name OR @database_name IS NULL) - + UNION ALL - + SELECT bd.* - FROM #blocked_sh AS bd + FROM #blocked_sh AS bd WHERE (bd.currentdbname = @database_name OR @database_name IS NULL) ) AS kheb @@ -848,9 +849,9 @@ BEGIN CROSS APPLY b.blocked_process_report.nodes('/blocked-process/process/executionStack/frame[not(@sqlhandle = "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")]') AS n(c) WHERE (b.currentdbname = @database_name OR @database_name IS NULL) - + UNION ALL - + SELECT available_plans = 'available_plans', @@ -898,7 +899,7 @@ BEGIN ( SECOND, deqs.creation_time, - deqs.last_execution_time + NULLIF(deqs.last_execution_time, '1900-01-01 00:00:00.000') ), 0 ), @@ -917,14 +918,22 @@ BEGIN min_used_grant_mb = deqs.min_used_grant_kb * 8. / 1024., max_used_grant_mb = - deqs.max_used_grant_kb * 8. / 1024., + deqs.max_used_grant_kb * 8. / 1024., deqs.min_reserved_threads, deqs.max_reserved_threads, deqs.min_used_threads, deqs.max_used_threads, deqs.total_rows INTO #dm_exec_query_stats_sh - FROM sys.dm_exec_query_stats AS deqs; + FROM sys.dm_exec_query_stats AS deqs + WHERE EXISTS + ( + SELECT + 1/0 + FROM #available_plans_sh AS ap + WHERE ap.sql_handle = deqs.sql_handle + ) + AND deqs.query_hash IS NOT NULL; CREATE CLUSTERED INDEX deqs_sh @@ -933,7 +942,7 @@ BEGIN sql_handle, plan_handle ); - + SELECT ap.available_plans, ap.currentdbname, @@ -1033,7 +1042,7 @@ SELECT SYSDATETIME() ), c.value('@timestamp', 'datetime2') - ), + ), database_name = DB_NAME(c.value('(data[@name="database_id"]/value/text())[1]', 'int')), database_id = c.value('(data[@name="database_id"]/value/text())[1]', 'int'), object_id = c.value('(data[@name="object_id"]/value/text())[1]', 'int'), @@ -1086,32 +1095,32 @@ ADD query_text AS PERSISTED; ALTER TABLE #blocked -ADD blocking_desc AS +ADD blocking_desc AS ISNULL ( - '(' + - CAST(blocking_spid AS varchar(10)) + - ':' + - CAST(blocking_ecid AS varchar(10)) + - ')', + '(' + + CAST(blocking_spid AS varchar(10)) + + ':' + + CAST(blocking_ecid AS varchar(10)) + + ')', 'unresolved process' ) PERSISTED, blocked_desc AS - '(' + - CAST(blocked_spid AS varchar(10)) + - ':' + - CAST(blocked_ecid AS varchar(10)) + + '(' + + CAST(blocked_spid AS varchar(10)) + + ':' + + CAST(blocked_ecid AS varchar(10)) + ')' PERSISTED; -CREATE CLUSTERED INDEX - blocking +CREATE CLUSTERED INDEX + blocking ON #blocked (monitor_loop, blocking_desc); -CREATE INDEX - blocked +CREATE INDEX + blocked ON #blocked - (monitor_loop, blocked_desc); + (monitor_loop, blocked_desc); IF @debug = 1 BEGIN SELECT '#blocked' AS table_name, * FROM #blocked AS wa OPTION(RECOMPILE); END; @@ -1127,7 +1136,7 @@ SELECT SYSDATETIME() ), c.value('@timestamp', 'datetime2') - ), + ), database_name = DB_NAME(c.value('(data[@name="database_id"]/value/text())[1]', 'int')), database_id = c.value('(data[@name="database_id"]/value/text())[1]', 'int'), object_id = c.value('(data[@name="object_id"]/value/text())[1]', 'int'), @@ -1180,54 +1189,54 @@ ADD query_text AS PERSISTED; ALTER TABLE #blocking -ADD blocking_desc AS +ADD blocking_desc AS ISNULL ( - '(' + - CAST(blocking_spid AS varchar(10)) + - ':' + - CAST(blocking_ecid AS varchar(10)) + - ')', + '(' + + CAST(blocking_spid AS varchar(10)) + + ':' + + CAST(blocking_ecid AS varchar(10)) + + ')', 'unresolved process' ) PERSISTED, blocked_desc AS - '(' + - CAST(blocked_spid AS varchar(10)) + - ':' + - CAST(blocked_ecid AS varchar(10)) + + '(' + + CAST(blocked_spid AS varchar(10)) + + ':' + + CAST(blocked_ecid AS varchar(10)) + ')' PERSISTED; -CREATE CLUSTERED INDEX - blocking +CREATE CLUSTERED INDEX + blocking ON #blocking (monitor_loop, blocking_desc); -CREATE INDEX - blocked +CREATE INDEX + blocked ON #blocking - (monitor_loop, blocked_desc); + (monitor_loop, blocked_desc); IF @debug = 1 BEGIN SELECT '#blocking' AS table_name, * FROM #blocking AS wa OPTION(RECOMPILE); END; -WITH - hierarchy AS +WITH + hierarchy AS ( - SELECT - b.monitor_loop, + SELECT + b.monitor_loop, blocking_desc, blocked_desc, level = 0, - sort_order = + sort_order = CAST ( - blocking_desc + - ' <-- ' + + blocking_desc + + ' <-- ' + blocked_desc AS varchar(400) ) FROM #blocking b - WHERE NOT EXISTS + WHERE NOT EXISTS ( - SELECT + SELECT 1/0 FROM #blocking b2 WHERE b2.monitor_loop = b.monitor_loop @@ -1236,18 +1245,18 @@ WITH UNION ALL - SELECT + SELECT bg.monitor_loop, bg.blocking_desc, bg.blocked_desc, h.level + 1, - sort_order = + sort_order = CAST ( - h.sort_order + - ' ' + - bg.blocking_desc + - ' <-- ' + + h.sort_order + + ' ' + + bg.blocking_desc + + ' <-- ' + bg.blocked_desc AS varchar(400) ) FROM hierarchy h @@ -1256,7 +1265,7 @@ WITH AND bg.blocking_desc = h.blocked_desc ) UPDATE #blocked -SET +SET blocking_level = h.level, sort_order = h.sort_order FROM #blocked b @@ -1267,7 +1276,7 @@ JOIN hierarchy h OPTION(RECOMPILE); UPDATE #blocking -SET +SET blocking_level = bd.blocking_level, sort_order = bd.sort_order FROM #blocking bg @@ -1291,25 +1300,25 @@ SELECT RTRIM(kheb.object_id) ), kheb.activity, - blocking_tree = - REPLICATE(' > ', kheb.blocking_level) + + blocking_tree = + REPLICATE(' > ', kheb.blocking_level) + CASE kheb.activity - WHEN 'blocking' + WHEN 'blocking' THEN '(' + kheb.blocking_desc + ') is blocking (' + kheb.blocked_desc + ')' ELSE ' > (' + kheb.blocked_desc + ') is blocked by (' + kheb.blocking_desc + ')' END, - spid = + spid = CASE kheb.activity - WHEN 'blocking' + WHEN 'blocking' THEN kheb.blocking_spid ELSE kheb.blocked_spid END, ecid = CASE kheb.activity - WHEN 'blocking' + WHEN 'blocking' THEN kheb.blocking_ecid ELSE kheb.blocked_ecid - END, + END, query_text = CASE WHEN kheb.query_text @@ -1317,7 +1326,7 @@ SELECT THEN ( SELECT - [processing-instruction(query)] = + [processing-instruction(query)] = OBJECT_SCHEMA_NAME ( SUBSTRING @@ -1377,7 +1386,7 @@ SELECT kheb.last_transaction_completed, client_option_1 = SUBSTRING - ( + ( CASE WHEN kheb.clientoption1 & 1 = 1 THEN ', DISABLE_DEF_CNST_CHECK' ELSE '' END + CASE WHEN kheb.clientoption1 & 2 = 2 THEN ', IMPLICIT_TRANSACTIONS' ELSE '' END + CASE WHEN kheb.clientoption1 & 4 = 4 THEN ', CURSOR_CLOSE_ON_COMMIT' ELSE '' END + @@ -1432,14 +1441,14 @@ SELECT kheb.sort_order INTO #blocks FROM -( +( SELECT bg.*, contentious_object = OBJECT_SCHEMA_NAME ( bg.object_id, - bg.database_id + bg.database_id ) + N'.' + OBJECT_NAME @@ -1450,16 +1459,16 @@ FROM FROM #blocking AS bg WHERE (bg.database_name = @database_name OR @database_name IS NULL) - + UNION ALL - + SELECT bd.*, contentious_object = OBJECT_SCHEMA_NAME ( bd.object_id, - bd.database_id + bd.database_id ) + N'.' + OBJECT_NAME @@ -1467,7 +1476,7 @@ FROM bd.object_id, bd.database_id ) - FROM #blocked AS bd + FROM #blocked AS bd WHERE (bd.database_name = @database_name OR @database_name IS NULL) ) AS kheb @@ -1534,7 +1543,7 @@ OPTION(RECOMPILE); SELECT DISTINCT b.* -INTO #available_plans +INTO #available_plans FROM ( SELECT @@ -1559,9 +1568,9 @@ FROM OR @database_name IS NULL) AND (b.contentious_object = @object_name OR @object_name IS NULL) - + UNION ALL - + SELECT available_plans = 'available_plans', @@ -1615,7 +1624,7 @@ SELECT ( SECOND, deqs.creation_time, - deqs.last_execution_time + NULLIF(deqs.last_execution_time, '1900-01-01 00:00:00.000') ), 0 ), @@ -1634,7 +1643,7 @@ SELECT min_used_grant_mb = deqs.min_used_grant_kb * 8. / 1024., max_used_grant_mb = - deqs.max_used_grant_kb * 8. / 1024., + deqs.max_used_grant_kb * 8. / 1024., deqs.min_reserved_threads, deqs.max_reserved_threads, deqs.min_used_threads, @@ -1651,11 +1660,11 @@ WHERE EXISTS ) AND deqs.query_hash IS NOT NULL; -CREATE CLUSTERED INDEX - deqs +CREATE CLUSTERED INDEX + deqs ON #dm_exec_query_stats ( - sql_handle, + sql_handle, plan_handle ); @@ -1783,7 +1792,7 @@ SELECT N' has been involved in ' + CONVERT(nvarchar(20), COUNT_BIG(DISTINCT b.transaction_id)) + N' blocking sessions.', - sort_order = + sort_order = ROW_NUMBER() OVER (ORDER BY COUNT_BIG(DISTINCT b.transaction_id) DESC) FROM #blocks AS b WHERE (b.database_name = @database_name @@ -1825,7 +1834,7 @@ SELECT N' has been involved in ' + CONVERT(nvarchar(20), COUNT_BIG(DISTINCT b.transaction_id)) + N' blocking sessions.', - sort_order = + sort_order = ROW_NUMBER() OVER (ORDER BY COUNT_BIG(DISTINCT b.transaction_id) DESC) FROM #blocks AS b WHERE (b.database_name = @database_name @@ -1873,7 +1882,7 @@ SELECT N' select queries involved in blocking sessions in ' + b.database_name + N'.', - sort_order = + sort_order = ROW_NUMBER() OVER (ORDER BY COUNT_BIG(DISTINCT b.transaction_id) DESC) FROM #blocks AS b WHERE b.lock_mode IN @@ -1916,7 +1925,7 @@ SELECT N' repeatable read queries involved in blocking sessions in ' + b.database_name + N'.', - sort_order = + sort_order = ROW_NUMBER() OVER (ORDER BY COUNT_BIG(DISTINCT b.transaction_id) DESC) FROM #blocks AS b WHERE b.isolation_level LIKE N'repeatable%' @@ -1954,7 +1963,7 @@ SELECT N' serializable queries involved in blocking sessions in ' + b.database_name + N'.', - sort_order = + sort_order = ROW_NUMBER() OVER (ORDER BY COUNT_BIG(DISTINCT b.transaction_id) DESC) FROM #blocks AS b WHERE b.isolation_level LIKE N'serializable%' @@ -1991,7 +2000,7 @@ SELECT N' sleeping queries involved in blocking sessions in ' + b.database_name + N'.', - sort_order = + sort_order = ROW_NUMBER() OVER (ORDER BY COUNT_BIG(DISTINCT b.transaction_id) DESC) FROM #blocks AS b WHERE b.status = N'sleeping' @@ -2028,7 +2037,7 @@ SELECT N' background tasks involved in blocking sessions in ' + b.database_name + N'.', - sort_order = + sort_order = ROW_NUMBER() OVER (ORDER BY COUNT_BIG(DISTINCT b.transaction_id) DESC) FROM #blocks AS b WHERE b.status = N'background' @@ -2065,7 +2074,7 @@ SELECT N' implicit transaction queries involved in blocking sessions in ' + b.database_name + N'.', - sort_order = + sort_order = ROW_NUMBER() OVER (ORDER BY COUNT_BIG(DISTINCT b.transaction_id) DESC) FROM #blocks AS b WHERE b.transaction_name = N'implicit_transaction' @@ -2102,7 +2111,7 @@ SELECT N' user transaction queries involved in blocking sessions in ' + b.database_name + N'.', - sort_order = + sort_order = ROW_NUMBER() OVER (ORDER BY COUNT_BIG(DISTINCT b.transaction_id) DESC) FROM #blocks AS b WHERE b.transaction_name = N'user_transaction' @@ -2155,7 +2164,7 @@ SELECT N'UNKNOWN' ) + N'.', - sort_order = + sort_order = ROW_NUMBER() OVER (ORDER BY COUNT_BIG(DISTINCT b.transaction_id) DESC) FROM #blocks AS b WHERE (b.database_name = @database_name @@ -2243,7 +2252,7 @@ SELECT 14 ) + N' [dd hh:mm:ss:ms] of lock wait time.', - sort_order = + sort_order = ROW_NUMBER() OVER (ORDER BY SUM(CONVERT(bigint, b.wait_time_ms)) DESC) FROM b AS b WHERE (b.database_name = @database_name @@ -2328,7 +2337,7 @@ SELECT ) + N' [dd hh:mm:ss:ms] of lock wait time in database ' + b.database_name, - sort_order = + sort_order = ROW_NUMBER() OVER (ORDER BY SUM(CONVERT(bigint, b.wait_time_ms)) DESC) FROM b AS b WHERE (b.database_name = @database_name @@ -2373,4 +2382,4 @@ ORDER BY bf.sort_order OPTION(RECOMPILE); END; --Final End -GO \ No newline at end of file +GO diff --git a/sp_LogHunter/sp_LogHunter.sql b/sp_LogHunter/sp_LogHunter.sql index c611c55..4fde07f 100644 --- a/sp_LogHunter/sp_LogHunter.sql +++ b/sp_LogHunter/sp_LogHunter.sql @@ -4,6 +4,7 @@ SET ANSI_WARNINGS ON; SET ARITHABORT ON; SET CONCAT_NULL_YIELDS_NULL ON; SET QUOTED_IDENTIFIER ON; +SET IMPLICIT_TRANSACTIONS OFF; SET STATISTICS TIME, IO OFF; GO @@ -568,3 +569,4 @@ BEGIN OPTION(RECOMPILE); END; END; +GO diff --git a/sp_PressureDetector/sp_PressureDetector.sql b/sp_PressureDetector/sp_PressureDetector.sql index 85f75a7..5249158 100644 --- a/sp_PressureDetector/sp_PressureDetector.sql +++ b/sp_PressureDetector/sp_PressureDetector.sql @@ -4,8 +4,8 @@ SET ANSI_WARNINGS ON; SET ARITHABORT ON; SET CONCAT_NULL_YIELDS_NULL ON; SET QUOTED_IDENTIFIER ON; -SET STATISTICS IO OFF; -SET STATISTICS TIME OFF; +SET IMPLICIT_TRANSACTIONS OFF; +SET STATISTICS TIME, IO OFF; GO /* @@ -1875,4 +1875,4 @@ OPTION(MAXDOP 1, RECOMPILE);', END; END; END; -GO \ No newline at end of file +GO diff --git a/sp_QuickieStore/sp_QuickieStore.sql b/sp_QuickieStore/sp_QuickieStore.sql index 9bf7a15..f3b0d1d 100644 --- a/sp_QuickieStore/sp_QuickieStore.sql +++ b/sp_QuickieStore/sp_QuickieStore.sql @@ -5,8 +5,7 @@ SET ARITHABORT ON; SET CONCAT_NULL_YIELDS_NULL ON; SET QUOTED_IDENTIFIER ON; SET IMPLICIT_TRANSACTIONS OFF; -SET STATISTICS IO OFF; -SET STATISTICS TIME OFF; +SET STATISTICS TIME, IO OFF; GO /* @@ -8084,4 +8083,4 @@ BEGIN END; /*End debug*/ RETURN; /*Yeah sure why not?*/ END;/*Final End*/ -GO \ No newline at end of file +GO