What are the disadvantages to Indexes in database tables?

前端 未结 2 765
伪装坚强ぢ
伪装坚强ぢ 2021-02-18 22:48

Is there any reason I shouldn\'t create an index for every one of my database tables, as a means of increasing performance? It would seem there must be some reason(s) else all t

2条回答
  •  无人及你
    2021-02-18 23:34

    One index on a table is not a big deal. You automatically have an index on columns (or combinations of columns) that are primary keys or declared as unique.

    There is some overhead to an index. The index itself occupies space on disk and memory (when used). So, if space or memory are issues then too many indexes could be a problem. When data is inserted/updated/deleted, then the index needs to be maintained as well as the original data. This slows down updates and locks the tables (or parts of the tables), which can affect query processing.

    A small number of indexes on each table are reasonable. These should be designed with the typical query load in mind. If you index every column in every table, then data modifications would slow down. If your data is static, then this is not an issue. However, eating up all the memory with indexes could be an issue.

提交回复
热议问题