Home Forums SQL Server 2008 T-SQL (SS2K8) how to find duplicate indexes in all the tables in a database RE: how to find duplicate indexes in all the tables in a database

  • Hi,

    The query doesn't differentiate a "normal" index column from an "include" index column...

    In following statements idx_dupIndexes_03 and idx_dupIndexes_06 are considered duplicate but they're not.

    CREATE TABLE dupIndexes (id1 INT, id2 INT, id3 INT, id4 INT)

    CREATE INDEX idx_dupIndexes_01 ON dupIndexes (id1, id2)

    CREATE INDEX idx_dupIndexes_02 ON dupIndexes (id2, id1)

    CREATE INDEX idx_dupIndexes_03 ON dupIndexes (id2, id1) INCLUDE (id3)

    CREATE INDEX idx_dupIndexes_04 ON dupIndexes (id2, id1) INCLUDE (id3, id4)

    CREATE INDEX idx_dupIndexes_05 ON dupIndexes (id2, id1) INCLUDE (id4, id3)

    CREATE INDEX idx_dupIndexes_06 ON dupIndexes (id2, id1, id3)

    One more question, and in this one I might be saying nonsense...

    In the following statements:

    CREATE TABLE dupIndexes2 (id1 INT, id2 INT, id3 INT, id4 INT)

    CREATE INDEX idx_dupIndexes2_01 ON dupIndexes2 (id1, id2)

    CREATE INDEX idx_dupIndexes2_02 ON dupIndexes2 (id1, id2, id3)

    should both indexes be considered equal since 02 has all the columns 01 has?

    When I run "SELECT id1 FROM dupIndexes2 WHERE id1 = 1 AND id2 = 2" the sql uses idx_dupIndexes2_02 (according to the execution plan).

    Thks,

    Pedro



    If you need to work better, try working less...