views:

17

answers:

0

Browsing through examples all over the web, I can see that people generate the 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 - http://stackoverflow.com/questions/2797720/sorting-tree-with-a-materialized-path, using zero padding to the tree_id make it easy to sort it by the 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 fix length string like this also make it easy for me to calculate the level - length(tree_id)/5. What I'm worried is it would limit me to maximum 9999 users rather than 9999 per branch. Am I right here ?

9999  | Tar | 0001.9999
10000 | Tor | 0001.??