Searching method of tree data structure of Mysql database
A technology of data structure and data structure table, applied in the field of database retrieval, can solve problems such as poor portability, poor readability, and difficult maintenance, and achieve the effect of improving retrieval efficiency and enhancing readability
- Summary
- Abstract
- Description
- Claims
- Application Information
AI Technical Summary
Problems solved by technology
Method used
Image
Examples
no. 1 example
[0026] A method for retrieving a tree-shaped data structure under a Mysql database, comprising the following steps:
[0027] Step 1: Add a path field based on the standard tree data structure table, such as image 3 As shown, the path field records the path of each node, and the content of the path field is: this node and all nodes of the superior are spliced by characters, image 3 Shown is splicing with colons; a new tree data structure table is obtained;
[0028] Step 2: When performing data query, if you want to query all nodes under "Heilongjiang", just match the node according to the path field of the node "Heilongjiang", and find all nodes under this node.
[0029] Sql instance: query all nodes under "Heilongjiang"
[0030] Select * from location where path like '1:5%';
[0031] The result obtained is as Figure 4 shown.
no. 2 example
[0033] A method for retrieving a tree-shaped data structure under a Mysql database, comprising the following steps:
[0034] Step 1: Add a path field on the basis of the standard tree data structure table, the path field records the path of each node, and the content of the path field is: this node and all the upper-level nodes are spliced by characters; a new tree is obtained shape data structure table;
[0035] Step 2: Add a layer field on the basis of the new tree data structure table, such as Figure 5 As shown, the layer field records the level of each node;
[0036] Step 3: When performing data query, match nodes according to the layer field of the node to be queried, and find all nodes at a certain level, or the number of nodes at a certain level.
example
[0037] Sql example: query all third-level nodes under "administrative organization"
[0038] Select * from location where path like '1:%' and layer=3 ;
[0039] The result obtained is as Image 6 shown.
[0040] Sql example: query the number of all third-level nodes under "administrative organization"
[0041] Select count(id) from location where path like '1:%' and layer=3 ;
[0042] The result obtained is as Figure 7 shown.
[0043] The invention provides a simple and effective retrieval method for tree data structure under Mysql database, which enhances the readability, maintainability and portability of SQL statements and improves retrieval efficiency.
PUM

Abstract
Description
Claims
Application Information

- R&D
- Intellectual Property
- Life Sciences
- Materials
- Tech Scout
- Unparalleled Data Quality
- Higher Quality Content
- 60% Fewer Hallucinations
Browse by: Latest US Patents, China's latest patents, Technical Efficacy Thesaurus, Application Domain, Technology Topic, Popular Technical Reports.
© 2025 PatSnap. All rights reserved.Legal|Privacy policy|Modern Slavery Act Transparency Statement|Sitemap|About US| Contact US: help@patsnap.com