From: | "Josh Berkus" <josh(at)agliodbs(dot)com> |
---|---|
To: | "Aasmund Midttun Godal" <postgresql(at)envisity(dot)com>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Tree structure index usage |
Date: | 2002-01-02 19:38:28 |
Message-ID: | web-539545@davinci.ethosmedia.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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(at)agliodbs(dot)com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Kreiner | 2002-01-02 21:45:57 | Getting Hour From a Time in Different Time Zone |
Previous Message | Bruce Momjian | 2002-01-02 18:26:31 | Re: [SQL] Unpredictable text -> date implicit casting behaviour/to_date |