X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 74DC49DCACB for ; Sat, 3 Dec 2005 20:09:45 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 53692-02 for ; Sat, 3 Dec 2005 20:09:40 -0400 (AST) X-Greylist: delayed 00:06:43.524201 by SQLgrey- Received: from mail5.dslextreme.com (mail5.dslextreme.com [66.51.199.81]) by postgresql.org (Postfix) with SMTP id AF2CD9DCA94 for ; Sat, 3 Dec 2005 20:09:40 -0400 (AST) Received: (qmail 6955 invoked from network); 4 Dec 2005 00:02:30 -0000 Received: from unknown (HELO [10.1.1.1]) (66.245.216.181) by mail5.dslextreme.com with SMTP; Sat, 03 Dec 2005 16:02:30 -0800 Subject: Re: Faster db architecture for a twisted table. From: Mitchell Skinner To: pgsql-performance@postgresql.org In-Reply-To: <3cf983d0512031500r2a9da709r8eb362806e91f61@mail.gmail.com> References: <3cf983d0512031500r2a9da709r8eb362806e91f61@mail.gmail.com> Content-Type: text/plain Date: Sat, 03 Dec 2005 16:02:58 -0800 Message-Id: <1133654578.15792.8.camel@firebolt> Mime-Version: 1.0 X-Mailer: Evolution 2.2.3 (2.2.3-2.fc4) Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200512/212 X-Sequence-Number: 16033 On Sat, 2005-12-03 at 23:00 +0000, Rodrigo Madera wrote: > CREATE TABLE person( > id bigint PRIMARY KEY, > first_name TEXT, > age INT, > mother bigint REFERENCES person, > father biging REFERENCES person, > siblings array of bigints (don't remember the syntax, but you get the point) > ); > > Well, this is ok, but imagine a search for "brothers of person id > 34". We would have to search inside the record's 'siblings' array. Is > this a bad design? is this going to be slow? Well, I don't know how close this example is to your actual problem, but the siblings array is redundant, AFAICS. If you got rid of it, you could query for full sibling brothers with something like (not tested): select bro.* from person p inner join person bro on (p.mother = bro.mother) AND (p.father = bro.father) where bro.sex='M' and p.id=34 ...assuming you added a "sex" field, which you would need in any case to query for brothers. You could query for half-siblings by changing the AND into an OR, I think. Mitch