Index Defragmentation and update stats

  • Comments posted to this topic are about the item Index Defragmentation and update stats

    /* ----------------------------- */
    Tochter aus Elysium, Wir betreten feuertrunken, Himmlische, dein Heiligtum!

  • An interesting note, I just found this error. I will look at how to address it.

    Msg 2725, Level 16, State 2, Line 1

    An online operation cannot be performed for index 'PK_notable_query_plan' because the index contains column 'query_plan' of data type text, ntext, image, varchar(max), nvarchar(max), varbinary(max), xml, or large CLR type. For a non-clustered index, the column could be an include column of the index. For a clustered index, the column could be any column of the table. If DROP_EXISTING is used, the column could be part of a new or old index. The operation must be performed offline.

    /* ----------------------------- */
    Tochter aus Elysium, Wir betreten feuertrunken, Himmlische, dein Heiligtum!

  • You may want to reconsider your use of sp_updatestats as the only way to update the statistics of the database. This normally will only sample a portion of each table and you may not be getting the best query plan as a result. I have seen where it will do a full scan, but sometimes I have seen it scan below 1% if the table is large enough.

  • There is included an option for a full rescan if update stats is a selected option

    /* ----------------------------- */
    Tochter aus Elysium, Wir betreten feuertrunken, Himmlische, dein Heiligtum!

  • I changed a few references to @DBName to quotename(@DBName) as there is an issue with database names with spaces.

    Otherwise, thanks very much.

  • Some changes I would make:

    - get rid of the switch from full or bulk to simple mode or make this an option. This could break log shipping, backup chains, etc. if not careful.

    - If the index is rebuilt, skip the update stats portion. An index rebuild always updates stats with a 100% sampling rate. (See http://www.sqlskills.com/BLOGS/PAUL/post/Search-Engine-QA-10-Rebuilding-Indexes-and-Updating-Statistics.aspx)

    Otherwise, very nice.

  • shaun.stuart (6/9/2011)


    Some changes I would make:

    - get rid of the switch from full or bulk to simple mode or make this an option. This could break log shipping, backup chains, etc. if not careful.

    Oops. just noticed this was an option already 🙂

  • if i excecute i got below error.

    Msg 2552, Level 16, State 1, Line 1

    The index "INDEXNAME" (partition 1) on table "TABLENAME" cannot be reorganized because page level locking is disabled.

    Does allow_page_locks should be considered?

  • I think it if page level locking is disabled then you have to rebuild and not reorganize.

  • skraghava (8/24/2011)


    I think it if page level locking is disabled then you have to rebuild and not reorganize.

    Send me a private message and I will send you the latest version of this script, it has a few kinks worked out after further QA in different environments.

    /* ----------------------------- */
    Tochter aus Elysium, Wir betreten feuertrunken, Himmlische, dein Heiligtum!

  • Thanks for the script.

Viewing 11 posts - 1 through 10 (of 10 total)

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