A data query optimization method and terminal
By adding an index cache layer to the index tree to store the index paths of high-frequency data, the problem of low query efficiency of the B+ tree index structure is solved, and the rapid location and query optimization of high-frequency data are achieved.
Patent Information
- Application Number
- CN202410254098.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-06
- Publication Date
- 2025-12-05
- Estimated Expiration
- 2044-03-06
AI Technical Summary
The existing B+ tree index structure still needs improvement in data query efficiency, especially when querying high-frequency data, the query steps are cumbersome and inefficient.
Create an index cache layer in the index tree to store the index paths of frequently accessed data, and retrieve the index paths directly from the cache layer during queries, skipping nodes that do not need to be queried and directly locating non-leaf nodes.
By adding an index caching layer, non-leaf nodes of high-frequency data can be quickly located, improving data query efficiency and reducing query time.
Smart Images

Figure CN118210823B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, and in particular to a data query optimization method and terminal. Background Technology
[0002] In modern internet systems, indexes are commonly used to support fast data retrieval. Indexes sort data, enabling quick retrieval of desired results. Taking a common MySQL database as an example, it typically creates a B+ tree index for a single table to improve query efficiency. A B+ tree usually has three levels of nodes (three levels high), with data stored in the non-leaf nodes at the bottom level. When querying data, the root node is queried first, followed by the second and third levels, ultimately retrieving data from the non-leaf nodes. However, this index structure still has room for improvement in terms of data retrieval efficiency. Summary of the Invention
[0003] The technical problem to be solved by this invention is to provide a data query optimization method and terminal to effectively improve data query efficiency.
[0004] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is as follows:
[0005] A data query optimization method includes the following steps:
[0006] S1. Periodically monitor and retrieve frequently queried data from the index tree, and mark it as high-frequency data;
[0007] S2. Create an index cache layer and store the index paths of the high-frequency data;
[0008] S3. During the indexing process, when the query of the high-frequency data is triggered, the system jumps to the index cache layer, obtains the index path corresponding to the high-frequency data, and then performs the query using the index path.
[0009] To solve the above-mentioned technical problems, another technical solution adopted by the present invention is as follows:
[0010] A data query optimization terminal includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it performs the following steps.
[0011] S1. Periodically monitor and retrieve frequently queried data from the index tree, and mark it as high-frequency data;
[0012] S2. Create an index cache layer and store the index paths of the high-frequency data;
[0013] S3. During the indexing process, when the query of the high-frequency data is triggered, the system jumps to the index cache layer, obtains the index path corresponding to the high-frequency data, and then performs the query using the index path.
[0014] The beneficial effects of this invention are as follows: It provides a data query optimization method and terminal. By adding an independent index cache layer to store the index paths of frequently queried high-frequency data in the index tree within a certain period, based on the existing index tree query mechanism, the index path of high-frequency data can be directly obtained from the index cache layer according to whether it is high-frequency data. Based on the information in the path, nodes that do not need to be queried can be quickly skipped and the non-leaf nodes in the index tree can be directly located. Compared with the old index tree query steps that start from the root node and query level by level, the data query efficiency is effectively improved. Attached Figure Description
[0015] Figure 1 This is a flowchart of a data query optimization method according to an embodiment of the present invention;
[0016] Figure 2 This is an example diagram of an index tree structure in a data query optimization method according to an embodiment of the present invention;
[0017] Figure 3 This is a schematic diagram of the structure of a data query optimization terminal according to an embodiment of the present invention.
[0018] Label Explanation:
[0019] 1. A data query optimization terminal; 2. Memory; 3. Processor. Detailed Implementation
[0020] To explain in detail the technical content, objectives, and effects of the present invention, the following description is provided in conjunction with the embodiments and accompanying drawings.
[0021] Please refer to Figure 1 and Figure 2 A data query optimization method includes the following steps:
[0022] S1. Periodically monitor and retrieve frequently queried data from the index tree, and mark it as high-frequency data;
[0023] S2. Create an index cache layer and store the index paths of the high-frequency data;
[0024] S3. During the indexing process, when the query of the high-frequency data is triggered, the system jumps to the index cache layer, obtains the index path corresponding to the high-frequency data, and then performs the query using the index path.
[0025] As can be seen from the above description, the beneficial effects of the present invention are as follows: It provides a data query optimization method and terminal, which stores the index paths of frequently queried high-frequency data in the index tree within a certain period by adding an independent index cache layer. In the subsequent indexing process, the index path of high-frequency data can be directly obtained from the index cache layer based on whether it is high-frequency data. According to the information in the path, nodes that do not need to be queried can be quickly skipped and the non-leaf nodes in the index tree can be directly located. Compared with the old index tree query steps that start from the root node and query level by level, the data query efficiency is effectively improved.
[0026] Furthermore, the high-frequency data refers to data that has been queried more than a preset number of times within a preset period.
[0027] As described above, data is periodically monitored and queried more than a preset number of times, and then new high-frequency data is periodically updated and obtained.
[0028] Further, step S2 specifically includes:
[0029] An index cache layer is created to cache the index path of the high-frequency data. The name of the high-frequency data is used as the key, and the node path of the high-frequency data in the index tree is used as the value. The index path of the high-frequency data is stored in the index cache layer in the form of (key, value).
[0030] As described above, storing the index path of high-frequency data in the form of a (key, value) data structure effectively reduces the space occupied by the index cache layer, and at the same time, it can directly trigger high-frequency data through the key, thereby directly obtaining the corresponding index path.
[0031] Furthermore, step S3 also includes:
[0032] When the input data name is incomplete, the fuzzy search method is used first to check whether the high-frequency data containing the incomplete name exists. If it exists, the indexing step of the high-frequency data is directly triggered to obtain the index path of the high-frequency data containing the incomplete name in the index cache layer and then the query is performed using the index path. Otherwise, the normal indexing step is used to traverse the child nodes in the index tree from the root node until the data containing the incomplete name is found.
[0033] As described above, for queries of high-frequency data with known data names, the index cache layer can be used to quickly locate the specific non-leaf node in the index tree. Similarly, for queries of data with incomplete names, it is possible to determine whether the data is high-frequency. A fuzzy search method can be used to determine whether the incomplete name contains the name of a corresponding high-frequency data. If so, the index cache layer can be used to quickly locate the relevant index path. Based on the information in the path, nodes that do not need to be queried can be quickly skipped, and the non-leaf node containing the matching data can be found. Then, staff can directly make a judgment, further improving the efficiency of data query.
[0034] Furthermore, after step S3, the method further includes:
[0035] S4. When the high-frequency data is updated, the index path in the index cache layer is updated or deleted synchronously.
[0036] As described above, this corresponds to the periodic monitoring and acquisition of high-frequency data in step S1. When the high-frequency data is updated, the index path stored in the index cache layer also needs to be updated accordingly to ensure the accuracy and efficiency of the query.
[0037] Please refer to Figure 3 A data query optimization terminal includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it performs the following steps.
[0038] S1. Periodically monitor and retrieve frequently queried data from the index tree, and mark it as high-frequency data;
[0039] S2. Create an index cache layer and store the index paths of the high-frequency data;
[0040] S3. During the indexing process, when the query of the high-frequency data is triggered, the system jumps to the index cache layer, obtains the index path corresponding to the high-frequency data, and then performs the query using the index path.
[0041] As can be seen from the above description, the beneficial effects of the present invention are as follows: Based on the same technical concept, and in conjunction with the above-mentioned data query optimization method, a data query optimization terminal is provided. By adding an independent index cache layer to store the index paths of frequently queried high-frequency data in the index tree within a certain period, in the subsequent indexing process, the index path of high-frequency data can be directly obtained from the index cache layer based on whether it is high-frequency data. According to the information in the path, nodes that do not need to be queried can be quickly skipped, and the non-leaf nodes in the index tree can be directly located. Compared with the old index tree query steps that start from the root node and query level by level, the data query efficiency is effectively improved.
[0042] Furthermore, the high-frequency data refers to data that has been queried more than a preset number of times within a preset period.
[0043] As described above, data is periodically monitored and queried more than a preset number of times, and then new high-frequency data is periodically updated and obtained.
[0044] Further, step S2 specifically includes:
[0045] An index cache layer is created to cache the index path of the high-frequency data. The name of the high-frequency data is used as the key, and the node path of the high-frequency data in the index tree is used as the value. The index path of the high-frequency data is stored in the index cache layer in the form of (key, value).
[0046] As described above, storing the index path of high-frequency data in the form of a (key, value) data structure effectively reduces the space occupied by the index cache layer, and at the same time, it can directly trigger high-frequency data through the key, thereby directly obtaining the corresponding index path.
[0047] Furthermore, step S3 also includes:
[0048] When the input data name is incomplete, the fuzzy search method is used first to check whether the high-frequency data containing the incomplete name exists. If it exists, the indexing step of the high-frequency data is directly triggered to obtain the index path of the high-frequency data containing the incomplete name in the index cache layer and then the query is performed using the index path. Otherwise, the normal indexing step is used to traverse the child nodes in the index tree from the root node until the data containing the incomplete name is found.
[0049] As described above, for queries of high-frequency data with known data names, the index cache layer can be used to quickly locate the specific non-leaf node in the index tree. Similarly, for queries of data with incomplete names, it is possible to determine whether the data is high-frequency. A fuzzy search method can be used to determine whether the incomplete name contains the name of a corresponding high-frequency data. If so, the index cache layer can be used to quickly locate the relevant index path. Based on the information in the path, nodes that do not need to be queried can be quickly skipped, and the non-leaf node containing the matching data can be found. Then, staff can directly make a judgment, further improving the efficiency of data query.
[0050] Furthermore, after step S3, the method further includes:
[0051] S4. When the high-frequency data is updated, the index path in the index cache layer is updated or deleted synchronously.
[0052] As described above, this corresponds to the periodic monitoring and acquisition of high-frequency data in step S1. When the high-frequency data is updated, the index path stored in the index cache layer also needs to be updated accordingly to ensure the accuracy and efficiency of the query.
[0053] This invention provides a data query optimization method and terminal, mainly applied in scenarios where data is queried using an index tree in internet systems and related products. The following is a detailed description with reference to specific embodiments:
[0054] Please refer to Figure 1 Embodiment 1 of the present invention is as follows:
[0055] A data query optimization method, such as Figure 1 As shown, the steps include:
[0056] S1. Periodically monitor and retrieve frequently queried data from the index tree, and mark it as high-frequency data.
[0057] High-frequency data refers to data that has been queried more than a preset number of times within a preset period.
[0058] S2. Create an index cache layer and store the index paths of frequently accessed data.
[0059] S3. During the indexing process, when a query for frequently accessed data is triggered, the system jumps to the index cache layer, obtains the index path corresponding to the frequently accessed data, and then performs the query using the index path.
[0060] S4. When high-frequency data is updated, the index path in the index cache layer is updated or deleted synchronously.
[0061] In this embodiment, an independent index cache layer is added to store the index paths of frequently queried high-frequency data in the index tree within a certain period. During subsequent indexing, the index path of high-frequency data can be directly obtained from the index cache layer based on whether it is high-frequency data. According to the information in the path, nodes that do not need to be queried can be quickly skipped, and the non-leaf nodes in the index tree can be located directly. Compared with the old index tree query steps that start from the root node and query level by level, the data query efficiency is effectively improved. In particular, by periodically monitoring data that has been queried more than a preset number of times, new high-frequency data is periodically updated and obtained. When high-frequency data is updated, the index path stored in the index cache layer also needs to be updated accordingly, thereby ensuring the accuracy and efficiency of the query.
[0062] Please refer to Figure 2 Embodiment two of the present invention is as follows:
[0063] A data query optimization method, based on the above embodiment one, specifically includes step S2 as follows:
[0064] Create an index cache layer to cache the index paths of frequently accessed data. Use the name of the frequently accessed data as the key and the node path of the frequently accessed data in the index tree as the value. Store the index paths of the frequently accessed data in the index cache layer in the form of (key, value) data structure.
[0065] like Figure 2 As shown in this embodiment, it is assumed that there is a table with an index on a name field, so there is an index tree for name.
[0066] The monitoring module monitors data that is queried more than 20 times within 10 seconds (preset period). For example, if the query result is data with name = alan, then alan is recorded as high-frequency data.
[0067] At this point, add an index cache with a data structure of (key, value) in the index cache layer, where key is the data name and value is the node path. Then, the data of the high-frequency data alan cache in the index cache layer is (alan, 1-2-4), and its index path is 1-2-4. 1 represents the first node of the first level in the B+ tree, 2 represents the second node of the second level, and 3 represents the fourth node of the third level.
[0068] When querying new ALAN data again, the index path 1-2-4 corresponding to the data will be retrieved directly from the index cache layer. The fourth node of the third level in the new index tree will be directly retrieved to locate the ALAN data to be queried and then obtain its specific data content.
[0069] In addition, in this embodiment, since the index cache layer is built independently of the index tree and is an additional cache space, it will occupy a certain amount of memory space. By storing the index path of high-frequency data in the form of (key, value) data structure, the space occupied by the index cache layer can be effectively reduced.
[0070] In this embodiment, step S3 also includes:
[0071] When the input data name is incomplete, the fuzzy search method is used first to check whether high-frequency data containing incomplete names exists. If it exists, the indexing step of high-frequency data is directly triggered to obtain the index path of high-frequency data containing incomplete names in the index cache layer and then query with the index path. Otherwise, the normal indexing step is used to traverse the child nodes in the index tree from the root node until the data containing incomplete names is found.
[0072] For example Figure 2As shown, when querying the name "ala", the system will first perform a fuzzy search based on "ala" to see if there is a key containing "ala" in the index cache layer. If the high-frequency data "alan" contains "ala", the system will directly perform a step-by-step search in the index tree based on the value 1-2-4 of "alan" in the index cache layer. When the system reaches the second node of the second level, it will find that "alan" has already been found. Therefore, it can directly query the subordinate nodes under that node without having to traverse the data level by level.
[0073] In this embodiment, for queries of high-frequency data with known data names, the index cache layer can be used to quickly locate the specific non-leaf node in the index tree. Similarly, for queries of data with incomplete data names, it can be determined whether the data is high-frequency. A fuzzy search method can be used to determine whether the incomplete name is contained in the name of a corresponding high-frequency data. If so, the index cache layer can be used to quickly locate the data, find the associated index path, and quickly skip nodes that do not need to be queried based on the information in the path. The non-leaf node containing the matching data can then be found and directly judged by the staff, further improving the efficiency of data query.
[0074] Please refer to Figure 3 Embodiment five of the present invention is as follows:
[0075] A data query optimization terminal 1 includes a memory 2, a processor 3, and a computer program stored on the memory 2 and executable on the processor 3. When the processor 3 executes the computer program, it completes the steps in a data query optimization method of Embodiment 1 or Embodiment 2 described above.
[0076] In summary, the data query optimization method and terminal provided by this invention adds an independent index cache layer to store the index paths of frequently queried high-frequency data in the index tree within a certain period. In subsequent indexing processes, precise queries for high-frequency data can quickly locate non-leaf nodes, and for fuzzy matching queries, the index paths in the cache layer can be associated, and nodes that do not need to be queried can be quickly skipped based on the information in the path, thereby further improving data query efficiency.
[0077] The above description is merely an embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent modifications made based on the content of the present invention specification and drawings, or direct or indirect applications in related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. A method for data query optimization, the method comprising: The method comprises the steps of: S1, periodically monitoring and obtaining high-frequency query data in an index tree, and marking the data as high-frequency data; S2, creating an index cache layer and storing an index path of the high-frequency data; S3, in an index process, when the high-frequency data is triggered to be queried, jumping to the index cache layer, obtaining the index path corresponding to the high-frequency data, and performing a query by using the index path; The step S2 is specifically: creating an index cache layer, caching the index path of the high-frequency data, taking the name of the high-frequency data as a key, taking the node path of the high-frequency data in the index tree as a value, taking a data structure in the form of (key, value) as the index path of the high-frequency data, and storing the index path into the index cache layer; The step S3 further comprises: when the input data name is incomplete, preferentially using a fuzzy query method to query whether the high-frequency data containing the incomplete name exists, if the high-frequency data containing the incomplete name exists, triggering an index step of the high-frequency data to obtain the index path of the high-frequency data containing the incomplete name in the index cache layer, and then performing a query by using the index path, otherwise, performing a query from a root node in the index tree to a child node in a level-by-level manner until data containing the incomplete name is queried; The step S3 further comprises: S4, when the high-frequency data is updated, synchronously updating or deleting the index path in the index cache layer.
2. The data query optimization method of claim 1, wherein, The high-frequency data is data that is queried more than a preset number of times within a preset period.
3. A data query optimization terminal, characterized by, The computer program product comprises a memory, a processor, and a computer program stored in the memory and capable of running on the processor, and the processor implements the following steps when executing the computer program; S1, periodically monitoring and obtaining high-frequency query data in an index tree, and marking the data as high-frequency data; S2, creating an index cache layer and storing an index path of the high-frequency data; S3, in an index process, when the high-frequency data is triggered to be queried, jumping to the index cache layer, obtaining the index path corresponding to the high-frequency data, and performing a query by using the index path; The step S2 is specifically: creating an index cache layer, caching the index path of the high-frequency data, taking the name of the high-frequency data as a key, taking the node path of the high-frequency data in the index tree as a value, taking a data structure in the form of (key, value) as the index path of the high-frequency data, and storing the index path into the index cache layer; The step S3 further comprises: when the input data name is incomplete, preferentially using a fuzzy query method to query whether the high-frequency data containing the incomplete name exists, if the high-frequency data containing the incomplete name exists, triggering an index step of the high-frequency data to obtain the index path of the high-frequency data containing the incomplete name in the index cache layer, and then performing a query by using the index path, otherwise, performing a query from a root node in the index tree to a child node in a level-by-level manner until data containing the incomplete name is queried; The step S3 further comprises: S4, when the high-frequency data is updated, synchronously updating or deleting the index path in the index cache layer.
4. The data query optimization terminal of claim 3, wherein, The high-frequency data is data queried more than a preset number of times within a preset period.
Citation Information
Patent Citations
Second level method and device and computer readable storage medium
CN110674432A
Data caching processing method, device and system
CN116974467A