Say I have two tables, a and b:
a {
pk as int
fk as int
...
}
b {
pk as int
...
}
I want to join a and b in a query like so:
FROM a
JOIN b on a.fk = b.pk
Which of the following scenarios will be faster?
a.fkis set up to be a foreign key onb.pk–b.pkis indexeda.fkis set up to be a foreign key onb.pk–b.pkis not indexed- there is no relationship between the tables –
b.pkis indexed - there is no relationship between the tables –
b.pkis not indexed
Bonus question – how much faster/slower will each of these scenarios be?
If you could back up your answer with a reference then that’d be awesome. Thank you!
Best practice
Logically, this gives following ranking performance wise
a.fkis set up to be a foreign key onb.pk–b.pkis indexedb.pkis indexeda.fkis set up to be a foreign key on b.pk –b.pkis not indexedb.pkis not indexed