Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disadvantages of many indexes in MySQL [closed]

Situation

I have a table called follow and this is the table structure:

- follower_id
- following_id
- when // timestamp

These are the SQL Queries I execute:

SELECT * FROM follow WHERE follower_id = ? ORDER BY when LIMIT 0,20
SELECT * FROM follow WHERE following_id = ? ORDER BY when LIMIT 0,20
SELECT * FROM follow WHERE follower_id = ?
SELECT * FROM follow WHERE following_id = ?

and these are my indexes:

follower_id, when
following_id, when
follower_id
following_id

Question

Is this approach true? And is there any disadvantage of having this amount (or more than this) of indexes in DB ?

like image 205
Can Geliş Avatar asked Nov 16 '13 18:11

Can Geliş


People also ask

What are the disadvantages of too many indexes?

The downside to adding indexes to a table is that they affect the performance of writes. Moreover, improperly created indexes can even adversely affect SELECT queries! Any table configuration where performance suffers due to excessive, improper, or missing indexes is considered to be poor indexing.

What are the disadvantages of indexes in MySQL?

The Drawbacks of Using IndexesIndexes consume disk space – an index occupies its own space, so indexed data will consume more disk space too; Redundant and duplicate indexes can be a problem – MySQL allows you to create duplicate indexes on a column and it does not “protect you” from doing such a mistake.

What happens if there are too many indexes on a table?

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.

How many indexes are too many in MySQL?

If a UNIQUE INDEX is created, an error occurs. 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. FULLTEXT, UNIQUE INDEXes, and INDEXes do not have this limitation.


1 Answers

And is there any disadvantage of having this amount (or more than this) of indexes in DB ?

I dont think that these amount of indexes will affect your performance.

However you may note that Indexes are good and speedy when using SELECT rather than INSERT.

Disadvantages of Index from [here][1] says that:

When an index is created on the column(s), MySQL also creates a separate file that is sorted, and contains only the field(s) you're interested in sorting on.

Firstly, the indexes take up disk space. Usually the space usage isn’t significant, but because of creating index on every column in every possible combination, the index file would grow much more quickly than the data file. In the case when a table is of large table size, the index file could reach the operating system’s maximum file size.

Secondly, the indexes slow down the speed of writing queries, such as INSERT, UPDATE and DELETE. Because MySQL has to internally maintain the “pointers” to the inserted rows in the actual data file, so there is a performance price to pay in case of above said writing queries because every time a record is changed, the indexes must be updated. However, you may be able to write your queries in such a way that do not cause the very noticeable performance degradation.

[1]: spam link removed

like image 65
Rahul Tripathi Avatar answered Sep 28 '22 04:09

Rahul Tripathi