• anthony.green - Thursday, November 9, 2017 1:36 AM

    No they are not duplicates as the key order is different.

    Key order is important as its the way the optimizer searches the index

    So IndexA (Col1,Col2), IndexB (Col2,Col1) are not considered duplicated

    But IndexA (Col1, Col2), IndexB (Col1, Col2, Col3) then IndexA would be considered the duplicate

    I'd say a potential duplicate. Everything say is 100% correct, but it's possible that, depending on the query, IndexB is more useful than IndexA in a given situation because we're filtering on Col1-Col3, not just on Col1 & Col2. That also goes the other way. The first index is smaller than the second, so may be more useful situationally. All that even though, within a pure definition, IndexA is duplicating what IndexB does in your second example. That's why this all gets so hard.

    Another point on duplicates is that the first column is the one used to create the histogram for the index, which is one of the primary (but not the only) drivers for the optimizer to determine which index is useful. In that case, depending on your queries, one of those two indexes may never get used, even though it's the better index for a given situation.

    Ain't SQL Server fun.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning