Storage of a tree-structured database

Source: Internet
Author: User

In the process of programming, we often use the tree structure to characterize some data related relations, such as enterprise subordinate departments, column structure, commodity classification, etc., usually, these tree structure need to use the database to complete the persistence. The ideal tree structure should have the following characteristics: The data storage redundancy is small and intuitive, the retrieval traversal process is simple and efficient, and the node additions and deletions are efficient for crud operation.

An example of a food genealogy is presented, which organizes food by category, color and variety, and the tree structure is as follows:

1, the most intuitive analysis of the tree structure is the inheritance relationship between nodes, through the display to describe a node's parent node, so as to establish a two-dimensional relational table, the tree table structure of this scheme is usually designed to: {node_id,parent_id} 2, in the general database-based application, The requirements of the query are always greater than the deletions and modifications.      In order to avoid the "recursive" process of tree structure query, we design a new zero-recursive query and infinite grouping of left-and right-value coding schemes based on tree's pre-sequence traversal to save the tree data.      As for the above two methods of the specific introduction and implementation and excellent lack of reference: tree-shaped structure of the database table schema design. In fact, our most important data is this way: {catagory: "Food", Foodcategory: "Fruit", Color: "Red", Name: "Cherry"} {catagory: ' food ', foodcategory : "Fruit", Color: "Yellow", Name: "Banana"} {catagory: "Food", Foodcategory: "Meat", Name: "Beef"} {catagory: ' food ', FOODCA      Tegory: "Meat", Name: "Pork"} ... In fact, I think this relational database can be stored in MONGODB (JSON data format), so that the idea of non-relational database to solve this problem is not better? This can not be through the recursive process of continuous access to the database, each database IO will have time overhead, but also to avoid the second node to add, delete and modify the cost is large, will be related to the table of various data changes. Is it Meng da? Opinion, welcome to shoot Bricks!

Storage of a tree-structured database

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.