duplicate indexes , need opinion on dropping unwanted indexes.

Heisenberg 261 Reputation points
2021-09-15T18:06:27.06+00:00

hi all,
We really have bad database design for one of the table, table size is around 100G and index sizes are around 200G. I ran a query to find duplicate indexes and found following indexes list. The index that can be dropped ive marked them with the arrow, if anyone has a suggestion on dropping any other index that will be great. Another question is if i ve one index on column1 and another one on column 1 and column 2 then can i drop first index thats solely on column1 as this column is covered by 2nd index.

132486-image.png

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,651 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,549 questions
{count} votes

5 answers

Sort by: Most helpful
  1. Tom Phillips 17,716 Reputation points
    2021-09-15T18:40:37.037+00:00

    Indexes should support queries. The simplest thing to do is to remove all the unused indexes and then add back specific ones if you find a performance issue.

    Having index size greater than the data in the table is not really an issue to be solved. If you have lots of indexes that is very possible.

    I suggest you read this:
    https://www.sqlshack.com/how-to-identify-and-monitor-unused-indexes-in-sql-server/

    0 comments No comments

  2. Heisenberg 261 Reputation points
    2021-09-15T20:02:50.527+00:00

    Thanks Tom,

    My other question is.

    1. if you compare package_req_id, search_type_code index with package_req_id, search_type_code, order_date_time do these indexes make case of duplicate index? so that i can only keep second one as it includes columns from first one too.
    2. how can i check the impact of dropping these indexes other than testing in lower environments.
    0 comments No comments

  3. Erland Sommarskog 100.8K Reputation points MVP
    2021-09-15T21:52:59.073+00:00

    if anyone has a suggestion on dropping any other index that will be great.

    Supposedly, you know more about that table than we do. It's difficult to suggest about indexing on a table I know nothing about.

    Another question is if i ve one index on column1 and another one on column 1 and column 2 then can i drop first index thats solely on column1 as this column is covered by 2nd index.

    Probably. However, say that this query is very important:

    SELECT column1, COUNT(*) FROM tbl GROUP BY column1
    

    If you drop the index on only column1, this query will run slower, as it now has to scan the composite index on (column1, column2).

    But, yes, in most cases you can consider such indexes redundant. I think I noticed a few more in the list above.

    how can i check the impact of dropping these indexes other than testing in lower environments.

    You drop them in production, and then waits to see if someone starts screaming.

    More seriously, you can dig in the plan cache to see which queries where these indexes are used, but I don't have any query canned for that. And I am not sure that it's worth the effort.

    0 comments No comments

  4. Heisenberg 261 Reputation points
    2021-09-15T22:21:25.487+00:00

    Thank you Erland for your response. Dropping index in production definitely sounds like a good plan :)

    One more question, if i've 2 indexes on the same set of columns , but order of these columns is different, can i call it redundant and drop one of them ?
    I'm talking in reference to following indexes in the screenshot.

    132439-image.png


  5. AmeliaGu-MSFT 13,961 Reputation points Microsoft Vendor
    2021-09-16T05:34:54.287+00:00

    Hi SQLServerBro,

    if i've 2 indexes on the same set of columns , but order of these columns is different, can i call it redundant and drop one of them?

    If two indexes contain the same index keys, but the order of the keys is different, they are not redundant. The difference in keys order may cause one index to be more beneficial for queries than another similar index.
    Please refer to this thread and this article which might be helpful.

    Best Regards,
    Amelia

    0 comments No comments