I run the Ola Hallengren scripts on all of my servers for index and statistics maintenance. When I look through the command log table, I notice long periods of time between a command ending, and the next command starting. Sometimes this gap is over an hour.
Does anyone else observe this on their systems? Is there something I can do to shorten the (I'm guessing) discovery time between items to maintain? Below is the parameter set I'm running them with.
sqlcmd -E -S $(ESCAPE_SQUOTE(SRVR)) -d master -Q "EXECUTE [dbo].[IndexOptimize]
@Databases = 'USER_DATABASES',
@LogToTable = 'Y',
@FragmentationLow = NULL,
@FragmentationMedium = 'INDEX_REORGANIZE,INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE',
@FragmentationHigh = 'INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE',
@FragmentationLevel1 = 50,
@FragmentationLevel2 = 80,
@UpdateStatistics = 'ALL',
@OnlyModifiedStatistics = 'Y' " -b
So when I run this:
SELECT DATEDIFF(MINUTE, cl.StartTime, cl.EndTime)
, *
FROM master.dbo.CommandLog AS cl
WHERE cl.StartTime > '2014-12-13'
ORDER BY cl.ID
I see this:
Best Answer
The root cause is the DMF
sys.dm_db_index_physical_stats
in conjunction with the Scanning Modes and heaps.(My emphasis on the LIMITED portions of the original description)
Reference: sys.dm_db_index_physical_stats (Transact-SQL) | Scanning Modes (Microsoft Docs)
Even if Ola's script is executing the
sys.dm_db_index_physical_stats
inLIMITED
mode, depending on the amount of data, it can take a long time to scan a very large heap. And because you are using@UpdateStatistics = 'ALL'
you are telling the script to update all the statistics (INDEX
andCOLUMN
) which will include statistics on heap columns.Possible Solution
You might want to consider not updating the statistics on all objects, but instead limiting the scope to
INDEX
or then consider changing the following parameter:the default is
N
Reference: SQL Server Index and Statistics Maintenance (ola.hallengren.com)