Optimizing Indexes

  • Comments posted to this topic are about the item Optimizing Indexes

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • I must be missing something:

    Documentation states that

    REORGANIZE cannot be specified for a disabled index or an index with ALLOW_PAGE_LOCKS set to OFF.

    http://msdn.microsoft.com/en-us/library/ms188388(SQL.90).aspx

    Also testing it directly in SQL2K5 resolves to the same thing:

    USE tempdb;

    CREATE TABLE dbo.Test (

    PKCol int IDENTITY (1,1) NOT NULL

    ,DataCol varchar(50) NOT NULL

    ,CONSTRAINT PK_Test PRIMARY KEY CLUSTERED(PKCol)

    );

    INSERT dbo.Test VALUES ('Test');

    CREATE UNIQUE NONCLUSTERED INDEX UQ_DataCol ON dbo.Test (DataCol) WITH (ALLOW_PAGE_LOCKS = OFF)

    ALTER INDEX UQ_DataCol ON dbo.Test REORGANIZE

    DROP TABLE dbo.Test;

    (1 row(s) affected)

    Msg 2552, Level 16, State 1, Line 11

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

    Any hints as to what I have missed in the QOTD?

    Best Regards,

    Chris Büttner

  • Christian Buettner (7/13/2009)


    I must be missing something:

    Documentation states that

    REORGANIZE cannot be specified for a disabled index or an index with ALLOW_PAGE_LOCKS set to OFF.

    http://msdn.microsoft.com/en-us/library/ms188388(SQL.90).aspx

    Also testing it directly in SQL2K5 resolves to the same thing:

    USE tempdb;

    CREATE TABLE dbo.Test (

    PKCol int IDENTITY (1,1) NOT NULL

    ,DataCol varchar(50) NOT NULL

    ,CONSTRAINT PK_Test PRIMARY KEY CLUSTERED(PKCol)

    );

    INSERT dbo.Test VALUES ('Test');

    CREATE UNIQUE NONCLUSTERED INDEX UQ_DataCol ON dbo.Test (DataCol) WITH (ALLOW_PAGE_LOCKS = OFF)

    ALTER INDEX UQ_DataCol ON dbo.Test REORGANIZE

    DROP TABLE dbo.Test;

    (1 row(s) affected)

    Msg 2552, Level 16, State 1, Line 11

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

    Any hints as to what I have missed in the QOTD?

    The question says that "You have determined that for this index the ALLOW_PAGE_LOCKS is NOT set to OFF so the reorganize option is the correct method.

  • So I missed the "not" - verrrry tricky! 😀

    If it was intended to be tricky, then I admit it was well done.

    If not, I assume rephrasing to "ALLOW_PAGE_LOCKS is set to ON" would have made more sense.

    Thanks for the clarification and of course very nice QOTD - I wasn't aware of that reorg limitation.

    Best Regards,

    Chris Büttner

  • Christian Buettner (7/13/2009)


    So I missed the "not" - verrrry tricky! 😀

    If it was intended to be tricky, then I admit it was well done.

    If not, I assume rephrasing to "ALLOW_PAGE_LOCKS is set to ON" would have made more sense.

    Thanks for the clarification and of course very nice QOTD - I wasn't aware of that reorg limitation.

    I misread the question and got it wrong too :rolleyes:

  • Agree with previous comments regarding inability to reorganize with the page locks option off. You don't have any option but to rebuild or drop/recreate the index with Allow_page_locks on. Why put that in the question if it isn't taken into account?

  • Hmm

  • Christian Buettner

    If it was intended to be tricky, then I admit it was well done

    The question was not intended to be tricky, but to draw attention to an easily overlooked requirement. As a matter of fact a bold clue to the correct answer was

    Using Microsoft's BOL recommended guidelines to remedy this fragmentation

    chad.losee

    The correct answer is not in one's knowledge of indexes but in understanding poor grammar.

    My goal with the question was to expand the user's knowledge of the nuances of maintaining efficient indexing, nothing more nothing less. I thank you all for your comments/code snippets as they will assist me in composing additional QODs.

    Edited 10:27 to correct spelling error

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Christian Buettner (7/13/2009)


    So I missed the "not" - verrrry tricky! 😀

    If it was intended to be tricky, then I admit it was well done.

    If not, I assume rephrasing to "ALLOW_PAGE_LOCKS is set to ON" would have made more sense.

    Thanks for the clarification and of course very nice QOTD - I wasn't aware of that reorg limitation.

    I had it wrong as well because of "NOT set to OFF"

  • Chris Houghton (7/13/2009)


    Christian Buettner (7/13/2009)


    I must be missing something:

    Documentation states that

    REORGANIZE cannot be specified for a disabled index or an index with ALLOW_PAGE_LOCKS set to OFF.

    http://msdn.microsoft.com/en-us/library/ms188388(SQL.90).aspx

    Also testing it directly in SQL2K5 resolves to the same thing:

    USE tempdb;

    CREATE TABLE dbo.Test (

    PKCol int IDENTITY (1,1) NOT NULL

    ,DataCol varchar(50) NOT NULL

    ,CONSTRAINT PK_Test PRIMARY KEY CLUSTERED(PKCol)

    );

    INSERT dbo.Test VALUES ('Test');

    CREATE UNIQUE NONCLUSTERED INDEX UQ_DataCol ON dbo.Test (DataCol) WITH (ALLOW_PAGE_LOCKS = OFF)

    ALTER INDEX UQ_DataCol ON dbo.Test REORGANIZE

    DROP TABLE dbo.Test;

    (1 row(s) affected)

    Msg 2552, Level 16, State 1, Line 11

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

    Any hints as to what I have missed in the QOTD?

    The question says that "You have determined that for this index the ALLOW_PAGE_LOCKS is NOT set to OFF so the reorganize option is the correct method.

    Hmm. The book "Professional SQL Server 2005 Performance Tuning" by Steven Wort, et al, says on page 54, third paragraph under Index Fragmentation:

    "The best way to remedy index fragmentation is with the ALTER INDEX command. This should be appended with the fully qualified index and schema names and then either REBUILD or REORGANIZE. The reorganize operation is more lightweight, but it can't resolve inter-leaved data and index pages (external fragmentation). An index rebuild is an I/O intensive operation that will resolve both internal and external fragmentation and can be carried out online with Enterprise or Developer editions of SQL Server 2005." ...

    Since rebuild should take care of more kinds of fragmentation, I selected rebuild instead of reorganize.

  • An extract from the question as published

    jpowers

    Using Microsoft's BOL recommended guidelines to remedy this fragmentation

    - emphasis added for this post.

    Please note that the question specifically cited as a reference BOL. Also the question specifies a limited percentage of fragmentation.

    What does

    "Professional SQL Server 2005 Performance Tuning" by Steven Wort, et al,

    say in regards to various degrees of fragmentation?

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • What does BOL say about fragmentation level? My experience is that you should reorganize when you have a fragmentation between >10% and <=30% (rebuild when it is above 30%) as long as you have set allow page lock to ON

    (on vacation far away from SQL server, but not from SQLServerCentral)

    /Håkan Winther
    MCITP:Database Developer 2008
    MCTS: SQL Server 2008, Implementation and Maintenance
    MCSE: Data Platform

  • Hey Bitbucket, thanks for teaching me something new.

  • hakan.winther

    In answer to your question:

    BOL link

    http://msdn.microsoft.com/en-us/library/ms189858(SQL.90).aspx

    Which recommends:

    avg_fragmentation_in_percent value Corrective statement

    > 5% and 30% ALTER INDEX REBUILD WITH (ONLINE = ON)*

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • ohh, I missed that little word "not" as well !!!!

Viewing 15 posts - 1 through 14 (of 14 total)

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