SQL2005 Rebuild Index Not Working

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • wackyphill@yahoo.com

    SQL2005 Rebuild Index Not Working

    After rebuilding an index, it still shows as the same amount of
    fragmentation. ANy ideas what's wrong?

    I'm determining which indexes to rebuild using the following query:

    SELECT
    OBJECT_NAME(i.o bject_id) AS TableName,
    i.name AS IndexName,
    ips.avg_fragmen tation_in_perce nt
    FROM sys.dm_db_index _physical_stats (DB_ID(), NULL, NULL, NULL,
    'DETAILED') ips
    JOIN sys.indexes i ON
    i.object_id = ips.object_id
    AND i.index_id = ips.index_id
    WHERE ips.avg_fragmen tation_in_perce nt > 10

    (I know 10% is not enough where a full rebuild is called for, just
    wanted to see my fragmentation)

    Then I rebuild w/:

    ALTER INDEX IX_CustomerName ON Customers REBUILD

    When I rerun the 1st query the same amount of fragmentation is shown
    as before the rebuild. I'd appreciate any help.

  • smithabreddy@gmail.com

    #2
    Re: SQL2005 Rebuild Index Not Working

    Have you checked the fillfactor defined for these indexes?

    (use sys.indexes to get this information)

    wackyphill@yaho o.com wrote:[color=blue]
    > After rebuilding an index, it still shows as the same amount of
    > fragmentation. ANy ideas what's wrong?
    >
    > I'm determining which indexes to rebuild using the following query:
    >
    > SELECT
    > OBJECT_NAME(i.o bject_id) AS TableName,
    > i.name AS IndexName,
    > ips.avg_fragmen tation_in_perce nt
    > FROM sys.dm_db_index _physical_stats (DB_ID(), NULL, NULL, NULL,
    > 'DETAILED') ips
    > JOIN sys.indexes i ON
    > i.object_id = ips.object_id
    > AND i.index_id = ips.index_id
    > WHERE ips.avg_fragmen tation_in_perce nt > 10
    >
    > (I know 10% is not enough where a full rebuild is called for, just
    > wanted to see my fragmentation)
    >
    > Then I rebuild w/:
    >
    > ALTER INDEX IX_CustomerName ON Customers REBUILD
    >
    > When I rerun the 1st query the same amount of fragmentation is shown
    > as before the rebuild. I'd appreciate any help.[/color]

    Comment

    • wackyphill@yahoo.com

      #3
      Re: SQL2005 Rebuild Index Not Working

      The Fill_factor is 0 on all my indexes, however I must admit I don't
      know what fill factor really means.

      Comment

      • smithabreddy@gmail.com

        #4
        Re: SQL2005 Rebuild Index Not Working

        Fill Factor - please look this up in Books online.

        -------[color=blue]
        >From BOL:[/color]
        The fill factor option is provided for fine-tuning index data storage
        and performance. When an index is created or rebuilt, the fill factor
        value determines the percentage of space on each leaf level page to be
        filled with data, therefore reserving a percentage of free space for
        future growth. For example, specifying a fill factor value of 80 means
        that 20 percent of each leaf-level page will be left empty providing
        space for index expansion as data is added to the underlying table.

        The fill factor value is a percentage from 1 to 100. The server-wide
        default of 0 is the optimal choice in the majority of situations. When
        fill factor is set to 0, the leaf level is filled almost to capacity,
        but some space remains for at least one additional index row. With this
        setting, the leaf level space is used efficiently, but room remains for
        limited expansion before the page must be split.

        Note:
        Fill factor values 0 and 100 are the same in all respects.
        -------

        Not sure why the fragmentation still shows the same. After the
        rebuild, can you run the following and the the first SELECT query again
        see if the fragmentation has changed? (This is a very resource
        intensive operation).

        UPDATE STATISTICS Customers WITH FULLSCAN

        wackyphill@yaho o.com wrote:[color=blue]
        > The Fill_factor is 0 on all my indexes, however I must admit I don't
        > know what fill factor really means.[/color]

        Comment

        • wackyphill@yahoo.com

          #5
          Re: SQL2005 Rebuild Index Not Working

          Thanks for the info.

          After running UPDATE STATISTICS.

          I still received the same results from my 1st query (although I noticed
          it took signifigantly longer to run on the 1st attempt after running
          UPDATE STATISTICS.

          I still have an index at 83.333333333333 3 fragmentation. It's wierd.

          Comment

          • Jackie Brophy

            #6
            Re: SQL2005 Rebuild Index Not Working

            Do you have clustered indexes on the tables? They won't be defragmented
            without them.

            Jackie
            <wackyphill@yah oo.com> wrote in message
            news:1149873702 .943298.103510@ u72g2000cwu.goo glegroups.com.. .[color=blue]
            > Thanks for the info.
            >
            > After running UPDATE STATISTICS.
            >
            > I still received the same results from my 1st query (although I noticed
            > it took signifigantly longer to run on the 1st attempt after running
            > UPDATE STATISTICS.
            >
            > I still have an index at 83.333333333333 3 fragmentation. It's wierd.
            >[/color]


            Comment

            • wackyphill@yahoo.com

              #7
              Re: SQL2005 Rebuild Index Not Working

              Every table has a primary key which I believe (correct me if I'm wrong)
              would give them a clustered Index.

              Comment

              • Erland Sommarskog

                #8
                Re: SQL2005 Rebuild Index Not Working

                (wackyphill@yah oo.com) writes:[color=blue]
                > Every table has a primary key which I believe (correct me if I'm wrong)
                > would give them a clustered Index.[/color]

                By default, when you create a primary key, this results in a clustered
                index. However, that does not mean that just because there is a PK,
                that there is a clustered index on the table, as the PK can deliberately
                have been created as non-clustered.

                (And in many cases, clustering on the PK is not the best choice.)

                As for your original question, am I right to suspect that the table
                in question is fairly small? If there is only data for 1½ index page,
                there will be some free space that will look like fragmentation.

                --
                Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.se

                Books Online for SQL Server 2005 at

                Books Online for SQL Server 2000 at

                Comment

                • wackyphill@yahoo.com

                  #9
                  Re: SQL2005 Rebuild Index Not Working

                  I understand your point Erland, but these Primary keys were created w/o
                  specifying that they should be non-clustered, so I'm certain they are.
                  Why is it that w/o a clustered index defragmentation on non-clustered
                  indexes can't occur, or did I misunderstand the previous poster?

                  You are correct that these tables currently are small by most people's
                  standards. I'm guessing that the largest one has < 1000 records. Is it
                  mentioned somewhere in SQL books on-line about free space looking lile
                  fragmentaion, that I can read up on?

                  Also, I'm looking for a good SQL Server 2005 book, if anyone has a
                  recommendation I'd apreciate it. I'm an experienced programmer, but am
                  not an experienced DBA as far as actually creating and managing tables,
                  views, and indexes, etc. inteligently. I've usually just written
                  queries or stored procs that end up getting used in my frontend
                  programs that interact w/ an existing database someone else had
                  created.

                  A book that was more beginner DBA orientated I think would be helpful
                  to me. Thanks for your input everyone.

                  Comment

                  • Erland Sommarskog

                    #10
                    Re: SQL2005 Rebuild Index Not Working

                    (wackyphill@yah oo.com) writes:[color=blue]
                    > I understand your point Erland, but these Primary keys were created w/o
                    > specifying that they should be non-clustered, so I'm certain they are.[/color]

                    You can always use sp_helpindex to find out.
                    [color=blue]
                    > Why is it that w/o a clustered index defragmentation on non-clustered
                    > indexes can't occur, or did I misunderstand the previous poster?[/color]

                    I don't recall exactly what he said, but you can't defragment the data
                    pages without a clustering index. The NC indexes are defragmentable
                    nevertheless.
                    [color=blue]
                    > You are correct that these tables currently are small by most people's
                    > standards. I'm guessing that the largest one has < 1000 records. Is it
                    > mentioned somewhere in SQL books on-line about free space looking lile
                    > fragmentaion, that I can read up on?[/color]

                    Let me put it this way: with tables of that size, there's usually not
                    much reason to worry about fragementation anyway.

                    Fragmentation matters when it results in data being spread out on
                    many extra pages. Say that you have a table with 1 GB of data. If
                    the data pages are only 50% full, the server needs to read 2 GB of
                    disk to scan all data. This can affect the performance of the system.

                    Whether this is spelt out in clear in Books Online, I don't know. But
                    you can read about the physical architecture starting on
                    ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/33572c3b-343d-45aa-bb42-1d31423ae5cc.ht m.


                    --
                    Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.se

                    Books Online for SQL Server 2005 at

                    Books Online for SQL Server 2000 at

                    Comment

                    • wackyphill@yahoo.com

                      #11
                      Re: SQL2005 Rebuild Index Not Working

                      Yeah, I was just testing the rebuild process to see that it was
                      sucessful in correcting fragmentation in the event it became necessary
                      as well as to add the process into a maintenance plan.

                      Hopefully this behavior I'm experiencing is like you said, because of
                      the small amount of data present, as no one else seems to have posted
                      similar problems.

                      Thank you for your assistance. I appreciate you sharing your time and
                      experience.

                      Comment

                      Working...