3

I have a problem storing and querying graph to SQL database. I have read some tutorials about storing trees into relational db, but my graph is kinda diferent.

You can see sample graph in my picture https://i.stack.imgur.com/J57v6.png. It has root node and by edges you can "walk" to some specific nodes. Important is that this graph doesnt include circles (loops). If you choose some node, eg 3, you will walk to nodes 4,5,6. So there is always final amount of visited nodes.

Saving this wouldnt be big problem, but problem is that I need to query this graph. For example my query input can be node 3, than I expect to get result contains nodes 4,5,6 even there isnt edge between 3 and 4, but there is path from 3 to 4 over 5. And this is whole problem.

I expect this graph will have around 10 000 nodes. Most important is speed of query which i have written above. Inserting/deleting/updating nodes and edges can be much slower.

Do you have ideas how to store and query this graph?

Thank you in advance

Sample graph: https://i.stack.imgur.com/J57v6.png

Tomas Zaruba
  • 196
  • 1
  • 8
  • Go throw this awesome presentation http://www.slideshare.net/billkarwin/models-for-hierarchical-data ;) Later you can buy that guy's book named "SQL Antipatterns" ;) – Matej Baćo Mar 22 '12 at 12:45

0 Answers0