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 E1E8A9DCC27 for ; Sat, 3 Dec 2005 20:00:26 -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 46677-05 for ; Sat, 3 Dec 2005 20:00:22 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.186]) by postgresql.org (Postfix) with ESMTP id 888B69DCC16 for ; Sat, 3 Dec 2005 20:00:23 -0400 (AST) Received: from [84.143.50.85] (helo=pse.dyndns.org) by mrelayeu.kundenserver.de (node=mrelayeu0) with ESMTP (Nemesis), id 0MKwh2-1EihIl1aK7-00044P; Sun, 04 Dec 2005 01:00:23 +0100 Received: from p548f3255.dip0.t-ipconnect.de ([84.143.50.85] helo=[192.168.0.101]) by pse.dyndns.org with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.44) id 1EihIk-0004O0-11; Sun, 04 Dec 2005 01:00:22 +0100 Message-ID: <439230D3.9070006@pse-consulting.de> Date: Sun, 04 Dec 2005 00:57:07 +0100 From: Andreas Pflug User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Rodrigo Madera CC: pgsql-performance@postgresql.org Subject: Re: Faster db architecture for a twisted table. References: <3cf983d0512031500r2a9da709r8eb362806e91f61@mail.gmail.com> In-Reply-To: <3cf983d0512031500r2a9da709r8eb362806e91f61@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: kundenserver.de abuse@kundenserver.de login:0ce7ee5c3478b8d72edd8e05ccd40b70 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/108 X-Sequence-Number: 15929 Rodrigo Madera wrote: >Imagine a table named Person with "first_name" and "age". > >Now let's make it fancy and put a "mother" and "father" field that is >a reference to the own table (Person). And to get even fuzzier, let's >drop in some siblings: > >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? > >What would be a better design to have these kind of relationships? >(where you need several references to rows inside the table we are). > > Create a table "sibling" with parent_id, sibling_id and appropriate FKs, allowing the model to reflect the relation. At the same time, you can drop "mother" and "father", because this relation is covered too. Regards, Andreas