V
V
vrazbros2018-06-13 10:30:14
MySQL
vrazbros, 2018-06-13 10:30:14

How do indexes affect updating deleting records?

Does the index speed up updating or deleting records? After all, to delete, you still need to find the record)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lega, 2018-06-13
@lega

1) Indexes speed up the search for the desired rows, which adds performance (including changes / deletions)
2) Indexes slow down the change / delete query, because when changing, you need to update (rebuild) the indexes themselves

P
ponaehal, 2018-06-14
@ponaehal

In the general case, one cannot say unambiguously .... in general, indexes are designed to speed up access to records, incl. when removed and modified. But the index is a separate structure for the maintenance of which the DBMS spends its resources. For example, when inserting data into a table that has 5 indexes, there are five more inserts into each of these indexes. Moreover, inserting a new row into an index is much more difficult (in terms of DBMS resources, possibly depending on the DBMS used) than into a table, because first you need to find a place where to insert this line (now I'm talking about the most common b-tree indexes) and links to index blocks.
Moreover, to say that an index ALWAYS speeds up access to records is also wrong. It all depends on your request and how you access the data. If there is enough data for the query in the index, then the DBMS will scoop out the data without access to the table at all. This will in many cases (but not always :)) be much faster than extracting data directly from the table. If more data is retrieved in the query than the index contains, then the DBMS will (if forced) first access the index in order to find the address of the row in the table, and then get into the table and extract the necessary data). Will it be faster than just looking up the table? - in many respects depends on that how many% of records the request has to return. Usually the recommendation is this: if the query must return more than 15-20% of the rows of the table, then the use of indexes is inappropriate ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question