| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: transitive closure of a graph
Mikito Harakiri wrote:
> Adam Machanic wrote:
> > That won't work for the following undirected graph:
> >
> > E
> > / /\ \
> > A / \ D
> > \ / \ /
> > B C
> >
> > CREATE TABLE Edges (point1 CHAR(1), point2 CHAR(1))
> >
> > INSERT Edges VALUES ('A', 'A')
> > INSERT Edges VALUES ('B', 'B')
> > INSERT Edges VALUES ('C', 'C')
> > INSERT Edges VALUES ('D', 'D')
> > INSERT Edges VALUES ('E', 'E')
> > INSERT Edges VALUES ('E', 'A')
> > INSERT Edges VALUES ('A', 'E')
> > INSERT Edges VALUES ('E', 'D')
> > INSERT Edges VALUES ('D', 'E')
> > INSERT Edges VALUES ('A', 'B')
> > INSERT Edges VALUES ('B', 'A')
> > INSERT Edges VALUES ('D', 'C')
> > INSERT Edges VALUES ('C', 'D')
> > INSERT Edges VALUES ('B', 'E')
> > INSERT Edges VALUES ('E', 'B')
> > INSERT Edges VALUES ('C', 'E')
> > INSERT Edges VALUES ('E', 'C')
> >
> >
> > ... I don't think a solution is possible without string or binary
> > manipulation, due to the fact that you only have access to the last anchor
> > in the recursive part. If you had access to the entire set of preceding
> > rows it might be different...
>
>
>
>
The duplicates are not a problem at all. Since you represent the undirected graph with two bidirectional ones, the recursive query naturally fails as it encounters cycles. It will fail even on a trivial graph like that:
1---2---3
... if represented like {(1,2), (2,1), (2,3), (3,2)}
>
![]() |
![]() |