We use Postgres as our database. Now have a new requirement to model relationships like follow. Though it seems like a good fit for a graph database, there is no room for using graph db as postgres has already been used as db platform in this application.
What's the best way to model this in a relational design to avoid recursive self joins which will result in horrible query performance for a large recursive tree. -
Query requirement is such that display John Doe
's relationship tree along with every related member's relationship tree in there.
Note that following example is for illustration purposes but real use case involves very deep such recursive relationships.
{
"personId" : 1,
"name" : "John Doe",
"relationships": {
"cousineOf" : 23 //23 is a personId in the same table. say 23 is "Merry",
"fatherOf" : 3 //where 3 is a personId with name - "George",
"brotherOf" : 67 //where 67 is a personId with name - "Tony"
}
}