mysql - What are the known ways to store a tree structure in a relational DB? -


There, that means each record points to their parents.
Maintain that hard to read but easy to maintain.

And then there is a "directory structure key" method:

  0001.0000.0000.0000 main branch 1 0001.0001.0000.0000 one of the main branch etc etc  

Super easy to read, but difficult to maintain.
What are the other ways and their cons / professional?

As always: There is no best solution. Each solution makes different things easy or difficult. The right solution for this depends on which action you will take.

Relative approach with Parent-ID:

Professionals:

    Easy to implement

  • Easy to move any other parent to a large sub-location

  • Insert is cheap

  • Accessible area directly in SQL

Cons:

  • Retrieving the entire tree is recurring And so expensive

  • All parents are too expensive to find (SQA Revised ...)

Modified Prior Tree Treversal (A Start and End Point Saving):

Professionals:

  • Retrieving the entire tree is easy and cheap

  • It is cheaper to find all parents

  • Fields reaching directly in SQL

    >
  • Bonus: You are also saving the order of the hair node within your original node

Cons:

  • Insert / update is too expensive Because you have to update many nodes

Save paths in each node:

Professionals:

  • Insert is cheap

Cons:

  • Running a complete tree is expensive

  • The path on the way you save , You will not be able to work with it directly in SQL, so you will always need to get & amp; If you want to change it, then parse it.

I like one of the last two, depending on how often the data changes.

Also see:


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -