Table Fragmentation Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)How to identify fragmentation level of the table data itself not the table indexes, and then defragInnoDB, Hash Table, Reference Table and FragmentationMeasure fragmentation of a single index?SQL Server Index, difference between Average fragmentation and Total fragmentationWhat is Heap Fragmentation sans Indexes?Index with high fragmentation percentageDeleting data from a table containing LOBs did not reduce the amount of data reported INTERNALLY by the table or databaseFragmentation of indexes with small a databaseTable and Index fragmentationFragmentation Level for Heaps

Strange behavior of Object.defineProperty() in JavaScript

Random body shuffle every night—can we still function?

The Nth Gryphon Number

Getting prompted for verification code but where do I put it in?

Deconstruction is ambiguous

If Windows 7 doesn't support WSL, then what is "Subsystem for UNIX-based Applications"?

Can the Flaming Sphere spell be rammed into multiple Tiny creatures that are in the same 5-foot square?

Why can't I install Tomboy in Ubuntu Mate 19.04?

Is there any word for a place full of confusion?

A term for a woman complaining about things/begging in a cute/childish way

Is there public access to the Meteor Crater in Arizona?

Is CEO the "profession" with the most psychopaths?

What does 丫 mean? 丫是什么意思?

Is there hard evidence that the grant peer review system performs significantly better than random?

What do you call the main part of a joke?

What's the point of the test set?

What is the chair depicted in Cesare Maccari's 1889 painting "Cicerone denuncia Catilina"?

Flash light on something

Tannaka duality for semisimple groups

Why are my pictures showing a dark band on one edge?

Did any compiler fully use 80-bit floating point?

How often does castling occur in grandmaster games?

Do wooden building fires get hotter than 600°C?

How does Belgium enforce obligatory attendance in elections?



Table Fragmentation



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)How to identify fragmentation level of the table data itself not the table indexes, and then defragInnoDB, Hash Table, Reference Table and FragmentationMeasure fragmentation of a single index?SQL Server Index, difference between Average fragmentation and Total fragmentationWhat is Heap Fragmentation sans Indexes?Index with high fragmentation percentageDeleting data from a table containing LOBs did not reduce the amount of data reported INTERNALLY by the table or databaseFragmentation of indexes with small a databaseTable and Index fragmentationFragmentation Level for Heaps



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















If I execute the following:



SELECT dbschemas.[name] as 'Schema', 
dbtables.[name] as 'Table',
dbindexes.[name] as 'Index',
indexstats.alloc_unit_type_desc,
indexstats.avg_fragmentation_in_percent as avg,
indexstats.page_count
FROM sys.dm_db_index_physical_stats (DB_ID('dbname'), NULL, NULL, NULL, NULL) AS indexstats
INNER JOIN sys.tables dbtables on dbtables.[object_id] = indexstats.[object_id]
INNER JOIN sys.schemas dbschemas on dbtables.[schema_id] = dbschemas.[schema_id]
INNER JOIN sys.indexes AS dbindexes ON dbindexes.[object_id] = indexstats.[object_id]
AND indexstats.index_id = dbindexes.index_id
WHERE indexstats.database_id = DB_ID('dbname')
ORDER BY indexstats.avg_fragmentation_in_percent desc


It shows fragmentation level. I then ran Ola Hallengren's index optimise script which obviously reduces indexes.



If I run the query again it now shows high fragmentation in tables without an index e.g:



Schema Table Index alloc_unit_type_desc avg page_cont
dbo tablename NULL IN_ROW_DATA 99.4362934362934 8176


Should I be concerned by these?



Anything I can do?



Anything I should be doing?



We are experiencing performance issues. I am aware that 2008 is not ideal and that is being addressed.



The datafile is also showing as 220gb but the actual space used is 140gb.










share|improve this question



















  • 3





    "Performance issues" is a huge area. Maybe you can pinpoint a specific query or table that's the problem and troubleshoot it. If it's the heap, then consider adding a clustered index in accordance to the queries and operations in which it's involved.

    – EzLo
    Apr 11 at 11:37











  • I recently had a case with a heap with lots and lots of empty space. Only some 6000 rows and a simple SELECT * without WHERE took several minutes. The problem was humongous amount of empty space. This is one of the downsides you can encounter with heaps. I just created a clustered index (on a suitable column) and all was normal.

    – Tibor Karaszi
    Apr 12 at 6:40

















2















If I execute the following:



SELECT dbschemas.[name] as 'Schema', 
dbtables.[name] as 'Table',
dbindexes.[name] as 'Index',
indexstats.alloc_unit_type_desc,
indexstats.avg_fragmentation_in_percent as avg,
indexstats.page_count
FROM sys.dm_db_index_physical_stats (DB_ID('dbname'), NULL, NULL, NULL, NULL) AS indexstats
INNER JOIN sys.tables dbtables on dbtables.[object_id] = indexstats.[object_id]
INNER JOIN sys.schemas dbschemas on dbtables.[schema_id] = dbschemas.[schema_id]
INNER JOIN sys.indexes AS dbindexes ON dbindexes.[object_id] = indexstats.[object_id]
AND indexstats.index_id = dbindexes.index_id
WHERE indexstats.database_id = DB_ID('dbname')
ORDER BY indexstats.avg_fragmentation_in_percent desc


It shows fragmentation level. I then ran Ola Hallengren's index optimise script which obviously reduces indexes.



If I run the query again it now shows high fragmentation in tables without an index e.g:



Schema Table Index alloc_unit_type_desc avg page_cont
dbo tablename NULL IN_ROW_DATA 99.4362934362934 8176


Should I be concerned by these?



Anything I can do?



Anything I should be doing?



We are experiencing performance issues. I am aware that 2008 is not ideal and that is being addressed.



The datafile is also showing as 220gb but the actual space used is 140gb.










share|improve this question



















  • 3





    "Performance issues" is a huge area. Maybe you can pinpoint a specific query or table that's the problem and troubleshoot it. If it's the heap, then consider adding a clustered index in accordance to the queries and operations in which it's involved.

    – EzLo
    Apr 11 at 11:37











  • I recently had a case with a heap with lots and lots of empty space. Only some 6000 rows and a simple SELECT * without WHERE took several minutes. The problem was humongous amount of empty space. This is one of the downsides you can encounter with heaps. I just created a clustered index (on a suitable column) and all was normal.

    – Tibor Karaszi
    Apr 12 at 6:40













2












2








2


0






If I execute the following:



SELECT dbschemas.[name] as 'Schema', 
dbtables.[name] as 'Table',
dbindexes.[name] as 'Index',
indexstats.alloc_unit_type_desc,
indexstats.avg_fragmentation_in_percent as avg,
indexstats.page_count
FROM sys.dm_db_index_physical_stats (DB_ID('dbname'), NULL, NULL, NULL, NULL) AS indexstats
INNER JOIN sys.tables dbtables on dbtables.[object_id] = indexstats.[object_id]
INNER JOIN sys.schemas dbschemas on dbtables.[schema_id] = dbschemas.[schema_id]
INNER JOIN sys.indexes AS dbindexes ON dbindexes.[object_id] = indexstats.[object_id]
AND indexstats.index_id = dbindexes.index_id
WHERE indexstats.database_id = DB_ID('dbname')
ORDER BY indexstats.avg_fragmentation_in_percent desc


It shows fragmentation level. I then ran Ola Hallengren's index optimise script which obviously reduces indexes.



If I run the query again it now shows high fragmentation in tables without an index e.g:



Schema Table Index alloc_unit_type_desc avg page_cont
dbo tablename NULL IN_ROW_DATA 99.4362934362934 8176


Should I be concerned by these?



Anything I can do?



Anything I should be doing?



We are experiencing performance issues. I am aware that 2008 is not ideal and that is being addressed.



The datafile is also showing as 220gb but the actual space used is 140gb.










share|improve this question
















If I execute the following:



SELECT dbschemas.[name] as 'Schema', 
dbtables.[name] as 'Table',
dbindexes.[name] as 'Index',
indexstats.alloc_unit_type_desc,
indexstats.avg_fragmentation_in_percent as avg,
indexstats.page_count
FROM sys.dm_db_index_physical_stats (DB_ID('dbname'), NULL, NULL, NULL, NULL) AS indexstats
INNER JOIN sys.tables dbtables on dbtables.[object_id] = indexstats.[object_id]
INNER JOIN sys.schemas dbschemas on dbtables.[schema_id] = dbschemas.[schema_id]
INNER JOIN sys.indexes AS dbindexes ON dbindexes.[object_id] = indexstats.[object_id]
AND indexstats.index_id = dbindexes.index_id
WHERE indexstats.database_id = DB_ID('dbname')
ORDER BY indexstats.avg_fragmentation_in_percent desc


It shows fragmentation level. I then ran Ola Hallengren's index optimise script which obviously reduces indexes.



If I run the query again it now shows high fragmentation in tables without an index e.g:



Schema Table Index alloc_unit_type_desc avg page_cont
dbo tablename NULL IN_ROW_DATA 99.4362934362934 8176


Should I be concerned by these?



Anything I can do?



Anything I should be doing?



We are experiencing performance issues. I am aware that 2008 is not ideal and that is being addressed.



The datafile is also showing as 220gb but the actual space used is 140gb.







sql-server sql-server-2008 ola-hallengren fragmentation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 11 at 21:34









Paul White

54.3k14288461




54.3k14288461










asked Apr 11 at 11:06









RoundRound

203




203







  • 3





    "Performance issues" is a huge area. Maybe you can pinpoint a specific query or table that's the problem and troubleshoot it. If it's the heap, then consider adding a clustered index in accordance to the queries and operations in which it's involved.

    – EzLo
    Apr 11 at 11:37











  • I recently had a case with a heap with lots and lots of empty space. Only some 6000 rows and a simple SELECT * without WHERE took several minutes. The problem was humongous amount of empty space. This is one of the downsides you can encounter with heaps. I just created a clustered index (on a suitable column) and all was normal.

    – Tibor Karaszi
    Apr 12 at 6:40












  • 3





    "Performance issues" is a huge area. Maybe you can pinpoint a specific query or table that's the problem and troubleshoot it. If it's the heap, then consider adding a clustered index in accordance to the queries and operations in which it's involved.

    – EzLo
    Apr 11 at 11:37











  • I recently had a case with a heap with lots and lots of empty space. Only some 6000 rows and a simple SELECT * without WHERE took several minutes. The problem was humongous amount of empty space. This is one of the downsides you can encounter with heaps. I just created a clustered index (on a suitable column) and all was normal.

    – Tibor Karaszi
    Apr 12 at 6:40







3




3





"Performance issues" is a huge area. Maybe you can pinpoint a specific query or table that's the problem and troubleshoot it. If it's the heap, then consider adding a clustered index in accordance to the queries and operations in which it's involved.

– EzLo
Apr 11 at 11:37





"Performance issues" is a huge area. Maybe you can pinpoint a specific query or table that's the problem and troubleshoot it. If it's the heap, then consider adding a clustered index in accordance to the queries and operations in which it's involved.

– EzLo
Apr 11 at 11:37













I recently had a case with a heap with lots and lots of empty space. Only some 6000 rows and a simple SELECT * without WHERE took several minutes. The problem was humongous amount of empty space. This is one of the downsides you can encounter with heaps. I just created a clustered index (on a suitable column) and all was normal.

– Tibor Karaszi
Apr 12 at 6:40





I recently had a case with a heap with lots and lots of empty space. Only some 6000 rows and a simple SELECT * without WHERE took several minutes. The problem was humongous amount of empty space. This is one of the downsides you can encounter with heaps. I just created a clustered index (on a suitable column) and all was normal.

– Tibor Karaszi
Apr 12 at 6:40










1 Answer
1






active

oldest

votes


















7














Ola Hallengren's index optimize script does not perform Heap defragmentation.



In other words table rebuilds are not happening when running the procedure and that is expected.



You could run ALTER TABLE dbo.tablename REBUILD;
to remove the fragmentation.



This also rebuilds the nonclustered indexes on the heap.



Better option than rebuilding your heap tables



You do have to ask yourself or the application team why you can't add a clustered index to the table.
as rebuilding the heap uses a lot of resources and is a temporary solution.



If you add a clustered index, that index is included in the Index Optimize script, and fragmentation will be removed when the script runs.



Another option is to add the clustered index and stop worrying about index fragmentation.





We are experiencing performance issues. I am aware that 2008 is not
ideal and that is being addressed.




It could be that it is because of the forwarded records in the heap tables, but at 8167 pages I would say that that is not likely. A starting point could be looking at the queries being executed on your server.



SP_BlitzCache can help with finding your worst performing queries.





The datafile is also showing as 220gb but the actual space used is
140gb.




This should not be a problem. Apart from disk space you should not be too worried. You are not relying on autogrowth, which is a good thing.






share|improve this answer




















  • 1





    Alter table <table> REBUILD is supported in SQL Server 2008 onwards so you can do that to rebuild the heap. Tibor Karaszi has a script here: karaszi.com/rebuild-all-fragmented-heaps that is of great help

    – Spörri
    Apr 11 at 16:11











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "182"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f234551%2ftable-fragmentation%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









7














Ola Hallengren's index optimize script does not perform Heap defragmentation.



In other words table rebuilds are not happening when running the procedure and that is expected.



You could run ALTER TABLE dbo.tablename REBUILD;
to remove the fragmentation.



This also rebuilds the nonclustered indexes on the heap.



Better option than rebuilding your heap tables



You do have to ask yourself or the application team why you can't add a clustered index to the table.
as rebuilding the heap uses a lot of resources and is a temporary solution.



If you add a clustered index, that index is included in the Index Optimize script, and fragmentation will be removed when the script runs.



Another option is to add the clustered index and stop worrying about index fragmentation.





We are experiencing performance issues. I am aware that 2008 is not
ideal and that is being addressed.




It could be that it is because of the forwarded records in the heap tables, but at 8167 pages I would say that that is not likely. A starting point could be looking at the queries being executed on your server.



SP_BlitzCache can help with finding your worst performing queries.





The datafile is also showing as 220gb but the actual space used is
140gb.




This should not be a problem. Apart from disk space you should not be too worried. You are not relying on autogrowth, which is a good thing.






share|improve this answer




















  • 1





    Alter table <table> REBUILD is supported in SQL Server 2008 onwards so you can do that to rebuild the heap. Tibor Karaszi has a script here: karaszi.com/rebuild-all-fragmented-heaps that is of great help

    – Spörri
    Apr 11 at 16:11















7














Ola Hallengren's index optimize script does not perform Heap defragmentation.



In other words table rebuilds are not happening when running the procedure and that is expected.



You could run ALTER TABLE dbo.tablename REBUILD;
to remove the fragmentation.



This also rebuilds the nonclustered indexes on the heap.



Better option than rebuilding your heap tables



You do have to ask yourself or the application team why you can't add a clustered index to the table.
as rebuilding the heap uses a lot of resources and is a temporary solution.



If you add a clustered index, that index is included in the Index Optimize script, and fragmentation will be removed when the script runs.



Another option is to add the clustered index and stop worrying about index fragmentation.





We are experiencing performance issues. I am aware that 2008 is not
ideal and that is being addressed.




It could be that it is because of the forwarded records in the heap tables, but at 8167 pages I would say that that is not likely. A starting point could be looking at the queries being executed on your server.



SP_BlitzCache can help with finding your worst performing queries.





The datafile is also showing as 220gb but the actual space used is
140gb.




This should not be a problem. Apart from disk space you should not be too worried. You are not relying on autogrowth, which is a good thing.






share|improve this answer




















  • 1





    Alter table <table> REBUILD is supported in SQL Server 2008 onwards so you can do that to rebuild the heap. Tibor Karaszi has a script here: karaszi.com/rebuild-all-fragmented-heaps that is of great help

    – Spörri
    Apr 11 at 16:11













7












7








7







Ola Hallengren's index optimize script does not perform Heap defragmentation.



In other words table rebuilds are not happening when running the procedure and that is expected.



You could run ALTER TABLE dbo.tablename REBUILD;
to remove the fragmentation.



This also rebuilds the nonclustered indexes on the heap.



Better option than rebuilding your heap tables



You do have to ask yourself or the application team why you can't add a clustered index to the table.
as rebuilding the heap uses a lot of resources and is a temporary solution.



If you add a clustered index, that index is included in the Index Optimize script, and fragmentation will be removed when the script runs.



Another option is to add the clustered index and stop worrying about index fragmentation.





We are experiencing performance issues. I am aware that 2008 is not
ideal and that is being addressed.




It could be that it is because of the forwarded records in the heap tables, but at 8167 pages I would say that that is not likely. A starting point could be looking at the queries being executed on your server.



SP_BlitzCache can help with finding your worst performing queries.





The datafile is also showing as 220gb but the actual space used is
140gb.




This should not be a problem. Apart from disk space you should not be too worried. You are not relying on autogrowth, which is a good thing.






share|improve this answer















Ola Hallengren's index optimize script does not perform Heap defragmentation.



In other words table rebuilds are not happening when running the procedure and that is expected.



You could run ALTER TABLE dbo.tablename REBUILD;
to remove the fragmentation.



This also rebuilds the nonclustered indexes on the heap.



Better option than rebuilding your heap tables



You do have to ask yourself or the application team why you can't add a clustered index to the table.
as rebuilding the heap uses a lot of resources and is a temporary solution.



If you add a clustered index, that index is included in the Index Optimize script, and fragmentation will be removed when the script runs.



Another option is to add the clustered index and stop worrying about index fragmentation.





We are experiencing performance issues. I am aware that 2008 is not
ideal and that is being addressed.




It could be that it is because of the forwarded records in the heap tables, but at 8167 pages I would say that that is not likely. A starting point could be looking at the queries being executed on your server.



SP_BlitzCache can help with finding your worst performing queries.





The datafile is also showing as 220gb but the actual space used is
140gb.




This should not be a problem. Apart from disk space you should not be too worried. You are not relying on autogrowth, which is a good thing.







share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 11 at 11:51

























answered Apr 11 at 11:27









Randi VertongenRandi Vertongen

5,0711924




5,0711924







  • 1





    Alter table <table> REBUILD is supported in SQL Server 2008 onwards so you can do that to rebuild the heap. Tibor Karaszi has a script here: karaszi.com/rebuild-all-fragmented-heaps that is of great help

    – Spörri
    Apr 11 at 16:11












  • 1





    Alter table <table> REBUILD is supported in SQL Server 2008 onwards so you can do that to rebuild the heap. Tibor Karaszi has a script here: karaszi.com/rebuild-all-fragmented-heaps that is of great help

    – Spörri
    Apr 11 at 16:11







1




1





Alter table <table> REBUILD is supported in SQL Server 2008 onwards so you can do that to rebuild the heap. Tibor Karaszi has a script here: karaszi.com/rebuild-all-fragmented-heaps that is of great help

– Spörri
Apr 11 at 16:11





Alter table <table> REBUILD is supported in SQL Server 2008 onwards so you can do that to rebuild the heap. Tibor Karaszi has a script here: karaszi.com/rebuild-all-fragmented-heaps that is of great help

– Spörri
Apr 11 at 16:11

















draft saved

draft discarded
















































Thanks for contributing an answer to Database Administrators Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f234551%2ftable-fragmentation%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

រឿង រ៉ូមេអូ និង ហ្ស៊ុយលីយេ សង្ខេបរឿង តួអង្គ បញ្ជីណែនាំ

Crop image to path created in TikZ? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Crop an inserted image?TikZ pictures does not appear in posterImage behind and beyond crop marks?Tikz picture as large as possible on A4 PageTransparency vs image compression dilemmaHow to crop background from image automatically?Image does not cropTikzexternal capturing crop marks when externalizing pgfplots?How to include image path that contains a dollar signCrop image with left size given

QGIS export composer to PDF scale the map [closed] Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Print Composer QGIS 2.6, how to export image?QGIS 2.8.1 print composer won't export all OpenCycleMap base layer tilesSave Print/Map QGIS composer view as PNG/PDF using Python (without changing anything in visible layout)?Export QGIS Print Composer PDF with searchable text labelsQGIS Print Composer does not change from landscape to portrait orientation?How can I avoid map size and scale changes in print composer?Fuzzy PDF export in QGIS running on macSierra OSExport the legend into its 100% size using Print ComposerScale-dependent rendering in QGIS PDF output