Can foreign keys hurt query performance

前端 未结 11 1797
温柔的废话
温柔的废话 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:05

    If you're enforcing referential integrity, INSERTs, and UPDATEs that effect the FK field, will be slower. However, it's usually not much to worry about, especially as a lot of DBs are 80% read/20% write. It's also a price worth paying.

    Creating an index on a foreign key is often beneficial, though obviously it how much depends on what SELECT statements you're running.

    Generally, you need foreign keys due to normalisation (which avoids duplicate data and synchronisation problems). Normalise to the 3rd degree, and then after analysing real world performance can you consider de-normalising.

提交回复
热议问题