Fragmented SQL indexes can cause of number of issues in a GlobalSearch database, including:
- Searching index values is slow or unresponsive.
- Inability to Add/Edit Fields.
- Opening a document is slow.
- Results not displaying in GlobalSearch.
The following scripts can be used to identify and defragment any SQL indexes that might be causing database slowdown. This script can be put into a batch file and run as a scheduled task, run manually or as a stored procedure.
It is highly recommended to take backups before performing any SQL operations. Failure to perform proper backups may result in permanent data loss.
Identifying Fragmented Index Script
The above script will return a table-set of indexes and list their row count and average fragmentation. Any fragmented indexes with over 15% fragmentation will appear here. Don’t be scared if you see some high numbers – sometimes tables with only a couple hundred rows can return high fragmentation. This shouldn’t be considered too problematic. If however, you see indexes with thousands of rows coming back as highly fragmented (50% or higher) it may be worth running a defragmentation. To do that, you can run the script below:
The following script loops through the tables using a SQL cursor to rebuild the indexes, reducing the fragmentation on affected tables.
The following script may cause SQL performance degradation. Consider running when the server is not in use.
After running this script, it is recommended you run the "Identifying Fragmented Index Script" once again to see if you’ve lessened the fragmentation. Continue to do this until you see fragmentation go away entirely or until larger indexes are showing minimal fragmentation. It may never completely go away, but lessening index fragmentation can definitely help speed up a database and make things run a little smoother.