The execution plan is useful. You can add index’s on at anytime during the day, I dont bother with downtime as the system will build and just not use it until it’s done. You may need to clear your query cache. Which Version of SQL are you on and are you using the Legacy Cardinal Estimator?
I did a writeup and a thread somewhere that goes though some of the settings to apply to SQL to help with performace.
FYI below is what we use as a weekly main script. It’s basically the default MS SQL Server 2005 one (still the best scripti for the job
) passed though AI for any improvements.
USE Epicor10Live; --change this to you epicor database
SET NOCOUNT ON;
SET XACT_ABORT ON;
RAISERROR(‘=========================================’,0,1) WITH NOWAIT;
RAISERROR(‘WEEKEND MAINTENANCE STARTED’,0,1) WITH NOWAIT;
RAISERROR(‘=========================================’,0,1) WITH NOWAIT;
– CHECKDB (PHYSICAL ONLY)
RAISERROR(‘Running CHECKDB (PHYSICAL_ONLY)…’,0,1) WITH NOWAIT;
–DBCC CHECKDB WITH PHYSICAL_ONLY, NO_INFOMSGS;
RAISERROR(‘CHECKDB complete.’,0,1) WITH NOWAIT;
– Capture Fragmentation (>10%)
IF OBJECT_ID(‘tempdb..#frag’) IS NOT NULL DROP TABLE #frag;
SELECT
OBJECT_SCHEMA_NAME(ps.object_id) AS SchemaName,
OBJECT_NAME(ps.object_id) AS TableName,
i.name AS IndexName,
ps.avg_fragmentation_in_percent,
ps.page_count
INTO #frag
FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, ‘LIMITED’) ps
JOIN sys.indexes i
ON ps.object_id = i.object_id
AND ps.index_id = i.index_id
WHERE
ps.index_id > 0
AND ps.page_count > 1000
AND ps.avg_fragmentation_in_percent > 10;
– Rebuild
DECLARE @Schema sysname,
@Table sysname,
@Index sysname,
@sql nvarchar(max);
DECLARE rebuild_cursor CURSOR FOR
SELECT SchemaName, TableName, IndexName
FROM #frag;
OPEN rebuild_cursor;
FETCH NEXT FROM rebuild_cursor INTO @Schema, @Table, @Index;
WHILE @@FETCH_STATUS = 0
BEGIN
RAISERROR(‘Rebuilding %s.%s (%s)…’,0,1,@Schema,@Table,@Index) WITH NOWAIT;
SET @sql = '
ALTER INDEX [' + @Index + '] ON [' + @Schema + '].[' + @Table + ']
REBUILD WITH (SORT_IN_TEMPDB = ON, MAXDOP = 8);
';
EXEC(@sql);
FETCH NEXT FROM rebuild_cursor INTO @Schema, @Table, @Index;
END
CLOSE rebuild_cursor;
DEALLOCATE rebuild_cursor;
RAISERROR(‘Index rebuild phase complete.’,0,1) WITH NOWAIT;
– FULLSCAN Statistics
RAISERROR(‘Updating statistics WITH FULLSCAN…’,0,1) WITH NOWAIT;
DECLARE @tbl nvarchar(500);
DECLARE stats_cursor CURSOR FOR
SELECT QUOTENAME(SCHEMA_NAME(schema_id)) + ‘.’ + QUOTENAME(name)
FROM sys.tables
WHERE is_ms_shipped = 0;
OPEN stats_cursor;
FETCH NEXT FROM stats_cursor INTO @tbl;
WHILE @@FETCH_STATUS = 0
BEGIN
RAISERROR(‘Updating stats on %s…’,0,1,@tbl) WITH NOWAIT;
EXEC(‘UPDATE STATISTICS ’ + @tbl + ’ WITH FULLSCAN;’);
FETCH NEXT FROM stats_cursor INTO @tbl;
END
CLOSE stats_cursor;
DEALLOCATE stats_cursor;
RAISERROR(‘=========================================’,0,1) WITH NOWAIT;
RAISERROR(‘WEEKEND MAINTENANCE COMPLETE’,0,1) WITH NOWAIT;
RAISERROR(‘=========================================’,0,1) WITH NOWAIT;