Re: Computing transitive closure of a table

Lists: pgsql-general
From: "Chris Smith" <cdsmith(at)twu(dot)net>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Computing transitive closure of a table
Date: 2006-06-19 19:43:17
Message-ID: 01ac01c693d8$9d027200$af02a8c0@KYA
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

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


From: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
To: Chris Smith <cdsmith(at)twu(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Computing transitive closure of a table
Date: 2006-06-19 19:58:41
Message-ID: Pine.GSO.4.63.0606192358160.2921@ra.sai.msu.su
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

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(at)sai(dot)msu(dot)su, http://www.sai.msu.su/~megera/
phone: +007(495)939-16-83, +007(495)939-23-83


From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Chris Smith <cdsmith(at)twu(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Computing transitive closure of a table
Date: 2006-06-19 20:20:10
Message-ID: 20060619202010.GA29333@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Mon, Jun 19, 2006 at 13:43:17 -0600,
Chris Smith <cdsmith(at)twu(dot)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.


From: "Chris Smith" <cdsmith(at)twu(dot)net>
To: "Oleg Bartunov" <oleg(at)sai(dot)msu(dot)su>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Computing transitive closure of a table
Date: 2006-06-19 21:46:32
Message-ID: 025101c693e9$d647a380$af02a8c0@KYA
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

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


From: Bricklen Anderson <banderson(at)presinet(dot)com>
To: Chris Smith <cdsmith(at)twu(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Computing transitive closure of a table
Date: 2006-06-19 22:13:54
Message-ID: 449721A2.7080103@presinet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

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.