Answer the question
In order to leave comments, you need to log in
Will the index affect the performance of the database when inserting and updating?
Hello. There is a table with payments, in which one of the fields has several values (status) . at the current time, the field is implemented as a varchar20 string (it would be more correct to use char20, since the statuses are approximately the same length), their number is about 10. Tables are joined according to this parameter, various calculations are carried out. At the moment there are no brakes. In the future, the number of entries will increase. Should I create an index for this field and what negative consequences can we expect? For example, the speed of updating or inserting payments.
Thanks in advance.
ps. Advise the literature on optimization of a DB.
Answer the question
In order to leave comments, you need to log in
Of course, the index will slow down requests for insertion, deletion. For, during this procedure the index needs to be changed. That is, you remove an element from the middle of the table, so the DBMS will have to update the table indexes. On a large table, with frequent requests of these types, you will get a drawdown in speed. On queries with a selection, the use of indexes gives a big advantage in speed. From this little discussion, it can be understood that everything depends on what type of operations prevails on this table.
And yet, let me ask you, why should the "status" field be implemented as a string? Wouldn't it be more logical to do, for example, smallint? A certain number would correspond to a certain status. Working with numeric fields, and even more so if there is an index on them, is an order of magnitude (no, two orders of magnitude) faster. Yes, and disk space will be saved.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question