Index generation method and apparatus, computer device, and computer-readable storage medium

By analyzing the query model of data query requests, candidate indexes are generated and the target index is determined based on the matching degree. This solves the problem of excessively long database response time and realizes intelligent index optimization and improved response speed.

CN115705320BActive Publication Date: 2026-02-06TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110915018.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-08-10
Publication Date
2026-02-06
Estimated Expiration
2041-08-10

AI Technical Summary

Technical Problem

In existing technologies, the problem of excessively long database response times, especially when dealing with large amounts of data and a lack of suitable indexes, leads to slow query issues.

Method used

By analyzing the query model of the data query request, a first candidate index and a second candidate index are generated, and the target index is determined based on their matching degree with the target query model, thereby realizing intelligent index generation and optimizing the index structure of the database.

Benefits of technology

It improved the database response speed, reduced the occurrence of slow queries, and increased the efficiency of data retrieval.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115705320B_ABST
    Figure CN115705320B_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose an index generation method and device, computer equipment and a computer readable storage medium, which can obtain analysis data, the analysis data being obtained by analyzing a query model corresponding to a data query request, the analysis data including at least one query model, the query model including a target query model, the query model including query conditions, each query condition including query attribute information; generating a first candidate index according to the frequency of each query attribute information corresponding to a first query condition of the target query model; generating a second candidate index according to the frequency of target query attribute information corresponding to a second query condition of the target query model; and determining a target index from the first candidate index and the second candidate index according to the matching degree of the first candidate index with the target query model and the matching degree of the second candidate index, which can intelligently generate an index, automatically optimize the index of a database, and improve the response speed of the database.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of communication, in particular to an index generation method and device, computer equipment and computer readable storage medium. BACKGROUND

[0002] An index is a structure for sorting data in one or more columns of a data table of a database. Using an index can quickly access specific data in a database table. When a database responds to a data query request, it may take a long time to find the data required by the data query request due to a large amount of data in the database and the lack of appropriate indexes, and the response time is too long. If the response time exceeds a certain time (such as more than 100 ms), it can be considered that a slow query has occurred. The reasons for the slow query are usually manually analyzed according to the slow query log provided by the database, and appropriate indexes are manually created according to the reasons for the slow query to improve the response speed of the database. SUMMARY

[0003] The embodiments of the present application provide an index generation method, device, computer equipment and storage medium, which can generate a first candidate index and a second candidate index based on analysis data, and determine a target index according to the matching degrees of the first candidate index and the second candidate index. The embodiments of the present application can realize intelligent generation of indexes, automatically optimize the indexes of a database, and improve the response speed of the database.

[0004] The embodiments of the present application provide an index generation method, which comprises:

[0005] Obtain analysis data, wherein the analysis data is obtained by analyzing a query model corresponding to a received data query request, the analysis data comprises at least one query model, the query model comprises a target query model, the query model comprises at least one query condition, and each query condition comprises at least one query attribute information;

[0006] Generate a first candidate index of a database corresponding to the data query request according to the frequency of each query attribute information corresponding to a first query condition of the target query model in the analysis data;

[0007] Generate a second candidate index of the database according to the frequency of target query attribute information corresponding to a second query condition of the target query model in the analysis data;

[0008] Determine a target index of the database from the first candidate index and the second candidate index according to the matching degrees of the first candidate index and the target query model and the matching degrees of the second candidate index and the target query model.

[0009] Correspondingly, the embodiment of the present application further provides an index generation device, comprising:

[0010] a data acquisition unit configured to acquire analysis data, wherein the analysis data is obtained by analyzing a corresponding query model for a received data query request, the analysis data comprises at least one query model, the query model comprises a target query model, the query model comprises at least one query condition, and each query condition comprises at least one query attribute information;

[0011] a first index generation unit configured to generate a first candidate index of a database corresponding to the data query request according to a frequency of each query attribute information corresponding to a first query condition of the target query model in the analysis data;

[0012] a second index generation unit configured to generate a second candidate index of the database according to a frequency of target query attribute information corresponding to a second query condition of the target query model in the analysis data;

[0013] a target index determination unit configured to determine a target index of the database from the first candidate index and the second candidate index according to a matching degree of the first candidate index and the target query model and a matching degree of the second candidate index and the target query model.

[0014] Correspondingly, the embodiment of the present application further provides a computer device comprising a memory and a processor; the memory stores a computer program, and the processor is configured to run the computer program in the memory to execute any index generation method provided by the embodiment of the present application.

[0015] Correspondingly, the embodiment of the present application further provides a computer readable storage medium for storing a computer program, wherein the computer program is loaded by a processor to execute any index generation method provided by the embodiment of the present application.

[0016] The embodiment of the application can obtain analysis data, the analysis data is obtained by analyzing a corresponding query model for a received data query request, the analysis data includes at least one query model, the query model includes a target query model, the query model includes at least one query condition, each query condition includes at least one query attribute information; a first candidate index of a database corresponding to the data query request is generated according to the frequency of each query attribute information corresponding to a first query condition of the target query model in the analysis data; a second candidate index of the database is generated according to the frequency of target query attribute information corresponding to a second query condition of the target query model in the analysis data; and the target index of the database is determined from the first candidate index and the second candidate index according to the matching degree of the first candidate index and the target query model and the matching degree of the second candidate index and the target query model. The scheme can generate the first candidate index and the second candidate index based on the analysis data, and determine the target index according to the matching degree of the first candidate index and the second candidate index, so that intelligent index generation and automatic optimization of the index of the database can be realized, and the response speed of the database can be improved. BRIEF DESCRIPTION OF DRAWINGS

[0017] In order to more clearly illustrate the technical solutions in the embodiments of the application, the following will briefly introduce the drawings needed to be used in the embodiment description. Obviously, the drawings in the following description are only some embodiments of the application, and other drawings can also be obtained by those skilled in the art without creative effort on the basis of these drawings.

[0018] Figure 1 is a scene diagram of the index generation method provided by the embodiment of the application;

[0019] Figure 2 is a flowchart of the index generation method provided by the embodiment of the application;

[0020] Figure 3 is another flowchart of the index generation method provided by the embodiment of the application;

[0021] Figure 4 is a schematic diagram of the index generation device provided by the embodiment of the application;

[0022] Figure 5 is a structural schematic diagram of the terminal provided by the embodiment of the application. DETAILED DESCRIPTION

[0023] With reference to the drawings and the embodiments of the present application, the technical solutions in the embodiments of the present application will be described clearly and completely. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the scope of the present application.

[0024] The index generation method and device, the computer device and the computer readable storage medium are provided in the embodiments of the present application. The index generation device can be integrated in a computer device, which can be a server or a terminal or the like.

[0025] The terminal can include a mobile phone, a wearable smart device, a tablet computer, a notebook computer, a personal computer (PC), and a vehicle-mounted computer.

[0026] The server can be a standalone physical server, a server cluster or a distributed system composed of multiple physical servers, a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDNs, and basic cloud computing services such as big data and artificial intelligence platforms.

[0027] The terminal can include a mobile phone, a wearable smart device, a tablet computer, a notebook computer, and a personal computer (PC).

[0028] For example, as shown in Figure 1 The index generation method can be implemented through an index generation system, which can include a query model analysis process and an index generation process. The query model analysis process can receive a data query request sent by a data consumer through an open platform, such as a data query request triggered through a corresponding application, a client application, or a mini program. The data open platform analyzes the received data query request, determines the query model corresponding to each data analysis request, sends a query statement corresponding to the data query request to a business database to query data from the business database, records the response time of the database, and sends the query result returned by the business database to the consumer. The analysis data corresponding to the query model of the data query request and the response time of the business database are recorded in the platform cache of the data open platform. The analysis data in the platform cache will be landed to the platform database regularly, i.e., the analysis data is persisted and saved in the platform database.

[0029] The index generation process can periodically pull analysis data, filter the analysis data, filter the target query model from the analysis data, construct two different candidate indexes based on the target query model, starting from two different query conditions: a first candidate index and a second candidate index, determine the target index according to the matching degree of the first candidate index and the matching degree of the second candidate index, and create the target index to the business database to provide services for data query requests. The scheme can generate a first candidate index and a second candidate index based on the analysis data, determine the target index according to the matching degree of the first candidate index and the second candidate index, can realize intelligent generation of index, automatically optimize the index of the database, and improve the response speed of the database.

[0030] The following will be described in detail. It should be noted that the order of the following embodiments is not limited as the preferred order of the embodiments.

[0031] This embodiment will be described from the perspective of an image processing device, which can be integrated in a computer device, which can be a server, a terminal, or other devices. As shown in the figure, the specific process of the index generation method can be as follows: Figure 2

[0032] 101, obtain analysis data, the analysis data is obtained by analyzing the received data query request, the analysis data includes at least one query model, the query model includes a target query model, the query model includes at least one query condition, and each query condition includes at least one query attribute information.

[0033] Among them, the analysis data can be obtained by analyzing the received data query request to determine the query model corresponding to the data query request.

[0034] Among them, the query attribute information can be the information corresponding to the attribute data in the database, for example, the query attribute information is gender, and the corresponding gender data in the database. The query attribute information can be a query field, and the query field can correspond to a column data in the database, for example, the query field is gender, and the data in the column corresponding to the gender field in the database.

[0035] Among them, the query condition can be a constraint factor for obtaining data from the database, and the query condition can include a sorting condition and a filtering condition. The query condition can include at least one query attribute information.

[0036] The sorting condition indicates that the data in the database is sorted, for example, the users in the user data table are sorted by age from high to low.

[0037] ​The filtering condition represents filtering data in the database to filter out the required data. The filtering condition can include an equality condition (representing querying data equal to a condition value of query attribute information from the database, for example, querying users with a gender of male from a user data table in the database, where the query attribute information is gender and the condition value is male), a comparison condition (representing querying data greater than / less than a condition value of query attribute information from the database, for example, querying users with a total score > 90 from a user data table, where the query attribute information is the total score and the condition value is 90), an inclusion condition (representing querying part of data consistent with the query attribute information from a certain set in the database, for example, querying Chinese scores from a subject in the user data table), and a geographic location condition (the geographic location condition carries query attribute information of a geographic location, representing querying data with a geographic location satisfying a condition value of the query attribute information from the database, for example, querying users living within 1 km of School 1 from a user data table).

[0038] The condition value can be a standard for filtering data of the filtering condition.

[0039] The query model can be a model representing a specific query pattern of a data query request obtained by analyzing the data query request and extracting features of the data query request, such as query conditions (for example, query attribute information). For example, there is a user data table in the database, a first data query request queries the user data table for users with an age greater than 15, and a second data query request queries the user data table for users with an age greater than 20. The query conditions of the first data query request and the second data query request are both filtering conditions and the query attribute information included in the query conditions is the same. Although the condition values are different, the same field in the data table is queried with the same query condition, which can be considered to belong to the same query pattern. The first data query request and the second data query request belong to the same query model.

[0040] For example, the analysis data can be obtained from a model database. The model database can be the same database as the database queried by the data query request, or can be a different database, which is not limited herein. The analysis data can also be in a blockchain, and the computer device obtains corresponding analysis data from the blockchain.

[0041] The analysis data can be obtained by analyzing the received data query request. In an embodiment, before the step of obtaining the analysis data, the index generation method can further include:

[0042] receiving a data query request for the database;

[0043] The data query request is analyzed and processed based on the query condition carried by the data query request and the query field included in the query condition, to determine a query model corresponding to the data query request, and update the hit number of the model, which represents the number of data query requests corresponding to the query model.

[0044] The analysis data is generated according to the query model and the hit number of the query model.

[0045] The database can be a warehouse for organizing, storing and managing data according to data structure, which can be a long-term storage in a computer, organized, shareable and unified management of a large amount of data collection.

[0046] The hit number can represent the number of times a query model is hit by a data query request. For example, if data query request A is determined to correspond to query model S through analysis, the hit number of query model S is incremented by 1. The initial value of the hit number of the query model is zero. The query condition in the query model S is the query condition included in the data query request A. The query attribute information corresponding to the query condition in the query model S is the attribute information of the query condition in the data query request A.

[0047] For example, the received data query request can be analyzed to determine the database table and query attribute information to be queried by the data query request through the query statement included in the data query request, and the query condition included in the data query request can be determined according to the operator in the query statement. For example, if the data query request carries a statement indicating that data is selected from the database table with conditions, such as a where clause, the data query request includes a filtering condition. The specific filtering condition can be determined according to the operator in the statement, for example, the filtering condition is an equality condition if the carried operator is equal (=), or a comparison condition if the carried operator is less than or greater than. If the data query request carries a statement indicating that data is sorted according to a specified data, such as an order by clause, the data query request includes a sorting condition.

[0048] The query model corresponding to the query request is determined according to the query condition included in the query request and the query attribute information of the query condition. If the query condition in the query request a and the query attribute information corresponding to the query condition one-to-one correspond to the query model a, the query model corresponding to the query request is the query model a.

[0049] If the query conditions and the query attribute information corresponding to the query conditions included in the data query request a and the data query request b correspond one-to-one, the query models corresponding to the data query request a and the data query request b are the same, regardless of whether the order of different query conditions in the data query request is the same.

[0050] Optionally, if the sorting conditions contain multiple query attribute information, the multiple query attribute information has a query order, when two sorting conditions contain the same query attribute information and the order is consistent, the two sorting conditions are considered to be the same or corresponding.

[0051] According to the analysis of each data query request corresponding to the query model and the hit number of the query model, the analysis data can be generated, the analysis data includes at least one query model, each query model includes at least one query condition, and each query condition includes at least one query attribute information.

[0052] Each query model in the analysis data can also include the response time of the corresponding data query request, which can be the time required by the computer device from receiving the data query request to receiving the data returned by the database based on the data query request. In an embodiment, a target query model can be selected from the query model according to the response time, the hit number of the query model, and the matching degree of the query model and the current index of the database, that is, after the step of "obtaining analysis data", the index generation method further includes:

[0053] Obtain a to-be-processed query model in the analysis data with a hit number greater than a hit threshold;

[0054] For each to-be-processed query model, calculate the average response time of the to-be-processed query model according to the response time of each query request corresponding to the to-be-processed query model;

[0055] For each to-be-processed query model, match the current index of the database with the to-be-processed query model to obtain a model matching degree of the to-be-processed query model;

[0056] According to the average response time and the model matching degree, determine a target query model from the to-be-processed query model.

[0057] The model matching degree can be a value representing the matching degree of the current index of the database and the to-be-processed query model, and the lower the matching degree, the more difficult it is to quickly query data in the database according to the current index corresponding to the request of the to-be-processed model.

[0058] For example, the query model with a hit number greater than a hit threshold can be selected from the analysis data, and the hit threshold can be flexibly set according to needs, for example, it can be 5000, and the query model with a hit number greater than the hit threshold is taken as a to-be-processed query model.

[0059] When the data query request hits the query model, the hit number of the query model is incremented by 1, and the response time of the data query request is recorded.

[0060] According to the response time of the data query request corresponding to each to-be-processed query model, the average response time of the data query request corresponding to each to-be-processed query model is calculated, and the average response time of each to-be-processed model is obtained.

[0061] The current indexes of the database, i.e., the indexes established by the database, are acquired, each to-be-processed model is matched with each current index, and the matching degree of the to-be-processed query model and each current index is obtained. According to the matching degree of the to-be-processed query model and each current index, the model matching degree of the to-be-processed query model can be calculated, for example, the model matching degree of the to-be-processed query model is obtained by adding the matching degrees of the to-be-processed query model and each current index.

[0062] The to-be-processed query model whose average response time is greater than the first threshold value and whose matching degree is less than the second threshold value is determined as the target query model.

[0063] The average response time of the to-be-processed query model greater than the first threshold value indicates that the query request corresponding to the to-be-processed query model has a slow query (slow query: it takes more time to find the data required by the data query request), and the matching degree of the to-be-processed query model less than the second threshold value indicates that the data query request corresponding to the to-be-processed query model has a slow query due to the lack of a suitable index or the like.

[0064] Optionally, the hit frequency, the average response time, and the model matching degree of each query model can be acquired, and the target query model can be determined from the query models in the analysis data according to the hit frequency, the average response time, and the model matching degree, for example, the query model whose hit frequency is greater than a hit threshold value, whose average response time is greater than the first threshold value, and whose model matching degree is less than the second threshold value is taken as the target query model.

[0065] Optionally, the to-be-processed query models whose hit frequencies are greater than a hit threshold value can be filtered out first, the to-be-processed query models whose average response times are greater than the first threshold value are filtered out from the to-be-processed query models, and the query models whose model matching degrees are less than the second threshold value are filtered out from the to-be-processed query models, and the target query model is obtained.

[0066] The calculation method of the matching degree of the to-be-processed query model and the current index can refer to the related process in step 104, which is not described herein.

[0067] 102、According to the frequency of each query attribute information corresponding to the first query condition of the target query model in the analysis data, a first candidate index of the database corresponding to the data query request is generated.

[0068] The frequency can represent the number of occurrences of each query attribute information.

[0069] The first query condition can include at least one query condition, for example, can be a sorting condition or a filtering condition, and can also be a sorting condition and a filtering condition, etc.

[0070] The first candidate index can be an index constructed from the first query condition.

[0071] For example, if the first query condition includes one query condition, the query attribute information with the highest frequency in the query attribute information corresponding to the first query condition of all target query models is determined as the index information of the first candidate index, that is, the first candidate index can be represented as {key1}, where key1 is the query attribute information with the highest frequency.

[0072] The first query condition can also include a preset number of query attribute information as index information according to the frequency, for example, the two query attribute information with the highest frequency in the query attribute information corresponding to the first query condition is determined as the index information, the first candidate index is generated, and the first candidate index can be represented as {key1, key2}, where key1 and key2 are the two query attribute information with the highest frequency.

[0073] If the first query condition includes multiple query conditions, the query attribute information with a frequency meeting a condition (for example, the highest frequency or the frequency meeting a certain threshold) in the query condition can be obtained for each query condition included in the first query condition, and the first candidate index can be generated according to the query attribute information of each query condition.

[0074] In an embodiment, the first query condition can include a first sub-query condition and a second sub-query condition, and the index information can be determined according to the query attribute information of the first sub-query condition and the second sub-query condition in the second query condition, that is, in an embodiment, the first query condition includes two query conditions, the first sub-query condition and the second sub-query condition, and the step of "generating the first candidate index of the database corresponding to the data query request according to the frequency of each query attribute information corresponding to the first query condition of the target query model in the analysis data" can be specifically:

[0075] The query attribute information of the first sub-query condition meeting a preset condition in the target query model of the analysis data is determined as the first index information;

[0076] If the target query model including the first index information includes a second sub-query condition of a target type, the query attribute information corresponding to the second query condition of the target type is determined as the second index information;

[0077] The first candidate index of the database corresponding to the data query request is generated according to the first index information and the second index information.

[0078] The first subquery condition can be an order condition or a filter condition, etc.

[0079] The second subquery condition can include various types of second subquery conditions, such as differentiating the second query condition into different types of second subquery conditions according to the number of query attribute information contained in the second subquery condition.

[0080] The target type of second subquery condition can be a second subquery condition containing only one query attribute information.

[0081] For example, the first index information can include a preset number of query attribute information according to the frequency. The query model in which the query attribute information of the first subquery condition contains the first index information is determined from the target query model. Whether there is a target type of second subquery condition, if there is, the query attribute information corresponding to the target type of second query condition is taken as the second index information of the first candidate index, if not, the first candidate index only contains the first index information.

[0082] In an embodiment, the first subquery condition can be an equality condition, and the second subquery condition can be an order condition. From the query attribute information corresponding to the equality condition, the query attribute information with the highest frequency is selected as the index information of the first candidate index. Then, from the target query model containing the query attribute information with the highest frequency, an order condition containing only one query attribute information is obtained. The query attribute information is taken as the index information of the first candidate index. The index information determined according to the equality condition and the index information determined according to the order condition are used to generate the first candidate index.

[0083] 103. According to the frequency of the target query attribute information corresponding to the second query condition of the target query model in the analysis data, a second candidate index of the database is generated.

[0084] The second query condition can include at least one query condition, such as an order condition or a filter condition, or an order condition and a filter condition, etc. The second candidate index can be an index constructed from the second query condition.

[0085] The target query attribute information can be a query attribute information in a preset order, for example, the first query attribute information in the second query condition.

[0086] For example, the target query attribute information with the highest frequency in the first query attribute information (i.e., target query attribute information) of the second query condition of the target query model can be taken as the index information of the second candidate index, and the second candidate index can be generated according to the index information. For example, the second query condition contains a sorting condition, and the first query attribute information with the highest frequency in the sorting condition is taken as the index information of the second candidate index, and the second candidate index is generated. The second candidate index can be represented as {key0}, and key0 is the first query attribute information with the highest frequency. If the second query condition contains multiple query conditions, the index information of the second candidate index can be generated according to the target query attribute information with the highest frequency in the target model, and based on the index information corresponding to each condition in the second query condition.

[0087] It can be understood that, in addition to the target query attribute information with the highest frequency, the target query attribute information with a frequency satisfying a preset threshold can also be taken as the index information.

[0088] In an embodiment, the second query condition can include a third sub-query condition and a fourth sub-query condition, and the step of "generating a second candidate index of the database according to the frequency of the target query attribute information corresponding to the second query condition of the target query model in the analysis data" can specifically include:

[0089] The frequency of each target query attribute information corresponding to the target query order of the third sub-query condition in the target query model of the analysis data is obtained.

[0090] The target query attribute information with a frequency satisfying a preset condition is determined as the third index information.

[0091] If there is the same query attribute information in the query attribute information corresponding to the fourth sub-query condition in the target query model containing the third index information, the second candidate index is generated based on the same query attribute information and the third index information.

[0092] The query attribute information contained in the third sub-query condition has a query order, and the target query order can be the first, second, or other order, or a combination of the first, second, and other orders.

[0093] For example, the occurrence number of each target query attribute information corresponding to the target query order of the third sub-query condition in the target query model can be counted, and the target query attribute satisfying the preset condition is determined as the third index information. For example, the target query attribute information with the highest occurrence number in the first query attribute information of the third sub-query condition is determined as the third index information.

[0094] Further, the target query attribute information with the highest occurrence number in the second query attribute information can be determined as the third index information, i.e., the third index information can include two target query attribute information.

[0095] If the fourth sub-query condition of the target query model including the third index information includes the query attribute information X, the third index information and the query attribute information X are taken as the index information of the second candidate index, and the second candidate index is generated according to the index information.

[0096] In an embodiment, the third sub-query condition can be an order condition, and the fourth sub-query condition can be an equality condition. The query attribute information with the highest occurrence number in the first query attribute information of the order condition (the query attribute information with the first order) is taken as the third index information. The target query model whose first query attribute information of the third sub-query condition includes the third index information is filtered from the target query model. If the equality condition of the filtered target query model includes the same query attribute information, the second candidate index is generated according to the same attribute information and the third index information.

[0097] 104. The target index of the database is determined from the first candidate index and the second candidate index according to the matching degree of the first candidate index with the target query model and the matching degree of the second candidate index with the target query model.

[0098] The matching degree can represent the matching degree of the first candidate index or the second candidate index with the target query model.

[0099] For example, the candidate index with the highest matching degree can be taken as the target index, and the target index is created in the database.

[0100] In an embodiment, the matching degree of the first candidate index or the second candidate index can be calculated according to the matching of the query attribute information of the target query model with the index information of the first candidate index or the second candidate index. After the step of “determining the target index of the database from the first candidate index and the second candidate index according to the matching degree of the first candidate index with the target query model and the matching degree of the second candidate index with the target query model”, the index generation method can further include:

[0101] For each target query model, the query attribute information contained in each query condition in the target query model is matched with the index information contained in the first candidate index, so as to calculate the initial matching degree between the first candidate index and the target query model;

[0102] For each target query model, the query attribute information contained in each query condition in the target query model is matched with the index information contained in the second candidate index, so as to calculate the initial matching degree between the second candidate index and the target query model;

[0103] The hit number of each target query model and the initial matching degree between the target query model and the first candidate index are point-multiplication processed, so as to weight-sum the initial matching degree of the target query model, and the matching degree of the first candidate index is obtained.

[0104] The hit number of each target query model and the initial matching degree between the target query model and the second candidate index are point-multiplication processed, so as to weight-sum the initial matching degree of the target query model, and the matching degree of the second candidate index is obtained.

[0105] For example, the corresponding score of each query condition in the target query model can be set, for each target query model, each query condition in the target query model is matched with the same query condition in the first candidate index, if they are the same, the first candidate index obtains the score corresponding to the query condition, and the score of the first candidate index under each query condition is added to obtain the initial matching degree between the first candidate index and the target query model. According to the hit number of each target query model, the initial matching degree is weight-sum processed to obtain the matching degree of the first candidate index.

[0106] The matching degree calculation method of the second candidate index can refer to the matching degree calculation method of the first candidate index, which is not repeated here.

[0107] In an embodiment, the first query condition of the target query model can be set with a corresponding score, when the index information in the first candidate index hits the query attribute information in the first query condition of the target query model each time, a certain score is obtained from the corresponding score according to a preset rule, that is, the step "for each target query model, the query attribute information contained in each query condition in the target query model is matched with the index information contained in the first candidate index, so as to calculate the initial matching degree between the first candidate index and the target query model", specifically can be:

[0108] The target index information is determined from the index information contained in the first candidate index;

[0109] If the target index information is the same as the query attribute information corresponding to the first query condition in the target query model, the initial matching degree of the first candidate index and the target query model under the first query condition is calculated according to the target index information.

[0110] The associated index information of the target index information is determined as the target index information, and the execution of the initial matching degree of the first candidate index and the target query model under the first query condition is returned until the target index information is the preset index information, and the plurality of initial matching degrees under the first query condition are obtained.

[0111] The initial matching degree between the first candidate index and the target query model is calculated according to the plurality of initial matching degrees under the first query condition.

[0112] The associated index information can be the next index information of the target index information in sequence.

[0113] For example, the first query condition of the target query model can be set with a corresponding score for each target query model, the first index information in the first candidate index is obtained, the first index information is determined as the target index information, and if the target index information is the same as the query attribute information in the first query condition in the target query model, half of the score corresponding to the first query condition is taken to obtain the initial matching degree of the first candidate index and the target query model under the first query condition. The score corresponding to the first query condition is reduced by half.

[0114] The next index information of the target index information is determined as the target index information, and the execution of the initial matching degree of the first candidate index and the target query model under the first query condition is returned until the target index information is the preset index information, and the plurality of initial matching degrees under the first query condition are obtained.

[0115] The initial matching degree between the first candidate index and the target query model is calculated according to the plurality of initial matching degrees under the first query condition.

[0116] From the above, the embodiment of the application can obtain analysis data, the analysis data is obtained by analyzing the corresponding query model for the received data query request, the analysis data includes at least one query model, the query model includes a target query model, the query model includes at least one query condition, each query condition includes at least one query attribute information; according to the frequency of each query attribute information corresponding to the first query condition of the target query model in the analysis data, a first candidate index of the database corresponding to the data query request is generated; according to the frequency of the target query attribute information corresponding to the second query condition of the target query model in the analysis data, a second candidate index of the database is generated; according to the matching degree of the first candidate index and the target query model and the matching degree of the second candidate index and the target query model, the target index of the database is determined from the first candidate index and the second candidate index, which can generate the first candidate index and the second candidate index based on the analysis data, determine the target index according to the matching degree of the first candidate index and the second candidate index, can realize intelligent generation of index, automatically optimize the index of the database, and improve the response speed of the database.

[0117] On the basis of the above embodiment, the following will be further described in detail.

[0118] This embodiment will be described from the perspective of an index generation device, taking query attribute information as a query field, index information as a key field, the first query condition as an equality condition, and the second query condition as a sorting condition. The index generation device can be integrated in a computer device, which can be a server.

[0119] The index generation method provided by the embodiment of the application is as shown in Figure 3 The specific process of the index generation method can be as follows:

[0120] 201, analyze the data query request for the database, determine the query model corresponding to the data query request, and obtain analysis data.

[0121] For example, the data query request can be analyzed to determine the database table and the query field to be queried by the data query request according to the query statement contained in the data query request, and the query condition contained in the data query request can be determined according to the operator in the query statement. For example, if the data query request carries a statement indicating that data is selected from the database table conditionally, such as a where clause, the data query request includes a filtering condition. The specific filtering condition can be determined according to the operator in the statement. For example, if the operator carried is equal (=), the filtering condition is specifically an equality condition, and if the operator carried is less than or greater than, the filtering condition is specifically a comparison condition. If the data query request carries a statement indicating that data is sorted according to a specified data, such as an order by clause, the data query request includes a sorting condition.

[0122] According to the query condition contained in the query request and the query field of the query condition, the query model corresponding to the query request is determined. If the query condition in the query request a and the query field corresponding to the query condition are one-to-one corresponding to the query model a, the query model corresponding to the query request is the query model a.

[0123] If the query conditions and the query fields corresponding to the query conditions contained in the data query request a and the data query request b are one-to-one corresponding, whether the order of different query conditions appearing in the data query request is the same or not, the query models corresponding to the data query request a and the data query request b are the same.

[0124] If the sorting condition contains multiple query fields, the multiple query fields have a query order, and when two sorting conditions contain the same query fields and the order is consistent, the two sorting conditions are considered to be the same or corresponding.

[0125] When the data query request hits the query model, the hit number of the query model is incremented by 1, and the response time of the database responding to the data query request is recorded. According to the query model corresponding to each data query request, the response time, and the hit number of the query model, analysis data can be generated. The analysis data includes at least one query model, each query model includes at least one query condition, and each query condition includes at least one query field.

[0126] 202、From the analysis data, a target query model is selected.

[0127] For example, the analysis data can be obtained periodically (for example, monthly or weekly, or when a certain amount of analysis data is accumulated), and the query model with a hit number exceeding a hit threshold is selected from the analysis data. The hit threshold can be flexibly set according to needs, for example, it can be 5000, and the query model with a hit number greater than the hit threshold is taken as a query model to be processed.

[0128] According to the response time of the data query request corresponding to each to-be-processed query model, the average response time of the data query request corresponding to each to-be-processed query model is calculated, and the average response time of each to-be-processed model is obtained.

[0129] The current indexes of the database, i.e., the indexes established by the database, are obtained, for each to-be-processed query model, the to-be-processed model is matched with each current index, and the matching degree of the to-be-processed query model and each current index is obtained. According to the matching degree of the to-be-processed query model and each current index, the model matching degree of the to-be-processed query model can be calculated, for example, the model matching degree of the to-be-processed query model is obtained by adding the matching degrees of the to-be-processed query model and each current index.

[0130] The matching degree between each current index and the to-be-processed query model can refer to the method of calculating the matching degree between the first candidate index and the target query model in step 207, which will not be repeated here.

[0131] Optionally, when the equality condition or the containment condition of the to-be-processed query model matches the unique index in the current index, it indicates that the to-be-processed query model is not the target model, and the matching degree calculation process is ended; if there is a current index matching the sorting condition, it indicates that the to-be-processed query model is not the target model, and the matching degree calculation process is ended; if there is a geographic location condition in the to-be-processed query model and there is no sorting condition, an additional score can be added to the initial matching degree of the query condition, so as to ensure that the geographic location condition does not create a new index in the case that there is a corresponding index.

[0132] The to-be-processed query model with the average response time greater than a first threshold (for example, 1 second) and the matching degree less than a second threshold (for example, 20) is determined as the target query model.

[0133] 203. Determine the first key field of the first candidate index according to the number of occurrences of each query field corresponding to the equality condition in the target query model.

[0134] For example, the number of occurrences of each query field corresponding to the first query condition of the target query model can be counted, and the query field with the most occurrences among the query fields corresponding to the first query condition of all target query models is determined as the first key field of the first candidate index.

[0135] 204. If there is a target sorting condition in the target query model containing the first key field of the first candidate index, the first candidate index is generated according to the first key field and the query field of the target sorting condition.

[0136] The target sorting condition can be a sorting condition containing a single query field.

[0137] If the equality condition corresponds to a query field containing the first key field in the target query model, there is a single query field ordering condition, the query field corresponding to the single query field ordering condition is taken as the second key field of the first candidate index, and the first candidate index can be represented as {key11, key12}, where key11 is the query field with the highest frequency of occurrence, and key12 is the query field corresponding to the single query field ordering condition. If there is no single query field ordering condition, the first candidate index only includes the first key field and can be represented as {key11}.

[0138] 205、According to the frequency of occurrence of the query field in the target query model, the first key field of the second candidate index is determined.

[0139] For example, the query field in the sorting condition has a query order, such as the sorting condition of the data query request is sorted according to name, age, and score, the name is the first query field, the age is the second query field, and the score is the third query field, and so on. The frequency of occurrence of the first query field (which can be called the first query field for distinction) in the sorting condition of each target query model is counted, and the frequency of occurrence of the second query field (which can be called the second query field for distinction) is counted. The first query field with the highest frequency of occurrence and the second query field with the highest frequency of occurrence are determined as the first key field of the second candidate index. The first key field includes two key fields, which are key21 and key22. Among them, key21 is the first query field with the highest frequency of occurrence, and key22 is the second query field with the highest frequency of occurrence.

[0140] If the sorting condition of all target query models is a single query field sorting condition, and there is no second query field with the highest frequency of occurrence, the first key field of the second candidate index is key21.

[0141] 206、If the equality condition of the target query request containing the first key field of the second candidate index has the same query field, the second candidate index is generated according to the first key field and the same query field.

[0142] If the first query field and the second query field of the sorting condition respectively contain the same query field X in the equality condition of the target query model corresponding to the first key field, the query field X is determined as the second key field of the second candidate index, the second candidate index is generated according to the first key field and the second key field, and the second candidate index can be represented as {key21, key22, key23}, where key21 is the first query field with the highest frequency of occurrence, key22 is the second query field with the highest frequency of occurrence, and key23 is the query field X.

[0143] It can be understood that if the same query field X is not contained in the equality condition of the target query model containing the first key field, the second candidate index can be represented as {key21, key22}, where key21 is the first query field with the highest frequency of occurrence, and key22 is the second query field with the highest frequency of occurrence.

[0144] If all the sorting conditions of the target query model are sorting conditions containing a single query field, there is no second query field with the highest frequency of occurrence, and the same query field X is not contained in the equality condition of the target query model containing the first key field, the second candidate index can be represented as {key21}, where key21 is the first query field with the highest frequency of occurrence.

[0145] If the same query field X is contained in the equality condition of the target query model containing the first key field, there is no second query field with the highest frequency of occurrence, and the second candidate index can be represented as {key21, key23}, where key21 is the first query field with the highest frequency of occurrence, and key23 is the query field X.

[0146] 207、Calculate the matching degree between the first candidate index and the target query model, and the matching degree between the second candidate index and the target query model.

[0147] For example, the corresponding score of each query condition in the target query model can be set, for each target query model, each query condition in the target query model is matched with the same query condition in the first candidate index, if they are the same, the first candidate index obtains the corresponding score of the query condition, and the sum of the scores of the first candidate index under each query condition can obtain the initial matching degree between the first candidate index and the target query model. The initial matching degree is weighted according to the hit number of the target query model to obtain the matching degree of the first candidate index.

[0148] For example, the score of the filter condition can be set as 50 points, and the score of the sorting condition can be set as 40 points. The initial matching degree between the first candidate index and the target query model under the equality condition is calculated. Specifically, if the first candidate index is a unique index, for each target query model, if the equality condition or the containment condition of the target query model matches the first candidate index, the first candidate index and the target query model are a perfect match, and the initial matching degree is 100.

[0149] If the first candidate index is not a unique index, for each target query model, each key field of the first candidate index is matched with the query field corresponding to the equality condition of the target query model. If one key field matches (is the same as) the query field, half (25) of the score (50) corresponding to the filter condition is obtained, and the score of the filter condition is halved (25) accordingly. If other key fields are the same as the query field, half (12.5) of the score (25) corresponding to the filter condition is obtained. At this time, the initial matching degree between the first candidate index and the target query model is 25+12.5=37.5. In this way, until there is no key field in the first candidate index that matches the query field, the initial matching degree between the first candidate index and the target query model under the equality condition is obtained.

[0150] If the query field of the other filter condition matches one key field of the first candidate index, the initial matching degree under the filter condition is 10.

[0151] If the key fields of the first candidate index and the field order of the key fields are the same as the sorting condition of the target query model, the initial matching degree between the first candidate index and the target query model is 40, otherwise, the initial matching degree is 0.

[0152] The initial matching degree between the first candidate index and the target query model can be determined according to the initial matching degree of the first candidate index and the target query model under each condition.

[0153] The same processing is performed for each target query model, and the initial matching degree between each target query model and the first candidate index can be obtained.

[0154] The initial matching degrees between the target query models and the first candidate index are weighted and summed according to the hit times of each target query model, and the matching degree of the first candidate index is obtained.

[0155] The matching degree calculation method of the second candidate index can refer to the matching degree calculation method of the first candidate index, which will not be repeated here.

[0156] 208、determine the target index according to the matching degree between the first candidate index and the target query model and the matching degree between the second candidate index and the target query model.

[0157] For example, the candidate index with high matching degree can be taken as the target index, and the target index can be created into the database.

[0158] As can be seen from the above, the embodiments of the present application analyze the data query request for the database to determine the query model corresponding to the data query request to obtain analysis data, filter the target query model from the analysis data, determine the first key field of the first candidate index according to the number of occurrences of each query field corresponding to the equality condition in the target query model, generate the first candidate index according to the first key field and the query field of the target sorting condition if the target sorting condition exists in the target query model containing the first key field of the first candidate index, determine the first key field of the second candidate index according to the number of occurrences of the query field of the target query order in the sorting condition in the target query model, generate the second candidate index according to the first key field and the same query field if the same query field exists in the equality condition of the target query request containing the first key field of the second candidate index, calculate the matching degree between the first candidate index and the target query model and the matching degree between the second candidate index and the target query model, and determine the target index according to the matching degree between the first candidate index and the target query model and the matching degree between the second candidate index and the target query model. The scheme can generate the first candidate index and the second candidate index based on the analysis data, determine the target index according to the matching degree of the first candidate index and the second candidate index, can realize intelligent generation of index, automatically optimize the index of the database, and improve the response speed of the database.

[0159] In order to better implement the index generation method provided by the embodiments of the present application, an index generation device is also provided in an embodiment. The meanings of the terms are the same as those in the above index generation method, and the specific implementation details can be referred to the description in the method embodiment.

[0160] The index generation device can be integrated in a computer device, as shown in Figure 4 The index generation device can include a data acquisition unit 301, a first index generation unit 302, a second index generation unit 303, and a target index determination unit 304, and the details are as follows.

[0161] The data acquisition unit 301 is configured to acquire analysis data. The analysis data is obtained by analyzing a query model corresponding to the received data query request. The analysis data includes at least one query model. The query model includes a target query model. The query model includes at least one query condition. Each query condition includes at least one query attribute information.

[0162] For example, the analysis data can be acquired from a model database. The model database can be the same database as the database queried by the data query request, or can be a different database. In this embodiment of the application, the model database is not limited. The analysis data can also be in a block chain. The computer device acquires the corresponding analysis data from the block chain.

[0163] Optionally, the index generation apparatus further includes a receiving unit, an analysis unit, and a data generation unit. Specifically,

[0164] The receiving unit is configured to receive a data query request for a database.

[0165] The analysis unit is configured to analyze and process the data query request based on the query condition carried by the data query request and the query attribute information included in the query condition, to determine a query model corresponding to the data query request, and to update the hit number of the query model. The hit number represents the number of data query requests corresponding to the query model.

[0166] The data generation unit is configured to generate analysis data according to the query model and the hit number of the query model.

[0167] For example, the received data query request can be analyzed. The database table and the query attribute information to be queried by the data query request can be determined according to the query statement included in the data query request. The query condition included in the data query request can be determined according to the operator in the query statement. For example, if the data query request carries a statement for conditionally selecting data from the database table, such as a where clause, the data query request includes a filtering condition. The specific filtering condition can be determined according to the operator in the statement. For example, if the operator carried is equal to (=), the filtering condition is an equality condition. If the operator carried is less than or greater than, the filtering condition is a comparison condition. If the data query request carries a statement for sorting data according to a specified data, such as an order by clause, the data query request includes a sorting condition.

[0168] The query model corresponding to the query request is determined according to the query condition included in the query request and the query attribute information of the query condition. If the query condition in the query request a and the query attribute information corresponding to the query condition one by one correspond to the query model a, the query model corresponding to the query request is the query model a.

[0169] If the query conditions contained in the data query request a and the data query request b and the query attribute information corresponding to the query conditions are one-to-one correspondence, no matter whether the order of different query conditions appearing in the data query request is the same, the query model corresponding to the data query request a and the data query request b is the same.

[0170] Optionally, if the sorting condition contains a plurality of query attribute information, the plurality of query attribute information has a query order, when the query attribute information contained in two sorting conditions is the same and the order is consistent, the two sorting conditions are considered to be the same or corresponding.

[0171] According to the analysis of the query model corresponding to each data query request and the hit number of the query model, analysis data can be generated, the analysis data includes at least one query model, each query model includes at least one query condition, and each query condition includes at least one query attribute information.

[0172] Optionally, the index generation apparatus can further include an acquisition unit, a calculation unit, a matching unit and a determination unit, specifically:

[0173] The acquisition unit is configured to acquire, from the analysis data, a to-be-processed query model with a hit number greater than a hit threshold;

[0174] The calculation unit is configured to calculate, for each to-be-processed query model, an average response time of the to-be-processed query model according to a response time of each query request corresponding to the to-be-processed query model;

[0175] The matching unit is configured to match, for each to-be-processed query model, a current index of the database with the to-be-processed query model to obtain a model matching degree of the to-be-processed query model;

[0176] The determination unit is configured to determine a target query model from the to-be-processed query model according to the average response time and the model matching degree.

[0177] For example, the query model with a hit number greater than a hit threshold can be filtered from the analysis data, and the hit threshold can be flexibly set according to needs, for example, 5000. The query model with a hit number greater than the hit threshold is taken as a to-be-processed query model.

[0178] When a data query request hits a query model, the hit number of the query model is incremented by 1, and the response time of the data query request is recorded.

[0179] According to the response time of the data query request corresponding to each to-be-processed query model, the average response time of the data query request corresponding to each to-be-processed query model is calculated to obtain the average response time of each to-be-processed model.

[0180] The current index of the database, i.e., the index established by the database, is obtained, for each to-be-processed query model, the to-be-processed model is matched with each current index, the matching degree of the to-be-processed query model and each current index is obtained, and the model matching degree of the to-be-processed query model can be calculated according to the matching degree of the to-be-processed query model and each current index, for example, the average value is calculated according to the matching degree of the to-be-processed query model and each current index, and the average value is taken as the model matching degree of the to-be-processed query model.

[0181] The to-be-processed query model with the average response time greater than the first threshold and the matching degree less than the second threshold is determined as the target query model.

[0182] The average response time of the to-be-processed query model greater than the first threshold indicates that the query request corresponding to the to-be-processed query model has a slow query (slow query: it takes more time to complete the data query request required by the data query request), and the matching degree of the to-be-processed query model less than the second threshold indicates that the data query request corresponding to the to-be-processed query model has a slow query due to no suitable index or the like.

[0183] Optionally, the hit frequency, the average response time, and the model matching degree of each query model can be obtained, and the target query model can be determined from the query model in the analysis data according to the hit frequency, the average response time, and the model matching degree, for example, the query model with the hit frequency greater than the hit threshold, the average response time greater than the first threshold, and the model matching degree less than the second threshold is taken as the target query model.

[0184] Optionally, the to-be-processed query model with the hit frequency greater than the hit threshold can be filtered out first, the to-be-processed query model with the average response time greater than the first threshold can be filtered out from the to-be-processed query model, and the query model with the model matching degree less than the second threshold can be filtered out, to obtain the target query model.

[0185] The calculation method of the matching degree of the to-be-processed query model and the current index can refer to the related process in step 104, which will not be described here.

[0186] The first index generating unit 302 is configured to generate the first candidate index of the database corresponding to the data query request according to the frequency of each query attribute information corresponding to the first query condition of the target query model in the analysis data.

[0187] For example, the query attribute information with the highest frequency among the query attribute information corresponding to the first query condition of all target query models can be determined as the index information of the first candidate index, i.e., the first candidate index can be represented as {key1}, where key1 is the query attribute information with the highest frequency.

[0188] The preset number of query attribute information of the first query condition can also be taken as index information according to the frequency, for example, two query attribute information with the highest frequency in the query attribute information corresponding to the first query condition is determined as index information, and a first candidate index is generated, which can be represented as {key1, key2}, where key1 and key2 are the two query attribute information with the highest frequency.

[0189] Optionally, the first index generation unit 302 can include a first determination module, a second determination module, and a first generation module, specifically:

[0190] The first determination module is configured to determine, as first index information, the query attribute information of the first sub-query condition in the target query model of the analysis data, which meets a preset condition in terms of frequency.

[0191] The second determination module is configured to, if the target query model containing the first index information includes a second sub-query condition of a target type, determine, as second index information, the query attribute information corresponding to the second query condition of the target type.

[0192] The first generation module is configured to generate, according to the first index information and the second index information, a first candidate index of a database corresponding to the data query request.

[0193] For example, the first number of query attribute information of the first sub-query condition can be taken as the first index information according to the frequency, that is, the first index information includes the first number of query attribute information. It is determined whether the query model containing the query attribute information of the first sub-query condition in the target query model includes a second sub-query condition of a target type. If it exists, the query attribute information corresponding to the second sub-query condition of the target type is taken as the second index information of the first candidate index. If it does not exist, the first candidate index only contains the first index information.

[0194] The second index generation unit 303 is configured to generate a second candidate index of a database according to the frequency of the target query attribute information corresponding to the second query condition of the target query model in the analysis data.

[0195] For example, the target query attribute information with the highest frequency in the first query attribute information (i.e., the target query attribute information) of the second query condition of the target query model can be taken as the index information of the second candidate index, and the second candidate index is generated according to the index information.

[0196] Optionally, the second index generation unit 303 can include an acquisition module, a third determination module, and a second generation module, specifically:

[0197] The acquisition module is configured to acquire a frequency of each target query attribute information corresponding to a target query order of the third sub-query condition in the target query model of the analysis data.

[0198] The third determination module is configured to determine the target query attribute information satisfying the preset condition as the third index information according to the frequency.

[0199] The second generation module is configured to generate a second candidate index based on the same query attribute information and the third index information if the same query attribute information exists in the query attribute information corresponding to the fourth sub-query condition in the target query model containing the third index information.

[0200] For example, the number of occurrences of each target query attribute information corresponding to the target query order of the third sub-query condition in the target query model can be counted, and the target query attribute information satisfying the preset condition is determined as the third index information, for example, the target query attribute information with the largest number of occurrences in the first query attribute information in the second query condition is determined as the third index information.

[0201] Further, the target query attribute information with the largest number of occurrences in the second query attribute information can also be determined as the third index information, that is, the third index information includes two target query attribute information.

[0202] If the query attribute information X is contained in the fourth sub-query condition of the target query model containing the third index information, the third index information and the query attribute information X are taken as the index information of the second candidate index, and the second candidate index is generated according to the index information.

[0203] The target index determination unit 304 is configured to determine the target index of the database from the first candidate index and the second candidate index according to the matching degree of the first candidate index and the target query model and the matching degree of the second candidate index and the target query model.

[0204] For example, the candidate index with the highest matching degree can be taken as the target index, and the target index is created in the database.

[0205] Optionally, the target index determination unit 304 can include a matching module and a processing module, specifically:

[0206] The matching module is configured to match the query attribute information contained in each query condition in the query model with the index information contained in the first candidate index for each query model to calculate the matching degree between the first candidate index and the query model.

[0207] The processing module is configured to perform weighted processing on the initial matching degree between the query model and the first candidate index according to the hit number of each query model to obtain the matching degree of the first candidate index.

[0208] For example, each query condition in the target query model can correspond to a different score. For each target query model, each query condition in the target query model is matched with the same query condition in the first candidate index. If they are the same, the first candidate index obtains the score corresponding to the query condition. The scores of the first candidate index under each query condition are added to obtain the initial matching degree between the first candidate index and the target query model. The initial matching degree is weighted according to the hit number of the target query model to obtain the matching degree of the first candidate index.

[0209] The matching degree of the second candidate index is calculated in the same way as the matching degree of the first candidate index, which is not described here.

[0210] Optionally, the matching module can include a first determination submodule, a first calculation submodule, a second determination submodule, and a second calculation submodule. Specifically:

[0211] The first determination submodule is configured to determine target index information from the index information included in the first candidate index.

[0212] The first calculation submodule is configured to, for each target query model, if the target index information is the same as the query attribute information corresponding to the first query condition in the target query model, calculate the initial matching degree of the first candidate index and the target query model under the first query condition according to the target index information.

[0213] The second determination submodule is configured to determine the associated index information of the target index information as the target index information, and return to execute, for each target query model, if the target index information is the same as the query attribute information corresponding to the first query condition in the target query model, calculate the initial matching degree of the first candidate index and the target query model under the first query condition according to the target index information, until the target index information is the preset index information, to obtain multiple initial matching degrees under the first query condition.

[0214] The second calculation submodule is configured to calculate the initial matching degree between the first candidate index and the target query model according to the multiple initial matching degrees under the first query condition.

[0215] For example, for each target query model, a corresponding score is set for the first query condition of the target query model. The first index information in the first candidate index is obtained, and the first index information is determined as the target index information. If the target index information is the same as the query attribute information in the first query condition in the target query model, half of the score corresponding to the first query condition is taken to obtain the initial matching degree of the first candidate index and the target query model under the first query condition. The score corresponding to the corresponding first query condition is reduced by half.

[0216] The next index information of the target index information is determined as the target index information, and the initial matching degree between the first candidate index and the target query model under the first query condition is calculated by returning to execute the above calculation. A plurality of initial matching degrees under the first query condition can be obtained, and the initial matching degree between the first candidate index and the target query model under the first query condition can be obtained by adding the plurality of initial matching degrees.

[0217] The first initial matching degree between the first candidate index and the target query model can be obtained according to the initial similarity between the first candidate index and the target query model under each query condition.

[0218] As can be seen from the above, the index generation device of the embodiment of the application can obtain analysis data by the data acquisition unit 301, the analysis data is obtained by analyzing the corresponding query model for the received data query request, the analysis data includes at least one query model, the query model includes a target query model, the query model includes at least one query condition, and each query condition includes at least one query attribute information; the first index generation unit 302 generates the first candidate index of the database corresponding to the data query request according to the frequency of each query attribute information corresponding to the first query condition of the target query model in the analysis data; the second index generation unit 303 generates the second candidate index of the database according to the frequency of the target query attribute information corresponding to the second query condition of the target query model in the analysis data; and finally, the target index determination unit 304 determines the target index of the database from the first candidate index and the second candidate index according to the matching degree of the first candidate index and the target query model and the matching degree of the second candidate index and the target query model. The scheme can generate the first candidate index and the second candidate index based on the analysis data, and determine the target index according to the matching degree of the first candidate index and the second candidate index, so as to realize intelligent generation of index, automatically optimize the index of the database, and improve the response speed of the database.

[0219] The embodiment of the application further provides a computer device, which can be a terminal or a server, as shown in Figure 5 The computer device shows the structure schematic diagram of the computer device related to the embodiment of the application, and specifically:

[0220] The computer device can include a processor 1001 with one or more processing cores, a memory 1002 of one or more computer readable storage media (also referred to as storage media), a power supply 1003, and an input unit 1004. Those skilled in the art can understand that Figure 5The computer device structure shown in the figure is not a limitation of the computer device, and can include more or fewer components than shown, or combine certain components, or arrange different components. Among them:

[0221] The processor 1001 is the control center of the computer device, connects various parts of the computer device through various interfaces and lines, executes various functions of the computer device and processes data by running or executing software programs and / or modules stored in the memory 1002, and calling data stored in the memory 1002, thereby overall detecting the computer device. Optionally, the processor 1001 can include one or more processing cores; preferably, the processor 1001 can integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, computer program, etc., and the modem processor mainly processes wireless communication. It can be understood that the above-mentioned modem processor can also not be integrated into the processor 1001.

[0222] The memory 1002 can be used to store software programs and modules, and the processor 1001 executes various functions and data processing by running the software programs and modules stored in the memory 1002. The memory 1002 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, at least one computer program required by a function (such as a sound playing function, an image playing function, etc.) and the like; the data storage area can store data created according to the use of the computer device and the like. In addition, the memory 1002 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other volatile solid-state memory device. Accordingly, the memory 1002 can also include a memory controller to provide access for the processor 1001 to the memory 1002.

[0223] The computer device further includes a power supply 1003 for supplying power to various components, and preferably the power supply 1003 can be logically connected to the processor 1001 through a power management system, so as to realize functions such as management of charging, discharging, and power consumption management through the power management system. The power supply 1003 can also include one or more than one direct current or alternating current power supply, a recharging system, a power failure detection circuit, a power supply converter or inverter, a power supply state indicator, and any other components.

[0224] The computer device can also include an input unit 1004, which can be used to receive input digital or character information, and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.

[0225] Although not shown, the computer device can also include a display unit and the like, which will not be described here. In particular, in the present embodiment, the processor 1001 in the computer device will load one or more computer programs corresponding to the executable files of the processes of the computer programs into the memory 1002 according to the following instructions, and run the computer programs stored in the memory 1002 by the processor 1001, thereby realizing various functions, as follows:

[0226] Obtaining analysis data, the analysis data being obtained by analyzing a query model corresponding to the received data query request, the analysis data including at least one query model, the query model including a target query model, the query model including at least one query condition, each query condition including at least one query attribute information;

[0227] Generating a first candidate index of the database corresponding to the data query request according to a frequency of each query attribute information corresponding to a first query condition of the target query model in the analysis data;

[0228] Generating a second candidate index of the database according to a frequency of target query attribute information corresponding to a second query condition of the target query model in the analysis data;

[0229] Determining a target index of the database from the first candidate index and the second candidate index according to a matching degree of the first candidate index and the target query model and a matching degree of the second candidate index and the target query model.

[0230] The specific implementation of each operation can be referred to the foregoing embodiments, which will not be described here.

[0231] As can be seen from the above, the computer device of the present embodiment can obtain analysis data, the analysis data being obtained by analyzing a query model corresponding to the received data query request, the analysis data including at least one query model, the query model including a target query model, the query model including at least one query condition, each query condition including at least one query attribute information; a first candidate index of the database corresponding to the data query request is generated according to a frequency of each query attribute information corresponding to a first query condition of the target query model in the analysis data; a second candidate index of the database is generated according to a frequency of target query attribute information corresponding to a second query condition of the target query model in the analysis data; a target index of the database is determined from the first candidate index and the second candidate index according to a matching degree of the first candidate index and the target query model and a matching degree of the second candidate index and the target query model, which can generate the first candidate index and the second candidate index based on the analysis data, determine the target index according to the matching degrees of the first candidate index and the second candidate index, realize intelligent generation of the index, automatically optimize the index of the database, and improve the response speed of the database.

[0232] According to an aspect of the present application, a computer program product or computer program is provided, which comprises computer instructions stored in a computer readable storage medium. A processor of a computer device reads the computer instructions from the computer readable storage medium, and the processor executes the computer instructions, so that the computer device performs the method provided in various optional implementations of the above embodiments.

[0233] Those skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by a computer program, or by relevant hardware controlled by the computer program, which can be stored in a computer readable storage medium and loaded and executed by a processor.

[0234] To this end, the embodiments of the present application provide a computer readable storage medium, which stores a computer program. The computer program can be loaded by a processor to execute any index generation method provided by the embodiments of the present application.

[0235] The specific implementation of each operation can refer to the foregoing embodiments, which will not be described here.

[0236] The computer readable storage medium can include a read only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0237] Since the computer program stored in the computer readable storage medium can execute any index generation method provided by the embodiments of the present application, the beneficial effects of any index generation method provided by the embodiments of the present application can be achieved. Details are described in the foregoing embodiments, which will not be described here.

[0238] The above describes in detail the index generation method, device, computer device and computer readable storage medium provided by the embodiments of the present application. The principle and implementation manner of the present application are described by applying specific examples. The above embodiment is only used to help understand the method of the present application and its core idea. Meanwhile, for those skilled in the art, according to the idea of the present application, the specific implementation manner and application range can be changed. In conclusion, the content of the specification should not be understood as a limitation of the present application.

Claims

1. An index generation method, characterized in that, include: Acquire analytical data, which is obtained by analyzing the corresponding query model in response to a received data query request. The analytical data includes at least one query model, the query model includes a target query model, the query model includes at least one query condition, and each query condition includes at least one query attribute information. Based on the frequency of each query attribute information corresponding to the first query condition of the target query model in the analyzed data, a first candidate index of the database corresponding to the data query request is generated; Based on the frequency of the target query attribute information corresponding to the second query condition of the target query model in the analyzed data, a second candidate index of the database is generated; The target index of the database is determined from the first candidate index and the second candidate index based on the matching degree between the first candidate index and the target query model, and the matching degree between the second candidate index and the target query model. The target query model is obtained in the following way: Obtain the query models to be processed from the analyzed data whose hit count is greater than the hit threshold; For each query model to be processed, the average response time of the query model to be processed is calculated based on the response time of each query request corresponding to the query model to be processed. For each query model to be processed, the current index of the database is matched with the query model to be processed to obtain the model matching degree of the query model to be processed; Based on the average response time and the model matching degree, a target query model is determined from the query models to be processed; wherein, the query models with a hit count greater than a hit threshold, an average response time greater than a first threshold, and a model matching degree less than a second threshold are selected as target query models.

2. The method according to claim 1, characterized in that, The first query condition includes a first sub-query condition and a second sub-query condition. The second sub-query condition includes multiple types of second sub-query conditions. The step of generating a first candidate index for the database corresponding to the data query request based on the frequency of each query attribute information corresponding to the first query condition of the target query model in the analyzed data includes: The query attribute information of the first sub-query condition whose frequency in the target query model of the analyzed data meets the preset condition is determined as the first index information. If the target query model containing the first index information includes a second sub-query condition of the target type, then the query attribute information corresponding to the second sub-query condition of the target type is determined as the second index information; Based on the first index information and the second index information, a first candidate index of the database corresponding to the data query request is generated.

3. The method according to claim 1, characterized in that, The second query condition includes a third sub-query condition and a fourth sub-query condition. The query attribute information included in the third sub-query condition has a query order. The step of generating a second candidate index for the database based on the frequency of the target query attribute information corresponding to the second query condition of the target query model in the analyzed data includes: The frequency of each target query attribute information corresponding to the target query order of the third sub-query condition in the target query model for obtaining the analysis data; The target query attribute information that meets the preset conditions based on the frequency is determined as the third index information; If, in the target query model containing the third index information, there are identical query attribute information in the query attribute information corresponding to the fourth sub-query condition, then the second candidate index is generated based on the identical query attribute information and the third index information.

4. The method according to any one of claims 1 to 3, characterized in that, Before acquiring and analyzing the data, the method further includes: Receive data query requests for the database; Based on the query conditions carried in the data query request and the query attribute information contained in the query conditions, the data query request is analyzed and processed to determine the query model corresponding to the data query request, and the hit count of the query model is updated. The hit count represents the number of data query requests corresponding to the query model. Analysis data is generated based on the query model and the number of times the query model is hit.

5. The method according to claim 1, characterized in that, Before determining the target index of the database from the first candidate index and the second candidate index based on the matching degree between the first candidate index and the target query model, and the matching degree between the second candidate index and the target query model, the method further includes: For each target query model, the query attribute information contained in each query condition in the target query model is matched with the index information contained in the first candidate index to calculate the initial matching degree between the first candidate index and the target query model. For each target query model, the query attribute information contained in each query condition in the target query model is matched with the index information contained in the second candidate index to calculate the initial matching degree between the second candidate index and the target query model; The number of hits for each target query model and the initial matching degree with the first candidate index are multiplied by a dot product, and the initial matching degree of the target query model is weighted and summed to obtain the matching degree of the first candidate index. The number of hits for each target query model and its initial matching degree with the second candidate index are multiplied by a dot product to obtain the matching degree of the second candidate index by weighted summation of the initial matching degree of the target query model.

6. The method according to claim 5, characterized in that, For each target query model, the query attribute information contained in each query condition of the target query model is matched with the index information contained in the first candidate index to calculate the initial matching degree between the first candidate index and the target query model, including: Determine the target index information from the index information contained in the first candidate index; For each target query model, if the target index information is the same as the query attribute information corresponding to the first query condition in the target query model, then the initial matching degree between the first candidate index and the target query model under the first query condition is calculated based on the target index information. The associated index information of the target index information is determined as the target index information. The execution is returned for each target query model. If the target index information is the same as the query attribute information corresponding to the first query condition in the target query model, the initial matching degree between the first candidate index and the target query model under the first query condition is calculated based on the target index information until the target index information is the preset index information, and multiple initial matching degrees under the first query condition are obtained. Based on the multiple initial matching degrees under the first query condition, the initial matching degree between the first candidate index and the target query model is calculated.

7. An index generation apparatus, characterized in that, include: A data acquisition unit is used to acquire analysis data, which is obtained by analyzing the corresponding query model in response to a received data query request. The analysis data includes at least one query model, the query model includes a target query model, the query model includes at least one query condition, and each query condition includes at least one query attribute information. The first index generation unit is used to generate a first candidate index of the database corresponding to the data query request based on the frequency of each query attribute information corresponding to the first query condition of the target query model in the analyzed data. The second index generation unit is used to generate a second candidate index of the database based on the frequency of the target query attribute information corresponding to the second query condition of the target query model in the analyzed data. The target index determination unit is used to determine the target index of the database from the first candidate index and the second candidate index based on the matching degree between the first candidate index and the target query model, and the matching degree between the second candidate index and the target query model. The target query model is obtained as follows: The unprocessed query models with a hit count greater than a hit threshold are obtained from the analyzed data; for each unprocessed query model, the average response time of the unprocessed query model is calculated based on the response time of each query request corresponding to the unprocessed query model; for each unprocessed query model, the current index of the database is matched with the unprocessed query model to obtain the model matching degree of the unprocessed query model; the target query model is determined from the unprocessed query models based on the average response time and the model matching degree; wherein, the query models with a hit count greater than a hit threshold, an average response time greater than a first threshold, and a model matching degree less than a second threshold are selected as the target query models.

8. The apparatus according to claim 7, characterized in that, The first query condition includes a first sub-query condition and a second sub-query condition, and the second sub-query condition includes multiple types of second sub-query conditions; the first index generation unit includes a first determining module, a second determining module, and a first generating module; First determination module: used to determine the query attribute information of the first subquery condition whose frequency in the target query model of the analyzed data meets the preset condition as the first index information; The second determining module is used to determine the query attribute information corresponding to the second sub-query condition of the target type as the second index information if the target query model containing the first index information includes a second sub-query condition of the target type. First generation module: used to generate the first candidate index of the database corresponding to the data query request based on the first index information and the second index information.

9. The apparatus according to claim 7, characterized in that, The second query condition includes a third sub-query condition and a fourth sub-query condition, wherein the query attribute information included in the third sub-query condition has a query order; the second index generation unit includes an acquisition module, a third determination module, and a second generation module; Acquisition module: Used to acquire the frequency of each target query attribute information corresponding to the target query order of the third subquery condition in the target query model of the analysis data; The third determination module is used to determine the target query attribute information that meets preset conditions based on the frequency as the third index information; The second generation module is used to generate a second candidate index based on the same query attribute information and the third index information if the fourth subquery condition in the target query model containing the third index information has the same query attribute information.

10. The apparatus according to any one of claims 7 to 9, characterized in that, The index generation device further includes a receiving unit, an analysis unit, and a data generation unit; Receiving unit: Used to receive data query requests for the database; Analysis Unit: Used to analyze and process data query requests based on the query conditions carried by the data query request and the query attribute information contained in the query conditions, in order to determine the query model corresponding to the data query request and update the hit count of the model. The hit count represents the number of data query requests corresponding to the query model. Data generation unit: Used to generate analytical data based on the query model and the number of times the query model is hit.

11. The apparatus according to claim 7, characterized in that, The target index determination unit includes a matching module and a processing module; Matching module: For each target query model, the query attribute information contained in each query condition in the target query model is matched with the index information contained in the first candidate index to calculate the initial matching degree between the first candidate index and the target query model. And, for each target query model, to match the query attribute information contained in each query condition in the target query model with the index information contained in the second candidate index, so as to calculate the initial matching degree between the second candidate index and the target query model; Processing module: Used to perform dot product processing on the number of hits of each target query model and the initial matching degree with the first candidate index, so as to perform weighted summation on the initial matching degree of the target query model to obtain the matching degree of the first candidate index; And, to perform a dot product of the number of hits of each target query model and the initial matching degree with the second candidate index, so as to perform a weighted summation of the initial matching degree of the target query model to obtain the matching degree of the second candidate index.

12. The apparatus according to claim 11, characterized in that, The matching module includes a first determining submodule, a first calculating submodule, a second determining submodule, and a second calculating submodule; First determining submodule: used to determine target index information from the index information contained in the first candidate index; First calculation submodule: For each target query model, if the target index information is the same as the query attribute information corresponding to the first query condition in the target query model, then calculate the initial matching degree between the first candidate index and the target query model under the first query condition based on the target index information. The second determining submodule is used to determine the associated index information of the target index information as the target index information, and return to execute for each target query model. If the target index information is the same as the query attribute information corresponding to the first query condition in the target query model, then calculate the initial matching degree between the first candidate index and the target query model under the first query condition based on the target index information, until the target index information is the preset index information, and obtain multiple initial matching degrees under the first query condition. The second calculation submodule is used to calculate the initial matching degree between the first candidate index and the target query model based on multiple initial matching degrees under the first query condition.

13. A computer device, characterized in that, It includes a memory and a processor; the memory stores a computer program, and the processor is used to run the computer program in the memory to perform the index generation method according to any one of claims 1 to 6.

14. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store a computer program, which is loaded by a processor to perform the index generation method according to any one of claims 1 to 6.

15. A computer program product, characterized in that, The computer program product includes computer instructions stored in a computer-readable storage medium; the processor of the computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the index generation method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Data index search method, device and system

    CN103365883A

  • Data query method and device, storage medium and electronic equipment

    CN112905600A