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.fk
is set up to be a foreign key onb.pk
-b.pk
is indexeda.fk
is set up to be a foreign key onb.pk
-b.pk
is not indexed- there is no relationship between the tables -
b.pk
is indexed - there is no relationship between the tables -
b.pk
is 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!