How do you know if you have too many indexes on your table?

How do I know if I have too many indexes in my MySQL table?

For some tables that need to be accessed quite a lot, I added about 2-4 indexes in the columns to which access will be available. But how can I find out if they do more harm than good?

+4
source share
5 answers

Note that the only performance images appear when you update a table with indexes, because the specified indexes must be maintained as the data in the table changes. If you select only a table, indexes can usually only improve performance, rather than degrade. Obviously, you need to get rid of the table of any unused indexes, since they waste disk space unnecessarily and must be maintained again as the table changes over time.

Usually you need to check your execution plans to see which indexes are actually used based on your queries. Be sure to collect statistics before doing this to get accurate results. Performing this check of the execution plan is important, b / c, even if you have an index in the column, the optimizer may not select it based on factors such as column power, etc. On large tables where queries are very selective (i.e. you have 1M users, and you ask where userid = 'x', which will return 1 row), you will see that the index to select is worth the cost of maintenance. Small tables, say continental name tables, as a rule, will not benefit from the index as many times as a full table scan would be preferable to an index scan. This is because it will cost more to read the index, and then read the data block referenced by the index, and not just read a small amount of data directly. Again, these things will need to be checked based on your specific tables and needs, and all this is done by looking at the execution plans.

Favorable concatenated indexes with single column indexes if your queries lend themselves to these types of queries. For example, if your where clauses usually do something like "where emp_fname = 'jim' and emp_lname = 'smith', create one concatenated index for fname and lname instead of separate indexes for each column.

+2
source

If you insert and updates slowly, this is one way to say it.

+1
source

There are several elements to this question:

  • Are your indexes used?
  • Do your performance improve performance?

The answer to them depends on what control you use over your requests. Assuming you have a web application, you probably pretty well know the requests that come in. If not, turn on the query log for a while to find out what is happening.

Then run EXPLAIN for each of these queries and note which indexes are used to satisfy them. If any of them are not used, then you probably should remove them to save space and fine INSERT.

Then you need to find out if indexes help. Benchmarking is the most accurate method, but you can do it on a replica of your database, and not on a live copy.

+1
source

The danger of having too many indexes is that they can slow down inserts / updates / deletes, since indexes need to be recalculated. Checking the performance of attachments / update / removal. If you do not see a significant decrease in the performance of your indexes, leave them alone.

0
source

There are two methods.

  • Get query execution plans for the most common queries. Disable indexes. All other indexes - not displayed in query execution plans - are not used.

  • Measuring the performance of selected queries. Drop the index. Measure performance again and see if it has deteriorated or not.

You should consider the Insert and Update action, as well as Choose an action. Indexes make choices quick, but slowly inserted.

Not just studying and measuring one transaction. This is a common combination of transactions that determine the value of indexes.

In some cases, you might consider dropping some indexes for insertion and then restoring them.

0
source

Source: https://habr.com/ru/post/1301525/


All Articles