The target version is SQL SERVER 2019
The Ola Hallengren script's
EXECUTE dbo.IndexOptimize
@Databases = 'SYSTEM_DATABASES',
@FragmentationLow = NULL,
@FragmentationMedium = NULL,
@FragmentationHigh = NULL,
@UpdateStatistics = 'ALL',
@OnlyModifiedStatistics = 'N',
@StatisticsSample = 100
It doesn't seem to update statistics (user tables) in system databases. The workaround is to run the script :
https://www.dbdelta.com/sql-server-system-table-statistics-update/
USE msdb ; USE Master, and so on.
DECLARE @alenzi nvarchar(MAX) =
(
SELECT
STRING_AGG(
N'UPDATE STATISTICS '
+ QUOTENAME(OBJECT_SCHEMA_NAME(i.object_id))
+ N'.'
+ QUOTENAME(OBJECT_NAME(i.object_id))
,';')
FROM sys.indexes AS I
JOIN sys.partitions AS p ON
p.object_id = i.object_id
AND p.index_id = i.index_id
WHERE
OBJECTPROPERTYEX(i.object_id, 'IsSystemTable') = 0
AND i.index_id > 0
AND p.rows > 0
);
EXEC sp_executesql @alenzi ;
GO
Just a few lines. If Ola is correct, you may consider that it isn't good to touch system databases in production. So instead, let SQL servers manage the system databases completely. However, if you find an odd behavior like a very slow DMV that you suspect is related to outdated statistics in system tables, then consider this script.