Fragmentation Level for HeapsIndex fragmentation increase as more row being deletedSQL Server clustered index high fragmentationDoes index rebuild time depend on the fragmentation level?Would a table benefit if it was a heapIndex rebuild - Not reducing fragmentationOnline & Offline Index RebuildMSSQL: High number of logical reads when inserting into fragmented heapNon-Unique Clustered Indexes AdministrationSQL Server hangs on index rebuild, works well after SQL service restartSQL Staging Tables: Primary Key Clustered or Heap

Does .bashrc contain syntax errors?

In Aliens, how many people were on LV-426 before the Marines arrived​?

Is there a hypothetical scenario that would make Earth uninhabitable for humans, but not for (the majority of) other animals?

Bash - pair each line of file

Can a wizard cast a spell during their first turn of combat if they initiated combat by releasing a readied spell?

Maths symbols and unicode-math input inside siunitx commands

Why is indicated airspeed rather than ground speed used during the takeoff roll?

Matrix using tikz package

Practical application of matrices and determinants

How to generate binary array whose elements with values 1 are randomly drawn

Tikz: place node leftmost of two nodes of different widths

What is the significance behind "40 days" that often appears in the Bible?

How is the partial sum of a geometric sequence calculated?

What exactly term 'companion plants' means?

When to use snap-off blade knife and when to use trapezoid blade knife?

Brake pads destroying wheels

What if (if any) the reason to buy in small local stores?

I got the following comment from a reputed math journal. What does it mean?

Do I need to consider instance restrictions when showing a language is in P?

Suggestions on how to spend Shaabath (constructively) alone

Do native speakers use "ultima" and "proxima" frequently in spoken English?

Can you move over difficult terrain with only 5 feet of movement?

Help rendering a complicated sum/product formula

Knife as defense against stray dogs



Fragmentation Level for Heaps


Index fragmentation increase as more row being deletedSQL Server clustered index high fragmentationDoes index rebuild time depend on the fragmentation level?Would a table benefit if it was a heapIndex rebuild - Not reducing fragmentationOnline & Offline Index RebuildMSSQL: High number of logical reads when inserting into fragmented heapNon-Unique Clustered Indexes AdministrationSQL Server hangs on index rebuild, works well after SQL service restartSQL Staging Tables: Primary Key Clustered or Heap













2















I am currently using scripts provided by Mr. Ola Hallengren for executing maintenance job and of-late I have been noticing that there are many tables (heaps) fragmentation level is alarmingly high and needs to be looked and taken action upon. I checked FAQ at the site and seems his script doesn't support rebuilding heaps. I used below query to find the fragmentation level:



SELECT dbschemas.[name] as 'Schema', 
dbtables.[name] as 'Table',
dbindexes.[name] as 'Index',
indexstats.alloc_unit_type_desc,
indexstats.avg_fragmentation_in_percent,
indexstats.page_count
FROM sys.dm_db_index_physical_stats (DB_ID(), 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() and dbindexes.name is null
ORDER BY page_count desc, indexstats.avg_fragmentation_in_percent desc


My application is supported by vendor and I have been communicating with them to change these heaps to tables and create clustered index however it hasn't yielded any meaningful result yet since they have defined primary key as unique non-clustered index and it is also part of foreign key, so needs to change at many level before doing any change. First of all, it took many days for me to explain the difference between clustered index and primary key with unique index.



I also went through the tweaks suggested by Mr. Brent Ozar for changing the defaults at script provided by Mr. Ola Hallengren for index optimize in order to make it more efficient however I didn't find any details of heap rebuilding.



As per my understanding heap's fragmentation can be handled in two ways as described here:



  1. To create clustered index on table and drop it - This would clear all the fragmentation and also rebuild all non-clustered index however it would be time and I/O consuming.

  2. Rebuilding the heap - This would also clear the fragmentation and rebuild all non-clustered index part of table rebuild.

I can't go for option 1 because I am not aware of columns where clustered index can be created and also this could take longer than option 2.



I am looking for possibility of implementing option 1 in the scripts by Ola Hallengren or alternative method for handling this. Also to add, I would like to rebuild my heaps only when the size of heap is more than 10,000 pages and fragmentation level is more than 80.



I am using Microsoft SQL Server 2014 SP3 Enterprise Edition.



As a DBA - I don't prefer to have heaps in my database however since it is vendor supported application and since they have already defined primary key as unique index and these keys are foreign keys, its very difficult to change them to clustered due to references as well as likeliness of down time.










share|improve this question
























  • You say "I have been noticing that there are many tables (heaps) fragmentation level is alarmingly high and needs to be looked and taken action upon." What issues are you experiencing that make you think it needs attention?

    – SQLRaptor
    6 hours ago











  • @SQLRaptor I was checking those queries which are doing most number of reads operations at my server by running sp_blitzcache with sortorder "reads" and the top few out of 10 queries were concerning heaps having very high fragmentation ratio and this was the case for more than one database.

    – Learning_DBAdmin
    5 hours ago















2















I am currently using scripts provided by Mr. Ola Hallengren for executing maintenance job and of-late I have been noticing that there are many tables (heaps) fragmentation level is alarmingly high and needs to be looked and taken action upon. I checked FAQ at the site and seems his script doesn't support rebuilding heaps. I used below query to find the fragmentation level:



SELECT dbschemas.[name] as 'Schema', 
dbtables.[name] as 'Table',
dbindexes.[name] as 'Index',
indexstats.alloc_unit_type_desc,
indexstats.avg_fragmentation_in_percent,
indexstats.page_count
FROM sys.dm_db_index_physical_stats (DB_ID(), 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() and dbindexes.name is null
ORDER BY page_count desc, indexstats.avg_fragmentation_in_percent desc


My application is supported by vendor and I have been communicating with them to change these heaps to tables and create clustered index however it hasn't yielded any meaningful result yet since they have defined primary key as unique non-clustered index and it is also part of foreign key, so needs to change at many level before doing any change. First of all, it took many days for me to explain the difference between clustered index and primary key with unique index.



I also went through the tweaks suggested by Mr. Brent Ozar for changing the defaults at script provided by Mr. Ola Hallengren for index optimize in order to make it more efficient however I didn't find any details of heap rebuilding.



As per my understanding heap's fragmentation can be handled in two ways as described here:



  1. To create clustered index on table and drop it - This would clear all the fragmentation and also rebuild all non-clustered index however it would be time and I/O consuming.

  2. Rebuilding the heap - This would also clear the fragmentation and rebuild all non-clustered index part of table rebuild.

I can't go for option 1 because I am not aware of columns where clustered index can be created and also this could take longer than option 2.



I am looking for possibility of implementing option 1 in the scripts by Ola Hallengren or alternative method for handling this. Also to add, I would like to rebuild my heaps only when the size of heap is more than 10,000 pages and fragmentation level is more than 80.



I am using Microsoft SQL Server 2014 SP3 Enterprise Edition.



As a DBA - I don't prefer to have heaps in my database however since it is vendor supported application and since they have already defined primary key as unique index and these keys are foreign keys, its very difficult to change them to clustered due to references as well as likeliness of down time.










share|improve this question
























  • You say "I have been noticing that there are many tables (heaps) fragmentation level is alarmingly high and needs to be looked and taken action upon." What issues are you experiencing that make you think it needs attention?

    – SQLRaptor
    6 hours ago











  • @SQLRaptor I was checking those queries which are doing most number of reads operations at my server by running sp_blitzcache with sortorder "reads" and the top few out of 10 queries were concerning heaps having very high fragmentation ratio and this was the case for more than one database.

    – Learning_DBAdmin
    5 hours ago













2












2








2








I am currently using scripts provided by Mr. Ola Hallengren for executing maintenance job and of-late I have been noticing that there are many tables (heaps) fragmentation level is alarmingly high and needs to be looked and taken action upon. I checked FAQ at the site and seems his script doesn't support rebuilding heaps. I used below query to find the fragmentation level:



SELECT dbschemas.[name] as 'Schema', 
dbtables.[name] as 'Table',
dbindexes.[name] as 'Index',
indexstats.alloc_unit_type_desc,
indexstats.avg_fragmentation_in_percent,
indexstats.page_count
FROM sys.dm_db_index_physical_stats (DB_ID(), 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() and dbindexes.name is null
ORDER BY page_count desc, indexstats.avg_fragmentation_in_percent desc


My application is supported by vendor and I have been communicating with them to change these heaps to tables and create clustered index however it hasn't yielded any meaningful result yet since they have defined primary key as unique non-clustered index and it is also part of foreign key, so needs to change at many level before doing any change. First of all, it took many days for me to explain the difference between clustered index and primary key with unique index.



I also went through the tweaks suggested by Mr. Brent Ozar for changing the defaults at script provided by Mr. Ola Hallengren for index optimize in order to make it more efficient however I didn't find any details of heap rebuilding.



As per my understanding heap's fragmentation can be handled in two ways as described here:



  1. To create clustered index on table and drop it - This would clear all the fragmentation and also rebuild all non-clustered index however it would be time and I/O consuming.

  2. Rebuilding the heap - This would also clear the fragmentation and rebuild all non-clustered index part of table rebuild.

I can't go for option 1 because I am not aware of columns where clustered index can be created and also this could take longer than option 2.



I am looking for possibility of implementing option 1 in the scripts by Ola Hallengren or alternative method for handling this. Also to add, I would like to rebuild my heaps only when the size of heap is more than 10,000 pages and fragmentation level is more than 80.



I am using Microsoft SQL Server 2014 SP3 Enterprise Edition.



As a DBA - I don't prefer to have heaps in my database however since it is vendor supported application and since they have already defined primary key as unique index and these keys are foreign keys, its very difficult to change them to clustered due to references as well as likeliness of down time.










share|improve this question
















I am currently using scripts provided by Mr. Ola Hallengren for executing maintenance job and of-late I have been noticing that there are many tables (heaps) fragmentation level is alarmingly high and needs to be looked and taken action upon. I checked FAQ at the site and seems his script doesn't support rebuilding heaps. I used below query to find the fragmentation level:



SELECT dbschemas.[name] as 'Schema', 
dbtables.[name] as 'Table',
dbindexes.[name] as 'Index',
indexstats.alloc_unit_type_desc,
indexstats.avg_fragmentation_in_percent,
indexstats.page_count
FROM sys.dm_db_index_physical_stats (DB_ID(), 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() and dbindexes.name is null
ORDER BY page_count desc, indexstats.avg_fragmentation_in_percent desc


My application is supported by vendor and I have been communicating with them to change these heaps to tables and create clustered index however it hasn't yielded any meaningful result yet since they have defined primary key as unique non-clustered index and it is also part of foreign key, so needs to change at many level before doing any change. First of all, it took many days for me to explain the difference between clustered index and primary key with unique index.



I also went through the tweaks suggested by Mr. Brent Ozar for changing the defaults at script provided by Mr. Ola Hallengren for index optimize in order to make it more efficient however I didn't find any details of heap rebuilding.



As per my understanding heap's fragmentation can be handled in two ways as described here:



  1. To create clustered index on table and drop it - This would clear all the fragmentation and also rebuild all non-clustered index however it would be time and I/O consuming.

  2. Rebuilding the heap - This would also clear the fragmentation and rebuild all non-clustered index part of table rebuild.

I can't go for option 1 because I am not aware of columns where clustered index can be created and also this could take longer than option 2.



I am looking for possibility of implementing option 1 in the scripts by Ola Hallengren or alternative method for handling this. Also to add, I would like to rebuild my heaps only when the size of heap is more than 10,000 pages and fragmentation level is more than 80.



I am using Microsoft SQL Server 2014 SP3 Enterprise Edition.



As a DBA - I don't prefer to have heaps in my database however since it is vendor supported application and since they have already defined primary key as unique index and these keys are foreign keys, its very difficult to change them to clustered due to references as well as likeliness of down time.







sql-server sql-server-2014 ola-hallengren fragmentation heap






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago









Paul White

53.1k14283457




53.1k14283457










asked 15 hours ago









Learning_DBAdminLearning_DBAdmin

18311




18311












  • You say "I have been noticing that there are many tables (heaps) fragmentation level is alarmingly high and needs to be looked and taken action upon." What issues are you experiencing that make you think it needs attention?

    – SQLRaptor
    6 hours ago











  • @SQLRaptor I was checking those queries which are doing most number of reads operations at my server by running sp_blitzcache with sortorder "reads" and the top few out of 10 queries were concerning heaps having very high fragmentation ratio and this was the case for more than one database.

    – Learning_DBAdmin
    5 hours ago

















  • You say "I have been noticing that there are many tables (heaps) fragmentation level is alarmingly high and needs to be looked and taken action upon." What issues are you experiencing that make you think it needs attention?

    – SQLRaptor
    6 hours ago











  • @SQLRaptor I was checking those queries which are doing most number of reads operations at my server by running sp_blitzcache with sortorder "reads" and the top few out of 10 queries were concerning heaps having very high fragmentation ratio and this was the case for more than one database.

    – Learning_DBAdmin
    5 hours ago
















You say "I have been noticing that there are many tables (heaps) fragmentation level is alarmingly high and needs to be looked and taken action upon." What issues are you experiencing that make you think it needs attention?

– SQLRaptor
6 hours ago





You say "I have been noticing that there are many tables (heaps) fragmentation level is alarmingly high and needs to be looked and taken action upon." What issues are you experiencing that make you think it needs attention?

– SQLRaptor
6 hours ago













@SQLRaptor I was checking those queries which are doing most number of reads operations at my server by running sp_blitzcache with sortorder "reads" and the top few out of 10 queries were concerning heaps having very high fragmentation ratio and this was the case for more than one database.

– Learning_DBAdmin
5 hours ago





@SQLRaptor I was checking those queries which are doing most number of reads operations at my server by running sp_blitzcache with sortorder "reads" and the top few out of 10 queries were concerning heaps having very high fragmentation ratio and this was the case for more than one database.

– Learning_DBAdmin
5 hours ago










1 Answer
1






active

oldest

votes


















8














Heaps have a few special challenges that you can't experience with clustered indexes:



  • Forwarded Records

  • Captive Pages

I'd suggest running sp_BlitzIndex against your database to find out if either of these things is happening with your Heaps. If not, then leave them alone. If they are, you may need to consider rebuilding them.



At this time, you can't reorganize a Heap table, and rebuilding a Heap table will also rebuild any nonclustered indexes on it. It may be cheaper to drop them, rebuild the Heap table, and then recreate the nonclustered indexes afterwards.



You can read more about this stuff here:



  • sp_BlitzIndex Self Loathing Indexes

  • How To Fix Forwarded Records

  • Mysterious Forwarded Records

  • Forwarded Fetches and Bookmark Lookups





share|improve this answer
























    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%2f232357%2ffragmentation-level-for-heaps%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









    8














    Heaps have a few special challenges that you can't experience with clustered indexes:



    • Forwarded Records

    • Captive Pages

    I'd suggest running sp_BlitzIndex against your database to find out if either of these things is happening with your Heaps. If not, then leave them alone. If they are, you may need to consider rebuilding them.



    At this time, you can't reorganize a Heap table, and rebuilding a Heap table will also rebuild any nonclustered indexes on it. It may be cheaper to drop them, rebuild the Heap table, and then recreate the nonclustered indexes afterwards.



    You can read more about this stuff here:



    • sp_BlitzIndex Self Loathing Indexes

    • How To Fix Forwarded Records

    • Mysterious Forwarded Records

    • Forwarded Fetches and Bookmark Lookups





    share|improve this answer





























      8














      Heaps have a few special challenges that you can't experience with clustered indexes:



      • Forwarded Records

      • Captive Pages

      I'd suggest running sp_BlitzIndex against your database to find out if either of these things is happening with your Heaps. If not, then leave them alone. If they are, you may need to consider rebuilding them.



      At this time, you can't reorganize a Heap table, and rebuilding a Heap table will also rebuild any nonclustered indexes on it. It may be cheaper to drop them, rebuild the Heap table, and then recreate the nonclustered indexes afterwards.



      You can read more about this stuff here:



      • sp_BlitzIndex Self Loathing Indexes

      • How To Fix Forwarded Records

      • Mysterious Forwarded Records

      • Forwarded Fetches and Bookmark Lookups





      share|improve this answer



























        8












        8








        8







        Heaps have a few special challenges that you can't experience with clustered indexes:



        • Forwarded Records

        • Captive Pages

        I'd suggest running sp_BlitzIndex against your database to find out if either of these things is happening with your Heaps. If not, then leave them alone. If they are, you may need to consider rebuilding them.



        At this time, you can't reorganize a Heap table, and rebuilding a Heap table will also rebuild any nonclustered indexes on it. It may be cheaper to drop them, rebuild the Heap table, and then recreate the nonclustered indexes afterwards.



        You can read more about this stuff here:



        • sp_BlitzIndex Self Loathing Indexes

        • How To Fix Forwarded Records

        • Mysterious Forwarded Records

        • Forwarded Fetches and Bookmark Lookups





        share|improve this answer















        Heaps have a few special challenges that you can't experience with clustered indexes:



        • Forwarded Records

        • Captive Pages

        I'd suggest running sp_BlitzIndex against your database to find out if either of these things is happening with your Heaps. If not, then leave them alone. If they are, you may need to consider rebuilding them.



        At this time, you can't reorganize a Heap table, and rebuilding a Heap table will also rebuild any nonclustered indexes on it. It may be cheaper to drop them, rebuild the Heap table, and then recreate the nonclustered indexes afterwards.



        You can read more about this stuff here:



        • sp_BlitzIndex Self Loathing Indexes

        • How To Fix Forwarded Records

        • Mysterious Forwarded Records

        • Forwarded Fetches and Bookmark Lookups






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 2 hours ago









        Joe Obbish

        21.4k33187




        21.4k33187










        answered 11 hours ago









        Erik DarlingErik Darling

        21.6k1267108




        21.6k1267108



























            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%2f232357%2ffragmentation-level-for-heaps%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

            How to create a command for the “strange m” symbol in latex? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)How do you make your own symbol when Detexify fails?Writing bold small caps with mathpazo packageplus-minus symbol with parenthesis around the minus signGreek character in Beamer document titleHow to create dashed right arrow over symbol?Currency symbol: Turkish LiraDouble prec as a single symbol?Plus Sign Too Big; How to Call adfbullet?Is there a TeX macro for three-legged pi?How do I get my integral-like symbol to align like the integral?How to selectively substitute a letter with another symbol representing the same letterHow do I generate a less than symbol and vertical bar that are the same height?

            Category:Tremithousa Media in category "Tremithousa"Navigation menuUpload media34° 49′ 02.7″ N, 32° 26′ 37.32″ EOpenStreetMapGoogle EarthProximityramaReasonatorScholiaStatisticsWikiShootMe

            Dokschytsy (Steed) Kwelen | NawigatsjuunBelarus: Vitebsk Region, citypopulation.de