Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle performance with multiple same column indexes

I'm Working with a new Oracle DB, with one table having the following indexes:

  • Index 1: ColA, ColB
  • Index 2: ColA

Is the second index redundant, and Will this have a negative impact on performance?

like image 779
Whytespot Avatar asked Jun 19 '09 20:06

Whytespot


People also ask

Can we have multiple indexes on same column?

For example, if you have an index on column {a} or columns {a,b}, you can't create another index on the same column or set of columns in the same order. In 12c, you can have multiple indexes on the same column or set of columns as long as the index type is different.

Can Oracle use multiple indexes at once on a single table?

You can create multiple indexes on the same set of columns but only one of the indexes can be visible at a time and the indexes are physically different. Physical different means it is not possible to create two B-tree index on the same set of column.

Is it good to have multiple indexes on a table?

Standard indexes on a column can lead to substantial decreases in query execution times as shown in this article on optimizing queries. Multi-column indexes can achieve even greater decreases in query time due to its ability to move through the data quicker.

Do indexes affect performance?

The number of indexes on a table is the most dominant factor for insert performance. The more indexes a table has, the slower the execution becomes. The insert statement is the only operation that cannot directly benefit from indexing because it has no where clause.


2 Answers

Google is my best friend :

http://www.orafaq.com/node/926

The main point of this article is :

If 2 indexes ( I1 and I2 ) exist for a table and
   the number of columns in Index I1 is less or equal to the number of column in index I2 and
   index I1 has the same columns in the same order as leading columns of index I2 
Then
   If index I1 is UNIQUE then
      If index I2 is used to support Foregh Key or for Index Overload then
         Do Nothing
      Else
         Index I2 can be DROPPED
      End If
   Else
      Index I1 can be DROPPED
   End If
End If

And I'm agree with that ! In fact, search "duplicate indexes" in Google to have different kind of answer.

like image 174
Cyril Gandon Avatar answered Sep 22 '22 16:09

Cyril Gandon


The second index is different and is not redundant per se.

How about this query:

SELECT DISTINCT ColA FROM TABLE WHERE ColA IS NOT NULL;

Oracle can answer this question entirely from Index 2. Now, index 2 would be expected to be small (less blocks) than index 1. This means, it is a better index for the above query.

If your application never does a query that suits Index2 better than Index1, then it is redundant for your application.

Indexes are always a performance tradeoff. When an insert, update or delete is performed there is extra work to do in order to maintain each additional index.

Is this more than compensated for by the increased performance provided by the index? Depends on your application and data usage.

like image 23
WW. Avatar answered Sep 21 '22 16:09

WW.