Skip to content

Commit 40ef60c

Browse files
committed
#3680 sp_BlitzIndex stats sampling
Continued work on #3680. Moves 200-priority down to Mode 4, throws error if they pass in an invalid stats sampling rate.
1 parent f8300d4 commit 40ef60c

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

sp_BlitzIndex.sql

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ BEGIN
175175
RETURN;
176176
END;
177177

178+
IF(@UsualStatisticsSamplingPercent <= 0 OR @UsualStatisticsSamplingPercent > 100)
179+
BEGIN
180+
RAISERROR('Invalid value for parameter @UsualStatisticsSamplingPercent. Expected: 1 to 100',12,1);
181+
RETURN;
182+
END;
183+
178184
IF(@OutputType = 'TABLE' AND NOT (@OutputTableName IS NULL AND @OutputSchemaName IS NULL AND @OutputDatabaseName IS NULL AND @OutputServerName IS NULL))
179185
BEGIN
180186
RAISERROR(N'One or more output parameters specified in combination with TABLE output, changing to NONE output mode', 0,1) WITH NOWAIT;
@@ -4555,26 +4561,6 @@ BEGIN
45554561
)
45564562
OPTION ( RECOMPILE );
45574563

4558-
RAISERROR(N'check_id 126: Persisted Sampling Rates (Expected)', 0,1) WITH NOWAIT;
4559-
INSERT #BlitzIndexResults ( check_id, Priority, findings_group, finding, [database_name], URL, details, index_definition,
4560-
secret_columns, index_usage_summary, index_size_summary )
4561-
SELECT 126 AS check_id,
4562-
200 AS Priority,
4563-
'Statistics Warnings' AS findings_group,
4564-
'Persisted Sampling Rates (Expected)',
4565-
s.database_name,
4566-
'https://www.youtube.com/watch?v=V5illj_KOJg&t=758s' AS URL,
4567-
CONVERT(NVARCHAR(100), COUNT(*)) + ' statistic(s) with a persisted sample rate matching your desired persisted sample rate, ' + CONVERT(NVARCHAR(100), @UsualStatisticsSamplingPercent) + N'%. Set @UsualStatisticsSamplingPercent to NULL if you want to see all of them in this result set. Its default value is 100.' AS details,
4568-
s.database_name + N' (Entire database)' AS index_definition,
4569-
'N/A' AS secret_columns,
4570-
'N/A' AS index_usage_summary,
4571-
'N/A' AS index_size_summary
4572-
FROM #Statistics AS s
4573-
WHERE ABS(@UsualStatisticsSamplingPercent - s.persisted_sample_percent) <= 0.1
4574-
AND @UsualStatisticsSamplingPercent IS NOT NULL
4575-
GROUP BY s.database_name
4576-
OPTION ( RECOMPILE );
4577-
45784564
RAISERROR(N'check_id 92: Statistics with NO RECOMPUTE', 0,1) WITH NOWAIT;
45794565
INSERT #BlitzIndexResults ( check_id, Priority, findings_group, finding, [database_name], URL, details, index_definition,
45804566
secret_columns, index_usage_summary, index_size_summary )
@@ -5666,6 +5652,28 @@ BEGIN
56665652

56675653

56685654

5655+
RAISERROR(N'check_id 126: Persisted Sampling Rates (Expected)', 0,1) WITH NOWAIT;
5656+
INSERT #BlitzIndexResults ( check_id, Priority, findings_group, finding, [database_name], URL, details, index_definition,
5657+
secret_columns, index_usage_summary, index_size_summary )
5658+
SELECT 126 AS check_id,
5659+
200 AS Priority,
5660+
'Statistics Warnings' AS findings_group,
5661+
'Persisted Sampling Rates (Expected)',
5662+
s.database_name,
5663+
'https://www.youtube.com/watch?v=V5illj_KOJg&t=758s' AS URL,
5664+
CONVERT(NVARCHAR(100), COUNT(*)) + ' statistic(s) with a persisted sample rate matching your desired persisted sample rate, ' + CONVERT(NVARCHAR(100), @UsualStatisticsSamplingPercent) + N'%. Set @UsualStatisticsSamplingPercent to NULL if you want to see all of them in this result set. Its default value is 100.' AS details,
5665+
s.database_name + N' (Entire database)' AS index_definition,
5666+
'N/A' AS secret_columns,
5667+
'N/A' AS index_usage_summary,
5668+
'N/A' AS index_size_summary
5669+
FROM #Statistics AS s
5670+
WHERE ABS(@UsualStatisticsSamplingPercent - s.persisted_sample_percent) <= 0.1
5671+
AND @UsualStatisticsSamplingPercent IS NOT NULL
5672+
GROUP BY s.database_name
5673+
OPTION ( RECOMPILE );
5674+
5675+
5676+
56695677
END /* IF @Mode = 4 */
56705678

56715679

0 commit comments

Comments
 (0)