Supercharge Your Innovation With Domain-Expert AI Agents!

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

Inactive Publication Date: 2014-06-11
XIAMEN YEALINK NETWORK TECH
View PDF5 Cites 10 Cited by
  • Summary
  • Abstract
  • Description
  • Claims
  • Application Information

AI Technical Summary

Problems solved by technology

[0003] Both of the above two methods have defects. The first method cannot retrieve the target data at one time, and requires multiple accesses to the database, which is extremely inefficient; the second method is poor in readability, difficult to maintain, and poor in portability

Method used

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
View more

Image

Smart Image Click on the blue labels to locate them in the text.
Viewing Examples
Smart Image
  • Searching method of tree data structure of Mysql database
  • Searching method of tree data structure of Mysql database
  • Searching method of tree data structure of Mysql database

Examples

Experimental program
Comparison scheme
Effect test

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.

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to View More

PUM

No PUM Login to View More

Abstract

The invention relates to a searching method of a tree data structure of a Mysql database. The searching method comprises the following steps of adding a path field on the basis of a standard tree data structure table, wherein the path field records the path of each node, and the content of the path field contains the node and all nodes of the previous level which are spliced through characters; obtaining a new tree data structure table; when the data query is executed, matching the node according to the to-be-queried path field of the node, and finding all nodes under the node; additionally adding a layer field, and enabling the layer field to record the layer of each node; step 3, when the data query is executed, matching the node according to the to-be-queried layer field of the node, and finding all nodes of one layer, or the number of nodes of one layer. The method aims at solving the technical problem of providing a simple and effective researching method of the tree data structure of the Mysql database, so the readability, maintainability and portability of an sql (structural queried language) sentence are improved.

Description

technical field [0001] The invention relates to a Mysql database, belongs to the field of database retrieval, and particularly relates to a retrieval method for a tree-shaped data structure under the Mysql database. Background technique [0002] figure 1 It is a schematic diagram of the tree structure of the Mysql database. The standard structure diagram of its tree structure is as follows figure 2 As shown, the fields of the table in the figure are id, name, fid, where fid is the id of the parent node. There are two retrieval methods for this kind of table: the first method is: first query all child nodes through Parent_ID, and then query all subordinate nodes under the child nodes in turn. cycle in turn. The second method is: by defining a stored procedure. Use the cursor down to find all nodes. [0003] The above two methods have defects. The first method cannot retrieve the target data at one time, and requires multiple access to the database, which is extremely i...

Claims

the structure of the environmentally friendly knitted fabric provided by the present invention; figure 2 Flow chart of the yarn wrapping machine for environmentally friendly knitted fabrics and storage devices; image 3 Is the parameter map of the yarn covering machine
Login to View More

Application Information

Patent Timeline
no application Login to View More
Patent Type & Authority Applications(China)
IPC IPC(8): G06F17/30
CPCG06F16/2455G06F16/2246
Inventor 高峰
Owner XIAMEN YEALINK NETWORK TECH
Features
  • R&D
  • Intellectual Property
  • Life Sciences
  • Materials
  • Tech Scout
Why Patsnap Eureka
  • Unparalleled Data Quality
  • Higher Quality Content
  • 60% Fewer Hallucinations
Social media
Patsnap Eureka Blog
Learn More