From: Josh Berkus <josh@agliodbs.com>
To: Aasmund Midttun Godal <postgresql@envisity.com>
To: pgsql-sql@postgresql.org
Subject: Re: Tree structure index usage
Date: Wed, 02 Jan 2002 11:38:28 -0800
Message-ID: <web-539545@davinci.ethosmedia.com> (raw)
In-Reply-To: <20011229200610.29888.qmail@213-145-170-138.dd.nextgentel.com>
Aasmund,
> CREATE TABLE my_tree (
> id SERIAL PRIMARY KEY,
> dir INTEGER references my_tree ON DELETE CASCADE ON UPDATE CASCADE,
> name TEXT,
> UNIQUE(name, dir)
> );
>
> Then I have a function is_parent(integer, integer), it will tell you
> if the second integer (id) is a sub directory of the first
> (regardless of the number of levels).
>
> now obviously is_parent does some queries itself.
>
> and someone may choose to update the dir value of a row.
>
> is there any way I can create an efficient index on this
> structure/function?
Hmmm. Seperate indexes on ID and DIR should be sufficient for most
purposes. More complex approaches are only likely to slow things down.
How many records do you have? How many levels to the tree structure?
For an excellent discussion of efficient construction and queryin of
tree structures, see Joe Celko's "SQL for Smarties."
-Josh
______AGLIO DATABASE SOLUTIONS___________________________
Josh Berkus
Complete information technology josh@agliodbs.com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco
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: josh@agliodbs.com, postgresql@envisity.com
Subject: Re: Tree structure index usage
In-Reply-To: <web-539545@davinci.ethosmedia.com>
* 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