This question asks about storing a single graph in a relational database. The solution is clear in that case: one table for nodes, one table for edges.
这个问题询问关于在关系数据库中存储单个图。在这种情况下,解决方案很明确:一个表用于节点,一个表用于边缘。
I have a graph data structure that evolves over time, so I would like to store "snapshots" of this graph in a database. I imagine having hundreds of such snapshots.
我有一个图形数据结构随着时间的推移而发展,所以我想将这个图的“快照”存储在数据库中。我想有数百个这样的快照。
One solution is to create a whole new table pair of nodes and edges (as above) for each snapshot. Is there a better solution?
一种解决方案是为每个快照创建一个全新的表对节点和边(如上所述)。有更好的解决方案吗?
EDIT: It was asked what I would like to do with this database. I believe that I will not be doing any querying except to dump all of the graphs to MySQL from C++ and then load it all back into C++ data structures. So I'm looking to use MySQL for storage and not for efficient random access / searching.
编辑:有人问我想用这个数据库做什么。我相信除了将所有图表从C ++转储到MySQL然后将其全部加载回C ++数据结构之外,我不会进行任何查询。所以我希望将MySQL用于存储而不是用于有效的随机访问/搜索。
1 个解决方案
#1
5
You need a table
你需要一张桌子
graphs = (graphid, dateofsnapshot or other things unique to the snapshot)
and you need the nodes and edges tables but with a foriegn key reference to the graphs table. This way you can have an arbitrary number of graphs in the database.
你需要节点和边表,但有一个foriegn键参考图表。这样,您可以在数据库中拥有任意数量的图形。
#1
5
You need a table
你需要一张桌子
graphs = (graphid, dateofsnapshot or other things unique to the snapshot)
and you need the nodes and edges tables but with a foriegn key reference to the graphs table. This way you can have an arbitrary number of graphs in the database.
你需要节点和边表,但有一个foriegn键参考图表。这样,您可以在数据库中拥有任意数量的图形。