Database structure and querying hierarchical data and data trees

Possible duplicate:
What is the most efficient / elegant way to parse a flat table into a tree?

I find this quite complicated and would like to get some opinions on this issue. I am trying to store hierarchical data (such as a tree) with an unknown number of levels and branches. I want to be able to add new ones and delete any at any time.

I need to be able to query from any node in the hierarchy for all the child identifiers at a time and efficiently due to the large user base.

Let's look at a hypothetical example of a website where families communicate and update their status, for example, on Facebook, and at any time you can view members of the β€œWall” family, which will also include all the latest status updates from people below them in the hierarchy in chronological order.

Obviously, fetching messages when you have an array of family members that are children of these node family members is easy enough in a loop.

Let's look at an example of a simple table structure:

id  |  parentId  |  name
________________________

1   |    NULL    |  John
2   |     1      |  Peter
3   |     1      |  Bob
4   |     3      |  Emma
5   |     2      |  Sam
6   |     4      |  Gill

etc. You get the idea.

I need to do something like this if you do not think that the structure should be adapted.

I read on mySql a nested dialing model . This seems very inconvenient and can be unreliable if something is not updated correctly and ruins everything.

php mysql, . , ?

+3
3

, , .

, , ( , , ).

  • MySQL ( MySQL)
  • ( Sitepoint, , )

/ , ( ). node node .

+1

, , .

, , , , - .

, . hierarchal map /node.

:

:

id  |  fMemberId   |   parentid
=====================================
1   |      3       |       2  
2   |      4       |       3
3   |      4       |       2

1). , , .

2). , .

- map, , php , map. sql ,

, , db map, .

- , . , , SQL, , , db .

, InnoDB, , " " .

, , , . .

?

, . , . , id , . !

0

, . :

, . 2-2, 3-3, 4-4.

0

Source: https://habr.com/ru/post/1780112/


All Articles