Question

I have read that all foreign keys should be indexed for better join performance. Do that mean, by definition, that all bridge tables should have all fields indexed

for example lets say i have 3 table

Project: Id, Name

ProjectApplication: Id, ProjectId, ApplicationId

Application: Id, Name

in these cases, should ProjectId and ApplicationId both have indexes on them?

Was it helpful?

Solution

In your given example Id column in Project table have to be a Primary key(or atleast UNIQUE constraint) in order to be able to reference it in any other column i.e creating a foreign key constraint which references it same is true for Id column in Application table. So by default it will have a Clustered Index defined on it.

Now in your ProjectApplication table if you do create a foreign Key and create an Index on that column, and obviously when ever you need to retrieve information from these tables you will be joining these tables on these two fields so having a Clustered Index on one side and a nonclustered index on other side will most definitely have a great impact on the performance of your queries, well worth it , go for it .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top