Rebuild also reorgs?

  • Is it safe to say a Rebuild of an index also does a reorg, by default?

  • Technically no, but understand what the two do.

    Reorg shuffles the pages at the leaf level of an index back into order. It doesn't touch the non-leaf levels and it doesn't change what's on the page.

    Rebuild completely drops the old index and creates a new one. It'll try as best it can to put all the pages (leaf and non-leaf) in order and it will recreate all of the pages hence changing the free space on a page and other such things.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Gail

    Although they are not the same, the end result of Rebuild also accomplishes (or includes) what is done through a reorg (rearranging leaf level pages), right?

    Dan

  • Not necessarily. The leaf pages are moved, but not upper level ones. Potentially that means you could have fragmented intermediate pages that don't get cleaned up. I suppose, depending on how leaf levels are moved, anything less than a full rebuild might not clean that up.

  • OK... I'm confused... I thought that one of the major reasons for having a Clustered Index was so that it would reorg the data so that it wasn't fragmented and that a rebuild of the Clustered Index would do everything from defragmentation to "repacking" according to the Fill Factor as well as eliminating page splits... right down to the leaf level...

    --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)

  • repent_kog_is_near (10/25/2009)


    Although they are not the same, the end result of Rebuild also accomplishes (or includes) what is done through a reorg (rearranging leaf level pages), right?

    Both will fix the fragmentation at the leaf level.

    Rebuild will also fix the fragmentation at the non-leaf levels, pack the rows into pages (according to fill factor) and update the index's statistics.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Jeff Moden (10/25/2009)


    OK... I'm confused... I thought that one of the major reasons for having a Clustered Index was so that it would reorg the data so that it wasn't fragmented

    Huh? Don't understand, sorry.

    and that a rebuild of the Clustered Index would do everything from defragmentation to "repacking" according to the Fill Factor as well as eliminating page splits... right down to the leaf level...

    A rebuild will, yes.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • GilaMonster (10/26/2009)


    Jeff Moden (10/25/2009)


    OK... I'm confused... I thought that one of the major reasons for having a Clustered Index was so that it would reorg the data so that it wasn't fragmented

    Huh? Don't understand, sorry.

    and that a rebuild of the Clustered Index would do everything from defragmentation to "repacking" according to the Fill Factor as well as eliminating page splits... right down to the leaf level...

    A rebuild will, yes.

    Ah... never mind... the confusion was all mine. Serious misread on my part.

    --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 8 posts - 1 through 7 (of 7 total)

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