Best way to generate a path template for materialized path tree structures

Looking through examples all over the Internet, I see that people generate a path using something like "parent_id.node_id". Examples: -

uid | name | tree_id
--------------------
 1  | Ali  |   1.
 2  | Abu  |   2.
 3  | Ita  |   1.3.
 4  | Ira  |   1.3.
 5  | Yui  |   1.3.4

But as explained in this question - Sorting a tree with a materialized path? Using the null addition to tree_id makes it easy to sort by creation order.

uid | name | tree_id
--------------------
 1  | Ali  |   0001.
 2  | Abu  |   0002.
 3  | Ita  |   0001.0003.
 4  | Ira  |   0001.0003.
 5  | Yui  |   0001.0003.0004

Using a patch length string like this also simplifies the calculation of the level length (tree_id) / 5. I worry, this will limit me to a maximum of 9999 users, not 9999 per branch. I'm here?

9999  | Tar | 0001.9999
10000 | Tor | 0001.??
+3
source share
1 answer

: node . ID, . , int unsigned , 4 294 967 295. , , , , :

uid   | name | tree_id
9999  | Tar  | 0000000001.0000009999
10000 | Tor  | 0000000001.0000010000

, bigint unsigned, , , . node ID, , :

uid   | name | tree_id
9999  | Tar  | 00000001.0000270F
10000 | Tor  | 00000001.00002710

, ( ..).

, :

uid   | name | tree_id           | name_sort
9999  | Tar  | 00000001.0000270F | Ali.Tar
10000 | Tor  | 00000001.00002710 | Ali.Tor

, . name ( , ), .

, , , , , , - , , , node, .

+1

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


All Articles