Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficient way to store and query tree-like hierarchical data

Tags:

People also ask

Which is the most efficient tree for accessing data from a database?

The B-tree enables the database to find a leaf node quickly. The tree traversal is a very efficient operation—so efficient that I refer to it as the first power of indexing. It works almost instantly—even on a huge data set.

Which database is similar to hierarchical structure?

Hierarchical Database vs Relational Database The difference between relational and hierarchical databases lies in the data structures. While the hierarchical database architecture is tree-like, data in a relational database is stored in tables with a unique identifier for each record.

How do you store tree data structure in database?

The simplest way to serialize a tree is to give each node a parent_id column that contains the ID of the parent node. Any modification of the tree (like adding a node or changing a node's parent) only affect a single row in the table, so changes are fast. The number of queries grows with the depth of your tree.


Please see the image here:

https://picasaweb.google.com/108987384888529766314/CS3217Project#5717590602842112850

So, as you can see from the image, we are trying to store hierarchical data into a database. 1 publisher has may articles, 1 article has many comments and so on. Thus, if I use a relational database like SQL Server, I will have a publisher table, then an articles table and a comments table. But the comments table will grow very quickly and become very large.

Thus, is there any alternative which allows me to store and query such tree like data efficiently? How about NoSQL (MongoDB)?