Index all columns

前端 未结 6 2215
梦毁少年i
梦毁少年i 2021-02-18 14:58

Knowing that an indexed column leads to a better performance, is it worthy to indexes all columns in all tables of the database? What are the advantages/disadvantages of such ap

6条回答
  •  半阙折子戏
    2021-02-18 15:19

    No, you should not index all of your columns, and there's several reasons for this:

    • There is a cost to maintain each index during an insert, update or delete statement, that will cause each of those transactions to take longer.
    • It will increase the storage required since each index takes up space on disk.
    • If the column values are not disperse, the index will not be used/ignored (ex: A gender flag).
    • Composite indexes (indexes with more than one column) can greatly benefit performance for frequently run WHERE, GROUP BY, ORDER BY or JOIN clauses, and multiple single indexes cannot be combined.

    You are much better off using Explain plans and data access and adding indexes when necessary (and only when necessary, IMHO), rather than creating them all up front.

提交回复
热议问题