database - How to represent a tree like structure in a db -
i'm starting project , i'm in designing phase: i.e., haven't decided yet on db framework i'm going use. i'm going have code creates "forest" structure. is, many trees, each tree standard: nodes , edges. after code creates these trees want save them in db. (and pull them out eventually)
the naive approach representing data in db relational db 2 tables: nodes , edges. is, nodes table have node id, node data, etc.. , edges table mapping of node id node id.
is there better approach? or given (limited) assumptions i'm giving best approach? how if add assumption trees relatively small - better save whole tree blob in db? type of db should use in case? please comment on speed/scalability.
thanks
i showed solution similar nodes & edges tables, in answer stackoverflow question: what efficient/elegant way parse flat table tree? call solution "closure table".
i did presentation on different methods of storing , using trees in sql, models hierarchical data sql , php. demonstrated right indexes (depending on queries need run), closure table design can have performance, on large collections of edges (about 500k edges in demo).
i covered design in book, sql antipatterns: avoiding pitfalls of database programming.
Comments
Post a Comment