- 1

Does Foreign Key improve query performance?

17th Jan 2017, 5:24 AM
Akwin Lopez
Akwin Lopez - avatar
2 ответов
0
Foreign Keys are a referential integrity tool, not a performance tool. At least in SQL Server, the creation of an FK does not create an associated index, and you should create indexes on all FK fields to improve look up times.
17th Jan 2017, 5:25 AM
Akwin Lopez
Akwin Lopez - avatar
0
Foreign key constraint improve performance at the time of reading data but at the same time it slows down the performance at the time of inserting / modifying / deleting data. In case of reading the query, the optimizer can use foreign key constraints to create more efficient query plans as foreign key constraints are pre declared rules. This usually involves skipping some part of the query plan because for example the optimizer can see that because of a foreign key constraint, it is unnecessary to execute that particular part of the plan.
17th Jan 2017, 5:25 AM
Akwin Lopez
Akwin Lopez - avatar