X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id DA2E954FDB for ; Sun, 6 Mar 2005 18:29:01 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 22759-10 for ; Sun, 6 Mar 2005 18:28:56 +0000 (GMT) Received: from viefep19-int.chello.at (viefep11-int.chello.at [213.46.255.27]) by svr1.postgresql.org (Postfix) with ESMTP id F2E0454CFF for ; Sun, 6 Mar 2005 18:28:55 +0000 (GMT) Received: from [213.47.56.254] by viefep19-int.chello.at (InterMail vM.6.01.03.04 201-2131-111-106-20040729) with ESMTP id <20050306182853.GKGE4105.viefep19-int.chello.at@[213.47.56.254]>; Sun, 6 Mar 2005 19:28:53 +0100 Message-ID: <422B4B9A.8020606@foo.at> Date: Sun, 06 Mar 2005 19:27:38 +0100 From: Stefan Weiss Organization: Foo Orbital Operations User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Bruno Wolff III Cc: pgsql-sql@postgresql.org Subject: Re: Links between rows in a table References: <422A8A26.1070704@foo.at> <20050306174201.GA19019@wolff.to> In-Reply-To: <20050306174201.GA19019@wolff.to> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.025 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200503/84 X-Sequence-Number: 20563 On 2005-03-06 18:42, Bruno Wolff III wrote: >> We are currently designing a web-based application in which users can >> add other users as "friends". These links are bi-directional, meaning >> that when A adds B to his friends, he is automatically one of B's >> friends. Eventually we will have to add a feature that shows how A is > > This doesn't seem like a good idea unless the person getting linked to > gets to confirm he wants the link creator as a friend. Yes, we have an invitation/pending/confirm process, and users are also able to block other users. I haven't mentioned this because I did not think it relevant to the storage question. There is a different system for unilateral friendships ("favorites/fans"). >> SELECT friend_id FROM friends WHERE user_id = X >> UNION SELECT user_id FROM friends WHERE friend_id = X; > > It would probably be better to always have either both or neither of > the symmetric relationships in the table. You could make a set of triggers > to enforce this. We have also considered this, but since "friendship" in this application is mutual by definition, wouldn't that just lead to data duplication? We might still insert two rows instead of one, if we find that the union slows things down more than the larger table, or if the "connection finder" feature will be easier to implement that way. By the way, according to the MySQL documentation, "Rudimentary support for triggers is included beginning with MySQL 5.0.2". The MySQL compatibility requirement is none of my doing, I have given up trying to educate my customers about the benefits of a real database... regards, stefan weiss