Index Reorganize (2)

Hi All,
I was on a long vacation so couldn't post my comments for my previous query. Today i checked and could see lot of replies and arguments over the issue. And before i could reach to a conclusion the thread has been locked i guess and i'm not able to comment. So, i'm posting this new thread.
After giving just a single read to most of the replies(not all, coz some of those were deleted i guess), i was not able to decide what is the exact answer to my question.
You guys are Experts and i can count on you to give me what i need or atleast show me the right direction. It's been less than an year since i'm working in this Real-World environment.
So, i would request you all to give a me a clear answer(approach) for my query:
"How can i check for indexes that are more than 15% fragmented in my 9.2.0.8 DB?"
Thanks and Regards,
Nick.

two comments
1) the benefits of re-organization generally require justification
2) you haven't defined what you mean by 15% fragmented.
Google tells me that I wrote the following in response to an advocate of rebuilding who regularly rebuilds indexes and will likely have his own script as an answer to your query.
>
Nick's already received adequate answers to his query in the form of the queries that detect indexes that are significantly larger than they should be. He's also been told that a simple rule of thumb like '15% of index entries are for deleted rows' is inappropriate. In addition I'm not the one advocating rebuilding according to formulae, or who claims to rebuild thousands of indexes without issue. I'd have thought that the self proclaimed expert who delights in advocating rebuilding would be a more likely candidate for being in a position to share with us their rules for index rebuilds.
Personally I think that a query of the form
select (del_lf_rows/lf_rows) from index_stats;post analyze .. validate structure which is probably the closest to Nick's original request, is likely to be only a little better statistically than
select index_name from dba_indexes where uniqueness = 'NON-UNIQUE'
for identifying candidate indexes for rebuilds.
In the end it's all about understanding the data, if we know that that 15% of data has been deleted, and similar values will never again be inserted into the table - and exisiting data will never be updated to similar values, then you've probably got a good candidate for rebuilding, but it isn't the 15% it's the fact that the leaf nodes will not be reused that is important. It's also this, that puts the lie to the idea that 'it follows that a query will detect them', how can a query exist that will tell us what the behaviour of yet to be inserted data will be? Now for what it's worth I don't think it has been shown that most indexes are on columns where data arrives in random order - though many are - I suspect that many are on sequence or date derived columns (or similar data) where indeed it maybe that deleted space (so long as all the old data doesn't get deleted) is not reusable, but it still remains a function of the data that has been deleted and the data that is yet to come.
>
You'll see that I'd identify your candidate indexes by doing analyze index... validate structure; and use averages across the index. I'd also not actually execute any of this unless I was persuaded by other means that I needed to rebuilt on a 'how much free space is there' basis. Incidentally this suggestion got shot down because calculating this stuff is resource intensive, one of my main objections to doing it in the first place.
How to find unexpectedly large indexes is shown at http://www.jlcomp.demon.co.uk/index_efficiency.html and the psoug library.
In summary I'd say
1) why bother, why aren't your deletions going to be reused?
2) if you are bothering it costs, is the cost worth it?
3) why 15% rather than 35%?
Niall
PS: others will advocate frequent rebuilding, I'd pay close attention to the criteria they give you - mostly missing from the debate so far.

Similar Messages

  • Oracle index reorganize architecter

    hi all,
         normaly we all know oracle index rebuild means drop index and created it again. I want to know what is index reorganizeing is? And after index reorganize happpen what is the storage level behind macanisum? And how is that(index reorganize) effected in DB blok, segments ,extentd and table space level?
    Thank you
    Tharindu Dhaneenja

    Dhaneenja wrote:
    hi all,
         normaly we all know oracle index rebuild means drop index and created it again. I want to know what is index reorganizeing is? And after index reorganize happpen what is the storage level behind macanisum? And how is that(index reorganize) effected in DB blok, segments ,extentd and table space level?
    Technically Oracle's rebuild command creates a new copy of the index then drops the old copy. The reason for splitting hairs about this is that Oracle does not have a definition of "reorganizing" an index - so we need to have the context in which you saw the term so that we can decide what the author intended.
    There is a coalesce command that moves index entries from one leaf block to another in order to get some leaf blocks well-packed and make others completely free. Since this is a delete/insert operation it generates a lot of undo and redo.
    There are also two versions of the "shrink" command that play similar games.
    Rebuild, and "shrink space" can result in less space being allocated in the tablespace for the final state of the index; "shrink space compact" and coalesce don't move the index segment at all, and don't free any space back to the tablespace.
    Regards
    Jonathan Lewis

  • What happens inside ...... when fired Index Reorganize

    Hi all,
    what happens inside ...... when fired Index Reorganize
    Thanks
    vijay

    Logical scan fragmentation is removed (where possible). This can improve performance of certain queries, because it reduces the amount of big disk head movements need to go through all the pages.
    In addition to that, it brings the amount of unused space in line with the original fill factor of the index. If you haven't specified any fill factor when the index was first created, then all unused space will be removed (where possible). It does this
    by joining the rows of multiple pages onto fewer pages and releasing the empty pages. This can improve performance of many queries, since fewer I/O and less memory is now needed to access the same amount of row data.
    When the command runs, it will lock just one or a few pages at a time. This way, most blocking is avoided, and any blocking that does occur will be short lived.
    This also means that the reorganization occurs inline, within the pages and extents that are already allocated for the specific index. This is one of the big differences with Reindexing, where new pages (and extents) are allocated.
    Gert-Jan

  • Auto-indexing is slow for arrays with 1 dimensions

    Hi,
    I was looking at the performance of operations on all individual elements in 3D arrays, especially the difference between auto-indexing (left image) and manual-indexing (right image, calling "Index array" and "Replace array subset" in the innermost loop). I'm a bit puzzled by the results and post it here for discussion and hopefully somebody's benefit in the future.
    Left: auto-indexing; right: manual-indexing
    In the tests I added a different random number to all individual elements in a 3D array. I found that auto-indexing is 1.2 to 1.5 times slower than manual-indexing. I also found that the performance of auto-indexing is much more dependent on the size the dimensions: an array with 1000x200x40 elements is 20% slower than an array with 1000x40x200 elements. For manual-indexing there is hardly any difference. The detailed results can be found at the end of this post.
    I was under the impression that auto-indexing was the preferred method for this kind of operation: it achieves exactly the same result and it is much clearer in the block diagram. I also expected that auto-indexing would have been optimized in LabView, but the the tests show this is clearly not the case.
    What is auto-indexing doing?
    With two tests I looked at how auto-index works.
    First, I looked if auto-indexing reorganizes the data in an inefficient way. To do this I made a method "fake-auto-indexing" which calls "Array subset" and "Reshape array" (or "Index array" for a 1D-array) when it enters _every_ loop and calls "Replace array subset" when exiting _every_ loop (as opposed to manual-indexing, where I do this only in the inner loop). I replicated this in a test (calling it fake-auto-indexing) and found that the performance is very similar to auto-indexing, especially looking at the trend for the different array lengths.
    Fake-auto-indexing
    Second, I looked if Locality of reference (how the 3D array is stored in memory and how efficiently you can iterate over that) may be an issue. Auto-indexing loops over pages-rows-columns (i.e. pages in the outer for-loop, rows in the middle for-loop, columns in the inner for-loop). This can't be changed for auto-indexing, but I did change it for manual and fake-indexing. The performance of manual-indexing is now similar to auto-indexing, except for two cases that I can't explain. Fake-auto-indexing performs way worse in all cases.
    It seems that the performance problem with auto-indexing is due to inefficient data organization.
    Other tests
    I did the same tests for 1D and 2D arrays. For 1D arrays the three methods perform identical. For 2D arrays auto-indexing is 15% slower than manual-indexing, while fake-auto-indexing is 8% slower than manual-indexing. I find it interesting that auto-indexing is the slowest of the three methods.
    Finally, I tested the performance of operating on entire columns (instead of every single element) of a 3D array. In all cases it is a lot faster than iterating over individual elements. Auto-indexing is more than 1.8 to 3.4 times slower than manual-indexing, while fake-auto-indexing is about 1.5 to 2.7 times slower. Because of the number of iterations that has to be done, the effect of the size of the column is important: an array with 1000x200x40 elements is in all cases much slower than an array with 1000x40x200 elements.
    Discussion & conclusions
    In all the cases I tested, auto-indexing is significantly slower than manual-indexing. Because auto-indexing is the standard way of indexing arrays in LabView I expected the method to be highly optimized. Judging by the tests I did, that is not the case. I find this puzzling.
    Does anybody know any best practices when it comes to working with >1D arrays? It seems there is a lack of documentation about the performance, surprising given the significant differences I found.
    It is of course possible that I made mistakes. I tried to keep the code as straightforward as possible to minimize that risk. Still, I hope somebody can double-check the work I did.
    Results
    I ran the tests on a computer with a i5-4570 @ 3.20 GHz processor (4 cores, but only 1 is used), 8 GB RAM running Windows 7 64-bit and LabView 2013 32-bit. The tests were averaged 10 times. The results are in milliseconds.
    3D-arrays, iterate pages-rows-columns
    pages x rows x cols : auto    manual  fake
       40 x  200 x 1000 : 268.9   202.0   268.8
       40 x 1000 x  200 : 276.9   204.1   263.8
      200 x   40 x 1000 : 264.6   202.8   260.6
      200 x 1000 x   40 : 306.9   205.0   300.0
     1000 x   40 x  200 : 253.7   203.1   259.3
     1000 x  200 x   40 : 307.2   206.2   288.5
      100 x  100 x  100 :  36.2    25.7    33.9
    3D-arrays, iterate columns-rows-pages
    pages x rows x cols : manual  fake
       40 x  200 x 1000 : 277.6   457       
       40 x 1000 x  200 : 291.6   461.5
      200 x   40 x 1000 : 277.4   431.9
      200 x 1000 x   40 : 452.5   572.1
     1000 x   40 x  200 : 298.1   460.4     
     1000 x  200 x   40 : 460.5   583.8
      100 x  100 x  100 :  31.7    51.9
    2D-arrays, iterate rows-columns
    rows  x cols  : auto     manual   fake
      200 x 20000 :  123.5    106.1    113.2    
    20000 x   200 :  119.5    106.1    115.0    
    10000 x 10000 : 3080.25  2659.65  2835.1
    1D-arrays, iterate over columns
    cols   : auto  manual  fake
    500000 : 11.5  11.8    11.6
    3D-arrays, iterate pages-rows, operate on columns
    pages x rows x cols : auto    manual  fake
       40 x  200 x 1000 :  83.9   23.3     62.9
       40 x 1000 x  200 :  89.6   31.9     69.0     
      200 x   40 x 1000 :  74.3   27.6     62.2
      200 x 1000 x   40 : 135.6   76.2    107.1
     1000 x   40 x  200 :  75.3   31.2     68.6
     1000 x  200 x   40 : 133.6   71.7    108.7     
      100 x  100 x  100 :  13.0    5.4      9.9
    VI's
    I attached the VI's I used for testing. "ND_add_random_number.vi" (where N is 1, 2 or 3) is where all the action happens, taking a selector with a method and an array with the N dimensions as input. It returns the result and time in milliseconds. Using "ND_add_random_number_automated_test.vi" I run this for a few different situations (auto/manual/fake-indexing, interchanging the dimensions). The VI's starting with "3D_locality_" are used for the locality tests. The VI's starting with "3D_norows_" are used for the iterations over pages and columns only.
    Attachments:
    3D_arrays_2.zip ‏222 KB

    Robert,
    the copy-thing is not specific for auto-indexing. It is common for all tunnels. A tunnel is first of all a unique data space.
    This sounds hard, but there is an optimization in the compiler trying to reduce the number of copies the VI will create. This optimization is called "in-placeness".
    The in-placeness algorithm checks, if the wire passing data to the is connected to anything else ("branch"). If there is no other connection then the tunnel, chance is high that the tunnel won't create an additional copy.
    Speaking of loops, tunnels always copies. The in-placeness algorithm cannot opt that out.
    You can do a small test to elaborate on this: Simply wire "0" (or anything less than the array sizy of the input array) to the 'N' terminal.......
    Norbert
    PS: Auto-indexing is perfect for a "by element" operation of analysis without modification of the element in the array. If you want to modify values, use shift registers and Replace Array Subset.
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • Compress Indexes

    I have using the dba cockpit to enable the compression of the "Biggest table" of the SAP Bank Analyzer ( reducing the table from 360GB to 100GB ). This OFFLINE process took 23 hours.
    Please , advise us how to the compress also the INDEXES of the tables.

    Hello Mr. Arun,
    Thanks for contacting us.
    Kindly use the below command to enable the compression on a particular table. But before enabling the compression, make sure that you have executed query given in note 886231 to make sure whether compression is required for this table or not.
    ALTER TABLE <tabname> ACTIVATE VALUE COMPRESSION
    Kindly refer below note
    #1942183 - DB6: When to consider a table or index reorganization
    #975352 - DB6: Configuring DB2 Auto Reorg for Space Reclamation and Index Cleanup
    Hope the above information helps!
    Best Regards,
    Gunjan

  • TUNING  TIP

    제품 : ORACLE SERVER
    작성날짜 : 2002-05-31
    TUNING TIP
    ===========
    PURPOSE
    INDEX RANGE SCAN 을 사용하게 하기 위한 TIP
    Explanation
    index range scan 을 위해 index full scan 이나, fast full index 을 피하는
    방법은 다음과 같습니다.
    먼저 index range scan 보다 index full scan , FFIS 를 선택한 이유는
    index 의 LEAFCNT(leaf block count)전체를 읽는 cost 보다, branch level
    (BLEVEL ) 의 cost, 또는 CLUFAC(clustering factor) 의 cost 가 크다는
    의미입니다.
    근본적인 해결을 위해서는 index 의 height 를 줄이기 위해 db_block_size
    를 늘리거나 , index reorganization 이 필요하며,
    일시적으로 이를 방지하려면 역으로 FFIS 나 full index scan cost 를
    높이기 위해 index cost 를 결정하는 parameter 를 조정합니다.
    -fast_full_scan_enabled =false
    -db_file_multiblock_read_count
    -sort_area_size
    의 값을 작게 조정합니다.
    Example
    Reference Document
    ------------------

    >>
    "Try to avoid large data retrievals, since if the data being retrieved from a table is more than 10%-20% of the total data, Oracle will most likely do the FST."
    >>
    There are sort of myths floating around.
    Remember, FTS is not always as bad nor INDEX SCAN always are good.
    It is not % of data, in fact, it is depends on number blocks the query touching to fetch the data.
    FTS is Full Table Scan - Multi block read - A physical read
    If optimizer things doing multi block read would achive the result faster then it produces FTS plan to retrieve the data.
    Jaffar

  • Shrink Datafiles for database in Avalability Group

    We're running SharePoint 2010 on SQL Server 2012.   We are also using Availability Groups for all databases (Primary and Secondary replica).   I'm running low on space and would like to shrink the datafiles for one of the content
    databases.  The content database has 2 datafiles spread across 2 LUNS.  The SharePoint content database had a run away situation that caused the database to grow very large.  The situation has been corrected and the database now has about 98%
    free space.  The database will not grow much larger than it is now.  I know shrinking datafiles is generally not a good idea, but in the case I think it's appropriate.
    My question is, has anyone done this before on a database/datafiles that are in a High Availability Group?  Are there any risks?  Any recommendations?
    Thanks!

    Hi,
    SharePoint content database is different than the ordinary database . You need to test the effect in the test environment before making the changes to the product environment.
    There is a good article regarding Database Maintenance for SharePoint
    http://technet.microsoft.com/en-us/library/cc262731(v=office.14).aspx#DBMaintenanceForSPS2010_ShrinkingDataFiles
    Only perform shrink operations rarely, and only after you perform an operation that removes a lot of data from a database, and then only when you do not expect to use that free space again.
    Because shrinking causes index fragmentation, do not shrink database files regularly. Instead, shrink database files only in response to large quantities of unused space that appear as a result of operations that significantly impact the
    relative amount of used space in a database. If at all possible, avoid shrinking a database.
    However, if you must shrink a database, use the following guidelines:
    •Do not auto-shrink databases or configure a maintenance plan that programmatically shrinks your databases.
    •Shrink a database only when users or administrators remove 50% or more of the content and you do not expect to reuse the unused space.
    •Shrink only content databases. Users and administrators do not delete enough data from the configuration database, Central Administration content database, and various service application
    databases to contain significant free space.
    •Shrinking databases is an extremely resource-intensive operation. Therefore, if you absolutely must shrink a database, carefully consider when you schedule the shrink operation.
    •After you shrink a database, the indexes in that database are fragmented. Use ALTER INDEX… REORGANIZE to address the fragmentation. If you are not configured to allow instant file initialization,
    shrink the database to a target size that accommodates the size required for the near-term growth that you expect. For more information, see
    Database File Initialization.
    Thanks.
    Tracy Cai
    TechNet Community Support

  • Manual Maintenance Plan

    Hi All,
    Using SQL Server 2008 R2 in multiple servers.
    1. Any script (links) for creating a manual maintenance plan? I would like to manually run the script for some databases in multiple servers.
    2. It is a way to collect the statistics before and after the maintenance? I would like to show the improvement after the plan running.
    3. Am I missing anything in this maintenance plan steps?
    - Full Backup of the database.
    - Transaction Log Backup.
    - Check DB integrity
    - Cleanup Backups more than two months
    - Rebuild Indexes
    - Reorganize indexes
    - Shrink databases
    - Update Statistics
    Thanks for your help in advanced.
    Best,

    I echo Raju: start at http://ola.hallengren.com
    A few more points:
    3. Am I missing anything in this maintenance plan steps?
    You have too much!
    - Full Backup of the database.
    - Transaction Log Backup.
    T-Log backup is something that should occur regularly through the day. How often depends on your RPO, that is, how much data loss you can accept in case of a disaster. Every 15 minutes may be a good frequency.
    - Rebuild Indexes
    - Reorganize indexes
    One of them. Not both. (Unless you have a table with LOB data that is updated frequently. You need REORGANIZE to get LOB compaction, but you may still want index rebuild, since it makes a more thoroufg work than reorganize. But this is a true edge case.)
    And only rebuild/reorganize when there is a need to. (Which is exactly what Ola's scripts perform for you.)
    - Shrink databases
    No! No! No! Shrinking databases should never be part of any regular maintenance. Shrinking a database file is an exceptional activity that you may perform when you have deleted a lot of data that never will return. Or when a log file has exploded after an
    occasional accident. But shrinking on a regular basis is only detrimental. Shrinking introduces massive fragmentation (why it's pointless to rebuild indexes first). And what shrank will only grow again and growing takes time. While autogrow is good in
    the sense that it prevent a complete outage when a file is full, it should still not happen during buisness hours but during maintenance windows.
    - Update Statistics
    If you rebuild an index (not reorganize), statistics are updated as part of that operation, and they are updated with FULLSCAN, and not sampled. Anyway, this is also something that Ola's scripts handle for you.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Databace Maintenace tasks

    I'm wondering if there are basic database maintenance task to perform regularly? We have a small usage (250 users) online database? Should i rebuild indexes, reorganize tables - I've heard someone talking about "dumps" - what does that mean?

    You may be interested in this information:
    Oracle Database Administrator's Guide
    http://download-west.oracle.com/docs/cd/B13789_01/server.101/b10739/toc.htm
    Oracle Database 2-Day DBA Manual (applies to 10g only)
    http://download-west.oracle.com/docs/cd/B13789_01/server.101/b10742/toc.htm
    Regards, OTN

  • Reorganization of tablespaces, tables and indexes.

    Hello Experts,
    What is the concept of tablespaces, statistics , tables and indexes in SAP/Oracle ? Where are they used and what are they meant for ?
    Wt is the concept and procedure of performing Reorganization of tablespaces, tables and indexes ? why do we need it for ?
    Requested to revertb at earliest as its urgent . points guaranteed .
    Regards,
    Somya

    Hello Somya,
    Probably difficult to explain entire information in this thread. But you definately get good information in the following link
    http://help.sap.com/saphelp_47x200/helpdata/en/0d/d2fafd4a0c11d182b80000e829fbfe/frameset.htm
    Please drill down through menus, and you will be able to get good information.
    Also you can check the following SAP notes
    666061     FAQ: Database objects, segments and extents
    912620     FAQ: Oracle indexes
    588668     FAQ: Database statistics
    592393     FAQ: Oracle
    541538     FAQ: Reorganizations
    Regards,
    Madhukar

  • How to reorganization index in new tablespace

    How to reorganization index in new tablespace? for size? for? number of extents? or both?

    What's Oracle version?
    Why you want to reorg your index?
    You could rebuild your index
    alter index <index_name> rebuild tablespace <tablespace_name>check Jonathan's note regarding index rebuild,
    http://jonathanlewis.wordpress.com/2008/02/09/index-rebuild-10g/

  • Question on fragmentation and ALTER INDEX REBUILD/REORGANIZE not effecting it

    The problem I ran into was troubleshooting a sporadically slow singleton lookup on a Clustered Index in a table with about 8 million rows, which is a separate issue I may need to submit for help. That aside, during that troubleshooting I noticed fragmentation
    on the Unique Clustered Index (it's a VARCHAR(20)), and then noticed the fragmentation in other indexes on this table. See sys.dm_db_index_physical_stats and DBCC SHOWCONTIG results below.
    SELECT
     substring(OBJECT_NAME(i.object_id),1,30) AS TableName,
     substring(i.name,1,40) AS TableIndexName,
     i.index_id, phystat.index_level,
     phystat.avg_fragmentation_in_percent 
    FROM
     sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, 'DETAILED') phystat inner JOIN sys.indexes i 
    ON i.object_id = phystat.object_id 
    AND i.index_id = phystat.index_id WHERE
    OBJECT_NAME(i.object_id) = 'CONSUMERS'
    TableName                      TableIndexName                           index_id    index_level avg_fragmentation_in_percent
    CONSUMERS                      UNI2K_CONSUMERS                          1           0      
        0.154827346202469
    CONSUMERS                      UNI2K_CONSUMERS                          1           1      
        35.2941176470588
    CONSUMERS                      UNI2K_CONSUMERS                          1           2      
        0
    CONSUMERS                      PK__CONSUMER__7F6B0B8B286302EC           2           0           0.336078590685822
    CONSUMERS                      PK__CONSUMER__7F6B0B8B286302EC           2           1           100
    CONSUMERS                      PK__CONSUMER__7F6B0B8B286302EC           2           2           0
    CONSUMERS                      UNI1K_CONSUMERS                          3           0      
        0.156451316031658
    CONSUMERS                      UNI1K_CONSUMERS                          3           1      
        61.1510791366906
    CONSUMERS                      UNI1K_CONSUMERS                          3           2      
        0
    CONSUMERS                      IDX1_CONSUMERS                           4           0      
        0.215271389144434
    CONSUMERS                      IDX1_CONSUMERS                           4           1      
        40
    CONSUMERS                      IDX1_CONSUMERS                           4           2      
        100
    CONSUMERS                      IDX1_CONSUMERS                           4           3      
        0
    CONSUMERS                      IDX2_CONSUMERS                           5           0      
        0.222614710968834
    CONSUMERS                      IDX2_CONSUMERS                           5           1      
        38.6281588447653
    CONSUMERS                      IDX2_CONSUMERS                           5           2      
        75
    CONSUMERS                      IDX2_CONSUMERS                           5           3      
        0
    (17 row(s) affected)
    DBCC SHOWCONTIG('CONSUMERS') WITH ALL_INDEXES
    DBCC SHOWCONTIG scanning 'CONSUMERS' table...
    Table: 'CONSUMERS' (645577338); index ID: 1, database ID: 5
    TABLE level scan performed.
    - Pages Scanned................................: 70401
    - Extents Scanned..............................: 8827
    - Extent Switches..............................: 8843
    - Avg. Pages per Extent........................: 8.0
    - Scan Density [Best Count:Actual Count].......: 99.51% [8801:8844]
    - Logical Scan Fragmentation ..................: 0.15%
    - Extent Scan Fragmentation ...................: 23.76%
    - Avg. Bytes Free per Page.....................: 47.2
    - Avg. Page Density (full).....................: 99.42%
    DBCC SHOWCONTIG scanning 'CONSUMERS' table...
    Table: 'CONSUMERS' (645577338); index ID: 2, database ID: 5
    LEAF level scan performed.
    - Pages Scanned................................: 27077
    - Extents Scanned..............................: 3402
    - Extent Switches..............................: 3402
    - Avg. Pages per Extent........................: 8.0
    - Scan Density [Best Count:Actual Count].......: 99.47% [3385:3403]
    - Logical Scan Fragmentation ..................: 0.34%
    - Extent Scan Fragmentation ...................: 11.88%
    - Avg. Bytes Free per Page.....................: 24.1
    - Avg. Page Density (full).....................: 99.70%
    DBCC SHOWCONTIG scanning 'CONSUMERS' table...
    Table: 'CONSUMERS' (645577338); index ID: 3, database ID: 5
    LEAF level scan performed.
    - Pages Scanned................................: 54330
    - Extents Scanned..............................: 6803
    - Extent Switches..............................: 6805
    - Avg. Pages per Extent........................: 8.0
    - Scan Density [Best Count:Actual Count].......: 99.79% [6792:6806]
    - Logical Scan Fragmentation ..................: 0.16%
    - Extent Scan Fragmentation ...................: 7.03%
    - Avg. Bytes Free per Page.....................: 50.3
    - Avg. Page Density (full).....................: 99.38%
    DBCC SHOWCONTIG scanning 'CONSUMERS' table...
    Table: 'CONSUMERS' (645577338); index ID: 4, database ID: 5
    LEAF level scan performed.
    - Pages Scanned................................: 54350
    - Extents Scanned..............................: 6808
    - Extent Switches..............................: 6837
    - Avg. Pages per Extent........................: 8.0
    - Scan Density [Best Count:Actual Count].......: 99.36% [6794:6838]
    - Logical Scan Fragmentation ..................: 0.22%
    - Extent Scan Fragmentation ...................: 7.17%
    - Avg. Bytes Free per Page.....................: 53.2
    - Avg. Page Density (full).....................: 99.34%
    DBCC SHOWCONTIG scanning 'CONSUMERS' table...
    Table: 'CONSUMERS' (645577338); index ID: 5, database ID: 5
    LEAF level scan performed.
    - Pages Scanned................................: 54354
    - Extents Scanned..............................: 6804
    - Extent Switches..............................: 6846
    - Avg. Pages per Extent........................: 8.0
    - Scan Density [Best Count:Actual Count].......: 99.24% [6795:6847]
    - Logical Scan Fragmentation ..................: 0.22%
    - Extent Scan Fragmentation ...................: 7.13%
    - Avg. Bytes Free per Page.....................: 53.8
    - Avg. Page Density (full).....................: 99.33%
    DBCC execution completed. If DBCC printed error messages, contact your system administrator.
    This fragmentation I found shocking because I reorg nightly and have a weekly rebuild task running that I set up through the Maintenance Plan wizard (which I've verified has been running). So I attempted to reorg these manually (especially index ID: 1)
    and to my shock the fragmentation % did not change at all. I then took the SQL provided by the Maintenance Plan for rebuilding the indexes and found that after running that it didn't change the fragementation % at all either (commands run shown below).
    ALTER INDEX [IDX1_CONSUMERS] ON [dbo].[CONSUMERS] REBUILD PARTITION = ALL WITH ( PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, ONLINE = ON, SORT_IN_TEMPDB = ON )
    GO
    ALTER INDEX [IDX2_CONSUMERS] ON [dbo].[CONSUMERS] REBUILD PARTITION = ALL WITH ( PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, ONLINE = ON, SORT_IN_TEMPDB = ON )
    GO
    ALTER INDEX [UNI1K_CONSUMERS] ON [dbo].[CONSUMERS] REBUILD PARTITION = ALL WITH ( PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, IGNORE_DUP_KEY  = OFF, ONLINE = ON, SORT_IN_TEMPDB
    = ON )
    GO
    ALTER INDEX [UNI2K_CONSUMERS] ON [dbo].[CONSUMERS] REBUILD PARTITION = ALL WITH ( PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, IGNORE_DUP_KEY  = OFF, ONLINE = ON, SORT_IN_TEMPDB
    = ON )
    GO
    Fragmentation did not change until I performed a "CREATE ... DROP_EXISTING = ON" on the 4 non PK indexes and a manual rebuild of Primary Key offline not specifying any other parameters, which all seemed completely overkill to ensure the defragmentation
    actually got done. Final sys.dm_db_index_physical_stats and DBCC SHOWCONTIG results below.
    SELECT
     substring(OBJECT_NAME(i.object_id),1,30) AS TableName,
     substring(i.name,1,40) AS TableIndexName,
     i.index_id, phystat.index_level,
     phystat.avg_fragmentation_in_percent 
    FROM
     sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, 'DETAILED') phystat inner JOIN sys.indexes i 
    ON i.object_id = phystat.object_id 
    AND i.index_id = phystat.index_id WHERE
    OBJECT_NAME(i.object_id) = 'CONSUMERS'
    TableName                      TableIndexName                           index_id    index_level avg_fragmentation_in_percent
    CONSUMERS                      UNI2K_CONSUMERS                          1           0      
        0.0213458562356583
    CONSUMERS                      UNI2K_CONSUMERS                          1           1      
        11.2426035502959
    CONSUMERS                      UNI2K_CONSUMERS                          1           2      
        0
    CONSUMERS                      PK__CONSUMER__7F6B0B8B286302EC           2           0           0.0460971112476951
    CONSUMERS                      PK__CONSUMER__7F6B0B8B286302EC           2           1           14.2857142857143
    CONSUMERS                      PK__CONSUMER__7F6B0B8B286302EC           2           2           0
    CONSUMERS                      UNI1K_CONSUMERS                          3           0      
        0.0225314031431307
    CONSUMERS                      UNI1K_CONSUMERS                          3           1      
        10.6194690265487
    CONSUMERS                      UNI1K_CONSUMERS                          3           2      
        0
    CONSUMERS                      IDX1_CONSUMERS                           4           0      
        0.0225318262045139
    CONSUMERS                      IDX1_CONSUMERS                           4           1      
        10.7296137339056
    CONSUMERS                      IDX1_CONSUMERS                           4           2      
        0
    CONSUMERS                      IDX1_CONSUMERS                           4           3      
        0
    CONSUMERS                      IDX2_CONSUMERS                           5           0      
        0.0225314031431307
    CONSUMERS                      IDX2_CONSUMERS                           5           1      
        12.0171673819742
    CONSUMERS                      IDX2_CONSUMERS                           5           2      
        0
    CONSUMERS                      IDX2_CONSUMERS                           5           3      
        0
    (17 row(s) affected)
    DBCC SHOWCONTIG('CONSUMERS') WITH ALL_INDEXES
    DBCC SHOWCONTIG scanning 'CONSUMERS' table...
    Table: 'CONSUMERS' (645577338); index ID: 1, database ID: 5
    TABLE level scan performed.
    - Pages Scanned................................: 56217
    - Extents Scanned..............................: 7029
    - Extent Switches..............................: 7028
    - Avg. Pages per Extent........................: 8.0
    - Scan Density [Best Count:Actual Count].......: 99.99% [7028:7029]
    - Logical Scan Fragmentation ..................: 0.02%
    - Extent Scan Fragmentation ...................: 0.44%
    - Avg. Bytes Free per Page.....................: 32.4
    - Avg. Page Density (full).....................: 99.60%
    DBCC SHOWCONTIG scanning 'CONSUMERS' table...
    Table: 'CONSUMERS' (645577338); index ID: 2, database ID: 5
    LEAF level scan performed.
    - Pages Scanned................................: 26032
    - Extents Scanned..............................: 3256
    - Extent Switches..............................: 3255
    - Avg. Pages per Extent........................: 8.0
    - Scan Density [Best Count:Actual Count].......: 99.94% [3254:3256]
    - Logical Scan Fragmentation ..................: 0.05%
    - Extent Scan Fragmentation ...................: 0.31%
    - Avg. Bytes Free per Page.....................: 11.1
    - Avg. Page Density (full).....................: 99.86%
    DBCC SHOWCONTIG scanning 'CONSUMERS' table...
    Table: 'CONSUMERS' (645577338); index ID: 3, database ID: 5
    LEAF level scan performed.
    - Pages Scanned................................: 53259
    - Extents Scanned..............................: 6659
    - Extent Switches..............................: 6658
    - Avg. Pages per Extent........................: 8.0
    - Scan Density [Best Count:Actual Count].......: 99.98% [6658:6659]
    - Logical Scan Fragmentation ..................: 0.02%
    - Extent Scan Fragmentation ...................: 0.35%
    - Avg. Bytes Free per Page.....................: 40.5
    - Avg. Page Density (full).....................: 99.50%
    DBCC SHOWCONTIG scanning 'CONSUMERS' table...
    Table: 'CONSUMERS' (645577338); index ID: 4, database ID: 5
    LEAF level scan performed.
    - Pages Scanned................................: 53258
    - Extents Scanned..............................: 6659
    - Extent Switches..............................: 6658
    - Avg. Pages per Extent........................: 8.0
    - Scan Density [Best Count:Actual Count].......: 99.98% [6658:6659]
    - Logical Scan Fragmentation ..................: 0.02%
    - Extent Scan Fragmentation ...................: 0.53%
    - Avg. Bytes Free per Page.....................: 40.3
    - Avg. Page Density (full).....................: 99.50%
    DBCC SHOWCONTIG scanning 'CONSUMERS' table...
    Table: 'CONSUMERS' (645577338); index ID: 5, database ID: 5
    LEAF level scan performed.
    - Pages Scanned................................: 53259
    - Extents Scanned..............................: 6659
    - Extent Switches..............................: 6658
    - Avg. Pages per Extent........................: 8.0
    - Scan Density [Best Count:Actual Count].......: 99.98% [6658:6659]
    - Logical Scan Fragmentation ..................: 0.02%
    - Extent Scan Fragmentation ...................: 0.59%
    - Avg. Bytes Free per Page.....................: 40.5
    - Avg. Page Density (full).....................: 99.50%
    DBCC execution completed. If DBCC printed error messages, contact your system administrator.
    For the record, here's the version I'm running:
    select @@VERSION
    Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (X64) 
     Jun 17 2011 00:54:03 
     Copyright (c) Microsoft Corporation
     Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1)
    In summary my question is - why didn't ALTER INDEX ... REBUILD/REORGANIZE modify the index_level 1 fragmentation as reported by sys.dm_db_index_physical_stats, nor would it correct the Extent Scan Fragmentation as reported by DBCC SHOWCONTIG?

    Hi Brian.cs ,
    SQL Server will not rebuild indexes that are not large enough. Could you please have a look a the
    fragment_count which is  one of the fields in the
    sys.dm_db_index_physical_stats view to check whether it is low or not ?
    Best Regards,
    Peja
    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Peja, here's the information you requested, and of course this was after I dropped/recreated because rebuild didn't seem to actually address the fragmentation - the index I was most concerned about at index_level = 0 showed a fragment_count = 8922. FYI this
    table has over 8 million rows. And apologies for the delayed response, was on vacation over the near year.
    SELECT
     substring(OBJECT_NAME(i.object_id),1,30) AS TableName,
     substring(i.name,1,40) AS TableIndexName,
     i.index_id, phystat.index_level,
     phystat.avg_fragmentation_in_percent, fragment_count 
    FROM
     sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, 'DETAILED') phystat inner JOIN sys.indexes i 
    ON i.object_id = phystat.object_id 
    AND i.index_id = phystat.index_id WHERE
    OBJECT_NAME(i.object_id) = 'CONSUMERS'
    TableName                      TableIndexName                           index_id    index_level avg_fragmentation_in_percent
    fragment_count
    CONSUMERS                      UNI2K_CONSUMERS                          1           0        
      0.259780818806428            8922
    CONSUMERS                      UNI2K_CONSUMERS                          1           1        
      39.4190871369295             86
    CONSUMERS                      UNI2K_CONSUMERS                          1           2        
      0                            1
    CONSUMERS                      PK__CONSUMER__7F6B0B8B286302EC           2           0           0.240887634434766    
           5182
    CONSUMERS                      PK__CONSUMER__7F6B0B8B286302EC           2           1           80.3738317757009    
            84
    CONSUMERS                      PK__CONSUMER__7F6B0B8B286302EC           2           2           0          
                     1
    CONSUMERS                      UNI1K_CONSUMERS                          3           0        
      0.0661472879611936           8532
    CONSUMERS                      UNI1K_CONSUMERS                          3           1        
      53.4883720930233             86
    CONSUMERS                      UNI1K_CONSUMERS                          3           2        
      0                            1
    CONSUMERS                      IDX1_CONSUMERS                           4           0        
      0.192426334498663            8598
    CONSUMERS                      IDX1_CONSUMERS                           4           1        
      31.5315315315315             95
    CONSUMERS                      IDX1_CONSUMERS                           4           2        
      85.7142857142857             7
    CONSUMERS                      IDX1_CONSUMERS                           4           3        
      0                            1
    CONSUMERS                      IDX2_CONSUMERS                           5           0        
      0.189494094835184            8613
    CONSUMERS                      IDX2_CONSUMERS                           5           1        
      31.8840579710145             97
    CONSUMERS                      IDX2_CONSUMERS                           5           2        
      85.7142857142857             7
    CONSUMERS                      IDX2_CONSUMERS                           5           3        
      0                            1

  • Is it worth skipping Indexes during Database reorganization?

    Hi All,
    we are planning for Database reorganization using ALTER TABLE...MOVE TABLESPACE. Can we skip the indexes or we need to perform the ALTER INDEX ...REBUILD TABLESPACE....
    After going through the asktom post we decided to skip the indexes, we are looking for all your suggestion on this topic.
    Ref: http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:6601312252730
    Thanks in advance,
    karv

    depends on the version of the database also, you need to select appropriate method of defragmentation
    if your db is 10g, not required to use move command. you can use shrink command which will give benefit to not rebuild indexes

  • ALTER INDEX  .. REORGANIZE vs.REBUILD

    What is the difference between ALTER INDEX .. REORGANIZE and ALTER INDEX .. REBUILD ?
    Thanks, Christine & Danny

    Are you talking about Oracle here?
    There is no REORGANIZE with ALTER INDEX. Its valid command for SQLServer.
    If you are talking about SqlServer here, then, read the article from the below link:
    http://msdn2.microsoft.com/en-us/library/ms189858.aspx
    If you are concerned about Oracle's ALTER INDEX REBUILD, read my blog about functionality/machanism of rebuilding index online and normally, Part 1 and Part 2.
    http://jaffardba.blogspot.com/search/label/Indexes

  • FIM SQL rebuild/reorganize indexes

    Hi,
    In FIM 2010 R2, do we need to manually create the SQL jobs to rebuild/reorganize indexes? Or is this a default configuration that just runs on SQL? I am referring to the 2 FIM databases.
    Thanks,
    SK

    Hi SK,
    We have to manually create & schedule SQL Jobs to automate the indexing.
    Regards,
    Manuj Khurana

Maybe you are looking for