Sql-server – Are some these indexes redundant

sql serversql-server-2012

Let's say I have a table of 4 columns: A, B, C, D. A primary key is on A, B, C.

Index1: is A, D, B, C in that order
Index2: A, B, C, D in that order
and the primary key index: A, B, C

There are queries selecting different columns in different numbers and order. I don't all the queries that hit the table.

Are some indexes here redundant?

I collected some scripts from the web for finding redundant indexes and they don't return the same results for the database. I guess every author has their own interpretation of what constitutes a duplicate or redundant index.

Best Answer

Not quite.

If the PK is A,B,C, you already have that unique index.

A,B,C,D is a covering index for queries that need exactly those four columns, but would be better as A,B,C INCLUDE D

A,D,B,C is definitely not redundant; it's the only one that can work with both A and D on queries that use those two but don't use B or C in the index. Depending on the cardinality of A and D, it might be critical, or worthless... but it's not redudant.

Remember, SQL Server starts at the left and goes to the right; when it hits a column that's not used, it stops.