Standard Practices for database storage layers and tree structures

Source: Internet
Author: User
There are three standard practices: 1. The earliest practice: the node id contains the complete path (Great Grandfather id-ye id-parent id-Ben id) the Financial Accounting subject number is basically used now. 2. Recursive practice: parent id and local id (the early and complete relationship can be obtained through recursion) currently, the common advantage is that it is intuitive and simple. The disadvantage of adding or deleting a tree is that it is easy to generate a tree.

There are three standard practices: 1. The earliest practice: the node id contains the complete path (Great Grandfather id-ye id-parent id-Ben id) the Financial Accounting subject number is basically used now. 2. Recursive practice: parent id and local id (the early and complete relationship can be obtained through recursion) currently, the common advantage is that it is intuitive and simple. The disadvantage of adding or deleting a tree is that it is easy to generate a tree.

There are three standard practices:
1. earliest practice: the node id contains the complete path (Great Grandfather id-ye id-parent id-Ben id)
This is what the financial account number does.
It is rarely used now.

2. recursive method: the parent id and the local id (the early and complete link can be obtained after recursion)
It is common
The advantage is that it is intuitive and easy to add and delete
The disadvantage is that tree generation requires recursion.

3. Direct storage method: local id, root id, number of layers, serial number in the root (subtree)
I don't seem to see anyone using this. I used it in my own tree-shaped Forum offline reader.
The advantage is that recursion is avoided and tree records are generated efficiently and conveniently.
The disadvantage is to add or delete nodes and update the node records of the half subtree.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.