Retrieval method, device and equipment based on tree structure data and medium
By building a tree data table model and using index queries, the problem of low efficiency and errors in tree structure data retrieval is solved, and fast and accurate node queries are achieved.
Patent Information
- Application Number
- CN202411005203.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-25
- Publication Date
- 2024-08-23
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In the existing technology, retrieval of tree-structured data requires reading the disk multiple times, resulting in low retrieval efficiency and easy node retrieval errors.
Build a tree data table model. The node ID and parent node ID are unique and fixed-length strings. Create a node path index. Generate a node path field by splicing the node ID and parent node ID. Use the index to query subordinate or superior nodes to avoid multiple errors. Search and fuzzy search errors.
It improves the data retrieval efficiency, reduces the number of disk reads, avoids retrieval errors, and achieves fast and accurate node query.
Smart Images

Figure CN118535772A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a retrieval method, device, equipment and medium based on tree structure data. Background Art
[0002] As one of the common data structures, tree structure is widely used in data processing, data retrieval, information management and visualization. The tree structure table is composed of nodes arranged in a hierarchical relationship, which can clearly and concisely represent the superior-subordinate relationship of data. In the tree structure table, the database can be queried according to the node path information of any node to retrieve the data of the superior and subordinate nodes of the node.
[0003] In the prior art, data retrieval is often performed by concatenating node IDs into strings, and then fuzzily querying the upper level and the lower level based on the path field. However, since node IDs are irregular, data retrieval is performed according to the data stored in the data set, so multiple disk reads are required, which can easily cause node retrieval errors and lead to low retrieval efficiency. Summary of the invention
[0004] In view of this, the present invention provides a retrieval method, device, equipment and medium based on tree structure data to solve the problem in the prior art that data retrieval requires multiple disk reads, which easily causes node retrieval errors and low retrieval efficiency.
[0005] In a first aspect, the present invention provides a retrieval method based on tree structure data, the method comprising: Construct a tree data table model, which contains the node ID, node name, parent node ID and node path fields corresponding to each bank, and creates an index for the node path. Both the node ID and parent node ID are unique and fixed-length strings. When a request for adding a bank node is received, the ID of a new node and the ID of a new parent node corresponding to the request for adding a bank node are obtained, and the node path field corresponding to the new node ID is concatenated according to the ID of the new node and the ID of the new parent node, and the tree data table model is updated to obtain an updated tree data model table; When receiving a lower-level data query request, use the tree data model table to perform index query on the current-level bank node and the lower-level bank node corresponding to the lower-level data query request; When a superior data query request is received, the tree data model table is used to perform index query on the current bank node and the superior bank node corresponding to the superior data query request.
[0006] The present invention constructs a tree data table model, and updates the tree data table model according to a new request for a bank node to obtain a tree data model table. Since the node ID and the parent node ID are unique and have a fixed length, when the tree data model table is used to index and query the bank nodes of the same level and the lower-level bank nodes corresponding to the lower-level data query request, or when querying the bank nodes of the same level and the upper-level bank nodes corresponding to the upper-level data query request, only one query is required to realize the retrieval, thus avoiding the low retrieval efficiency caused by multiple searches, and also avoiding the retrieval errors caused by fuzzy searches, thereby improving the retrieval efficiency.
[0007] In an optional implementation, building a tree-shaped data table model includes: Set the node ID prefix of all banks in the same province to be the same; Set the parent node ID prefix of bank branches in the same province to be the same; The node path of the parent node corresponding to the current node and the current node ID are concatenated to obtain the node path field corresponding to the current node.
[0008] The present invention sets the node ID prefixes of all banks in the same province to be the same, and sets the node ID prefixes of bank branches in the same province to be the same, so as to centrally store the node data of the same group, reduce the number of disk reads when reading bank nodes in the same province or when retrieving bank nodes in the same province, and obtain the node path field of the node according to the node path of the parent node corresponding to the node and the node ID of the node, so as to facilitate index query according to the node path, avoid the situation where too much data is loaded due to step-by-step query, and improve the efficiency of data retrieval.
[0009] In an optional implementation, the node path field corresponding to the newly added node ID is concatenated according to the newly added node ID and the newly added parent node ID, including: Determine the parent bank corresponding to the newly added parent node ID and the node path field corresponding to the parent bank; The node path field corresponding to the parent bank and the newly added node ID are concatenated to obtain the node path field corresponding to the newly added node ID.
[0010] The present invention splices the node path field of the newly added node ID according to the parent bank corresponding to the newly added parent node ID and the node path field corresponding to the parent bank, so as to update the tree data table model according to the splicing result, thereby facilitating index query according to the node path during data retrieval.
[0011] In an optional implementation, after concatenating the node path field corresponding to the newly added node ID according to the newly added node ID and the newly added parent node ID, the method further includes: The node path field corresponding to the newly added node ID is split according to the preset split length, the node address corresponding to the node path field corresponding to the newly added node ID is determined, and a mapping relationship between the node path field corresponding to the newly added node ID and the node address is established.
[0012] The present invention divides the node path field and determines the node address to establish a mapping relationship between the node path field and the node address, so that there is no need to traverse each row of data in the tree data model table during data retrieval, thereby further improving data retrieval efficiency.
[0013] In an optional implementation, using a tree data model table to perform index query on the current-level bank node and the lower-level bank node corresponding to the lower-level data query request includes: Use the tree data model table index to query the node ID corresponding to the subordinate data query request and the node path field corresponding to the node ID; The tree-shaped data model table is used to perform matching according to the preset matching rules of the node path field to obtain the current-level bank node and the lower-level bank node corresponding to the lower-level data query request.
[0014] The present invention queries the node ID corresponding to the subordinate data request and the node path field corresponding to the node ID in the tree data model table, and matches the current-level bank node and the subordinate bank node corresponding to the subordinate data request according to the preset matching rule of the node path field, so as to avoid the problem of low retrieval efficiency caused by multiple level-by-level queries according to the parent node ID.
[0015] In an optional implementation, matching is performed according to a preset matching rule of the node path field, including: The node path field is split according to the preset split length, and the split strings are indexed and matched in the tree data model table in order from left to right.
[0016] The present invention divides the point path field to perform index matching according to the divided character strings, and performs index matching in the tree data model table in a left-to-right order, so that there is no need to match each character string during the matching process, thereby reducing resource consumption during the matching process.
[0017] In an optional implementation, using a tree data model table to perform an index query on a current-level bank node and a higher-level bank node corresponding to a higher-level data query request includes: Use the tree data model table index to query the node ID corresponding to the upper-level data query request and the node path field corresponding to the node ID; Split the node path field according to the preset split length to obtain an ID array; The tree data model table index is used to query the current level bank node and the upper level bank node corresponding to the ID array.
[0018] The present invention divides the node path field, and indexes and queries the bank nodes of the current level nodes and the upper level bank nodes corresponding to the ID array obtained by the division, so as to realize rapid retrieval of the upper level node data, avoid multiple level-by-level queries according to the parent node ID, and also avoid the situation where the upper level node query error is caused by the node ID including the node path connection string.
[0019] In a second aspect, the present invention provides a retrieval device based on tree structure data, the device comprising: A construction module is used to construct a tree data table model. The tree data table model contains the node ID, node name, parent node ID and node path fields corresponding to each bank, and creates an index for the node path. Both the node ID and the parent node ID are unique and fixed-length strings. An update module is used for, when receiving a request for adding a bank node, obtaining a new node ID and a new parent node ID corresponding to the request for adding a bank node, concatenating a node path field corresponding to the new node ID according to the new node ID and the new parent node ID, updating the tree data table model, and obtaining an updated tree data model table; A first query module is used for, when receiving a lower-level data query request, using the tree data model table to perform index query on the current-level bank node and the lower-level bank node corresponding to the lower-level data query request; The second query module is used for, when receiving a superior data query request, using the tree data model table to perform index query on the current bank node and the superior bank node corresponding to the superior data query request.
[0020] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the tree-structured data retrieval method according to the first aspect or any corresponding embodiment thereof by executing the computer instructions.
[0021] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the tree-structured data retrieval method according to the first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0023] Figure 1 is a schematic diagram of existing tree structure data according to an embodiment of the present invention; Figure 2 is a flowchart of a retrieval method based on tree structure data according to an embodiment of the present invention; Figure 3 is a flowchart of another retrieval method based on tree structure data according to an embodiment of the present invention; Figure 4 is a flowchart of another retrieval method based on tree structure data according to an embodiment of the present invention; Figure 5 is a schematic diagram of an application of a retrieval method based on tree structured data according to an embodiment of the present invention; Figure 6 is a structural block diagram of a retrieval device based on tree structure data according to an embodiment of the present invention; Figure 7 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0024] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0025] In software systems, tree-structured data is often stored, such as Figure 1 As shown, the data storage method generally adopted by its relational database is shown in Table 1. The fields contained in the table include node ID, node name, parent node ID (P_ID) and node path (node_path) fields.
[0026] Table 1
[0027] When querying the upper and lower nodes of a node, the following two methods are usually used. Method 1: query the lower level one by one according to the node ID being equal to the parent node P_ID of the current level node, and query the upper level one by one according to the parent node P_ID being equal to the upper node ID; Method 2: concatenate the ID of the upper node through strings to find the node path field, and fuzzy query all upper levels according to the path field. The upper level query is based on the parent node ID, querying the upper level one by one, or splitting the node path field to obtain the upper node ID, and querying the upper level according to the ID.
[0028] However, both of the above methods have their corresponding defects. The defect of method one is that it requires multiple calls to the database to query all subordinate and superior nodes, and the need to query the database multiple times leads to poor retrieval performance. The defect of method two is that the node ID contains the node path connection string, which will cause errors in querying the superior node. For example, the node path uses the connection string "-". When the node ID also carries the connection string, such as the parent node ID is "1-1", the child node ID is "2", and the node_path of the child node is "1-1-2", the node_path of the child node is divided to obtain the superior node ID array [1, 1, 2]. This does not match the actual [1-1, 2], resulting in errors in retrieving the superior node. At the same time, the node ID of method two has no regularity, and the node data of the same family is not stored continuously on the disk. For example Figure 1 The B direct-controlled branch is not stored together with its subordinate nodes. Compared with centralized storage in sequence, this method requires multiple disk reads and has low retrieval performance.
[0029] According to an embodiment of the present invention, a retrieval method embodiment based on tree-structured data is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0030] In this embodiment, a retrieval method based on tree structure data is provided, which can be used in a mobile terminal. Figure 2 is a flowchart of a retrieval method based on tree structure data according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps: Step S201, construct a tree data table model and create an index for the node path.
[0031] In the embodiment of the present invention, the tree data table model includes the node ID, node name, parent node ID and node path fields corresponding to each bank, and the node ID and parent node ID are both unique and fixed-length character strings.
[0032] Build a tree data table model that contains the primary key (ID), node name, parent node primary key (P_ID) and node path (node_path) fields of each bank node. The node ID, parent node ID and node path are all string types, and create an index for the node path node_path field.
[0033] Specifically, ID is used as the unique identifier of the node, P_ID is used as the ID of the parent node, and node_path is the node_path string of the parent node, after which the node ID is concatenated. The node ID is a fixed-length string, and its length can be set according to the amount of data to ensure that the node ID is unique. For example, if the amount of data is 10,000, a combination of numbers and uppercase letters is used as the ID, and the ID length can be set to four digits, with a value range of 0000~ZZZZ. Like the node ID, the parent node ID is also a fixed-length string. The node path node_path has a variable length, and the maximum length is the product of the ID length and the maximum node path length. For example, if the node ID length is four digits and the maximum node path length is ten digits, then the maximum length of the node_path is 4*10=40 digits.
[0034] Step S202, when a request for adding a bank node is received, obtain the new node ID and the new parent node ID corresponding to the request for adding the bank node, concatenate the node path field corresponding to the new node ID according to the new node ID and the new parent node ID, update the tree data table model, and obtain an updated tree data model table.
[0035] In an embodiment of the present invention, according to the tree data table model constructed in the previous step, when a request for adding a bank node is received, the bank node is added. The input items are the node ID and the parent node ID, that is, the new node ID and the new parent node ID corresponding to the request for adding a bank node are obtained. According to the new node ID and the new parent node ID, the node path field corresponding to the new node ID is spliced, and the tree data table model is updated according to the splicing result, and the updated tree data model table is obtained and saved in the database.
[0036] Exemplarily, the tree data table is as shown in Table 2 below.
[0037] Table 2
[0038] Step S203, when a lower-level data query request is received, the tree-shaped data model table is used to perform index query on the current-level bank node and the lower-level bank node corresponding to the lower-level data query request.
[0039] In an embodiment of the present invention, when it is detected that a user triggers a lower-level search query instruction, the bank node at the current level and the lower-level bank node are queried according to the updated tree data model table. For example, if the user wants to query all subordinates of the A Province Branch, the tree data model table is used to perform index queries on the A Province Branch's A Province B City Branch, all branches under the A Province B City Branch, A Province C City Branch, all branches under the A Province C City Branch, etc.
[0040] Step S204: when a superior data query request is received, the tree data model table is used to perform index query on the current bank node and the superior bank node corresponding to the superior data query request.
[0041] In an embodiment of the present invention, when it is detected that a user triggers a superior search query instruction, the current-level bank node and the superior bank node are queried according to the updated tree data model table. For example, if the user wants to query the superior of the first branch of City C, the tree data model table is used to index and query the superior Province B of the first branch of City C and the superior head office of Province B.
[0042] The data retrieval method based on tree structured data provided in the present embodiment constructs a tree data table model, and updates the tree data table model according to a new request for a bank node to obtain a tree data model table. Since the node ID and the parent node ID are unique and have a fixed length, when the tree data model table is used to index and query the bank nodes of the current level and the lower-level bank nodes corresponding to the lower-level data query request, or when querying the bank nodes of the current level and the upper-level bank nodes corresponding to the upper-level data query request, only one query is required to realize the retrieval, thereby avoiding the low retrieval efficiency caused by multiple searches, and also avoiding the retrieval errors caused by fuzzy searches, thereby improving the retrieval efficiency.
[0043] In this embodiment, a retrieval method based on tree structure data is provided, which can be used in the above-mentioned mobile terminal. Figure 3 is a flowchart of a retrieval method based on tree structure data according to an embodiment of the present invention. Figure 3 As shown, the process includes the following steps: Step S301, construct a tree data table model and create an index for the node path.
[0044] Specifically, the construction of the tree data table model in the above step S301 includes: Step S3011, setting the node ID prefix corresponding to all banks in the same province to be the same.
[0045] Step S3012, setting the parent node ID prefix corresponding to bank branches in the same province to be the same.
[0046] Step S3013, concatenate the node path of the parent node corresponding to the node and the node ID to obtain the node path field corresponding to the node.
[0047] In an embodiment of the present invention, when constructing a tree-shaped data table model, the node ID prefixes of all banks in the same province (i.e., the same group) are set to be the same. For example, Zhejiang Province and all branches and sub-branches under Zhejiang Province use the "A" string as the id prefix, and Shanghai and all branches and sub-branches under Shanghai use the "B" string as the id prefix. The parent node ID prefixes corresponding to bank sub-branches in the same province are set to be the same. For example, the parent node ID of the Wenzhou branch in Zhejiang Province is prefixed with "A", and the parent node ID of the Jiaxing branch in Zhejiang Province is also prefixed with "A". When the database stores data, the data is stored in ID order. Therefore, when reading data in the same group, the number of disk reads is reduced, thereby improving retrieval efficiency.
[0048] When setting the node path field, the node path of the parent node corresponding to the node and the node ID are concatenated. For example, if the node ID is A001 and its parent node ID is 0001, the node path of the node ID 0001 is 0001. Then the node path field corresponding to the node is the concatenation of "A001" and "0001", that is, "0001A001".
[0049] The node ID prefixes of all banks in the same province are set to be the same, and the node ID prefixes of bank branches in the same province are set to be the same, so as to centrally store the data of the same group of nodes. When reading bank nodes in the same province or retrieving bank nodes in the same province, the number of disk reads is reduced. The node path field of this node is obtained by concatenating the node path of the parent node corresponding to this node and the node ID of this node, so as to facilitate index query based on the node path, avoid the situation where too much data is loaded due to step-by-step query, and improve the efficiency of data retrieval.
[0050] Step S302, when a request for adding a bank node is received, obtain the new node ID and the new parent node ID corresponding to the request for adding the bank node, concatenate the node path field corresponding to the new node ID according to the new node ID and the new parent node ID, update the tree data table model, and obtain an updated tree data model table.
[0051] Specifically, in the above step S302, the node path field corresponding to the newly added node ID is concatenated according to the newly added node ID and the newly added parent node ID, including: Step S3021, determine the parent bank corresponding to the newly added parent node ID and the node path field corresponding to the parent bank.
[0052] Step S3022, concatenate the node path field corresponding to the parent bank and the newly added node ID to obtain the node path field corresponding to the newly added node ID.
[0053] In an embodiment of the present invention, according to the tree data table model constructed in step S301, a new node is added, and the input items are the new node ID and the new parent node ID. The node path node_path string corresponding to the new parent node ID is determined according to the new parent node ID, and the new node ID is spliced after the node path field corresponding to the new parent node ID to obtain the node path field corresponding to the new node ID.
[0054] For example, taking the first branch of City B as an example, the newly added node ID is B003, and the corresponding newly added parent node ID is B002. The node with node ID B002 is the business department of the City B branch. The node path node_path string corresponding to the business department of the City B branch is "0001B001B002". The newly added node B003 is spliced thereafter, and the node path field corresponding to the newly added node ID is "0001B001B002B003", which is saved in the database.
[0055] According to the parent bank corresponding to the newly added parent node ID and the node path field corresponding to the parent bank, the node path field of the newly added node ID is spliced to update the tree data table model according to the splicing result, thereby facilitating index query according to the node path during data retrieval.
[0056] Step S303, segment the node path field corresponding to the newly added node ID according to the preset segmentation length, determine the node address corresponding to the node path field corresponding to the newly added node ID, and establish a mapping relationship between the node path field corresponding to the newly added node ID and the node address.
[0057] In the embodiment of the present invention, since an index is created for the node path node_path in the tree data table model when constructing the tree data table model, after adding a new node, a mapping relationship is made between the node path field content and the node address, and the address where the data is stored on the disk can be quickly found according to the node path node_path, which can effectively improve data retrieval efficiency.
[0058] The segmentation length is preset, for example, when the ID length is four bits, the preset segmentation length is also four bits, the node path field corresponding to the newly added node ID is segmented, and the last four bits of the node_path field after the segmentation are determined as the node address to establish a mapping relationship between the node path field corresponding to the newly added node ID and the node address.
[0059] For example, the node path field of the newly added node ID is "0001B001B002B003", and the node path field is divided into "0001", "B001", "B002", and "B003", that is, "B003" is determined as the node address, and a mapping relationship between the path field "0001B001B002B003" and the node address "B003" is established.
[0060] Table 3 is a mapping relationship table between the node path field and the node address using the "node path (node_path) index model" as the index model.
[0061] Table 3
[0062] Step S304: when a lower-level data query request is received, the tree-shaped data model table is used to perform index query on the current-level bank node and the lower-level bank node corresponding to the lower-level data query request.
[0063] For details, please see Figure 2 Step S203 of the illustrated embodiment will not be described in detail here.
[0064] Step S305: when a superior data query request is received, the tree data model table is used to perform index query on the current bank node and the superior bank node corresponding to the superior data query request.
[0065] For details, please see Figure 2 Step S204 of the illustrated embodiment will not be described in detail here.
[0066] The tree-structured data retrieval method provided in this embodiment divides the node path field and determines the node address to establish a mapping relationship between the node path field and the node address, so that there is no need to traverse every row of data in the tree data model table during data retrieval, thereby further improving data retrieval efficiency.
[0067] In this embodiment, a retrieval method based on tree structure data is provided, which can be used in the above-mentioned mobile terminal. Figure 4 is a flowchart of a retrieval method based on tree structure data according to an embodiment of the present invention. Figure 4 As shown, the process also includes the following steps: Step S401, construct a tree data table model and create an index for the node path.
[0068] For details, please see Figure 2 Step S201 of the illustrated embodiment will not be described in detail here.
[0069] Step S402, when a request for adding a bank node is received, obtain the new node ID and the new parent node ID corresponding to the request for adding the bank node, concatenate the node path field corresponding to the new node ID according to the new node ID and the new parent node ID, update the tree data table model, and obtain an updated tree data model table.
[0070] For details, please see Figure 2 Step S202 of the illustrated embodiment will not be described in detail here.
[0071] Step S403, when a lower-level data query request is received, the tree-shaped data model table is used to perform index query on the current-level bank node and the lower-level bank node corresponding to the lower-level data query request.
[0072] Specifically, the current-level bank nodes and the lower-level bank nodes corresponding to the lower-level data query request using the tree-shaped data model table for index query in the above step S403 include: Step S4031, using the tree data model table index to query the node ID corresponding to the lower-level data query request and the node path field corresponding to the node ID.
[0073] Step S4032, using the tree data model table to perform matching according to the preset matching rules of the node path field, to obtain the current-level bank node and the lower-level bank node corresponding to the lower-level data query request.
[0074] In the embodiment of the present invention, when a subordinate data query request is received, all the bank nodes at the same level and the subordinate bank nodes corresponding to the subordinate data query request are retrieved according to the updated tree data model table. For example, when querying all subordinates of node A001 (A Province Branch), according to its node path field 0001A001, matching is performed according to the preset matching rules, so that all subordinate nodes of A Province Branch can be queried with only one search.
[0075] In the tree data model table, query the node ID corresponding to the subordinate data request and the node path field corresponding to the node ID, and match the current-level bank node and the subordinate bank node corresponding to the subordinate data request according to the preset matching rules of the node path field, so as to avoid the problem of low retrieval efficiency caused by multiple level-by-level queries based on the parent node ID.
[0076] Specifically, the matching according to the preset matching rule of the node path field in the above step S4032 includes: Step S40321, split the node path field according to the preset split length, and index match the split character strings in the tree data model table in order from left to right.
[0077] In an embodiment of the present invention, a segmentation length is preset. For example, when the ID length is four digits, the preset segmentation length is also four digits. The node path field is segmented according to the preset segmentation length. For example, the node path field is "0001A001", and the segmentation results in "0001" and "A001". According to the string left matching rule, the tree data model table is indexed in sequence, and the nodes whose node paths start with "0001" and open with "0001A001" are determined as the current-level bank nodes and the lower-level bank nodes, so as to retrieve all the current-level bank nodes and the lower-level bank nodes.
[0078] The retrieved branch level of Province A and all its subordinates are shown in Table 4.
[0079] Table 4
[0080] By splitting the point path field, index matching is performed according to the split strings, and index matching is performed in the tree data model table from left to right, so that there is no need to match each string during the matching process, thereby reducing resource consumption during the matching process.
[0081] Step S404: when a superior data query request is received, the tree data model table is used to perform index query on the current bank node and the superior bank node corresponding to the superior data query request.
[0082] Specifically, the matching according to the preset matching rule of the node path field in the above step S404 includes: Step S4041, using the tree data model table index to query the node ID corresponding to the upper-level data query request and the node path field corresponding to the node ID.
[0083] Step S4042, split the node path field according to a preset split length to obtain an ID array.
[0084] Step S4043, using the tree data model table index to query the current level bank node and the upper level bank node corresponding to the ID array.
[0085] In the embodiment of the present invention, when receiving a query request for superior data, all the bank nodes of the same level and the superior bank nodes corresponding to the query request for superior data are retrieved according to the updated tree data model table. For example, when querying all superiors of node B003 (the first branch of City B), according to its node path field 0001B001B002B003, the node path field is split according to the preset split length of four bits, and the ID array [0001, B001, B002, B003] is obtained. The tree data model table index is used to query through the node ID, so that all superior nodes of the first branch of City B can be queried with only one search.
[0086] All the retrieved superiors of the First Branch of City B are shown in Table 5.
[0087] Table 5
[0088] The retrieval method based on tree structured data provided in this embodiment divides the node path field, and indexes the bank nodes of the current level nodes and the parent bank nodes corresponding to the ID array obtained by the division, so as to realize fast retrieval of the parent node data, avoid multiple level-by-level queries according to the parent node ID, and avoid the situation where the parent node query error is caused by the node ID including the node path connection string.
[0089] like Figure 5 As shown, the retrieval method based on tree structure data provided in this embodiment includes the following four steps: S1, build a tree data table model, which includes node ID, parent node ID (P_ID) and node path (node_path) fields, and create an index for the node path node_path.
[0090] S2, when adding a new node, obtain the node_path of the parent node according to P_ID, and concatenate the current node ID after it as the node_path of the current node.
[0091] S3, get all subordinates, through the node path node_path index, according to the string left matching rule, retrieve all subordinate nodes.
[0092] S4, get all the superiors, split the string by fixed length through the node path, get the superior node id array, and retrieve all the superior nodes.
[0093] In the present embodiment, a retrieval device based on tree structure data is also provided, and the device is used to implement the above-mentioned embodiment and preferred implementation mode, and the description has been made no further. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the device described in the following embodiments is preferably implemented with software, the implementation of hardware, or a combination of software and hardware is also possible and conceived.
[0094] This embodiment provides a retrieval device based on tree structure data, such as Figure 6 As shown, including: Construction module 601 is used to construct a tree data table model, which contains the node ID, node name, parent node ID and node path fields corresponding to each bank, and creates an index for the node path. The node ID and parent node ID are both unique and fixed-length strings.
[0095] Update module 602 is used to obtain the new node ID and the new parent node ID corresponding to the new bank node request when receiving the new bank node request, and to update the tree data table model based on the node path field corresponding to the new node ID and the new parent node ID to obtain an updated tree data model table.
[0096] The first query module 603 is used for, when receiving a lower-level data query request, using the tree data model table to perform index query on the current-level bank node and the lower-level bank node corresponding to the lower-level data query request.
[0097] The second query module 604 is used for, when receiving a superior data query request, using the tree data model table to perform index query on the current bank node and the superior bank node corresponding to the superior data query request.
[0098] In some optional implementations, the building block 601 includes: The first setting unit is used to set the node ID prefix corresponding to all banks in the same province to be the same.
[0099] The second setting unit is used to set the parent node ID prefix corresponding to the bank branches in the same province to be the same.
[0100] The first concatenation unit is used to concatenate the node path of the parent node corresponding to the current node and the current node ID to obtain a node path field corresponding to the current node.
[0101] In some optional implementations, the updating module 602 includes: The determination unit is used to determine the parent bank corresponding to the newly added parent node ID and the node path field corresponding to the parent bank.
[0102] The second concatenation unit is used to concatenate the node path field corresponding to the parent bank and the newly added node ID to obtain the node path field corresponding to the newly added node ID.
[0103] In some optional embodiments, the device further comprises: The mapping relationship establishment module is used to split the node path field corresponding to the newly added node ID according to the preset segmentation length, determine the node address corresponding to the node path field corresponding to the newly added node ID, and establish a mapping relationship between the node path field corresponding to the newly added node ID and the node address.
[0104] In some optional implementations, the first query module 603 includes: The first query unit is used to query the node ID corresponding to the lower-level data query request and the node path field corresponding to the node ID by using the tree data model table index.
[0105] The matching unit is used to use the tree data model table to perform matching according to the preset matching rules of the node path field to obtain the current-level bank node and the lower-level bank node corresponding to the lower-level data query request.
[0106] In some optional implementations, the matching unit includes: The matching subunit is used to split the node path field according to a preset split length, and to index and match the split strings in sequence from left to right in the tree data model table.
[0107] In some optional implementations, the second query module 604 includes: The second query unit is used to query the node ID corresponding to the upper-level data query request and the node path field corresponding to the node ID by using the tree data model table index.
[0108] The segmentation unit is used to segment the node path field according to a preset segmentation length to obtain an ID array.
[0109] The third query unit is used to query the current-level bank node and the upper-level bank node corresponding to the ID array by using the tree data model table index.
[0110] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.
[0111] The retrieval device based on tree structure data in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.
[0112] The embodiment of the present invention also provides a computer device having the above Figure 6 The retrieval device based on tree structure data is shown.
[0113] See also Figure 7 , Figure 7 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Figure 7As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 7 A processor 10 is taken as an example.
[0114] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.
[0115] The memory 20 stores instructions executable by at least one processor 10, so that at least one processor 10 executes the method shown in the above embodiment.
[0116] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0117] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.
[0118] The computer device also includes an input device 30 and an output device 40. The processor 10, the memory 20, the input device 30 and the output device 40 may be connected via a bus or other means. Figure 7 The example of connecting through bus is taken in the following.
[0119] The input device 30 can receive input digital or character information and generate key signal input related to user settings and function control of the computer device, such as a touch screen, etc. The output device 40 can include a display device, etc.
[0120] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.
[0121] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A retrieval method based on tree structure data, characterized in that: The method comprises: Constructing a tree-shaped data table model, the tree-shaped data table model includes the node ID, node name, parent node ID and node path fields corresponding to each bank, and creating an index for the node path, wherein the node ID and the parent node ID are both unique and fixed-length strings; When a request for adding a bank node is received, a new node ID and a new parent node ID corresponding to the request for adding a bank node are obtained, and a node path field corresponding to the new node ID is concatenated according to the new node ID and the new parent node ID, and the tree data table model is updated to obtain an updated tree data model table; When receiving a lower-level data query request, use the tree-shaped data model table to perform index query on the current-level bank node and the lower-level bank node corresponding to the lower-level data query request; When an upper-level data query request is received, the tree-shaped data model table is used to perform index query on the current-level bank node and the upper-level bank node corresponding to the upper-level data query request.
2. The method according to claim 1, characterized in that The step of constructing a tree-shaped data table model includes: Set the node ID prefix of all banks in the same province to be the same; Set the parent node ID prefix of bank branches in the same province to be the same; The node path of the parent node corresponding to the current node and the current node ID are concatenated to obtain the node path field corresponding to the current node.
3. The method according to claim 1, characterized in that The step of concatenating the node path field corresponding to the newly added node ID according to the newly added node ID and the newly added parent node ID includes: Determine the parent bank corresponding to the newly added parent node ID and the node path field corresponding to the parent bank; The node path field corresponding to the parent bank and the newly added node ID are concatenated to obtain the node path field corresponding to the newly added node ID.
4. The method according to claim 1, characterized in that: After concatenating the node path field corresponding to the newly added node ID according to the newly added node ID and the newly added parent node ID, the method further includes: The node path field corresponding to the newly added node ID is split according to a preset split length, the node address corresponding to the node path field corresponding to the newly added node ID is determined, and a mapping relationship between the node path field corresponding to the newly added node ID and the node address is established.
5. The method according to claim 1, characterized in that The method of using the tree data model table to perform index query on the current-level bank node and the lower-level bank node corresponding to the lower-level data query request includes: Utilize the tree data model table index to query the node ID corresponding to the subordinate data query request and the node path field corresponding to the node ID; The tree-shaped data model table is used to perform matching according to the preset matching rule of the node path field to obtain the current-level bank node and the lower-level bank node corresponding to the lower-level data query request.
6. The method according to claim 5, characterized in that The matching according to the preset matching rule of the node path field includes: The node path field is segmented according to a preset segmentation length, and the segmented character strings are indexed and matched in sequence from left to right in the tree data model table.
7. The method according to claim 1, characterized in that The method of using the tree data model table to perform index query on the current-level bank node and the upper-level bank node corresponding to the upper-level data query request includes: Utilize the tree data model table index to query the node ID corresponding to the upper-level data query request and the node path field corresponding to the node ID; Splitting the node path field according to a preset split length to obtain an ID array; The tree data model table index is used to query the current-level bank node and the upper-level bank node corresponding to the ID array.
8. A retrieval device based on tree structure data, characterized in that: The device comprises: A construction module is used to construct a tree data table model, wherein the tree data table model includes the node ID, node name, parent node ID and node path fields corresponding to each bank, and creates an index for the node path, wherein the node ID and the parent node ID are both unique strings with fixed length; An update module, configured to, when receiving a request for adding a bank node, obtain a new node ID and a new parent node ID corresponding to the request for adding a bank node, and update the tree data table model by concatenating a node path field corresponding to the new node ID with the new parent node ID to obtain an updated tree data model table; A first query module, for, when receiving a lower-level data query request, using the tree-shaped data model table to perform index query on the current-level bank node and the lower-level bank node corresponding to the lower-level data query request; The second query module is used for, when receiving a superior data query request, using the tree data model table to perform index query on the current-level bank node and the superior bank node corresponding to the superior data query request.
9. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the tree-structured data retrieval method according to any one of claims 1 to 7 by executing the computer instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the tree-structured data retrieval method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Universal tree structure data query method and device
CN110704430A
Data processing method and device, storage medium and electronic equipment
CN117743316A
Method for processing branch map coding
TW201403356A
