Re: Modeling General Graphs in SQL

From: <mikharakiri_nospaum_at_yahoo.com>
Date: 16 Dec 2005 15:07:30 -0800
Message-ID: <1134774450.355642.323260_at_g49g2000cwa.googlegroups.com>


Robert Klemme wrote:
> --CELKO-- wrote:
> > to get a starting point?
>
> A quick first thought without fully digesting your posting: as you might
> know there is a fairly easy way to store a tree in a RDBMS which allows
> for fast access to subtrees and paths (even without Oracle's CONNECT BY
> PRIOR). Maybe that can be used somehow in this context for storing a DFS
> traversal. The tricky part will be the storage of backwards edges...
>
> From memory:
>
> CREATE TABLE SOME_TREE (
> node_id int,
> pre int,
> post int
> )
>
> subtree
>
> SELECT node_id
> FROM SOME_TREE ST, (SELECT pre, post FROM SOME_TREE WHERE node_id =
> &rootid) RT
> WHERE ST.pre >= RT.pre
> AND ST.post <= RT.post
>
> path
>
>
> SELECT node_id
> FROM SOME_TREE ST, (SELECT pre, post FROM SOME_TREE WHERE node_id =
> &childid) CT
> WHERE ST.pre <= CT.pre
> AND ST.post >= CT.post
>
> Updates are also fairly easy.

Celko has been referenced to his own method! Remarkable. Received on Sat Dec 17 2005 - 00:07:30 CET

Original text of this message