Re: Faster db architecture for a twisted table.

From: Mitchell Skinner <mitch(at)arctur(dot)us>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: Faster db architecture for a twisted table.
Date: 2005-12-04 00:02:58
Message-ID: 1133654578.15792.8.camel@firebolt
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message David Lang 2005-12-04 01:17:03 Re: Database restore speed
Previous Message Andreas Pflug 2005-12-03 23:57:07 Re: Faster db architecture for a twisted table.