Unix Technical Forum

Computing transitive closure of a table

This is a discussion on Computing transitive closure of a table within the Pgsql General forums, part of the PostgreSQL category; --> I am doing some preliminary work on the next major release of a piece of software that uses PostgreSQL. ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 11:16 AM
Chris Smith
 
Posts: n/a
Default Computing transitive closure of a table

I am doing some preliminary work on the next major release of a piece of
software that uses PostgreSQL. As odd as this sounds, it seems that a huge
percentage of the new features that have been requested involve computing
the transitive closure of a binary relation that's expressed in a database
table.

For example:

- Given a list of relationships of the form "X is a direct subgroup of Y",
determine the full list of groups of which some group is a (not necessarily
direct) subgroup.

- Given a list of statements of the form "X must happen before Y", determine
everything that needs to happen for some objective to be achieved.

And the list goes on and on... I'm aware that it's not possible to solve
the transitive closure problem using a simple SQL query. Anyone have any
recommendations? Are there any thoughts on implementing efficient
transitive closures within PostgreSQL? If I wanted to do it, are there
preferences on syntax or other such things?

My thoughts on an ideal feature would involve being able to create a sort of
"transitive closure" index which could be kept up to date automatically by
the database back end.

Or should I just punt and let the queries be slow (not a good option, since
the group thing is necessary for permission checking, which may happen up to
a half-dozen times per HTTP request).

Thanks,

--
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation


---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-09-2008, 11:16 AM
Oleg Bartunov
 
Posts: n/a
Default Re: Computing transitive closure of a table

Chris,

have you seen contrib/ltree ?

Oleg
On Mon, 19 Jun 2006, Chris Smith wrote:

> I am doing some preliminary work on the next major release of a piece of
> software that uses PostgreSQL. As odd as this sounds, it seems that a huge
> percentage of the new features that have been requested involve computing the
> transitive closure of a binary relation that's expressed in a database table.
>
> For example:
>
> - Given a list of relationships of the form "X is a direct subgroup of Y",
> determine the full list of groups of which some group is a (not necessarily
> direct) subgroup.
>
> - Given a list of statements of the form "X must happen before Y", determine
> everything that needs to happen for some objective to be achieved.
>
> And the list goes on and on... I'm aware that it's not possible to solve the
> transitive closure problem using a simple SQL query. Anyone have any
> recommendations? Are there any thoughts on implementing efficient transitive
> closures within PostgreSQL? If I wanted to do it, are there preferences on
> syntax or other such things?
>
> My thoughts on an ideal feature would involve being able to create a sort of
> "transitive closure" index which could be kept up to date automatically by
> the database back end.
>
> Or should I just punt and let the queries be slow (not a good option, since
> the group thing is necessary for permission checking, which may happen up to
> a half-dozen times per HTTP request).
>
> Thanks,
>
>


Regards,
Oleg
__________________________________________________ ___________
Oleg Bartunov, Research Scientist, Head of AstroNet (www.astronet.ru),
Sternberg Astronomical Institute, Moscow University, Russia
Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/
phone: +007(495)939-16-83, +007(495)939-23-83

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-09-2008, 11:16 AM
Bruno Wolff III
 
Posts: n/a
Default Re: Computing transitive closure of a table

On Mon, Jun 19, 2006 at 13:43:17 -0600,
Chris Smith <cdsmith@twu.net> wrote:
> I am doing some preliminary work on the next major release of a piece of
> software that uses PostgreSQL. As odd as this sounds, it seems that a huge
> percentage of the new features that have been requested involve computing
> the transitive closure of a binary relation that's expressed in a database
> table.


I believe this is covered by the following on the TODO list:
Add SQL:2003 WITH RECURSIVE (hierarchical) queries to SELECT

I think someone did some work on this a while ago, but that not much has
happened recently.

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-09-2008, 11:16 AM
Chris Smith
 
Posts: n/a
Default Re: Computing transitive closure of a table

Oleg Bartunov wrote:
> Chris,
>
> have you seen contrib/ltree ?


I hadn't. Thanks! I will look into it further, but I'm currently a bit
concerned by the word "tree" in the title. Many of the problems I'm solving
are not trees, though nearly all are DAGs.

--
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-09-2008, 11:16 AM
Bricklen Anderson
 
Posts: n/a
Default Re: Computing transitive closure of a table

There was a thread last November entitled "Transitive closure of a
directed graph" on the [HACKERS] list. There may be some information of
use there.

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:58 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com