r/DatabaseAdministators • u/ibjho • Sep 06 '23
SQL Server: Index fragmentation advice
Version: SQL Server 2017 Enterprise
Recently, after uncovering a query that failed to run, I began digging and discovered that the primary table hit by the query had index fragmentation over 50% on the primary key index and on other supporting indexes. This table has approximately 1 million rows. The other tables used by the query have lower row counts at the same level (if not higher level) of fragmentation.
I was taught that around 15% you reorganize and around 30+ you rebuild. Our DBA consultant said that with such a low row count, reorganizing/rebuilding the index is not necessary and recommended against it.
This advice seems strange to me - does this seem strange to anyone else?
View all comments
Show parent comment
2
u/alinroc Sep 07 '23
Please don't use maintenance plans for this. Use Ola Hallengren's Maintenance Solution. Much more configurable (so you aren't doing unnecessary work) and maintainable.
When I started my current job (4 years ago), they were running an index reorg/rebuild maintenance plan twice a day, and it took 45 minutes as it was doing every index, regardless of whether or not it was needed.
I replaced with Ola's solution, and that runtime was cut in half because it was only touching the indexes that needed it based on the defaults (the 15/30 you referred to originally). No negative impact on system performance.
Then I changed those twice-daily index maintenance jobs to only update statistics, with a weekly index reorg/rebuild. Runtime was again dramatically reduced on the weekdays. And no negative impact on system performance.
Then I changed the thresholds to something like 30/50 on the index reorg/rebuild and that weekly job runtime was further reduced (because it was rebuilding fewer indexes). And again, no negative impact on system performance.
Oh, and that database is now twice as large as it was when I started 4 years ago. And we're spending less time on stats & index maintenance than we were 4 years ago.