Multi-level query optimization method and system for tree-structured database based on AI model

Through AI model, multi-level query of tree structure database is optimized, dynamic query strategy and load balancing are used to solve the problems of low query efficiency and insufficient scalability in the existing technology, and efficient and stable multi-level query and system capabilities are achieved. Extensibility.

CN119025557BActive Publication Date: 2024-12-27SHANGHAI ZHUOCHEN INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411519227.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-29
Publication Date
2024-12-27
Estimated Expiration
2044-10-29

AI Technical Summary

Technical Problem

Existing tree-based database query methods are inefficient and computationally cost-effective when queries are multi-level, especially in depth increase and lack of data distribution and load balancing in distributed environments, which limits the scalability of the system.

Method used

Adopt multi-level query optimization method based on AI model, by obtaining tree structure data, analyzing query instructions, optimizing index information, and using dynamic query strategies and load balancing strategies to optimize the query process to reduce unnecessary full-table scans and resource waste. , ensure the reasonable distribution of data.

Benefits of technology

It significantly improves query efficiency, reduces latency, enhances the scalability and stability of the system, and avoids performance bottlenecks caused by single-point overload.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119025557B_ABST
    Figure CN119025557B_ABST
Patent Text Reader

Abstract

The present invention belongs to the field of database optimization, and in particular to a multi-level query optimization method and system for a tree-structured database based on an AI model. The method first obtains tree-structured data, which is generated based on a distributed database and a configured table space directory, and includes multi-level nodes. The multi-level nodes include corresponding index information under each level of the nodes. Secondly, a query instruction is obtained, and the query instruction is parsed to obtain query index information corresponding to each level of the nodes, and the obtained query index information is optimized using a preset index information optimization library. Finally, according to the optimized query index information, data under the index information of each level of the nodes corresponding to the query index information is obtained from the tree-structured data through a configured dynamic query strategy to obtain a corresponding query data set. The present invention can effectively improve query efficiency and reduce query delay.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of database optimization, and in particular to a tree-structured database multi-level query optimization method and system based on an AI model. Background Art

[0002] In the era of big data, the amount of data of various types is growing exponentially, which puts higher requirements on data storage and retrieval technology. As a common form of data organization, tree structure has been widely used in the database field. Tree structure can efficiently represent data with hierarchical relationships and support a variety of query operations, such as finding information about a specific node and its descendant nodes.

[0003] Existing database query methods based on tree structures, such as patent publication number CN102110171A, disclose a query and update method of Bloom filter based on tree structure. Although the invention can realize efficient query and update of data, it mainly relies on Bloom filter mechanism to reduce unnecessary disk access, and does not involve multi-level query optimization and index selection. In addition, patent publication number CN113515517A discloses a method and computer device for querying data sets based on tree structure data. Although the invention discloses a method for querying data sets based on tree structure data, it can obtain tree structure data according to query instructions and obtain query data sets. However, as the depth of the tree structure increases, the query performance may be affected, especially when the query involves a large number of descendant nodes, which may lead to higher computing costs and longer response times. In addition, in a distributed environment, the lack of consideration for data distribution and load balancing may limit the scalability of the system. Summary of the invention

[0004] In view of the shortcomings of the prior art, the present invention proposes a multi-level query optimization method for a tree-structured database based on an AI model. The method first obtains tree-structured data, where the tree-structured data is generated based on a distributed database and a configured table space directory, and includes multi-level nodes. The multi-level nodes include corresponding index information under each level of the nodes. Secondly, query instructions are obtained and parsed to obtain query index information corresponding to each level of the nodes, and the obtained index information is optimized using a preset index information optimization library. Finally, according to the optimized query index information, data under the index information of each level of the nodes corresponding to the query index information is obtained from the tree-structured data through the configured dynamic query strategy to obtain the corresponding query data set. The present invention can effectively improve query efficiency and reduce query delay.

[0005] To achieve the above object, the present invention provides the following technical solutions:

[0006] The multi-level query optimization method of tree-structured database based on AI model includes:

[0007] Obtain tree structure data, the tree structure data is generated based on the distributed database and the configured table space directory; the tree structure data includes multi-level nodes, and the multi-level nodes include the table name corresponding to each level of nodes, table structure data information and index information corresponding to each level of nodes;

[0008] Obtaining a query instruction, parsing the query instruction using a parsing model, obtaining query index information corresponding to nodes at all levels, and optimizing the obtained query index information corresponding to nodes at all levels using a preset index information optimization library, to obtain optimized query index information corresponding to nodes at all levels; the query index information corresponds to the index information at nodes at all levels;

[0009] According to the optimized query index information corresponding to each level of nodes, the data under the index information of each level of nodes corresponding to the query index information are obtained from the tree structure data through the configured dynamic query strategy to obtain the corresponding query data set;

[0010] The tree structure data includes a tree table space directory, and the tree table space directory includes a root node and multi-level nodes;

[0011] The steps of generating tree structure data include:

[0012] A multi-level node includes a parent node and a corresponding mounted child node; the table structure in the parent node is automatically inherited in the corresponding mounted child node through a trigger and cannot be modified; when an independent field is added to the table structure in the child node, an independent table space is configured for the added independent field according to the size of the added independent field and the block division of the table space corresponding to the first-level node, and the table structure before the addition of the independent field is used as the parent table, and the table structure after the addition of the independent field is used as the child table, and the child table is automatically inherited to the lower-level child node of the parent table corresponding to the current child node, and the association relationship between the parent table and the child table is recorded, and the index information between the independent fields and the common fields corresponding to the parent table and the child table is constructed using the association relationship.

[0013] Specifically, the steps of constructing index information between independent fields and common fields corresponding to the parent table and the child table include:

[0014] Determine the index information of each parent node and the corresponding mounted child node in the multi-level node through the index information preset by each root node;

[0015] And through the index information of the parent table corresponding to the parent node and the child table corresponding to the child node and the recorded association relationship between the parent table and the child table, the independent fields in the child table and the index information of the common fields corresponding to the parent table and the child table are established, and the independent fields are associated with the common fields through the established index information.

[0016] Specifically, a load balancing strategy is configured in the root node added to the tablespace directory to achieve load balancing of the storage status of multiple nodes under each root node. The steps include:

[0017] A1. Obtain the load status data of nodes at all levels under each root node, the number of accesses to table data at all levels under each node, and the type of storage table data;

[0018] A2. Construct a load assessment model based on the fuzzy comprehensive assessment algorithm, and embed the constructed three-level load score interval into the load assessment model;

[0019] A3. Input the acquired load status data of nodes at all levels under each root node into the load evaluation model to obtain the evaluation scores and load levels corresponding to the nodes at all levels, and mark the acquired evaluation scores and load levels on the corresponding nodes, and dynamically update the marked evaluation scores using the real-time acquired load status data of nodes at all levels;

[0020] A4. Obtain the access frequency level of the corresponding type of storage table data through a fuzzy comprehensive evaluation algorithm according to the access times of the table data under each level of nodes and the type of storage table data;

[0021] A5. Establish a mapping relationship between access frequency level and load level. According to the load level of each node under the same root node and the access frequency level of the corresponding type table data under each node, perform dynamic migration between the child nodes mounted on the same parent node through the established mapping relationship, and update the index relationship between the migrated child table and the corresponding parent table in real time.

[0022] A6. When new sub-table data is added to the database, the added sub-table data is matched with the corresponding type data stored in nodes at all levels through the configured matching model to obtain the maximum matching score;

[0023] A7. Set a matching score threshold. If the maximum matching score is greater than the matching score threshold, the newly added sub-table data and the data stored under the node corresponding to the maximum matching score are of the same type, and the access frequency level of the corresponding type of data under the node with the maximum matching score is assigned to the newly added sub-table data.

[0024] A8, according to the assigned access frequency level, through the mapping relationship between the access frequency level and the load level constructed in A5, the newly added sub-table data is allocated to the corresponding sub-node for storage;

[0025] A9. If the maximum matching score is less than or equal to the matching score threshold, the newly added sub-table data is allocated to the sub-node with the smallest load evaluation score for storage.

[0026] Specifically, the mapping relationship between the access frequency level and the load level is established as follows:

[0027] The three-level load score intervals include: light load score interval, medium load score interval and heavy load score interval; the light load score interval corresponds to the light load level, the medium load score interval corresponds to the medium load level, and the heavy load score interval corresponds to the heavy load level;

[0028] The access frequency level is 1-9; among them, 1-3 is a light access frequency level, 4-6 is a medium access frequency level, and 7-9 is a heavy access frequency level;

[0029] The light load level corresponds to the heavy access frequency level; the medium load level corresponds to the medium access frequency level; the heavy load level corresponds to the light access frequency level;

[0030] According to the reverse order of the number of accesses corresponding to the light access frequency level, the medium access frequency level and the heavy access frequency level, table data deletion and update frequencies of nodes corresponding to the light access frequency level, the medium access frequency level and the heavy access frequency level are set.

[0031] Specifically, the configured dynamic query strategy has a built-in enhanced query model. The steps for building the enhanced query model include:

[0032] B1. Construct the current input state according to the index information, table name, table structure data information, load information of each node and optimized query instruction information corresponding to the multi-level node of the acquired tree structure data , where X represents the index information space between multi-level nodes corresponding to the tree structure data, and Y represents the index information space between the independent fields in the sub-table established under the multi-level nodes and the common fields corresponding to the parent table and the sub-table. Indicates the table name of the jth parent table or child table under the i-th node. Indicates the table structure data information of the jth parent table or child table under the i-th node. Indicates the query index information after optimization at the current time t. Indicates that the nth optimized query index information corresponds to the load status information of the ith query node. Indicates the access frequency level of the i-th node corresponding to the n-th optimized query index information.

[0033] Specifically, the steps of strengthening the query model construction also include:

[0034] B2. According to the current input status of the build, set the current query trigger information, including:

[0035] When the nth optimized query index information only specifies the jth subtable under the ith node, the first execution action information is triggered;

[0036] That is, when the nth optimized query index information only specifies the jth subtable under the ith node, the query is limited to the jth subtable under the ith node. Even if the query index information contains the common fields in the parent table corresponding to the jth subtable under the ith node, the parent table is not scanned in its entirety.

[0037] When the nth optimized query index information specifies a parent node and the query index information also includes some child table-specific fields under the child node corresponding to the specified parent node, the second execution action information is triggered;

[0038] That is, when the nth optimized query index information specifies a parent node and the query index information also includes the independent fields of some sub-tables under the sub-node corresponding to the specified parent node, the query scope is first limited to the sub-table corresponding to the independent field, and then the common fields of the sub-table corresponding to the parent table are queried through the index information established by the independent field in the sub-table and the corresponding common fields of the parent table and the sub-table, so as to obtain complete data information;

[0039] When the nth optimized query index information specifies the kth parent table under the ith node and the query index information only contains common fields, the third execution action information is triggered;

[0040] That is, when the nth optimized query index information specifies the kth parent table under the ith node and the query index information only contains common fields, the parsing model will delete the query index information of the independent fields of the child table corresponding to the kth parent table, so that the query is only performed in the kth parent table under the ith node.

[0041] Specifically, the steps of strengthening the query model construction also include:

[0042] When the nth optimized query index information includes multiple fields of the parent table and the corresponding child table at the same time, the fourth execution action information is triggered;

[0043] That is, when the nth optimized query index information includes multiple fields of the parent table and the corresponding child table at the same time, the query index information is decomposed into sub-query index information corresponding to the parent table and sub-query index information corresponding to the child table through the index information optimization library, and the obtained sub-query index information corresponding to the parent table and the sub-query index information corresponding to the child table are executed concurrently;

[0044] When the query subnode corresponding to the nth optimized query index information is at a heavy load level, the fifth execution information is triggered;

[0045] That is, the query table data stored under the query child node is migrated to the child node with the smallest load level under the same parent node corresponding to the query child node for query;

[0046] When there are at least two optimized query index information for query, and each optimized query index information corresponds to only one node query, the sixth execution information is triggered;

[0047] That is, when there are at least two optimized query index information for query, the query priority corresponding to the optimized query index information is assigned according to the access frequency level of the node corresponding to each optimized query index information.

[0048] Specifically, the steps of strengthening the query model construction also include:

[0049] B3: Construct the current execution action based on the current query trigger information set in B2 ,in Indicates the action that triggers the first execution action information to be executed. Indicates the action that triggers the second execution action information to be executed. Indicates the action that triggers the execution of the corresponding action of the third execution action information. Indicates the action executed by triggering the fourth execution action information. Indicates the action executed by triggering the fifth execution action information; Indicates the action executed by triggering the sixth execution action information;

[0050] B4. Construct the current moment reward function based on the action performed at the current moment , specifically;

[0051] ,

[0052] in, Indicates the query response time corresponding to the g-th execution action at the current time t. represents the query cost corresponding to the g-th execution action at the current time t, It indicates the query success rate corresponding to the g-th execution action at the current time t. Indicates the number of times the sixth execution action is successfully executed. The weights of rewards corresponding to the reward functions are as follows;

[0053] B5. Construct a reinforcement query model based on reinforcement learning, and input the current input state, query trigger information, execution action and reward function into the constructed reinforcement query model for training, obtain the trained reinforcement query model, and embed the trained reinforcement query model into the corresponding query interface of the tree structure database;

[0054] B6. Obtain query instructions in real time, and obtain the query data set corresponding to the query instructions from the tree structure data through the parsing model and the built-in enhanced query model.

[0055] Specifically, the query index information in the query instruction allows the table name to be represented by the storage path of the parent table or child table corresponding to the query;

[0056] The query index information in the query instruction supports wildcards and when querying and splitting the data in the database, the table name in the query index information is followed by the query field name;

[0057] The query fields in the query index information obtained after query instruction parsing optimization support wildcards and double equal signs "==" support expression search, regular expressions and built-in functions.

[0058] A multi-level query optimization system for tree-structured database based on AI model, including: database construction module, query parsing module and query module;

[0059] The database construction module is used to generate and construct a tree-structured database through a distributed database and a configured table space directory, and to add index information to each node in the tree-structured database;

[0060] The query parsing module is used to parse the query instruction using the parsing model, and optimize the parsed index information using the preset index information optimization library to obtain the optimized query index information corresponding to each level of nodes;

[0061] The query module is used to query the data information corresponding to the query index information in the tree structure database according to the optimized query index information under the corresponding nodes at all levels, by configuring the enhanced query model in the dynamic query strategy, to obtain the query data set.

[0062] A computer-readable storage medium, characterized in that computer instructions are stored thereon, and when the computer instructions are executed, a multi-level query optimization method for a tree-structured database based on an AI model is executed.

[0063] Compared with the prior art, the present invention has the following beneficial effects:

[0064] In view of the deficiencies of the prior art, the present invention introduces dynamic query strategies and enhanced query models, and can intelligently select the most appropriate query strategy according to the optimized query index information, thereby significantly reducing unnecessary full table scans and irrelevant data columns involved, and improving query efficiency. In addition, by configuring the load balancing strategy, the load status of each node can be monitored and adjusted in real time to ensure that data is reasonably distributed among different nodes, avoiding system performance bottlenecks caused by single-point overload, thereby enhancing the system scalability and overall stability in a distributed environment. BRIEF DESCRIPTION OF THE DRAWINGS

[0065] Figure 1This is a flow chart of a multi-level query optimization method for a tree-structured database based on an AI model according to Embodiment 1 of the present invention;

[0066] Figure 2 The table structure segmentation process style diagram is imported into Example 1 of the present invention;

[0067] Figure 3 This is a pattern diagram of unique fields and common fields in Example 1 of the present invention;

[0068] Figure 4 This is a module diagram of a multi-level query optimization system for a tree-structured database based on an AI model according to Embodiment 2 of the present invention. DETAILED DESCRIPTION

[0069] Example 1

[0070] See also Figure 1 An embodiment provided by the present invention is a tree-structure database multi-level query optimization method based on an AI model, which is applied to a column-type storage OLAP database, and the steps include:

[0071] S1. Obtain tree structure data, where the tree structure data is generated based on a distributed database and a configured table space directory; the tree structure data includes multiple levels of nodes, where the multiple levels of nodes include table names corresponding to each level of nodes, table structure data information, and index information corresponding to each level of nodes;

[0072] Furthermore, the step of generating tree structure data in this embodiment includes:

[0073] Obtain a tree-shaped tablespace directory, add a root node to the tablespace directory based on a distributed database, add multi-level nodes to each root node, automatically allocate tablespace to a first-level node in the multi-level node corresponding to each root node, and divide the tablespace automatically allocated to each first-level node into blocks according to the preset storage unit space size;

[0074] Multi-level nodes include parent nodes and corresponding mounted child nodes; the table structure in the parent node is automatically inherited in the corresponding mounted child node through triggers, and the parent node table structure fields cannot be modified in the corresponding inherited child node;

[0075] When an independent field is added to the table structure in the child node, an independent table space is configured for the added independent field according to the size of the added independent field and the block of the table space corresponding to the first-level node, and the table structure before the addition of the independent field is used as the parent table, and the table structure after the addition of the independent field is used as the child table. The child table is automatically inherited to the lower-level child node of the parent table corresponding to the current child node through a trigger, and the association relationship between the parent table and the child table is recorded, and the index information between the independent fields and the common fields corresponding to the parent table and the child table is constructed using the association relationship;

[0076] The common fields of the parent table and the corresponding child table except the independent fields are stored in column storage mode, and the independent fields are stored in the configured independent table space to generate tree structure data.

[0077] Furthermore, in this embodiment, the step of constructing index information between the independent fields and the common fields corresponding to the parent table and the child table includes:

[0078] Determine the index information of each parent node and the corresponding mounted child node in the multi-level node through the index information preset by each root node;

[0079] And through the index information of the parent table corresponding to the parent node and the child table corresponding to the child node and the recorded association relationship between the parent table and the child table, the independent field in the child table and the index information of the common field corresponding to the parent table and the child table are established, and the independent field is associated with the common field through the established index information; further, the independent field in this embodiment is as follows Figure 2 As shown in 002, the common fields are as follows Figure 2 As shown in 001, the rest will not be repeated here.

[0080] Furthermore, in this embodiment, the nodes at all levels added corresponding to the root node are child nodes of the root node, the nodes stored in the parent table corresponding to the child table are child nodes, and the nodes stored in the parent table are parent nodes relative to the child nodes stored in the child table.

[0081] This process effectively realizes efficient storage and management of data by adding a root node and its multi-level nodes to the tablespace directory in the distributed database and automatically allocating tablespace and blocks. Among them, the table structure inheritance mechanism between the parent node and the child node in the multi-level node simplifies the design of the data model and ensures the consistency of the data. At the same time, it allows the child node to expand independent fields based on inheritance, thereby enhancing the flexibility of the data model. Moreover, by configuring independent tablespaces for the newly added independent fields and adopting columnar storage for the common fields, this method not only improves the data access speed but also optimizes the storage efficiency. In addition, by constructing the index information of the independent fields and the common fields between the parent table and the child table, the query performance is further enhanced, and unnecessary full table scans and queries on the corresponding data of irrelevant data columns are reduced. Especially when processing complex queries, it can significantly reduce the computing cost and improve the response speed.

[0082] Furthermore, the distributed database in this embodiment provides an interface to support importing data from other table structure files (CSV, etc.), databases, etc., and the interface has a built-in table discrimination mechanism. When some fields in the corresponding imported table structure are not available in the entire table, the imported table structure is automatically split into a parent table and corresponding child tables, and stored in the corresponding parent node and the child node mounted by the parent node. The imported table structure corresponds to the style before and after the split, such as Figure 3As shown, gender and age are common fields in all tables, but A and B do not have corresponding fields for R&D skills and accounting qualifications, C does not have an accounting qualification field, and D does not have a corresponding field for R&D skills. These missing fields constitute non-common fields. Therefore, according to the table structure corresponding to the original parent table, A and B are divided into a sub-table according to the common fields and non-common fields, and C and D are each divided into a sub-table for storage, so that there is no problem of missing fields in the stored table, avoiding confusion in the query.

[0083] Furthermore, in this embodiment, a load balancing strategy is configured in the root node added to the table space directory to achieve load balancing of the storage status of multiple nodes under each root node, and the steps include:

[0084] A1. Obtain the load status data of nodes at all levels under each root node, the number of accesses to table data at all levels under each node, and the type of storage table data;

[0085] A2. Construct a load assessment model based on the fuzzy comprehensive assessment algorithm, and embed the constructed three-level load score interval into the load assessment model;

[0086] A3. Input the acquired load status data of nodes at all levels under each root node into the load evaluation model to obtain the evaluation scores and load levels corresponding to the nodes at all levels, and mark the acquired evaluation scores and load levels on the corresponding nodes, and dynamically update the marked evaluation scores using the real-time acquired load status data of nodes at all levels;

[0087] A4. Obtain the access frequency level of the corresponding type of storage table data through a fuzzy comprehensive evaluation algorithm according to the access times of the table data under each level of nodes and the type of storage table data;

[0088] A5. Establish a mapping relationship between access frequency level and load level. According to the load level of each node under the same root node and the access frequency level of the corresponding type table data under each node, perform dynamic migration between the child nodes mounted on the same parent node through the established mapping relationship, and update the index relationship between the migrated child table and the corresponding parent table in real time.

[0089] Furthermore, in this embodiment, the mapping relationship between the access frequency level and the load level is established as follows:

[0090] The three-level load score intervals include: light load score interval, medium load score interval and heavy load score interval; the light load score interval corresponds to the light load level, the medium load score interval corresponds to the medium load level, and the heavy load score interval corresponds to the heavy load level;

[0091] The access frequency level is 1-9; among them, 1-3 is a light access frequency level, 4-6 is a medium access frequency level, and 7-9 is a heavy access frequency level;

[0092] The light load level corresponds to the heavy access frequency level; the medium load level corresponds to the medium access frequency level; the heavy load level corresponds to the light access frequency level;

[0093] According to the reverse order of the number of accesses corresponding to the light access frequency level, the medium access frequency level and the heavy access frequency level, table data deletion and update frequencies of nodes corresponding to the light access frequency level, the medium access frequency level and the heavy access frequency level are set.

[0094] Furthermore, in this embodiment, according to the reverse order of the number of accesses corresponding to the light access frequency level and the heavy access frequency level, the table data deletion frequency of the nodes corresponding to the light access frequency level, the medium access frequency level and the heavy access frequency level is set, specifically: the number of accesses corresponding to the light access frequency level is set as the deletion and update frequency of the table data of the node corresponding to the heavy access frequency level, the number of accesses corresponding to the heavy access frequency level is set as the deletion and update frequency of the table data of the node corresponding to the light access frequency level; the number of accesses corresponding to the medium access frequency level is set as the deletion and update frequency of the table data of the node corresponding to the medium access frequency level;

[0095] A6. When new sub-table data is added to the database, the added sub-table data is matched with the corresponding type data stored in nodes at all levels through the configured matching model to obtain the maximum matching score;

[0096] A7. Set a matching score threshold. If the maximum matching score is greater than the matching score threshold, the newly added sub-table data and the data stored under the node corresponding to the maximum matching score are of the same type, and the access frequency level of the corresponding type of data under the node with the maximum matching score is assigned to the newly added sub-table data.

[0097] A8, according to the assigned access frequency level, through the mapping relationship between the access frequency level and the load level constructed in A5, the newly added sub-table data is allocated to the corresponding sub-node for storage;

[0098] A9. If the maximum matching score is less than or equal to the matching score threshold, the newly added sub-table data is allocated to the sub-node with the smallest load evaluation score for storage.

[0099] The load evaluation model constructed by the fuzzy comprehensive evaluation algorithm in this process can accurately measure the load conditions of each node, enabling the system to dynamically adjust data distribution according to the actual load status, avoiding the problem of some nodes being overloaded while other nodes have idle resources; secondly, by setting the reverse mapping relationship between different access frequency levels and load levels, the system can intelligently migrate high-frequency accessed data to nodes with lower load, and vice versa, thus ensuring the maximization of data access efficiency while reducing the pressure on high-load nodes; in addition, for newly added data, the system first attempts to match it to the node where the existing type of data is located, which can not only reduce the additional overhead caused by frequent migration but also quickly locate the appropriate storage location based on the existing access pattern; for data that cannot be well matched, it is assigned to the node with the lowest current load to ensure that the overall load of the system is maintained in a balanced state.

[0100] S2. Obtain a query instruction, parse the query instruction using the parsing model to obtain query index information corresponding to each level of nodes, and optimize the obtained query index information corresponding to each level of nodes using a preset index information optimization library to obtain optimized query index information corresponding to each level of nodes; the query index information corresponds to the index information under each level of nodes; further, the parsing model in this embodiment is constructed by a support vector machine.

[0101] Further, in this embodiment, the query index information in the query instruction allows the table name to be represented by the storage path of the corresponding parent table or child table of the query. Exemplarily, such as " / a certain enterprise / sales department"; " / a certain enterprise / sales department" means retrieving the "sales department" table located under the "a certain enterprise" node.

[0102] The query index information in the query instruction supports wildcards. Exemplarily, such as " / a certain enterprise / * department", which matches all departments, meaning retrieving all tables ending with "department" under the "a certain enterprise" node.

[0103] When the query index information in the query instruction divides the query of data in the database, the table name in the query index information is followed by the query field name. Exemplarily, such as " / a certain enterprise / * department. gender = male", which means retrieving records with gender being male in all tables ending with "department" under the "a certain enterprise" node.

[0104] The query fields in the query index information obtained after optimizing the query instruction parsing support wildcards. Exemplarily, for example, " / a certain enterprise / department. = 24" means retrieving records with any field value being 24 in all tables ending with "department" under the "a certain enterprise" node.

[0105] The double equal sign "==" in the query index information in the query instruction supports expression search, regular expressions, and built-in functions; for example, " / a certain enterprise / department.==^d{11}$" means retrieving records where any field value in all tables ending with "department" under the "a certain enterprise" node is an 11-digit number.

[0106] Use the above corresponding representation method to construct a query instruction template, and build the constructed query instruction template into a preset index information optimization library.

[0107] Furthermore, in this embodiment, the preset index information optimization library is constructed by the query instruction corresponding to the shortest historical query response time;

[0108] After parsing the query instruction through the parsing model to obtain the query index information under the corresponding nodes at all levels, through the instruction reconstruction model built into the index information optimization library, according to the built-in query instruction template and the query instruction corresponding to the shortest query response time, reconstruct the optimized query index information under the corresponding nodes at all levels; furthermore, the instruction reconstruction model in this embodiment is constructed by the random forest algorithm.

[0109] S3. According to the optimized query index information under the corresponding nodes at all levels, obtain the data under the index information of each level of nodes corresponding to the query index information from the tree-structured data through the configured dynamic query strategy, and obtain the corresponding query dataset.

[0110] Furthermore, the configured dynamic query strategy in this embodiment incorporates a reinforcement query model. The steps for constructing the reinforcement query model include:

[0111] B1. Construct the input state at the current moment based on the index information, table names, table structure data information, load information of each level of nodes, and optimized query instruction information corresponding to the multi-level nodes of the obtained tree-structured data , where X represents the index information space between the multi-level nodes of the tree-structured data, Y represents the index information space of the independent fields in the sub-tables established under the multi-level nodes and the common fields corresponding to the parent table and sub-tables, represents the table name of the jth parent table or sub-table under the ith node, represents the table structure data information of the jth parent table or sub-table under the ith node, represents the nth optimized query index information at the current moment t, represents the load status information of the nth optimized query index information corresponding to querying the ith node, represents the access frequency level of the nth optimized query index information corresponding to the ith node;

[0112] B2. According to the constructed input state at the current moment, set the query trigger information at the current moment, including:

[0113] When the nth optimized query index information only specifies the jth subtable under the ith node, the first execution action information is triggered;

[0114] That is, when the nth optimized query index information only specifies the jth subtable under the ith node, the query is limited to the jth subtable under the ith node. Even if the query index information contains the common fields in the parent table corresponding to the jth subtable under the ith node, the parent table is not scanned in its entirety.

[0115] For example, suppose there is a tree-structured database, which includes a parent table ParentTable and a child table ChildTable; the query index information is " / a certain enterprise / sales department.gender=male", which means to query the records with gender male in the "sales department" table under the "a certain enterprise" node;

[0116] Query index information: / Enterprise / Sales Department.Gender=Male

[0117] Execution action: The query is executed only in the "Sales Department" child table, and the parent table "Enterprise" is not scanned in its entirety.

[0118] When the nth optimized query index information specifies a parent node and the query index information also includes some child table-specific fields under the child node corresponding to the specified parent node, the second execution action information is triggered;

[0119] That is, when the nth optimized query index information specifies a parent node and the query index information also includes the independent fields of some sub-tables under the sub-node corresponding to the specified parent node, the query scope is first limited to the sub-table corresponding to the independent field, and then the common fields of the sub-table corresponding to the parent table are queried through the index information established by the independent field in the sub-table and the corresponding common fields of the parent table and the sub-table, so as to obtain complete data information;

[0120] For example, assume that the query index information is " / a certain enterprise / sales department.salary=5000", where the "salary" field is a field unique to the child table, and "sales department" is a child node of the parent table;

[0121] Query index information: / a company / sales department.salary=5000

[0122] Execution action: First query the record with a salary of 5000 in the "Sales Department" child table, and then obtain the common field information of this record in the parent table "A Certain Enterprise" through the index information.

[0123] When the nth optimized query index information specifies the kth parent table under the ith node and the query index information only contains common fields, the third execution action information is triggered;

[0124] That is, when the nth optimized query index information specifies the kth parent table under the ith node and the query index information only contains common fields, the parsing model will delete the query index information of the independent fields of the child table corresponding to the kth parent table, so that the query is only performed in the kth parent table under the ith node;

[0125] For example, assume that the query index information is " / Some Enterprise.Age>30", where "Age" is a common field in the parent table "Some Enterprise";

[0126] Query index information: / a company.age>30

[0127] Execution action: The query is only performed in the parent table "A Certain Enterprise", ignoring the fields specific to the child table.

[0128] When the nth optimized query index information includes multiple fields of the parent table and the corresponding child table at the same time, the fourth execution action information is triggered;

[0129] That is, when the nth optimized query index information includes multiple fields of the parent table and the corresponding child table at the same time, the query index information is decomposed into sub-query index information corresponding to the parent table and sub-query index information corresponding to the child table through the index information optimization library, and the obtained sub-query index information corresponding to the parent table and the sub-query index information corresponding to the child table are executed concurrently;

[0130] For example, assume that the query index information is " / a certain enterprise / sales department.age>30 AND gender=male AND salary>5000", where "age" and "gender" are common fields in the parent table, and "salary" is an independent field in the child table;

[0131] Query index information: / Company / Sales Department.Age>30 AND Gender=Male AND Salary>5000

[0132] Execution action: Decompose the query into two subqueries. One is to query the records in the parent table whose age is greater than 30 and whose gender is male. The other is to query the records in the child table whose salary is greater than 5000. Execute these two subqueries concurrently.

[0133] When the query subnode corresponding to the nth optimized query index information is at a heavy load level, the fifth execution information is triggered;

[0134] That is, the query table data stored under the query child node is migrated to the child node with the smallest load level under the same parent node corresponding to the query child node for query;

[0135] For example, assume that the query index information is " / a certain enterprise / sales department", and the current load of the "sales department" sub-node is too high;

[0136] Query index information: / a certain enterprise / sales department

[0137] Execution action: Migrate the data under the "Sales Department" child node to the child node with the smallest load level under the same parent node "Enterprise" for query.

[0138] When there are at least two optimized query index information for query, and each optimized query index information corresponds to only one node query, the sixth execution information is triggered;

[0139] That is, when there are at least two optimized query index information for query, the query priority corresponding to the optimized query index information is assigned according to the access frequency level of the node corresponding to each optimized query index information;

[0140] For example, assume that there are two query index information " / a certain enterprise / sales department.gender=male" and " / a certain enterprise / R&D department.age<25", which correspond to different node queries respectively;

[0141] Query index information: / a certain company / sales department.gender=male and / a certain company / R&D department.age<25

[0142] Execution action: Assign query priority according to the access frequency level of the node corresponding to each query index information, and give priority to queries with higher access frequency levels.

[0143] B3: Construct the current execution action based on the current query trigger information set in B2 ,in Indicates the action that triggers the first execution action information to be executed. Indicates the action that triggers the second execution action information to be executed. Indicates the action that triggers the execution of the corresponding action of the third execution action information. Indicates the action executed by triggering the fourth execution action information. Indicates the action executed by triggering the fifth execution action information; Indicates the action executed by triggering the sixth execution action information;

[0144] B4. Construct the current moment reward function based on the action performed at the current moment , specifically;

[0145] ,

[0146] in, Indicates the query response time corresponding to the g-th execution action at the current time t. represents the query cost corresponding to the g-th execution action at the current time t, It indicates the query success rate corresponding to the g-th execution action at the current time t. Indicates the number of times the sixth execution action is successfully executed; The weights of rewards corresponding to the reward functions are as follows;

[0147] Furthermore, the reward function takes into account the query response time, query cost and query success rate, and gives additional rewards for the successful execution of the sixth action. The purpose of this is to encourage the system to choose actions that are faster, more accurate and more resource-efficient, and also to encourage the system to use the sixth action as much as possible to improve query efficiency;

[0148] B5. Construct a reinforcement query model based on reinforcement learning, and input the current input state, query trigger information, execution action and reward function constructed into the constructed reinforcement query model for training, obtain the trained reinforcement query model, and build the trained reinforcement query model into the query interface corresponding to the tree structure database; further, the reinforcement learning in this embodiment includes a deep strategy algorithm and a SAC algorithm;

[0149] B6. Obtain query instructions in real time, and obtain the query data set corresponding to the query instructions from the tree structure data through the parsing model and the built-in enhanced query model.

[0150] By constructing the current input state and setting the query trigger information, the system can trigger the optimal execution action according to different query conditions, such as limiting sub-table queries, executing multi-table queries concurrently, migrating high-load node data, etc., thereby avoiding unnecessary full table scans and resource waste; in addition, by building a reward function through a reinforcement learning model and optimizing it according to the query response time, cost and success rate, the system can dynamically adjust the query strategy to ensure that each query can achieve the highest success rate at the lowest cost in the shortest time; this method not only reduces unnecessary computing overhead, but also avoids hot spots through load balancing strategies, ensuring the stability and efficient operation of the system.

[0151] Example 2

[0152] See also Figure 4 , another embodiment provided by the present invention: a tree-structured database multi-level query optimization system based on an AI model, comprising: a database construction module, a query parsing module and a query module;

[0153] The database construction module is used to generate and construct a tree-structured database through a distributed database and a configured table space directory, and to add index information to nodes at all levels in the tree-structured database;

[0154] The query parsing module is used to parse the query instruction using the parsing model, and optimize the parsed index information using the preset index information optimization library to obtain the optimized query index information corresponding to each level of nodes;

[0155] The query module is used to query the data information corresponding to the query index information in the tree structure database according to the optimized query index information under the corresponding nodes at all levels, by configuring the enhanced query model in the dynamic query strategy, to obtain the query data set.

[0156] Example 3

[0157] A computer-readable storage medium stores computer instructions, which, when executed, execute a multi-level query optimization method for a tree-structured database based on an AI model.

[0158] An electronic device includes a memory and a processor, wherein the memory stores a computer program, and the processor implements a multi-level query optimization method for a tree-structured database based on an AI model when executing the computer program.

[0159] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation modes, which are merely illustrative rather than restrictive. Under the guidance of the present invention, ordinary technicians in the field may also change, modify, replace and modify the above-mentioned embodiments without departing from the scope of protection of the purpose of the present invention and the claims, and all of these are within the protection of the present invention.

[0160] If the disclosed technical solution involves personal information, the product using the disclosed technical solution has clearly informed the personal information processing rules and obtained the individual's voluntary consent before processing the personal information. If the disclosed technical solution involves sensitive personal information, the product using the disclosed technical solution has obtained the individual's separate consent before processing the sensitive personal information, and at the same time meets the "explicit consent" requirement. For example, on personal information collection devices such as cameras, clear and prominent signs are set to inform that the personal information collection scope has been entered and personal information will be collected. If the individual voluntarily enters the collection scope, it is deemed that he or she agrees to the collection of his or her personal information; or on the device that processes personal information, when the personal information processing rules are notified by obvious signs / information, the individual's authorization is obtained through pop-up information or by asking the individual to upload his or her personal information; among them, the personal information processing rules may include information such as the personal information processor, the purpose of personal information processing, the processing method, and the type of personal information processed.

Claims

1. A multi-level query optimization method for a tree-structured database based on an AI model, characterized in that: include: Acquire tree structure data, where the tree structure data is generated based on a distributed database and a configured table space directory; The tree structure data includes multiple levels of nodes, and the multiple levels of nodes include table names corresponding to each level of nodes, table structure data information, and index information corresponding to each level of nodes; Obtaining a query instruction, parsing the query instruction using a parsing model, obtaining query index information corresponding to each level of nodes, and optimizing the obtained query index information corresponding to each level of nodes using a preset index information optimization library, thereby obtaining optimized query index information corresponding to each level of nodes; The query index information corresponds to the index information under each level of nodes; According to the optimized query index information corresponding to each level of nodes, the data under the index information of each level of nodes corresponding to the query index information are obtained from the tree structure data through the configured dynamic query strategy to obtain the corresponding query data set; The tree structure data includes a tree table space directory, and the tree table space directory includes a root node and multiple levels of nodes; The step of generating the tree structure data comprises: The multi-level node includes a parent node and corresponding mounted child nodes; The table structure in the parent node is automatically inherited in the corresponding mounted child node through a trigger and cannot be modified; when an independent field is added to the table structure in the child node, an independent table space is configured for the added independent field according to the size of the added independent field and the block of the table space corresponding to the first-level node, and the table structure before the addition of the independent field is used as the parent table, and the table structure after the addition of the independent field is used as the child table, and the child table is automatically inherited to the lower-level child node of the parent table corresponding to the current child node, and the association relationship between the parent table and the child table is recorded, and the index information between the independent fields and the common fields corresponding to the parent table and the child table is constructed using the association relationship.

2. The tree structure database multi-level query optimization method based on AI model as claimed in claim 1, characterized in that: The step of constructing index information between independent fields and common fields corresponding to the parent table and the child table includes: Determine the index information of each parent node and the corresponding mounted child node in the multi-level nodes through the index information preset by each root node; And through the index information of the parent node corresponding to the parent table and the child node corresponding to the child table and the recorded association relationship between the parent table and the child table, the independent fields in the child table and the index information of the common fields corresponding to the parent table and the child table are established, and the independent fields are associated with the common fields through the established index information.

3. The AI ​​model-based tree structure database multi-level query optimization method according to claim 2, characterized in that: The root node added to the tablespace directory is configured with a load balancing strategy to achieve load balancing of the storage status of multiple nodes under each root node. The steps include: A1. Obtain the load status data of nodes at all levels under each root node, the number of accesses to table data at all levels under each node, and the type of storage table data; A2. Construct a load evaluation model based on the fuzzy comprehensive evaluation algorithm, and embed the constructed three-level load score interval into the load evaluation model; A3. Input the acquired load status data of nodes at all levels under each root node into the load evaluation model to obtain the evaluation scores and load levels corresponding to the nodes at all levels, and mark the acquired evaluation scores and load levels on the corresponding nodes, and dynamically update the marked evaluation scores using the real-time acquired load status data of nodes at all levels; A4. Obtain the access frequency level of the corresponding type of storage table data through a fuzzy comprehensive evaluation algorithm according to the access times of the table data under each level of nodes and the type of storage table data; A5. Establish a mapping relationship between access frequency level and load level. According to the load level of each node under the same root node and the access frequency level of the corresponding type table data under each node, perform dynamic migration between the child nodes mounted on the same parent node through the established mapping relationship, and update the index relationship between the migrated child table and the corresponding parent table in real time. A6. When new sub-table data is added to the database, the added sub-table data is matched with the corresponding type data stored in nodes at all levels through the configured matching model to obtain the maximum matching score; A7. Set a matching score threshold. If the maximum matching score is greater than the matching score threshold, the newly added sub-table data and the data stored under the node corresponding to the maximum matching score are of the same type, and the access frequency level of the corresponding type of data under the node with the maximum matching score is assigned to the newly added sub-table data. A8, according to the assigned access frequency level, through the mapping relationship between the access frequency level and the load level constructed in A5, the newly added sub-table data is allocated to the corresponding sub-node for storage; A9. If the maximum matching score is less than or equal to the matching score threshold, the newly added sub-table data is allocated to the sub-node with the smallest load evaluation score for storage.

4. The tree structure database multi-level query optimization method based on AI model as claimed in claim 3, characterized in that: The mapping relationship between the access frequency level and the load level is specifically established as follows: The three-level load score intervals include: a light load score interval, a medium load score interval and a heavy load score interval; the light load score interval corresponds to a light load level, the medium load score interval corresponds to a medium load level, and the heavy load score interval corresponds to a heavy load level; The access frequency level is 1-9, where 1-3 is a mild access frequency level, 4-6 is a moderate access frequency level, and 7-9 is a severe access frequency level; The light load level corresponds to the heavy access frequency level; the medium load level corresponds to the medium access frequency level; the heavy load level corresponds to the light access frequency level; According to the reverse order of the access times corresponding to the light access frequency level, medium access frequency level and heavy access frequency level, the table data deletion and update frequency of the nodes corresponding to the light access frequency level, medium access frequency level and heavy access frequency level is set.

5. The AI ​​model-based tree structure database multi-level query optimization method according to claim 4, characterized in that: The configured dynamic query strategy has a built-in enhanced query model, and the steps of building the enhanced query model include: B1. Construct the current input state according to the index information, table name, table structure data information, load information of each node and optimized query instruction information corresponding to the multi-level node of the acquired tree structure data , where X represents the index information space between multi-level nodes corresponding to the tree structure data, and Y represents the index information space between the independent fields in the sub-table established under the multi-level nodes and the common fields corresponding to the parent table and the sub-table. Indicates the table name of the jth parent table or child table under the i-th node. Indicates the table structure data information of the jth parent table or child table under the i-th node. Indicates the query index information after optimization at the current time t. Indicates that the nth optimized query index information corresponds to the load status information of the ith query node. Indicates the access frequency level of the i-th node corresponding to the n-th optimized query index information.

6. The AI ​​model-based tree structure database multi-level query optimization method according to claim 5, characterized in that: The step of strengthening the query model construction also includes: B2. According to the current input status of the build, set the current query trigger information, including: When the nth optimized query index information only specifies the jth subtable under the ith node, the first execution action information is triggered; That is, when the nth optimized query index information only specifies the jth subtable under the ith node, the query is limited to the jth subtable under the ith node. Even if the query index information contains the common fields in the parent table corresponding to the jth subtable under the ith node, the parent table is not scanned in its entirety. When the nth optimized query index information specifies a parent node and the query index information also includes some child table-specific fields under the child node corresponding to the specified parent node, the second execution action information is triggered; That is, when the nth optimized query index information specifies a parent node and the query index information also includes the independent fields of the sub-table under the child node corresponding to the specified parent node, the query scope is first limited to the sub-table corresponding to the independent field, and then the common fields of the parent table corresponding to the sub-table are queried through the index information established by the independent field in the sub-table and the corresponding common fields of the parent table and the sub-table, so as to obtain complete data information; When the nth optimized query index information specifies the kth parent table under the ith node and the query index information only contains common fields, the third execution action information is triggered; That is, when the nth optimized query index information specifies the kth parent table under the ith node and the query index information only contains common fields, the parsing model will delete the query index information of the independent fields of the child table corresponding to the kth parent table, so that the query is only performed in the kth parent table under the ith node.

7. The AI ​​model-based tree structure database multi-level query optimization method according to claim 6, characterized in that: The step of strengthening the query model construction also includes: When the nth optimized query index information includes multiple fields of the parent table and the corresponding child table at the same time, the fourth execution action information is triggered; That is, when the nth optimized query index information includes multiple fields of the parent table and the corresponding child table at the same time, the query index information is decomposed into sub-query index information corresponding to the parent table and sub-query index information corresponding to the child table through the index information optimization library, and the obtained sub-query index information corresponding to the parent table and the sub-query index information corresponding to the child table are executed concurrently; When the query subnode corresponding to the nth optimized query index information is at a heavy load level, the fifth execution information is triggered; That is, the query table data stored under the query child node is migrated to the child node with the smallest load level under the same parent node corresponding to the query child node for query; When there are at least two optimized query index information for query, and each optimized query index information corresponds to only one node query, the sixth execution information is triggered; That is, when there are at least two optimized query index information for query, the query priority corresponding to the optimized query index information is assigned according to the access frequency level of the node corresponding to each optimized query index information.

8. The AI ​​model-based tree structure database multi-level query optimization method according to claim 7, characterized in that: The step of strengthening the query model construction also includes: B3: Construct the current execution action based on the current query trigger information set in B2 ,in Indicates the action that triggers the first execution action information to be executed. Indicates the action that triggers the second execution action information to be executed. Indicates the action that triggers the execution of the corresponding action of the third execution action information. Indicates the action executed by triggering the fourth execution action information. Indicates the action executed by triggering the fifth execution action information; Indicates the action executed by triggering the sixth execution action information; B4. Construct the current moment reward function based on the action performed at the current moment , specifically; , in, Indicates the query response time corresponding to the g-th execution action at the current time t. represents the query cost corresponding to the g-th execution action at the current time t, It indicates the query success rate corresponding to the g-th execution action at the current time t. Indicates the number of times the sixth execution action is successfully executed. The weights of rewards corresponding to the reward functions are as follows; B5. Construct a reinforcement query model based on reinforcement learning, and input the current input state, query trigger information, execution action and reward function into the constructed reinforcement query model for training, obtain the trained reinforcement query model, and embed the trained reinforcement query model into the corresponding query interface of the tree structure database; B6. Obtain query instructions in real time, and obtain the query data set corresponding to the query instructions from the tree structure data through the parsing model and the built-in enhanced query model.

9. The AI ​​model-based tree structure database multi-level query optimization method according to claim 8, characterized in that: The query index information in the query instruction allows the table name to be represented by the storage path of the parent table or child table corresponding to the query; The query index information in the query instruction supports wildcards and when querying and segmenting the data in the database, the table name in the query index information is followed by the query field name; The query field in the query index information obtained after the query instruction parsing optimization supports wildcards and the double equal signs "==" support expression search, regular expressions and built-in functions.

10. A multi-level query optimization system for a tree-structured database based on an AI model, which is implemented based on the multi-level query optimization method for a tree-structured database based on an AI model according to any one of claims 1 to 9, characterized in that: include: Database construction module, query parsing module and query module; The database construction module is used to generate a tree-structured database through a distributed database and a configured table space directory, and add index information to each node in the tree-structured database; The query parsing module is used to parse the query instruction using the parsing model, and optimize the parsed index information using the preset index information optimization library to obtain the optimized query index information corresponding to each level of nodes; The query module is used to query the data information corresponding to the query index information in the tree structure database according to the optimized query index information under the corresponding nodes at all levels, by configuring the enhanced query model in the dynamic query strategy, to obtain the query data set.

11. A computer-readable storage medium, characterized in that: Computer instructions are stored thereon, and when the computer instructions are executed, the steps of the multi-level query optimization method for tree-structured database based on AI model described in any one of claims 1-9 are executed.