pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Victor Yegorov <viy@pirmabanka.lv>
To: Greg Stark <gsstark@mit.edu>
Cc: Achilleus Mantzios <achill@matrix.gatewaynet.com>
Cc: Bruno Wolff III <bruno@wolff.to>
Cc: pgsql-sql@postgresql.org
Subject: Re: Dynamic SELECT condition
Date: Mon, 3 Mar 2003 09:27:13 +0200
Message-ID: <20030303072713.GC9377@pirmabanka.lv> (raw)
In-Reply-To: <87smu5kg0z.fsf@stark.dyndns.tv>
References: <Pine.LNX.4.44.0303021347340.20034-100000@matrix.gatewaynet.com>
	<87smu5kg0z.fsf@stark.dyndns.tv>

* Greg Stark <gsstark@mit.edu> [02.03.2003 16:22]:
> Achilleus Mantzios <achill@matrix.gatewaynet.com> writes:
> 
> You might want to look into the "Nested Sets" cookbook page too:
> 
> http://www.brasileiro.net:8080/postgres/cookbook/view-recipes.adp?section_id=310&format=long
> 
> This representation of hierarchies has a lot of nice properties including
> being able to look up a whole subtree quickly. It makes it a bit of a pain to
> modify the tree though.
> 
> > If you want to know the direct kids (4,5 in the example) of id=3, then it is
> > select from table where itoar(3) ~ parents and level(parents)=2 (itoar and
> > level are simple C functions that convert an int4 to its corresponding 1x1
> > array and calculate the length of the array , respectively)
> 
> In the "int_agg" directory in contrib there are operators that do this, you
> can say "WHERE parents *= 3". I prefer to keep level in a separate column
> though.
> 
> I've find the features in the "int_agg" and "array" directories in the contrib
> directory to be extremely useful. The only disadvantage is that the optimizer
> doesn't have good basis for guessing the selectivity of the *= type operators.
> 
> GiST indexing of arrays is nice but depends on knowing which element of the
> array you're looking for. If you're looking for 3 anywhere in the hierarchy I
> don't think you can use the index.

Thanks a lot.
Nested sets are pretty good.

In my app trees arebeing updated quite often, so, instead of having a field
field in a tree tale, I've combined nested sets with adjacency list. Now I
have such table:

	tree_id		int4	not null,
	branch_id	int4	not null,
	leaf_id		int4	not null,
	left		int4	not null,
	right		int4	not null,
	...

Quite usefull, I think.

-- 

Victor Yegorov

view thread (7+ messages)  latest in thread

Message-ID: <20030303072713.GC9377@pirmabanka.lv>
Permalink:  ../20030303072713.GC9377@pirmabanka.lv/
Also on:    postgresql.org/message-id/20030303072713.GC9377@pirmabanka.lv

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: viy@pirmabanka.lv, gsstark@mit.edu, achill@matrix.gatewaynet.com, bruno@wolff.to
  Subject: Re: Dynamic SELECT condition
  In-Reply-To: <20030303072713.GC9377@pirmabanka.lv>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox