Heap rebuilds

  • Hi All,

    We are seeing heavy fragmentation 99% with page count more than 10000 pages.

    So, rebuilding those HEAP Tables using ALTER table tname REBUILD command.

    My question is, if I have 100 such tables which of the below 2 would perform better in terms of performance (time, transaction log management etc..)

    Database is in FULL recovery model. SQL Server 2012 Enterprise Edition.

    ALTER TABLE T1 REBUILD;

    ALTER TABLE T2 REBUILD;

    ALTER TABLE T3 REBUILD;

    ALTER TABLE T4 REBUILD;

    :

    ALTER TABLE T100 REBUILD;

    ------------- [OR]-----------------

    ALTER TABLE T1 REBUILD;

    GO

    ALTER TABLE T2 REBUILD;

    GO

    ALTER TABLE T3 REBUILD;

    GO

    ALTER TABLE T4 REBUILD;

    GO

    :

    ALTER TABLE T100 REBUILD;

    GO

    Thanks,

    Sam

  • Thanks for posting your issue and hopefully someone will answer soon.

    This is an automated bump to increase visibility of your question.

  • To answer your question, there will be no difference in performance or resource usage.  The only difference is that the first rendition could be created as a stored procedure and the second cannot because of the "GO" batch separators.

    Shifting gears a bit, the real key here is to figure out why you have so much fragmentation and fix it especially on HEAPs and CLUSTERED INDEXes.  Such massive fragmentation on HEAPs is normally due to ExpAnsive Updates.  On Clustered Indexes, such massive fragmentation is usually caused by ExpAnsive Updates and/or Out-of-Order Inserts.

    Another key is to determine if the 99% fragmentation is actually causing you performance issues.  For mostly single row lookups, logical fragmentation just won't matter.  You also need to look at what people refer to as "Physical Fragmentation", which is a misnomer for "Page Density" because it can be a VERY big deal in the form of totally wasted memory and disk space.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply