How to improve the speed of a heavily fragmented table?
We have a SQL 2000 database with several tables. During a day these tables have LOTS of SELECT / UPDATE / INSERT commands. Our system is beginning to be VERY slow so I thought i would investigate why this could be. After a bit of reading i researched into table indexes. Worryingly one of the most searched tables had this DBCC SHOWCONTIG info;
This was AFTER i did a DBCC DBREINDEX on the table, any ideas on how i can improve this?
Microsoft SQL ServerDatabases
Last Comment
ale1981
8/22/2022 - Mon
glumlun
what are the values? are they gnerally strings? if do use ntext as a data type.
ale1981
ASKER
Hi.. the values are generally a mix of char, datetime and integers.
Scott Pletcher
If there is LOTS of modify activity, you will need to decrease the fillfactor (which increases the freespace) on the table. For example:
DBCC DBREINDEX (tableName, '', 65)
That will leave 35% freespace in every block. It will increase the size of the table on disk, and increase the time to do a full scan of the table, but will dramatically speed up modification activities.
It often takes some trial and error to come up with the optimum fillfactor.
Will reducing the fill factor increase or decrease the SELECT speeds?
Scott Pletcher
To check current fillfactor:
SELECT OrigFillFactor
FROM sysindexes
WHERE OBJECT_NAME(id) = 'YourTableName'
AND indid = 1
Depends on how the SELECTs work.
If SELECT pulls a specific matching row from an index, the time should be the same.
If SELECT pulls a range of rows, then it will take longer; the more rows, the longer the increase in time.
ale1981
ASKER
I see, that SELECT command did not return a result for OrigFillFactor?!
SELECT OrigFillFactor
FROM sysindexes
WHERE OBJECT_NAME(id) = 'SOP30200'
AND indid = 1
OK, the table does not have a clus index. Use this to find the other index(es).
SELECT name AS [Name of Index],
CASE indid
WHEN 0 THEN 'Heap (main table, no index)'
WHEN 1 THEN 'Clustered index'
WHEN 255 THEN 'Text/Image data'
ELSE 'Non-clus index' END AS [Type of Index],
OrigFillFactor
FROM sysindexes
WHERE OBJECT_NAME(id) = 'SOP30200'
ale1981
ASKER
Ok, when running that statement i get LOTS of index's, all have a Fill Factor of 90 apart from the first one;
Name of Index Type of Index OrigFillFactor
SOP30200 Heap (main table, no index) 0
Scott Pletcher
90 is the default. I would reduce them to 80 for the next rebuild and see if things improve.
Btw, if you use maintenance plans, make sure the option to change freespace is NOT set on [set that option to: leave original freespace] -- in fact, the automatically change fs option should NEVER, EVER be set on, because it could overwrite tuning done on individual tables. Repeat: NEVER set that option on, and anyone who tells you should do so is WRONG, WRONG and more WRONG.
Defragging a non-clus index will compact only the index itself, not the base table data.
To compress the base table, you must create a *clustered* index. You can do it on the same column(s) as the main non-clus index. Then drop the clus index.
This may take time depending on the size of the table and the number of indexes, because all indexes have to be rebuilt when a clus-index is added or removed.
ale1981
ASKER
Thanks for the info Scott, how would I go about doing that?