when to defragment indexes

  • Hi All,

    I understand that indexes need to be defragmented when they get fragmented,

    however must one defragment an index even if it is 100% fragmented?

    I mean, if there are no searches done on the table, then it doesn't matter if it is 100% fragmented (does it?)

    but if searches are constantly done on the table then it would make sense to defrag the table so as to improve the search performance.

    Now comes my next question....

    How can I find out which tables are constantly searched and which ones are not

    Thanks

    UgoBoy

  • The effect of fragmentation depends on whether in order scans are being performed - common in reporting databases - and also on the size. There is no real benefit with less than a few hundred pages, unless you have a tiny amount of RAM - and then you've got more serious problems.

    To see which indexes are being scanned have a look at sys.dm_db_index_operational_stats

  • Thanks Richard,

    Just the info I was looking for

  • It can also be quite helpful to look at your cached execution plans to see which queries/procedures have inadequate query plans, this can be found by running the code belowSELECT

    DB_NAME(st .dbid),

    [cp] .[refcounts],

    [cp] .[usecounts],

    [cp] .[objtype], --,[st].[dbid]

    --,[st].[objectid]

    OBJECT_NAME(st .objectid),

    [st] .[text],

    [qp] .[query_plan]

    FROM sys .dm_exec_cached_plans AS cp

    CROSS APPLY sys. dm_exec_sql_text(cp .plan_handle) AS st

    CROSS APPLY sys. dm_exec_query_plan(cp .plan_handle) AS qp

    WHERE [st]. [dbid] IN (7, 12,13 ,15)

    AND [st].[text] NOT LIKE '%sp_M%'

    AND [st]. [text] NOT LIKE '%sys%'

    --AND cp.objtype = 'adhoc'

    ORDER BY usecounts DESC If tables aren't being used by any query(ies), then having indexes on them is really overkill and ends up just consuming valuable server resources...not to mention adds extra time to any indexing strategy you may have in place.

    ______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience

  • ugo boy (1/28/2013)


    I mean, if there are no searches done on the table

    then you should DROP these indexes.


    Alex Suprun

  • Alexander Suprun (1/28/2013)


    ugo boy (1/28/2013)


    I mean, if there are no searches done on the table

    then you should DROP these indexes.

    Keep in mind these statistics are cumulative and only show information since the last time the MSSQL service was started. If you recently restarted the service and check this DMV, you may find many indexes that don't appear to be used...so be careful deleting them without first checking whether they're really needed or not.

    ______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience

Viewing 7 posts - 1 through 6 (of 6 total)

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