Hello Dynamics365 Rocker,
I hope you are well.
Review the index fragmentation level for Case entity.
-- Ensure a USE statement has been executed first.
USE AdventureWorks
GO
-- Look at the Index Information
SELECT
DB_NAME(idxst.database_id) AS [database_name],
OBJECT_NAME(idxst.object_id, idxst.database_id) AS [object_name],
QUOTENAME(idxif.name) [index_name],
CASE
WHEN avg_fragmentation_in_percent < 10 THEN 'LOW'
WHEN avg_fragmentation_in_percent < 30 THEN 'MEDIUM'
WHEN avg_fragmentation_in_percent < 50 THEN 'HIGH'
ELSE 'EXTREME'
END as fragmentation_indicator,
idxst.*
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL , 'LIMITED') AS idxst -- not using DETAILED or SAMPLED
INNER JOIN sys.indexes idxif ON idxst.object_id = idxif.object_id AND idxst.index_id = idxif.index_id
ORDER BY [object_name], [index_name]
GO
-- Look at the usage of the indexes within all tables
SELECT ops.database_id, ops.index_id,
DB_NAME(ops.database_id) AS database_name, OBJECT_NAME(ops.object_id, database_id) AS tableview_name, idx.[name] as index_name,
ops.range_scan_count, ops.singleton_lookup_count, ops.row_lock_count, ops.page_lock_count
FROM sys.dm_db_index_operational_stats(DB_ID(), NULL, NULL, NULL) AS ops
RIGHT JOIN sys.indexes AS idx ON ops.object_id = idx.object_id and ops.index_id = idx.index_id
WHERE ops.database_id = DB_ID() AND ops.object_id > 100
ORDER BY ops.range_scan_count ASC, ops.row_lock_count DESC, ops.page_lock_count DESC
GO
If you have high levels of fragmentation, please, apply script to rebuild/reorganize them.
SET NOCOUNT ON;
DECLARE @objectid int;
DECLARE @indexid int;
DECLARE @partitioncount bigint;
DECLARE @schemaname nvarchar(130);
DECLARE @objectname nvarchar(130);
DECLARE @indexname nvarchar(130);
DECLARE @partitionnum bigint;
DECLARE @partitions bigint;
DECLARE @frag float;
DECLARE @command nvarchar(4000);
SELECT
object_id AS objectid,
index_id AS indexid,
partition_number AS partitionnum,
avg_fragmentation_in_percent AS frag
INTO #work_to_do
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL , NULL, 'LIMITED')
WHERE avg_fragmentation_in_percent > 10.0 AND index_id > 0;
DECLARE partitions CURSOR FOR SELECT * FROM #work_to_do;
OPEN partitions;
WHILE (1=1)
BEGIN;
FETCH NEXT
FROM partitions
INTO @objectid, @indexid, @partitionnum, @frag;
IF @@FETCH_STATUS < 0 BREAK;
SELECT @objectname = QUOTENAME(o.name), @schemaname = QUOTENAME(s.name)
FROM sys.objects AS o
JOIN sys.schemas as s ON s.schema_id = o.schema_id
WHERE o.object_id = @objectid;
SELECT @indexname = QUOTENAME(name)
FROM sys.indexes
WHERE object_id = @objectid AND index_id = @indexid;
SELECT @partitioncount = count (*)
FROM sys.partitions
WHERE object_id = @objectid AND index_id = @indexid;
IF @frag < 30.0
SET @command = N'ALTER INDEX ' @indexname N' ON ' @schemaname N'.' @objectname
N' REORGANIZE';
IF @frag >= 30.0
SET @command = N'ALTER INDEX ' @indexname N' ON ' @schemaname N'.' @objectname
N' REBUILD';
IF @partitioncount > 1
SET @command = @command N' PARTITION=' CAST(@partitionnum AS nvarchar(10));
EXEC (@command);
PRINT N'Executed: ' @command;
END;
CLOSE partitions;
DEALLOCATE partitions;
DROP TABLE #work_to_do;
GO
Moreover, apply script to update statistics.
exec sp_MSForEachTable "UPDATE STATISTICS ? with fullscan"
Finally, as the issue is happening on specific timeframe, I would say to validate the Maintenance Jobs schedule.