From: Aasmund Midttun Godal <postgresql@envisity.com>
To: pgsql-sql@postgresql.org
Subject: Tree structure index usage
Date: Sat, 29 Dec 2001 20:06:10 GMT
Message-ID: <20011229200610.29888.qmail@213-145-170-138.dd.nextgentel.com> (raw)
I have a tree structure like:
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?
The only way I have come up with, is to create an auxilliary table which basically looks like this:
CREATE TABLE my_tree_is_parent (
is_parent boolean,
dir INTEGER REFERENCES my_tree,
id INTEGER,
PRIMARY KEY (dir, id)
);
and the appropriate triggers to populate and update the table according to modifications in my_tree, however, albeit giving some performance increase (in some cases), it complicates the queries a lot and makes the whole system a lot less userfriendly.
any ideas?
Regards,
Aasmund Midttun Godal
aasmund@godal.com - http://www.godal.com/
+47 40 45 20 46
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: postgresql@envisity.com
Subject: Re: Tree structure index usage
In-Reply-To: <20011229200610.29888.qmail@213-145-170-138.dd.nextgentel.com>
References: <20011229200610.29888.qmail@213-145-170-138.dd.nextgentel.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