Most of the data around us, one way or another, has some structure and connections. For example, a biological classification or a sales department has a certain hierarchy. In this topic, you will learn about one of the first data models and its advantages and disadvantages.
How does Hierarchical database store data?
The natural way to explain hierarchy to the computer is to use a tree. A tree represents a connected graph that doesn't contain cycles. Otherwise, it is a parent-child structure, where one parent node can have many child nodes connected through links.
A Hierarchical Database model is a data model where data is stored as records but linked in a tree-like structure. Each record is a collection of fields (attributes) containing only one data value. A link is an association between precisely two records. Each record has only one parent. So, a Hierarchical Database is a set of such trees, which forms a forest.
To make it clearer, let's take a look at the picture below:
Pros and cons
A Relational database can be transformed into a Hierarchical one. To do this, you need to set a tree structure based on the existing relationships. One-to-one and one-to-many relationships are transformed naturally. The situation becomes more complicated in the case of many-to-many relationships. To imitate it, we have to duplicate trees. So a huge data duplication appears.
This is one of the main disadvantages of the data model. In addition, there are several more:
- The inflexibility of the model
- Adding a new record can lead to changes in the structure
- Change in structure leads to change in all application programs
- Lack of standard
- The existence of query restrictions, i.e. they are executed only from top to bottom
The advantages of the model include:
- The simplicity of the concept
- Automatic integrity maintenance
- Significant acceleration of some queries due to optimization of graph algorithms.
A hierarchical database is a good storage for those systems that initially have a tree-like structure. The model is great if you need to make frequent top-down selections. For example, you model a military unit, and the database user wants to get some employee's subordination tree. A hierarchical database deals with it much faster than a relational one. Also, if the data is logically split into small tightly connected fragments, the model can speed up its processing by applying graph optimization algorithms.
Use in practice
Despite the very narrow specialization, the model is actively used nowadays.
The most well-known and common Hierarchical Database management system is the IBM Information Management System (IMS). The first version appeared in 1968. it was used, for instance, in biology, geography, and anatomy. According to the principle of a top-down tree structure, the classification of living organisms is organized, hydrosphere objects are built, branching nerves and blood vessels are displayed.
The most common practical application of the Hierarchical Database is the traditional Windows file system. Going into the Explorer, we get to the root and see large structural units: "This computer", "Network", and others. Moving down and choosing one of the units, we go to the folders, then to the files and find the necessary information.
Thus, if you are confident in a strict descending hierarchy of your data, you can safely use a Hierarchical database. In other cases, it is worth choosing some more commonly used and universal data models.
Conclusion
A hierarchical database consists of a collection of records that are connected to each other through links and form trees. It is efficient for top-down hierarchy and one-to-many relationships. Now is commonly used in file systems.