Skip to content

Commit

Permalink
Merge pull request #186 from erikdarlingdata/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
erikdarlingdata authored Oct 21, 2022
2 parents 4b7cf31 + 52652d9 commit c18643f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 19 deletions.
4 changes: 2 additions & 2 deletions ClearTokenPerm/ClearTokenPerm Agent Job.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BEGIN TRANSACTION;
DECLARE
@ReturnCode int = 0,
@jobId binary(16),
@active_start_date datetime = GETDATE();
@active_start_date int = (SELECT CONVERT(int, CONVERT(varchar(35), GETDATE(), 112)));

IF NOT EXISTS
(
Expand Down Expand Up @@ -115,4 +115,4 @@ QuitWithRollback:
ROLLBACK TRANSACTION;

EndSave:
GO
GO
5 changes: 5 additions & 0 deletions sp_QuickieStore/Examples.sql
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ EXEC dbo.sp_QuickieStore
@top = 10,
@duration_ms = 10000;

/*Search for queries with a specific execution type*/
EXEC dbo.sp_QuickieStore
@database_name = 'StackOverflow2013',
@top = 10,
@execution_type_desc = 'aborted';

/*Search for a specific stored procedure*/
EXEC dbo.sp_QuickieStore
Expand Down
58 changes: 41 additions & 17 deletions sp_QuickieStore/sp_QuickieStore.sql
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ CREATE OR ALTER PROCEDURE
@start_date datetime = NULL,
@end_date datetime = NULL,
@execution_count bigint = NULL,
@duration_ms bigint = NULL ,
@duration_ms bigint = NULL,
@execution_type_desc nvarchar(60) = NULL,
@procedure_schema sysname = NULL,
@procedure_name sysname = NULL,
@include_plan_ids nvarchar(4000) = NULL,
Expand Down Expand Up @@ -149,6 +150,7 @@ BEGIN
WHEN '@end_date' THEN 'the end date of your search'
WHEN '@execution_count' THEN 'the minimum number of executions a query must have'
WHEN '@duration_ms' THEN 'the minimum duration a query must have'
WHEN '@execution_type_desc' THEN 'the type of execution you want to filter'
WHEN '@procedure_schema' THEN 'the schema of the procedure you''re searching for'
WHEN '@procedure_name' THEN 'the name of the programmable object you''re searching for'
WHEN '@include_plan_ids' THEN 'a list of plan ids to search for'
Expand Down Expand Up @@ -181,6 +183,7 @@ BEGIN
WHEN '@end_date' THEN 'January 1, 1753, through December 31, 9999'
WHEN '@execution_count' THEN 'a positive integer between 1 and 9,223,372,036,854,775,807'
WHEN '@duration_ms' THEN 'a positive integer between 1 and 9,223,372,036,854,775,807'
WHEN '@execution_type_desc' THEN 'regular, aborted, exception'
WHEN '@procedure_schema' THEN 'a valid schema in your database'
WHEN '@procedure_name' THEN 'a valid programmable object in your database'
WHEN '@include_plan_ids' THEN 'a string; comma separated for multiple ids'
Expand Down Expand Up @@ -213,6 +216,7 @@ BEGIN
WHEN '@end_date' THEN 'NULL'
WHEN '@execution_count' THEN 'NULL'
WHEN '@duration_ms' THEN 'NULL'
WHEN '@execution_type_desc' THEN 'NULL'
WHEN '@procedure_schema' THEN 'NULL; dbo if NULL and procedure name is not NULL'
WHEN '@procedure_name' THEN 'NULL'
WHEN '@include_plan_ids' THEN 'NULL'
Expand Down Expand Up @@ -1065,7 +1069,8 @@ SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;',
@start_date datetime,
@end_date datetime,
@execution_count bigint,
@duration_ms bigint',
@duration_ms bigint,
@execution_type_desc nvarchar(60)',
@plans_top =
CASE
WHEN @include_plan_ids IS NULL
Expand Down Expand Up @@ -1648,19 +1653,27 @@ OPTION(RECOMPILE);
/*
See if AGs are a thing so we can skip the checks for replica stuff
*/
SELECT
@ags_present =
CASE
WHEN EXISTS
(
SELECT
1/0
FROM sys.availability_groups AS ag
)
THEN 1
ELSE 0
END
OPTION(RECOMPILE);
IF (@azure = 1)
BEGIN
SELECT
@ags_present = 0
END
ELSE
BEGIN
SELECT
@ags_present =
CASE
WHEN EXISTS
(
SELECT
1/0
FROM sys.availability_groups AS ag
)
THEN 1
ELSE 0
END
OPTION(RECOMPILE);
END

/*
Get filters ready, or whatever
Expand Down Expand Up @@ -1697,6 +1710,13 @@ BEGIN
@where_clause += N'AND qsrs.avg_duration >= (@duration_ms * 1000.)' + @nc10;
END;

IF @execution_type_desc IS NOT NULL
BEGIN
SELECT
@where_clause += N'AND qsrs.execution_type_desc = @execution_type_desc' + @nc10;
END;


/*
In this section we set up the filter if someone's searching for
a single stored procedure in Query Store.
Expand Down Expand Up @@ -3051,7 +3071,8 @@ EXEC sys.sp_executesql
@start_date,
@end_date,
@execution_count,
@duration_ms;
@duration_ms,
@execution_type_desc;

IF @troubleshoot_performance = 1
BEGIN
Expand Down Expand Up @@ -3233,7 +3254,8 @@ EXEC sys.sp_executesql
@start_date,
@end_date,
@execution_count,
@duration_ms;
@duration_ms,
@execution_type_desc;

IF @troubleshoot_performance = 1
BEGIN
Expand Down Expand Up @@ -6367,6 +6389,8 @@ BEGIN
@execution_count,
duration_ms =
@duration_ms,
execution_type_desc =
@execution_type_desc,
procedure_schema =
@procedure_schema,
procedure_name =
Expand Down

0 comments on commit c18643f

Please sign in to comment.