Re: transitive closure of a graph

From: Mikito Harakiri <mikharakiri_nospaum_at_yahoo.com>
Date: 12 Oct 2005 10:27:53 -0700
Message-ID: <1129138072.995724.60230_at_g14g2000cwa.googlegroups.com>


Serge Rielau wrote:
> Mikito Harakiri wrote:
> > Mikito Harakiri wrote:
> >
> >>Transitive closure (TC) of a graph is
> >>
> >>with TransClosedEdges (tail, head) as
> >>( select tail, head from Edges
> >> union all
> >> select e.tail, ee.head from Edges e, TransClosedEdges ee
> >> where e.head = ee.tail
> >>)
> >>select distinct * from TransClosedEdges
> >>
> >>except that this query might never terminate.
> >
> >
> > Oops, it's actually quite obvious
> >
> > with TransClosedEdges (tail, head) as
> > ( select tail, head from Edges
> > where tail <> head --*******
> > union all
> > select e.tail, ee.head from Edges e, TransClosedEdges ee
> > where e.head = ee.tail
> > and e.tail <> ee.head --*******
> > )
> > select distinct * from TransClosedEdges
> >
> > Graeme handles more general case, hence the complication.
> >
> There will be a new developerWorks article on mapping CONnECT BY to DB2
> tomorrow (if all goes well).

There is July 2003 article by Torsten Steinbach. I guess your article would address 10g features, cycle handling first of all. Looking forward to read it.

Interestingly, that recursive "with" was brought up in past flame wars "A" vs. "B". (As if technical excellence really matters:-). It's amaising what difference a tiny standard uncomplience makes -- I mean "union all" instead of "union". Suddenly, transitive closure for graph with cycles is not expressible anymore. Received on Wed Oct 12 2005 - 19:27:53 CEST

Original text of this message