Skip to content

Commit a0c0446

Browse files
Merge pull request #543 from erikdarlingdata/dev
Dev
2 parents c0ef740 + c006cc8 commit a0c0446

File tree

2 files changed

+82
-32
lines changed

2 files changed

+82
-32
lines changed

sp_HumanEvents/sp_HumanEventsBlockViewer.sql

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -735,12 +735,12 @@ BEGIN
735735
lock_mode nvarchar(10) NULL,
736736
resource_owner_type nvarchar(256) NULL,
737737
transaction_count int NULL,
738-
transaction_name nvarchar(512) NULL,
738+
transaction_name nvarchar(1024) NULL,
739739
last_transaction_started datetime2(7) NULL,
740740
last_transaction_completed datetime2(7) NULL,
741741
client_option_1 varchar(261) NULL,
742742
client_option_2 varchar(307) NULL,
743-
wait_resource nvarchar(100) NULL,
743+
wait_resource nvarchar(1024) NULL,
744744
priority int NULL,
745745
log_used bigint NULL,
746746
client_app nvarchar(256) NULL,
@@ -1209,7 +1209,7 @@ BEGIN
12091209
wait_time = bd.value('(process/@waittime)[1]', 'bigint'),
12101210
lastbatchstarted = bd.value('(process/@lastbatchstarted)[1]', 'datetime2'),
12111211
lastbatchcompleted = bd.value('(process/@lastbatchcompleted)[1]', 'datetime2'),
1212-
wait_resource = bd.value('(process/@waitresource)[1]', 'nvarchar(100)'),
1212+
wait_resource = bd.value('(process/@waitresource)[1]', 'nvarchar(1024)'),
12131213
status = bd.value('(process/@status)[1]', 'nvarchar(10)'),
12141214
priority = bd.value('(process/@priority)[1]', 'integer'),
12151215
transaction_count = bd.value('(process/@trancount)[1]', 'integer'),
@@ -1266,7 +1266,7 @@ BEGIN
12661266
wait_time = bg.value('(process/@waittime)[1]', 'bigint'),
12671267
last_transaction_started = bg.value('(process/@lastbatchstarted)[1]', 'datetime2'),
12681268
last_transaction_completed = bg.value('(process/@lastbatchcompleted)[1]', 'datetime2'),
1269-
wait_resource = bg.value('(process/@waitresource)[1]', 'nvarchar(100)'),
1269+
wait_resource = bg.value('(process/@waitresource)[1]', 'nvarchar(1024)'),
12701270
status = bg.value('(process/@status)[1]', 'nvarchar(10)'),
12711271
priority = bg.value('(process/@priority)[1]', 'integer'),
12721272
transaction_count = bg.value('(process/@trancount)[1]', 'integer'),
@@ -1818,10 +1818,10 @@ SELECT
18181818
blocked_ecid = bd.value('(process/@ecid)[1]', 'integer'),
18191819
query_text_pre = bd.value('(process/inputbuf/text())[1]', 'nvarchar(max)'),
18201820
wait_time = bd.value('(process/@waittime)[1]', 'bigint'),
1821-
transaction_name = bd.value('(process/@transactionname)[1]', 'nvarchar(512)'),
1821+
transaction_name = bd.value('(process/@transactionname)[1]', 'nvarchar(1024)'),
18221822
last_transaction_started = bd.value('(process/@lasttranstarted)[1]', 'datetime2'),
18231823
last_transaction_completed = CONVERT(datetime2, NULL),
1824-
wait_resource = bd.value('(process/@waitresource)[1]', 'nvarchar(100)'),
1824+
wait_resource = bd.value('(process/@waitresource)[1]', 'nvarchar(1024)'),
18251825
lock_mode = bd.value('(process/@lockMode)[1]', 'nvarchar(10)'),
18261826
status = bd.value('(process/@status)[1]', 'nvarchar(10)'),
18271827
priority = bd.value('(process/@priority)[1]', 'integer'),
@@ -1938,10 +1938,10 @@ SELECT
19381938
blocked_ecid = bd.value('(process/@ecid)[1]', 'integer'),
19391939
query_text_pre = bg.value('(process/inputbuf/text())[1]', 'nvarchar(max)'),
19401940
wait_time = bg.value('(process/@waittime)[1]', 'bigint'),
1941-
transaction_name = bg.value('(process/@transactionname)[1]', 'nvarchar(512)'),
1941+
transaction_name = bg.value('(process/@transactionname)[1]', 'nvarchar(1024)'),
19421942
last_transaction_started = bg.value('(process/@lastbatchstarted)[1]', 'datetime2'),
19431943
last_transaction_completed = bg.value('(process/@lastbatchcompleted)[1]', 'datetime2'),
1944-
wait_resource = bg.value('(process/@waitresource)[1]', 'nvarchar(100)'),
1944+
wait_resource = bg.value('(process/@waitresource)[1]', 'nvarchar(1024)'),
19451945
lock_mode = bg.value('(process/@lockMode)[1]', 'nvarchar(10)'),
19461946
status = bg.value('(process/@status)[1]', 'nvarchar(10)'),
19471947
priority = bg.value('(process/@priority)[1]', 'integer'),

sp_QuickieStore/sp_QuickieStore.sql

Lines changed: 74 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4102,19 +4102,21 @@ BEGIN
41024102
/* Choose appropriate string split function based on data type */
41034103
IF @data_type = N'bigint'
41044104
BEGIN
4105-
SELECT @split_sql = @string_split_ints;
4105+
SELECT
4106+
@split_sql = @string_split_ints;
41064107
END
41074108
ELSE
41084109
BEGIN
4109-
SELECT @split_sql = @string_split_strings;
4110+
SELECT
4111+
@split_sql = @string_split_strings;
41104112
END;
41114113

41124114
/* Execute the initial insert with troubleshooting if enabled */
41134115
IF @troubleshoot_performance = 1
41144116
BEGIN
41154117
EXECUTE sys.sp_executesql
41164118
@troubleshoot_insert,
4117-
N'@current_table nvarchar(100)',
4119+
N'@current_table nvarchar(100)',
41184120
@current_table;
41194121

41204122
SET STATISTICS XML ON;
@@ -4131,9 +4133,14 @@ BEGIN
41314133
N')
41324134
EXECUTE sys.sp_executesql
41334135
@split_sql,
4134-
N''@ids nvarchar(4000)'',
4136+
N''@ids nvarchar(4000)'',
41354137
@param_value;';
41364138

4139+
IF @debug = 1
4140+
BEGIN
4141+
PRINT @dynamic_sql;
4142+
END;
4143+
41374144
EXEC sys.sp_executesql
41384145
@dynamic_sql,
41394146
N'@split_sql nvarchar(max),
@@ -4147,7 +4154,7 @@ BEGIN
41474154

41484155
EXECUTE sys.sp_executesql
41494156
@troubleshoot_update,
4150-
N'@current_table nvarchar(100)',
4157+
N'@current_table nvarchar(100)',
41514158
@current_table;
41524159

41534160
EXECUTE sys.sp_executesql
@@ -4168,7 +4175,9 @@ BEGIN
41684175
IF @param_name = 'include_query_ids'
41694176
OR @param_name = 'ignore_query_ids'
41704177
BEGIN
4171-
SELECT @secondary_sql = N'
4178+
SET @secondary_sql = @isolation_level;
4179+
4180+
SELECT @secondary_sql += N'
41724181
SELECT DISTINCT
41734182
qsp.plan_id
41744183
FROM ' + @database_name_quoted + N'.sys.query_store_plan AS qsp
@@ -4188,10 +4197,13 @@ BEGIN
41884197
OPTION(RECOMPILE);' + @nc10;
41894198
END;
41904199
ELSE
4200+
41914201
IF @param_name = 'include_query_hashes'
41924202
OR @param_name = 'ignore_query_hashes'
41934203
BEGIN
4194-
SELECT @secondary_sql = N'
4204+
SET @secondary_sql = @isolation_level;
4205+
4206+
SELECT @secondary_sql += N'
41954207
SELECT DISTINCT
41964208
qsp.plan_id
41974209
FROM ' + @database_name_quoted + N'.sys.query_store_plan AS qsp
@@ -4218,10 +4230,13 @@ BEGIN
42184230
OPTION(RECOMPILE);' + @nc10;
42194231
END;
42204232
ELSE
4233+
42214234
IF @param_name = 'include_plan_hashes'
42224235
OR @param_name = 'ignore_plan_hashes'
42234236
BEGIN
4224-
SELECT @secondary_sql = N'
4237+
SET @secondary_sql = @isolation_level;
4238+
4239+
SELECT @secondary_sql += N'
42254240
SELECT DISTINCT
42264241
qsp.plan_id
42274242
FROM ' + @database_name_quoted + N'.sys.query_store_plan AS qsp
@@ -4240,11 +4255,13 @@ BEGIN
42404255
OPTION(RECOMPILE);' + @nc10;
42414256
END;
42424257
ELSE
4243-
IF
4244-
@param_name = 'include_sql_handles'
4258+
4259+
IF @param_name = 'include_sql_handles'
42454260
OR @param_name = 'ignore_sql_handles'
42464261
BEGIN
4247-
SELECT @secondary_sql = N'
4262+
SET @secondary_sql = @isolation_level;
4263+
4264+
SELECT @secondary_sql += N'
42484265
SELECT DISTINCT
42494266
qsp.plan_id
42504267
FROM ' + @database_name_quoted + N'.sys.query_store_plan AS qsp
@@ -4284,40 +4301,67 @@ BEGIN
42844301
BEGIN
42854302
EXECUTE sys.sp_executesql
42864303
@troubleshoot_insert,
4287-
N'@current_table nvarchar(100)',
4304+
N'@current_table nvarchar(100)',
42884305
@current_table;
42894306

42904307
SET STATISTICS XML ON;
42914308
END;
42924309

4293-
INSERT INTO
4294-
#include_plan_ids
4295-
WITH
4296-
(TABLOCK)
4297-
(
4298-
plan_id
4299-
)
4300-
EXECUTE sys.sp_executesql
4301-
@secondary_sql;
4310+
IF @debug = 1
4311+
BEGIN
4312+
PRINT @secondary_sql;
4313+
END;
4314+
4315+
/* Insert into the correct target table based on include/ignore */
4316+
IF @is_include = 1
4317+
BEGIN
4318+
INSERT INTO
4319+
#include_plan_ids
4320+
WITH
4321+
(TABLOCK)
4322+
(
4323+
plan_id
4324+
)
4325+
EXECUTE sys.sp_executesql
4326+
@secondary_sql;
4327+
END
4328+
ELSE
4329+
BEGIN
4330+
INSERT INTO
4331+
#ignore_plan_ids
4332+
WITH
4333+
(TABLOCK)
4334+
(
4335+
plan_id
4336+
)
4337+
EXECUTE sys.sp_executesql
4338+
@secondary_sql;
4339+
END;
43024340

43034341
IF @troubleshoot_performance = 1
43044342
BEGIN
43054343
SET STATISTICS XML OFF;
43064344

43074345
EXECUTE sys.sp_executesql
43084346
@troubleshoot_update,
4309-
N'@current_table nvarchar(100)',
4347+
N'@current_table nvarchar(100)',
43104348
@current_table;
43114349

43124350
EXECUTE sys.sp_executesql
43134351
@troubleshoot_info,
4314-
N'@sql nvarchar(max), @current_table nvarchar(100)',
4352+
N'@sql nvarchar(max), @current_table nvarchar(100)',
43154353
@secondary_sql,
43164354
@current_table;
43174355
END;
43184356
END;
4357+
END;
43194358

4320-
/* Update where clause if needed */
4359+
/* Update where clause based on parameter type */
4360+
IF @param_name = 'include_plan_ids'
4361+
OR @param_name = 'ignore_plan_ids'
4362+
OR @requires_secondary_processing = 1
4363+
BEGIN
4364+
/* Choose the correct table and exists/not exists operator */
43214365
SELECT
43224366
@temp_target_table =
43234367
CASE
@@ -4332,6 +4376,7 @@ BEGIN
43324376
ELSE N'NOT EXISTS'
43334377
END;
43344378

4379+
/* Add the filter condition to the where clause */
43354380
SELECT
43364381
@where_clause +=
43374382
N'AND ' +
@@ -4343,6 +4388,11 @@ BEGIN
43434388
FROM ' + @temp_target_table + N' AS idi
43444389
WHERE idi.plan_id = qsrs.plan_id
43454390
)' + @nc10;
4391+
4392+
IF @debug = 1
4393+
BEGIN
4394+
PRINT @where_clause;
4395+
END;
43464396
END;
43474397

43484398
FETCH NEXT

0 commit comments

Comments
 (0)