An index-based dynamic combined query optimization method, device and storage medium
By creating a composite index tree in MySQL and performing dynamic combination query optimization in the field of information retrieval, the problem of the limited scope of composite index effectiveness has been solved, query speed and efficiency have been improved, data hotspot changes have been adapted, and memory resources have been saved.
Patent Information
- Application Number
- CN202310752204.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-25
- Publication Date
- 2026-01-02
- Estimated Expiration
- 2043-06-25
AI Technical Summary
In MySQL, the effectiveness of composite indexes is limited by field order restrictions, making it difficult to effectively hit the target. Furthermore, there is a conflict between the effectiveness of regular indexes and composite indexes, making it difficult for existing technologies to efficiently utilize indexes in queries involving multiple fields.
By creating a composite index tree, it is determined whether there is an intersection between the query field set and the preset field set, and then normalization is performed. Based on the strength of the normalized field set, it is determined whether the candidate data on the last node of the path is hit, and whether the strength of the normalized field set is less than the preset second strength threshold. If it is less than the threshold, the path of the composite index tree is pruned; otherwise, the state of the composite index tree is updated, or a normal index query is performed.
It enables dynamic adjustment of the effective scope of composite indexes, improving query speed and efficiency, saving memory resources, adapting to changes in data hotspots, and increasing the utilization rate of composite indexes.
Smart Images

Figure CN116775695B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of information retrieval, and in particular to an index-based dynamic combined query optimization method and device and storage medium. BACKGROUND
[0002] In an information retrieval system, multiple fields need to be indexed, and joint index lookup based on part or all of the fields is required for corresponding scenarios. In recent years, the commonly used joint index in MySQL is used.
[0003] MySQL can create a joint index for multiple fields, and the order of the fields is crucial. When using a joint index for querying, the "leftmost matching" needs to be met, that is, the fields to be queried must all appear on the left side of the field order when creating the index. For example, the field order when creating a joint index field is (A, B, C, D, E), so when the query fields are (A, B) or (B, A), the joint index can be effective, but when the query fields are (A, C) or (B, C), the joint index cannot be effective.
[0004] The defect of the joint index in MySQL is that the order of the fields when creating the joint index limits the scope of the joint index query, resulting in a large number of situations that cannot hit the joint index; multiple field combinations cannot be combined through normal index queries of multiple fields, but only through joint index queries, so there is a contradiction between the effectiveness of the joint index and the effectiveness of the normal index. SUMMARY
[0005] Therefore, the present application provides an index-based dynamic combined query optimization method, device and storage medium.
[0006] The first aspect of the present application provides an index-based dynamic combined query optimization method, comprising:
[0007] creating a joint index tree according to the fields in a preset field set;
[0008] determining whether there is an intersection between the query field set and the preset field set, if there is an intersection, extracting the fields in the intersection and normalizing them to obtain a normalized field set, and recording the strength of the normalized field set; otherwise, indexing the fields in the query field set;
[0009] determining whether the normalized field set hits the joint index tree, if yes, obtaining candidate data on the last node of the hit path, and determining whether the strength of the normalized field set is less than a preset second strength threshold, if the strength of the normalized field set is less than the preset second strength threshold, then the path of the joint index tree is trimmed according to the normalized field set to clear the candidate data; otherwise, a new query field set is obtained again for query; if no, determining whether the strength of the normalized field set is greater than or equal to a preset first strength threshold, if the strength of the normalized field set is greater than or equal to the preset first strength threshold, then the state of the joint index tree is updated according to the normalized field set; otherwise, the fields in the normalized field set are indexed normally.
[0010] Further, the fields in the preset field set are the field range on which the joint index takes effect.
[0011] Further, the normalization processing specifically includes: arranging the fields in the intersection, and reordering the fields in the intersection according to the order of the fields in the preset field set to obtain a normalized field set.
[0012] Further, the strength of the normalized field set is initially 0, and the strength of the normalized field set is increased by 1 on the basis of the original strength each time the normalized field set is queried.
[0013] Further, the determination of whether the normalized field set hits the joint index tree specifically includes: generating a plurality of ordered lists according to a plurality of paths of the joint index tree, determining whether there is an ordered list consistent with the fields and their order in the normalized field set in the plurality of ordered lists, if yes, obtaining the path corresponding to the ordered list, and determining whether there is candidate data on the last node of the path, if yes, the normalized field set hits the joint index tree; if no ordered list or candidate data exists, the normalized field set does not hit the joint index tree.
[0014] Further, the plurality of paths of the joint index tree correspond to the plurality of ordered lists one by one.
[0015] Further, the trimming of the path of the joint index tree according to the normalized field set specifically includes: finding the path corresponding to the normalized field set from the root node of the joint index tree according to the normalized field set, and clearing the candidate data on the last node of the path to complete the trimming of the path of the joint index tree.
[0016] Further, the updating the state of the joint index tree according to the normalized field set specifically comprises: judging whether a prefix part field of the normalized field set exists in the joint index tree, if the prefix part field exists, reusing a node corresponding to the prefix part field of the normalized field set, and adding nodes corresponding to subsequent part fields of the normalized field set in sequence on a last node of a path where the node corresponding to the prefix part field is located; if the prefix part field does not exist, adding a first path in the joint index tree, wherein the order of nodes on the first path is consistent with the order of fields in the normalized field set.
[0017] The second aspect of the present application provides an index-based dynamic combined query optimization device, comprising one or more processors for implementing the index-based dynamic combined query optimization method described above.
[0018] The third aspect of the present application provides a computer-readable storage medium having a program stored thereon, which, when executed by a processor, is used to implement the index-based dynamic combined query optimization method described above.
[0019] The index-based dynamic combined query optimization method, device and storage medium provided by the present application determine the effective range of joint index through a preset field set, and create a joint index tree accordingly, and maintain the joint index using a tree structure. The joint index hit determination process in the present application is irrelevant to the order of fields when the joint index is created, so that the order of fields created during combined query does not affect the effectiveness of the joint index. In the present application, as long as there is an intersection between the field set to be queried and the preset field set of the joint index, the joint index query can be effective, which helps to speed up the query process. The joint index in the present application is dynamically updated based on query frequency, so that even if the data hotspot changes, the query efficiency can be guaranteed, and cold data can be cleared, which is beneficial to save memory resources. Through the present application, the utilization rate of joint index can be improved, which is beneficial to speed up the query process and improve the query speed. BRIEF DESCRIPTION OF DRAWINGS
[0020] Figure 1 A flowchart of the index-based dynamic combined query optimization method provided by the present application is provided.
[0021] Figure 2 A structure diagram of the joint index tree provided by the present application is provided.
[0022] Figure 3 A determination diagram of the joint index tree hit provided by the present application is provided.
[0023] Figure 4 A structure diagram of the index-based dynamic combined query optimization device provided by the present application is provided. DETAILED DESCRIPTION
[0024] The exemplary embodiments will be described in detail herein with reference to the attached drawings. In the following description, like reference numerals refer to like elements unless the context clearly dictates otherwise. The following description of exemplary embodiments is not intended to represent all embodiments in accordance with the present application. On the contrary, the following description is intended only to illustrate some of the many aspects of devices and methods consistent with the present application as detailed in the appended claims.
[0025] The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the present application. As used herein, the singular forms "a", "an" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be further understood that the terms "comprises" and / or "comprising," when used in this specification, specify the presence of stated features, integers, steps, operations, elements, and / or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.
[0026] It is to be understood that the singular forms "a", "an", and "the" include plural referents unless the context clearly dictates otherwise. It will be further understood that the terms "comprises" and / or "comprising," when used in this specification, specify the presence of stated features, integers, steps, operations, elements, and / or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.
[0027] The present application provides an index-based dynamic combined query optimization method, device and storage medium. The field order created during the combined query does not affect the effectiveness of the joint index, which helps to speed up the query process, improve the query speed, clear the cold data and save the memory resources.
[0028] Referring to Figure 1 The index-based dynamic combined query optimization method provided by the present application specifically includes the following steps:
[0029] (1) Creating a joint index tree according to the fields in the preset field set.
[0030] In this embodiment, the field range for which the joint index is effective needs to be determined, that is, the joint index can be effective on the basis of certain fields. The fields in the preset field set are the field range for which the joint index is effective. Therefore, the joint index tree is created according to the fields in the preset field set. In this way, the joint index tree obtained can be used for query, and the query or change of other fields will not affect the state of the joint index tree.
[0031] It should be noted that the joint index tree is a tree structure, which is empty in the initial state. However, the state of the joint index tree created according to the preset field set is not empty.
[0032] It should be understood that by creating a joint index tree, the joint index is maintained using a tree structure, which helps to quickly find the required fields.
[0033] Further, the preset field set can be determined according to actual needs and experience.
[0034] Exemplarily, there are multiple fields, respectively A, B, C, D, E, F, G, H, each of which also has corresponding data, and an industry can determine the frequently queried fields A, B, C, D, E, F as the field range of the joint index according to its actual needs and experience, that is, to construct the preset field set described in the present application, the preset field set = (A = 2, B = 5, C = 23, D = 55, E = 300, F = 100).
[0035] (2) Determine whether there is an intersection between the query field set and the preset field set. If there is an intersection, extract the fields in the intersection and perform normalization processing on them to obtain a normalized field set, and record the strength of the normalized field set; otherwise, perform ordinary indexing on the fields in the query field set.
[0036] In the present embodiment, when querying fields, it is necessary to first determine whether all fields in the query field set and the preset field set of the joint index tree have an intersection. If there is no intersection, it means that there is no field to be queried in the preset field set of the joint index tree, and then ordinary index query needs to be performed on all fields in the query field set, and the intersection of the respective query results can be obtained. However, this is not the optimization method described in the present application, and therefore will not be described here. If there is an intersection, all fields in the intersection need to be extracted, and then normalization processing is performed on these fields to obtain a normalized field set, and the strength of the normalized field set is recorded, as shown in Figure 2 .
[0037] Further, the normalization processing specifically includes: sorting the fields in the intersection, and reordering the fields in the intersection according to the order of the fields in the preset field set to obtain a normalized field set.
[0038] It should be understood that by performing normalization processing on the fields in the intersection, the order of the fields in the query field set created when querying the fields does not affect the effectiveness of the joint index, that is, the order of the fields when creating the joint index does not affect the effectiveness of the joint index. When querying, as long as the queried fields are a subset of the preset field set corresponding to the joint index, the joint index query can be effective. Similarly, when querying, if the queried fields have an intersection with the preset field set corresponding to the joint index, part of the intersection will also be effective for the joint index query, which helps to speed up the query process and improve the query speed.
[0039] For example, if the preset field set is (A=2, B=5, C=23, D=55, E=300, F=100), the query field set is (A=2, F=100, B=5, G=20), all the fields in the query field set intersect with the preset field set, the intersection is (A=2, F=100, B=5), and the intersection is normalized, the fields are sorted, and the intersection is reordered according to the order of the fields in the preset field set, that is, the order of A, B, C, D, E, and F. Thus, the normalized field set (A=2, B=5, F=100) is obtained.
[0040] In this embodiment, the strength of the normalized field set is initially 0, and the strength of the normalized field set is increased by 1 based on the original strength when the normalized field set is searched once. It should be noted that the strength of the normalized field set can determine the number of queries of the field combination in the current time period, and the greater the strength, the more the number of queries of the field combination of the normalized field set, indicating that the field combination of the normalized field set is the current hot spot; the smaller the strength, the fewer the number of queries of the field combination of the normalized field set, indicating that the field combination of the normalized field set is the current cold spot.
[0041] It should be understood that the strength will decay over time, and when the corresponding normalized field set is queried again, the strength will be increased again.
[0042] For example, the strengths of the normalized field sets (A=2, B=5, F=100) and (A=2, B=5) are initially 0, the normalized field set (A=2, B=5, F=100) is currently queried, and thus the strength of the normalized field set (A=2, B=5, F=100) is increased by 1 and becomes 1; when the normalized field set (A=2, B=5) is queried, the strength will also become 1. The strength will decay over time, for example, when the strength of the normalized field set (A=2, B=5, F=100) gradually decays to 0.5, the normalized field set (A=2, B=5, F=100) is queried again, and the strength will be increased by 1 from 0.5 to 1.5; if the strength of the normalized field set (A=2, B=5) decays over time, and the normalized field set (A=2, B=5) has not been queried again since the beginning, the strength of the normalized field set (A=2, B=5) will decay to 0 over time.
[0043] (3) judging whether the normalized field set hits the joint index tree, if yes, obtaining the candidate data on the last node of the hit path, and judging whether the strength of the normalized field set is less than a preset second strength threshold, if the strength of the normalized field set is less than the preset second strength threshold, then pruning the path of the joint index tree according to the normalized field set to clear the candidate data; otherwise, obtaining new query field set again for query; if no, judging whether the strength of the normalized field set is greater than or equal to a preset first strength threshold, if the strength of the normalized field set is greater than or equal to the preset first strength threshold, then updating the state of the joint index tree according to the normalized field set; otherwise, making normal index on the fields in the normalized field set.
[0044] In the embodiment, whether the normalized field set hits the joint index tree specifically includes: generating a plurality of ordered lists according to the plurality of paths of the joint index tree, judging whether there is an ordered list consistent with the fields and the order in the normalized field set in the plurality of ordered lists, if there is an ordered list, obtaining the path corresponding to the ordered list, and judging whether there is candidate data on the last node of the path, if there is candidate data, the normalized field set hits the joint index tree; if there is no ordered list or candidate data, the normalized field set does not hit the joint index tree.
[0045] The plurality of paths of the joint index tree correspond to the plurality of ordered lists one by one.
[0046] Specifically, the joint index tree includes a plurality of nodes, and there are also a plurality of paths starting from the root node. According to the plurality of paths of the joint index tree, a plurality of corresponding ordered lists can be generated according to the order. The ordered list includes a plurality of fields and the plurality of fields are arranged in order. If there is an ordered list consistent with the fields and the order in the normalized field set in the plurality of ordered lists, and there is candidate data on the last node of the path corresponding to the ordered list, it indicates that the normalized field set hits the joint index tree. If there is an ordered list consistent with the fields and the order in the normalized field set in the plurality of ordered lists, but there is no candidate data on the last node of the path corresponding to the ordered list, it indicates that the normalized field set does not hit the joint index tree. If there is no ordered list consistent with the fields and the order in the normalized field set in the plurality of ordered lists, it indicates that the normalized field set does not hit the joint index tree, as shown in Figure 3
[0047] Exemplarily, the joint index tree includes multiple nodes, and a path formed from the root node also has multiple paths. According to the multiple paths of the joint index tree, a plurality of ordered lists are generated according to the order of the paths, for example, the multiple ordered lists are (A=2, B=5, C=23, D=55, E=300, F=100), (A=2, C=23, D=55, F=100), and (A=2, B=5, C=23, D=55). The multiple fields are included in the ordered lists and are arranged in order.
[0048] For example, the normalized field set obtained in the foregoing step (2) is (A=2, B=5, F=100). By judging the fields and the order of the fields in the ordered list and the fields and the order of the fields in the normalized field set, it can be found that the fields and the order of the fields in the first ordered list (A=2, B=5, C=23, D=55, E=300, F=100) are consistent with the fields and the order of the fields in the normalized field set (A=2, B=5, F=100), which indicates that there is an ordered list in which the fields and the order of the fields are consistent with the fields and the order of the fields in the normalized field set, and the last node of the path corresponding to the ordered list is F=100, and the node has candidate data, which indicates that the normalized field set hits the joint index tree.
[0049] If the first ordered list is (A=2, B=5, C=23, D=55, E=300, F), it can be found that the last node of the path corresponding to the ordered list does not have candidate data, which indicates that the normalized field set does not hit the joint index tree. It should be understood that, at this time, it can be considered that there is a partial hit, and the joint index query of (A=2, B=5) is performed to obtain a query result, and then the ordinary index of F=100 is performed, and then the intersection of the query result of the joint index query and the query result of the ordinary index query can be obtained, which requires 2 times of query and 1 time of intersection.
[0050] If there is no first ordered list, there is no ordered list in which the fields and the order of the fields are consistent with the fields and the order of the fields in the normalized field set, which also indicates that the normalized field set hits the joint index tree. It should be understood that, at this time, the ordinary index query of A=2, B=5, and F=100 can be performed respectively, and then the intersection of the three query results can be obtained, which requires 3 times of query and 2 times of intersection.
[0051] In summary, if the query hits the joint index and the ordinary index at the same time, the fields in the joint index all take effect in the joint index, and the remaining fields take effect in the ordinary index. The query by combining the joint index and the ordinary index can accelerate the search process and is beneficial to improving the query speed.
[0052] In the embodiment, when the normalized field set hits the joint index tree, the candidate data on the last node of the hit path is first acquired, and the candidate data is the result of the final query; then it is judged whether the strength of the normalized field set is less than the preset second strength threshold, if the strength of the normalized field set is less than the preset second strength threshold, the pruning of the joint index tree is triggered, and the path of the joint index tree can be pruned according to the normalized field set; otherwise, no processing is performed, that is, a new query field set is acquired again for query. It should be understood that with the increase of the number of queries, the path of the joint index tree will present an exponential explosion, and therefore the path of the joint index tree needs to be pruned, which helps to save memory.
[0053] Further, the pruning of the path of the joint index tree according to the normalized field set specifically includes: the normalized field set is used to find the path corresponding to the normalized field set from the root node of the joint index tree, and the candidate data on the last node of the path is cleared, so as to complete the pruning of the path of the joint index tree.
[0054] It should be noted that the joint index is dynamically updated based on query popularity, so that the query efficiency can be ensured even if the data hotspot changes. In addition, the strength of the normalized field set will decay over time, and when the strength is less than the preset second strength threshold, it indicates that the corresponding normalized field set is not a hotspot. Generally, the data stored on the last node of the path occupies a large memory, and therefore the path corresponding to the normalized field set is found from the root node of the joint index tree, and the candidate data on the last node of the path is cleared, so as to complete the pruning of the path of the joint index tree. In this way, the cold data can be cleared, and the memory resources can be effectively saved.
[0055] In the embodiment, when the normalized field set does not hit the joint index tree, it is necessary to judge whether the strength of the normalized field set is greater than or equal to the preset first strength threshold, if the strength of the normalized field set is greater than or equal to the preset first strength threshold, the state of the joint index tree is changed, and the state of the joint index tree needs to be updated according to the normalized field set; otherwise, the fields in the normalized field set are indexed normally.
[0056] Further, the updating of the state of the joint index tree according to the normalized field set specifically includes: it is judged whether there is a prefix part field of the normalized field set in the joint index tree, if there is, the node corresponding to the prefix part field of the normalized field set is reused, and the node corresponding to the subsequent part field of the normalized field set is sequentially added on the last node of the path where the node corresponding to the prefix part field of the normalized field set is located; if not, a first path is newly added in the joint index tree, and the order of the nodes on the first path is consistent with the order of the fields in the normalized field set.
[0057] Exemplarily, if the normalized field set is (A=2, B=5, C=23, F=100), the paths of the joint index tree are (A=2, C=23, D=55, F=100) and (A=2, B=5, C=23, D=55), it can be determined that the prefix part fields of the normalized field set are included in the paths of the joint index tree, that is, the second path includes the prefix part fields (A=2, B=5, C=23), therefore, the node corresponding to the prefix part fields of the normalized field set is reused, and the node corresponding to the subsequent part fields of the normalized field set is sequentially added to the last node on the path of the prefix part field, that is, a node corresponding to F is added to the last node C of the second path, that is, the sub-node F=100 is added, and thus the updating of the state of the joint index tree is completed.
[0058] If the normalized field set is (A=2, B=5, C=23, F=100), the paths of the joint index tree are (C=23, D=55) and (B=5, E=300, F=100), it can be determined that the prefix part fields of the normalized field set are not included in the paths of the joint index tree, and a first path is added to the joint index tree, wherein the order of the nodes on the first path is consistent with the order of the fields in the normalized field set, that is, a first path is added to the root node of the joint index tree, and the order of the nodes on the path is consistent with the order of the fields in the normalized field set (A=2, B=5, C=23, F=100), that is, the first path added is (root node -> A=2 -> B=5 -> C=23 -> F=100).
[0059] Further, when the normalized field set does not hit the joint index tree and the strength of the normalized field set is less than the first strength threshold, the fields in the normalized field set are normally indexed, and then the intersection is taken.
[0060] In the embodiment, the greater the first strength threshold is, the fewer the number of joint index queries that can be effectively queried is, and the smaller the range of the role is; the smaller the first strength threshold is, the greater the range of the role of the joint index is, and accordingly, the greater the space memory occupied is. The greater the second strength threshold is, the easier the data cleaning is, and accordingly, the more difficult the joint index tree is hit. Therefore, the first strength threshold and the second strength threshold can be determined according to actual needs and relevant experience.
[0061] The application determines the effective range of the joint index through a preset field set, and creates a joint index tree according to the preset field set, and uses a tree structure to maintain the joint index. The joint index hit determination process in the application is irrelevant to the order of the fields when the joint index is created, so that the order of the fields created when the combined query is performed does not affect the effectiveness of the joint index. In the application, as long as the field set queried exists an intersection with the preset field set of the joint index, the joint index query can be effective, which helps to speed up the query process. The joint index in the application is dynamically updated based on query heat, so that even if the data hotspot changes, the query efficiency can be guaranteed, and the cold data can be cleared, which is beneficial to save memory resources. Through the application, the utilization rate of the joint index can be improved, which is beneficial to speed up the query process and improve the query speed.
[0062] Corresponding to the foregoing embodiments of the index-based dynamic combined query optimization method, the application further provides embodiments of an index-based dynamic combined query optimization device.
[0063] Referring to Figure 4 , the index-based dynamic combined query optimization device provided by the embodiments of the application comprises one or more processors, which are used to implement the index-based dynamic combined query optimization method in the foregoing embodiments.
[0064] The embodiments of the index-based dynamic combined query optimization device of the application can be applied to any device with data processing capability, which can be a device or apparatus such as a computer. The device embodiments can be implemented by software, or by hardware or a combination of software and hardware. Taking the software implementation as an example, as a device in a logical sense, it is formed by reading the corresponding computer program instructions in the non-volatile memory into the memory and running by the processor of the device with data processing capability. From the hardware level, as shown in Figure 4 , it is a hardware structure diagram of the device with data processing capability of the index-based dynamic combined query optimization device of the application. In addition to the processor, the memory, the network interface, and the non-volatile memory shown in Figure 4 , the device with data processing capability in the embodiments usually includes other hardware according to the actual functions of the device with data processing capability, and details are not described herein.
[0065] The implementation process of the functions and roles of each unit in the foregoing device is specifically described in the implementation process of the corresponding steps in the foregoing method, and details are not described herein.
[0066] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts are described in the part of the method embodiments. The device embodiments described above are only illustrative, wherein the units described as separate components can or can not be physically separated, and the components displayed as units can or can not be physical units, i.e., can be located in one place or distributed on multiple network units. Some or all of the modules can be selected to achieve the purpose of the present application according to actual needs. Those skilled in the art can understand and implement it without creative labor.
[0067] The embodiment of the present application further provides a computer readable storage medium, which stores a program, and the program is executed by a processor to realize the index-based dynamic combination query optimization method in the above embodiment.
[0068] The computer readable storage medium can be an internal storage unit of any data processing capable device, such as a hard disk or a memory. The computer readable storage medium can also be any data processing capable device, such as a plug-in hard disk, a smart media card (SMC), an SD card, a flash card, etc. Further, the computer readable storage medium can also include an internal storage unit of any data processing capable device and an external storage device. The computer readable storage medium is used to store the computer program and other programs and data required by the data processing capable device, and can also be used to temporarily store data that has been output or will be output.
[0069] The above embodiments are only used to illustrate the technical solutions of the present application, rather than limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that the technical solutions recorded in the foregoing embodiments can be modified, or some technical features can be replaced by equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. An index-based dynamic combined query optimization method, characterized in that, The method comprises the following steps: creating a joint index tree according to fields in a preset field set; judging whether there is an intersection between a query field set and the preset field set, if there is an intersection, extracting fields in the intersection and performing normalization processing on the fields to obtain a normalized field set, and recording the strength of the normalized field set; otherwise, performing normal indexing on fields in the query field set; judging whether the normalized field set hits the joint index tree, if it hits, obtaining candidate data on the last node of the hit path, and judging whether the strength of the normalized field set is less than a preset second strength threshold, if the strength of the normalized field set is less than the preset second strength threshold, trimming the path of the joint index tree according to the normalized field set to remove the candidate data; otherwise, obtaining a new query field set for querying again; if it does not hit, judging whether the strength of the normalized field set is greater than or equal to a preset first strength threshold, if the strength of the normalized field set is greater than or equal to the preset first strength threshold, updating the state of the joint index tree according to the normalized field set; otherwise, performing normal indexing on fields in the normalized field set.
2. The index-based dynamic combined query optimization method according to claim 1, wherein, The fields in the preset field set are the field range of the joint index in effect.
3. The index-based dynamic combined query optimization method of claim 1, wherein, The normalization processing specifically comprises: arranging the fields in the intersection, and reordering the fields in the intersection according to the order of the fields in the preset field set to obtain the normalized field set.
4. The index-based dynamic combined query optimization method of claim 1, wherein, The strength of the normalized field set is initially 0, and the strength of the normalized field set is increased by 1 based on the original strength each time the normalized field set is queried.
5. The index-based dynamic combined query optimization method of claim 1, wherein, The judgment of whether the normalized field set hits the joint index tree specifically comprises: generating a plurality of ordered lists according to a plurality of paths of the joint index tree, judging whether there is an ordered list consistent with the fields and their order in the normalized field set in the plurality of ordered lists, if there is an ordered list, obtaining the path corresponding to the ordered list, and judging whether there is candidate data on the last node of the path, if there is candidate data, the normalized field set hits the joint index tree; if there is no ordered list or candidate data, the normalized field set does not hit the joint index tree.
6. The index-based dynamic combined query optimization method of claim 5, wherein, The plurality of paths of the joint index tree correspond to the plurality of ordered lists one by one.
7. The index-based dynamic combined query optimization method of claim 1, wherein, The trimming of the path of the joint index tree according to the normalized field set specifically comprises: finding the path corresponding to the normalized field set from the root node of the joint index tree according to the normalized field set, and removing the candidate data on the last node of the path to complete the trimming of the path of the joint index tree.
8. The index-based dynamic combined query optimization method of claim 1, wherein, The updating the state of the joint index tree according to the normalized field set specifically comprises: judging whether a prefix part field of the normalized field set exists in the joint index tree, if the prefix part field exists, reusing a node corresponding to the prefix part field of the normalized field set, and adding nodes corresponding to subsequent part fields of the normalized field set in sequence on a last node of a path where the node corresponding to the prefix part field of the normalized field set is located, if the prefix part field does not exist, adding a first path in the joint index tree, and an order of nodes on the first path is consistent with an order of fields in the normalized field set.
9. An index-based dynamic query optimization apparatus, comprising: The one or more processors are configured to implement the index-based dynamic combined query optimization method of any one of claims 1-8.
10. A computer-readable storage medium, characterized in that, The program is stored on the computer readable medium and, when executed by the processor, is configured to implement the index-based dynamic combined query optimization method of any one of claims 1-8.
Citation Information
Patent Citations
Multi-source department creation resource data fusion method
CN111708773A
Database joint index establishment method and device, equipment and storage medium
CN114817243A