Can foreign keys hurt query performance

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

    Foreign key checking takes more time than most people think. A current test with Oracle 11g and a table with two foreign keys showed that the time for an insert of about 800.000 rows took 60 seconds with enabled foreign keys but only 20 seconds without foreign keys. (The foreign key columns were indexed, of course)

    Anyway, I agree with all the other posters, that integrity constraints are not an option, but the only way to keep data consistent. However, for imports, especially into empty tables, it could be an option to disable the foreign key for the time of the import, if time is critical.

提交回复
热议问题