Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions IndexOptimize.sql
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ BEGIN

----------------------------------------------------------------------------------------------------

IF @StatisticsSample <= 0 OR @StatisticsSample > 100
IF @StatisticsSample <= -2 OR @StatisticsSample > 100
BEGIN
INSERT INTO @Errors ([Message], Severity, [State])
SELECT 'The value for the parameter @StatisticsSample is not supported.', 16, 1
Expand Down Expand Up @@ -2194,7 +2194,21 @@ BEGIN
SELECT 'FULLSCAN'
END

IF @CurrentStatisticsSample IS NOT NULL AND @CurrentStatisticsSample <> 100
IF @CurrentStatisticsSample IS NOT NULL AND @CurrentStatisticsSample = -1
BEGIN
INSERT INTO @CurrentUpdateStatisticsWithClauseArguments (Argument)
SELECT 'SAMPLE ' + CASE
WHEN @CurrentRowCount < 500000 THEN '100 PERCENT'
WHEN @CurrentRowCount < 1000000 THEN '50 PERCENT'
WHEN @CurrentRowCount < 5000000 THEN '25 PERCENT'
WHEN @CurrentRowCount < 10000000 THEN '10 PERCENT'
WHEN @CurrentRowCount < 50000000 THEN '2 PERCENT'
WHEN @CurrentRowCount < 100000000 THEN '1 PERCENT'
ELSE '3000000 ROWS '
END
END

IF @CurrentStatisticsSample IS NOT NULL AND @CurrentStatisticsSample BETWEEN 0 AND 99
BEGIN
INSERT INTO @CurrentUpdateStatisticsWithClauseArguments (Argument)
SELECT 'SAMPLE ' + CAST(@CurrentStatisticsSample AS nvarchar) + ' PERCENT'
Expand Down