querying tree/graphs modeled in SQL (Celko)
Do you know any reference where to开发者_Python百科 find SQL queries for traversing trees/graphs?
I found this one: http://www.artfulsoftware.com/mysqlbook/sampler/mysqled1ch20.html and Celko's book.
Problem is that the majority of resources I found refers to adiacency model trees, I'm using a normal edge list model.
Eg. queries or procedures to extract subpaths, subtrees, etc.
Thanks
Nested sets models are best for hierarchical aggregations. Traversals for general graphs are best done with the adjacency list model. But I have used nested sets for convergent graphs by splitting nodes
A
/ \
B C
\ /
D
Becomes
A
/ \
B C
| |
D D
Since nests sets keep nodes in a separate table, this is easy.
You can also do a general graph as a forest of all possible spanning trees
If your graph is not frequently updated, using a GRIPP index will let you handle graph traversal queries extremely well. The latter lets you answer parent-child and depth-related queries in more or less fixed time -- irrespective of the graph's number of nodes or density of links.
精彩评论