SQL Server - OH Index maintenance duration per index

Check which index’s maintenance is taking most time. Short script to answer this question. It is part of script series related to popular Ola Hallengren’s maintenance solution. If you are using it you should be familiar with CommandLog table in master database. You can find history of operations done over your databases. Unless you explicitly turned logging off using @LogToTable parameter.

Script is only aggregate query over operations tracked in mentioned table. It will give you quick overview what index is enjoying maintenance time the most.

HINT: You can run this query via multi-server query using Registered Servers feature of Management Studio.

SELECT 
	[DatabaseName]
	,[ObjectName]
	,[IndexName]
	,SUM(DATEDIFF(MINUTE, StartTime, EndTime)) AS DurationMinutes
FROM [master].[dbo].[CommandLog]
WHERE -- StartTime BETWEEN '2017-12-29 08:00:00' AND '2017-12-31 12:00:00' AND 
	CommandType = 'ALTER_INDEX'
GROUP BY [DatabaseName], [ObjectName], [IndexName]
ORDER BY SUM(DATEDIFF(MINUTE, StartTime, EndTime)) DESC

Results

Script results screen:

Results screen

Script results detailed description:

Column nameData typeDescription
DatabaseNamesysnameName of the database index is from.
ObjectNamesysnameName of the object index is from. Mostly this will be table name.
IndexNamesysnameIndex name
DurationMinutesintDuration of index maintenance in minutes.

Leave a Reply