While reading Graph Databases book, I came across this excerpt:
I can't figure out why the second query is more expensive than the first.
Indeed, both filter on the Bob
person.
May anyone explain it?
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.
Sign up to join this communityWhile reading Graph Databases book, I came across this excerpt:
I can't figure out why the second query is more expensive than the first.
Indeed, both filter on the Bob
person.
May anyone explain it?
The book is assuming that PersonFriend is indexed on PersonID, but not on FriendID. It also seems to assume that Person indexes PersonID and Person independently.
If this is the case, the first query comes back as
Then the second comes back as
This would be an elementary relational database design error. With a relationship table like this you would always index all keys, and the performance profile for both queries would be indistinguishable (ignoring variations in value distributions, etc).
At this point it sounds like the author is trying to show that relational databases are intrinsically deficient.
PersonFriend
is indexed on PersonID
, but not on FriendID
". So if I well figure it out, if FriendID
was also indexed, both queries would be similar regarding performance. Howerver the book explains that adding another index for this column (FriendId
) would be expensive (in memory, etc..). Am I right?