Published on

December 27, 2012

Understanding Redundant Indexes in SQL Server

When it comes to optimizing the performance of your SQL Server database, one of the common best practices is to drop redundant indexes. But what exactly is a redundant index and when should you consider keeping it? In this blog post, we will explore the concept of redundant indexes and discuss scenarios where they can actually be useful.

Before we dive into the details, let’s quickly recap what a redundant index is. In SQL Server, an index is considered redundant when it provides the same or similar benefits as another index on the same table. Redundant indexes can consume additional storage space and impact the performance of data modification operations, such as inserts, updates, and deletes.

In a previous blog post, we discussed the different types of redundant indexes and explored special cases where they should be dropped. However, there are situations where even though an index is clearly redundant, it can still be useful and should not be removed.

To illustrate this, let’s consider a scenario where we have two tables: SampleTable1 and SampleTable2. Both tables have the same data, but SampleTable2 has a wider column (CHAR(800)) compared to SampleTable1. We will create two non-clustered indexes on both tables: one on Col1 and Col2, and another one on Col1, Col2, and Col3.

Now, let’s run a query on both tables that selects a larger set of data. We will apply the appropriate index hint to each query to ensure that the index is used. In the case of SampleTable1, we will observe that both queries perform similarly, regardless of which index is used. This is because Col3 is an integer column, and the width of the column does not significantly impact the performance of the query.

However, when we run the same queries on SampleTable2, we will notice a significant difference in performance depending on which index is used. Since Col3 is a CHAR(800) column, the width of the column does make a big difference in the performance of the query. In this case, the index on Col1 and Col2 is the most optimal choice.

So, why should we keep the redundant index on SampleTable2? The answer lies in the specific usage patterns and query workloads. If a query only requires Col1 and Col2, the index on Col1 and Col2 will provide better performance compared to the index on Col1, Col2, and Col3. However, if the query includes Col3, the index on Col1, Col2, and Col3 becomes the more suitable choice.

It is important to note that these findings may not apply in all scenarios. The decision to keep or drop a redundant index should be based on careful evaluation of the usage patterns and query workloads in your specific environment. It is always recommended to thoroughly test different combinations before making any decisions.

In conclusion, while redundant indexes are often seen as unnecessary and should be dropped, there are cases where they can still be useful. When dealing with wider columns and specific query requirements, a redundant index may provide better performance compared to a more inclusive index. It is crucial to properly evaluate the usage patterns and query workloads before deciding to drop an index solely based on redundancy.

Stay tuned for more insights on SQL Server optimization in our upcoming blog posts!

Click to rate this post!
[Total: 0 Average: 0]

Let's work together

Send us a message or book free introductory meeting with us using button below.