What is the reason for the graph dbms being better at friend-of-a-friend queries than relational dbms?
0
votes
2
answers
119
views
I often read that graph dbms are well suited for social networks. So for example, followers on instagram or linkedin. I read that the SQL dbms performance can degrade if the query involves multiple joins, especially if the tables being joined are large.
What is the exact reason that SQL databases might perform poorly under joins? Assume that the
followers
table is indexed on both foreign keys.
The query:
SELECT DISTINCT f2.followed_id
FROM followers f1
JOIN followers f2 ON f1.followed_id = f2.follower_id
WHERE f1.follower_id = 4;
Execution plan for the query:
HashAggregate (cost=253.84..257.23 rows=339 width=8)
Group Key: f2.followed_id
-> Nested Loop (cost=0.84..253.00 rows=339 width=8)
-> Index Only Scan using followers_pkey on followers f1 (cost=0.42..16.22 rows=19 width=8)
Index Cond: (follower_id = 4)
-> Index Only Scan using followers_pkey on followers f2 (cost=0.42..12.27 rows=19 width=16)
Index Cond: (follower_id = f1.followed_id)
So I think that the execution plan does not show that tere are no complex operations being done. One thing I read is that when joining tables, the database engine needs to search for matching rows in both tables and combine them into a single result set. Is that the reason for poor performance?
Or maybe I'm missing some other valid point?
Asked by Damiano
(23 rep)
May 6, 2023, 08:06 AM
Last activity: May 7, 2023, 11:50 PM
Last activity: May 7, 2023, 11:50 PM