Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql too many indexes?

I am spending some time optimizing our current database.

I am looking at indexes specifically.

There are a few questions:

  • Is there such a thing as too many indexes?
  • What will indexes speed up?
  • What will indexes slow down?
  • When is it a good idea to add an index?
  • When is it a bad idea to add an index?
  • Pro's and Con's of multiple indexes vs multi-column indexes?
like image 216
Hailwood Avatar asked Nov 07 '10 22:11

Hailwood


People also ask

How many indices are too many MySQL?

Most things that I have seen say that having more than 5 indexes will begin to slow down your insert speed. Consider this, every index you have is like having a new table in your database with the same information just sorted a different way.

How many indexes can a MySQL table have?

In general, MySQL only allows you to create up to 16 indexes on a given table. If you are using a PRIMARY KEY index, you can only have one primary key per table.

How many indexes is too many?

To start, I'd say that most tables should have fewer than 15 indexes. In many cases, tables that focus on transaction processing (OLTP) might be in the single digits, whereas tables that are used more for decision support might be well into double digits.

What are the problems with having too many indexes?

Too many indexes create additional overhead associated with the extra amount of data pages that the Query Optimizer needs to go through. Also, too many indexes require too much space and add to the time it takes to accomplish maintenance tasks.


1 Answers

What will indexes speed up?

Data retrieval -- SELECT statements.

What will indexes slow down?

Data manipulation -- INSERT, UPDATE, DELETE statements.

When is it a good idea to add an index?

If you feel you want to get better data retrieval performance.

When is it a bad idea to add an index?

On tables that will see heavy data manipulation -- insertion, updating...

Pro's and Con's of multiple indexes vs multi-column indexes?

Queries need to address the order of columns when dealing with a covering index (an index on more than one column), from left to right in index column definition. The column order in the statement doesn't matter, only that of columns 1, 2 and 3 - a statement needs have a reference to column 1 before the index can be used. If there's only a reference to column 2 or 3, the covering index for 1/2/3 could not be used.

In MySQL, only one index can be used per SELECT/statement in the query (subqueries/etc are seen as a separate statement). And there's a limit to the amount of space per table that MySQL allows. Additionally, running a function on an indexed column renders the index useless - IE:

WHERE DATE(datetime_column) = ... 
like image 115
OMG Ponies Avatar answered Oct 04 '22 21:10

OMG Ponies