Modeling Friendship Relationships

Поиск
Список
Период
Сортировка
Искать
От
Robert DiFalco
Тема
Modeling Friendship Relationships
Дата
Msg-id
CAAXGW-ymv31Hh2m6LyKQ-46_W5v3F78ta0fZ+mJRdvn7OPTidA@mail.gmail.com
Список
Дерево обсуждения
Modeling Friendship Relationships Robert DiFalco <robert.difalco@gmail.com>
Re: Modeling Friendship Relationships Bill Moran <wmoran@potentialtech.com>
Re: Modeling Friendship Relationships John R Pierce <pierce@hogranch.com>
Re: Modeling Friendship Relationships David G Johnston <david.g.johnston@gmail.com>
Re: Modeling Friendship Relationships John R Pierce <pierce@hogranch.com>
Re: Modeling Friendship Relationships Alvaro Herrera <alvherre@2ndquadrant.com>
Re: Modeling Friendship Relationships Jonathan Vanasco <postgres@2xlp.com>
Re: Modeling Friendship Relationships Robert DiFalco <robert.difalco@gmail.com>
Re: Modeling Friendship Relationships Rob Sargent <robjsargent@gmail.com>
Re: Modeling Friendship Relationships Steve Crawford <scrawford@pinpointresearch.com>
I have a question about modeling a mutual relationship. It seems basic but I can't decide, maybe it is 6 of one a half dozen of the other. 

In my system any user might be friends with another user, that means they have a reciprocal friend relationship.

It seems I have two choices for modeling it. 

1. I have a table with two columns userOne and userTwo. If John is friends with Jane there will be one row for both of them. 
2. I have a table with two columns owner and friend. If John is friends with Jane there will be two rows, one that is {John, Jane} and another {Jane, John}.

The first option has the advantage of saving table size. But queries are more complex because to get John's friends I have to JOIN friends f ON  f.userA = "John" OR f.userB = "John" (not the real query, these would be id's but you get the idea).

In the second option the table rows would be 2x but the queries would be simpler -- JOIN friends f ON f.owner = "John".

There could be >1M users. Each user would have <200 friends.

Thoughts? Do I just choose one or is there a clear winner? TIA!
В списке pgsql-general по дате отправления
От: Thomas Kellerer
Дата:
От: Nestor A. Diaz
Дата:
FAQ