November 17, 2023 at 8:46 am
I have a table where over 50% has unused space
How can I reclaim this space back? Index maintenance?
November 17, 2023 at 9:06 am
You should be asking "why has this table 50% unused space" ?
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
November 17, 2023 at 1:47 pm
Could the way data is inserted into the table increase the unused space?
November 17, 2023 at 2:36 pm
yes, if it is causing page splits
( check clustered index, sort according to clustered index of possible )
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
November 19, 2023 at 9:40 pm
If the clustered index has an ever increasing key and the inserts are following that key, you won't get page splits. If, however, the inserts are followed by "ExpAnsive" Updates, you're guaranteed to get page splits and fragmentation and low page densities.
The key to us helping here is that we'd need to see the CREATE TABLE statement, including all of the indexes involved and then an example of what the inserts look like (being sure to NOT post any PII or other sensitive information).
Also, doing index maintenance to recover the disk space will only recover the disk space... it will NOT help you prevent the fragmentation all by itself. You've got to figure out WHY it is fragmenting. The info I asked for above can help a lot there.
I'll also state that "Index" maintenance will do absolutely nothing if this "table" is actually a "HEAP" (a table with no clustered index). You would have to do an ALTER TABLE REBUILD instead. The problem there is that it will also rebuild all non-clustered indexes on the HEAP because the RIDs (row IDs) of every row in the HEAP are included in every non-clustered index. Unless you have FK's pointing at the table, it would be better to first disable all the NCIs (non-clustered indexes), rebuild the HEAP, and then REBUILD all the NCI's to re-enable them.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 19, 2023 at 10:21 pm
Have you tried rebuilding the clustered index?
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply