B
B
BonBon Slick2021-03-28 22:18:41
Database design
BonBon Slick, 2021-03-28 22:18:41

When does it make sense to use a tree structure?

Please note that this is not data since or something like computer since, but RDBM where it is necessary to declare entity-to-entity relationships.
6060d689a9802949956025.jpeg
I'll give you an example,

Юзер ---> one to one ---> Role ---> one to many ---> Role


The example above, where roles are structured in a hierarchy, has parent and child categories.
What does the Admin role mean will inherit all the features of the lower roles.
Thus the user has one role.

Or use a flat approach, if we need to add some functionality or access for the user, we add another role to him, thereby getting rid of hierarchies.

User ---> many to many ---> Role
An example with the administrator, well, the administrator, as he had access, will have it.
But here the user can simultaneously be both PostModeratorRole and CommentModeratorRole, but at the same time not be in the role of ModeratorRole, as it would be in a hierarchical structure. we can have other SomeModeratorRole.

Another example, categories.

Open any store and you will see tree structures 100500+ deep.
rosetka, aliexpress, amazon, etc.
When this complex structure could simply be replaced with tags, because when a product is in many categories, these are already tags.

Lately, blogs have been doing this because a blog post can contain information from several categories, which makes it multi-categorical.

The question is, when is it appropriate to use trees?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VitalyChaikin, 2021-03-29
@VitalyChaikin

In my opinion: the more heterogeneous data on the branches, the more sense it makes to use trees;
In addition to heterogeneity, who generates the data also plays a role; For example: one branch is People formed in the Ministry of Internal Affairs, the second is the loans of these characters formed by the bank, the third is the schedule of telephone calls from billing; There is no way to combine all this except for the tree, also because these are external sources.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question