Can foreign keys hurt query performance

前端 未结 11 1820
温柔的废话
温柔的废话 2021-02-02 10:55

As I understood from this post, there are some scenarios where foreign keys can improve query performance.

I\'ve heard the opposite claim though, that because of refere

11条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-02 11:15

    Foreign keys slow down insertions and alterations, because each foreign key reference must be verified. Foreign keys can either not affect a selection, or make it go faster, depending on if the DBMS uses foreign key indexing.

    Foreign keys have a complex effect on deletion. If you're deleting the thing that refers to the foreign key, it won't affect anything, but if what you're deleting is referenced by a foreign key in another row/table, then it will generally cause problems.

    Foreign keys can cause a minor performance degradation in table creations and alterations.

    Of course, this all assumes foreign key verification is in use.

提交回复
热议问题