Re: tree structures in sql - my point of view (with request of comment from joe celko)

From: knut(dot)suebert(at)web(dot)de
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: tree structures in sql - my point of view (with request of comment from joe celko)
Date: 2002-09-04 17:46:08
Message-ID: 20020904174608.GA3296@fraxinus.reticulum
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Josh Berkus schrieb:

> Adjacency list trees are easier to understand conceptually, there are more
> tools on freshmeat.net for them, and they are the most efficient form of tree
> for graphical display.

Hi,

for graphical display it may be (the application to display could do the
work), but displaying data in tables (or tabulars, if you prefer
LaTeX-Syntax) leeds to recursion, I'd say.

> Nested Set trees are hard to wrap your mind around,

Yes ;-)

> lack a lot in the way of code samples on freshmeat, are harder to
> build GUI tools for, but are much, much faster for determining
> branch membership and branch parenthood.

While wrapping around my mind to understand Nested Sets, I got an idea
to speed up the count of subnodes and leaves (expensive if only "lft"
and "rgt" are used) by adding a third field called "lvl".

See

http://www.net-one.de/~ks/WOoK/postmaster.php
http://www.net-one.de/~ks/WOoK/nset.sql.txt

I wrote something about it here some months ago, got a few PMs with
positive reactions (so I'm writing this) and a correction. Due to time
lack, the 'documents' linked above are still draft, ugly written and
the examples may work or not, sorry.

The idea of "lvl" maybe useless or not? I'm not an expert.

> So which model you use depends on what you intend to do with the tree.

And try to understand Oleg's contrib/ltree. It may be better.

Greetings,
Knut Sübert

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bruce Momjian 2002-09-05 05:27:22 Re: LIMIT 1 FOR UPDATE or FOR UPDATE LIMIT 1?
Previous Message Bruce Momjian 2002-09-03 22:07:02 Re: tree structures in sql - my point of view (with request