I have a table just like this:
USER_RELATIONSHIP
----------------------
user_id follows_id
1 2
1 3
2 1
3 1
Both user_id and follows_id are Foreign keys that point to a User table. The USER_RELATIONSHIP table is quite large and I am frequently checking to see if a user relationship exists or not (eg. user A follows user B).
Given that these Foreign keys are indexed, is SQL able to find a relationship (given a user_id and a follows_id) in O(1)?
If not, is it more performant to condense the two fields above into an indexed Composite key that hashes a user_id and a follows_id and having the USER_RELATIONSHIP table like this?
USER_RELATIONSHIP
----------------------
composite_key
298437920
219873423
918204329
902348293
