How to efficient store graphs in SQL database (e.g., mysql)?
I have a tree like graphs 开发者_运维问答and I need to store them into database. I am looking for information how to efficiently store and query graphs in SQL database.
Tree graphs, hierarchies, can be stored using the "nested set model". A web search on this term will give you a lot of good articles on this subject. The nested set model allows tree traversal without recursive queries.
The more common approach has a name, "adjacency list model". This approach does require either recursion or DBMS specific extensions to SQL.
The advantage of adjacency lists lies in fast and easy updates. The advantage of nested sets lies in easy queries.
精彩评论