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
22 changes: 22 additions & 0 deletions IndexOptimize.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ ALTER PROCEDURE [dbo].[IndexOptimize]
@StatisticsModificationLevel int = NULL,
@StatisticsSample int = NULL,
@StatisticsResample nvarchar(max) = 'N',
@StatisticsRowsMin int = NULL,
@StatisticsRowsMax int = NULL,
@PartitionLevel nvarchar(max) = 'Y',
@MSShippedObjects nvarchar(max) = 'N',
@Indexes nvarchar(max) = NULL,
Expand Down Expand Up @@ -295,6 +297,8 @@ BEGIN
SET @Parameters += ', @StatisticsModificationLevel = ' + ISNULL(CAST(@StatisticsModificationLevel AS nvarchar),'NULL')
SET @Parameters += ', @StatisticsSample = ' + ISNULL(CAST(@StatisticsSample AS nvarchar),'NULL')
SET @Parameters += ', @StatisticsResample = ' + ISNULL('''' + REPLACE(@StatisticsResample,'''','''''') + '''','NULL')
SET @Parameters += ', @StatisticsRowsMin = ' + ISNULL(CAST(@StatisticsRowsMin AS nvarchar),'NULL')
SET @Parameters += ', @StatisticsRowsMax = ' + ISNULL(CAST(@StatisticsRowsMax AS nvarchar),'NULL')
SET @Parameters += ', @PartitionLevel = ' + ISNULL('''' + REPLACE(@PartitionLevel,'''','''''') + '''','NULL')
SET @Parameters += ', @MSShippedObjects = ' + ISNULL('''' + REPLACE(@MSShippedObjects,'''','''''') + '''','NULL')
SET @Parameters += ', @Indexes = ' + ISNULL('''' + REPLACE(@Indexes,'''','''''') + '''','NULL')
Expand Down Expand Up @@ -942,6 +946,22 @@ BEGIN

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

IF @StatisticsRowsMin < 0
BEGIN
INSERT INTO @Errors ([Message], Severity, [State])
SELECT 'The value for the parameter @StatisticsRowsMin is not supported.', 16, 1
END

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

IF @StatisticsRowsMax < 0
BEGIN
INSERT INTO @Errors ([Message], Severity, [State])
SELECT 'The value for the parameter @StatisticsRowsMax is not supported.', 16, 1
END

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

IF @PartitionLevel NOT IN('Y','N') OR @PartitionLevel IS NULL
BEGIN
INSERT INTO @Errors ([Message], Severity, [State])
Expand Down Expand Up @@ -2016,6 +2036,8 @@ BEGIN
AND ((@UpdateStatistics = 'ALL' AND (@CurrentIndexType IN (1,2,3,4,7) OR @CurrentIndexID IS NULL)) OR (@UpdateStatistics = 'INDEX' AND @CurrentIndexID IS NOT NULL AND @CurrentIndexType IN (1,2,3,4,7)) OR (@UpdateStatistics = 'COLUMNS' AND @CurrentIndexID IS NULL))
AND ((@OnlyModifiedStatistics = 'N' AND @StatisticsModificationLevel IS NULL) OR (@OnlyModifiedStatistics = 'Y' AND @CurrentModificationCounter > 0) OR ((@CurrentModificationCounter * 1. / NULLIF(@CurrentRowCount,0)) * 100 >= @StatisticsModificationLevel) OR (@StatisticsModificationLevel IS NOT NULL AND @CurrentModificationCounter > 0 AND (@CurrentModificationCounter >= SQRT(@CurrentRowCount * 1000))) OR (@CurrentIsMemoryOptimized = 1 AND NOT (@Version >= 13 OR SERVERPROPERTY('EngineEdition') IN (5,8))))
AND ((@CurrentIsPartition = 0 AND (@CurrentAction NOT IN('INDEX_REBUILD_ONLINE','INDEX_REBUILD_OFFLINE') OR @CurrentAction IS NULL)) OR (@CurrentIsPartition = 1 AND (@CurrentPartitionNumber = @CurrentPartitionCount OR (@PartitionLevelStatistics = 1 AND @CurrentIsIncremental = 1))))
AND (@StatisticsRowsMin IS NULL OR (NULLIF(@CurrentRowCount,0) >= @StatisticsRowsMin))
AND (@StatisticsRowsMax IS NULL OR (NULLIF(@CurrentRowCount,0) < @StatisticsRowsMax))
BEGIN
SET @CurrentUpdateStatistics = 'Y'
END
Expand Down