Can foreign keys hurt query performance

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

    Foreign keys can cause inserts(or some updates) in child tables or deletes from parent tables to take longer. This is a good thing however as it means that it is making sure that the data integrity remains. There is no reason whatsoever to skip using foriegn keys unless you don't want to have useful data. You wil not normally notice much differnce unless you have many foreign keys realted to the same parent table or if you are inserting or deleting many records in one batch. Further, I have noticed, users are more tolerant of a couple of extra seconds in an insert or delete than they are in a select. Users are also not tolerant at all of unreliable data which is what you have without foreign key constraints.

    You will need to index them to improve performance on select queries.

提交回复
热议问题