Database query method and device
By introducing online learning classification models in the database query system to evaluate and update the availability of execution plans, the problem of inability to effectively manage and maintain execution plan cache in the prior art is solved, and query efficiency and stability are improved.
Patent Information
- Application Number
- CN202410870819.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2025-02-11
AI Technical Summary
When facing a dynamic workload environment with massive data, existing database query systems are unable to effectively manage and maintain execution plan caches, resulting in inefficient query.
By introducing online learning classification models, the availability of execution plans is evaluated, and the classification model is dynamically updated based on feedback parameters of data queries to adapt it to workload changes.
It effectively reduces the risk of slowing down the query process by inappropriate execution plans, improves the stability and efficiency of data queries, and adapts to the dynamic changes of workloads.
Smart Images

Figure CN119415555A_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of the present specification relate to the field of database technology, and in particular, to a database query method and device. Background Art
[0002] Parameterized query of database is a form of data query, which can not only effectively prevent malicious SQL (Structured Query Language) injection attacks, but also provide the possibility of reusing execution plans. Reusing execution plans means that when the database management system receives a query request, it calls the query optimizer to analyze the query parameters and build the lowest-cost execution plan to complete the data query. Once the execution plan is created, it can be cached and reused in subsequent queries of the same or similar type, without repeatedly calling the optimizer to analyze and create the execution plan, thus reducing overhead.
[0003] However, the execution plan reuse scheme in the related art generally adopts a fixed cache method, which cannot adapt to the dynamic workload environment of massive data, and cannot perform intelligent dynamic management and maintenance of the cache plan set. Summary of the invention
[0004] In order to improve the stability and efficiency of data query, the embodiments of this specification provide a database query method, device, database system, storage medium and computer program product.
[0005] In a first aspect, some embodiments of this specification provide a database query method, comprising:
[0006] Obtaining a data query instruction, and determining a target execution plan and a target classification model associated with the target execution plan from a pre-cached execution plan set according to the data query instruction; wherein the execution plan set includes one or more execution plans, and a classification model and a predicate selection rate associated with each execution plan;
[0007] Converting the data query instruction to obtain a predicate selection rate corresponding to the data query instruction, and inputting the predicate selection rate into the target classification model to obtain an output result of the target classification model, wherein the output result indicates whether the target execution plan is reusable;
[0008] In the case where the output result of the target classification model is reusable, executing data query based on the data query instruction and the target execution plan to obtain a query result;
[0009] A model update sample is generated according to the feedback parameters of the data query process, and the target classification model is updated using the model update sample.
[0010] In some implementations, determining a target execution plan from a set of pre-cached execution plans according to the data query instruction, and a target classification model associated with the target execution plan, includes:
[0011] Determine a query template required for data query according to the data query instruction, and determine a target execution plan set associated with the query template from a plurality of pre-cached execution plan sets;
[0012] Converting the data query instruction to obtain a predicate selection rate corresponding to the data query instruction;
[0013] The predicate selection rate corresponding to the data query instruction is matched with the predicate selection rate of each execution plan cached in the target execution plan set, and the target execution plan and the target classification model are determined according to the matching result.
[0014] In some embodiments, the database query method exemplified in this specification further includes:
[0015] In the case where the execution plan set is an empty set, calling a query optimizer of the database to generate a new execution plan based on the data query instruction;
[0016] Execute data query based on the new execution plan to obtain query results;
[0017] Acquire the classification model and predicate selection rate associated with the new execution plan, and cache the new execution plan and its associated classification model and predicate selection rate in an execution plan set;
[0018] A model update sample is generated according to the feedback parameter of the data query, and all classification models in the execution plan set are updated using the model update sample.
[0019] In some implementations, when the output result of the target classification model is reusable, executing the data query based on the data query instruction and the target execution plan to obtain the query result includes:
[0020] In the case where the output result of the target classification model is reusable, the variables of the query template in the target execution plan are updated using the data query instruction, and the data query is executed based on the updated target execution plan to obtain the query result.
[0021] In some embodiments, the database query method exemplified in this specification further includes:
[0022] In the case where the output result of the target classification model is not reusable, calling the query optimizer of the database to generate a new execution plan based on the data query instruction, and executing the data query based on the new execution plan to obtain the query result;
[0023] Determine whether the new execution plan has been cached in the execution plan set;
[0024] If the new execution plan has been cached in the execution plan set, generating a model update sample according to the feedback parameter of the data query, and using the model update sample to update the target classification model;
[0025] If the new execution plan is not cached in the execution plan set, obtain the classification model and predicate selection rate corresponding to the new execution plan, cache the new execution plan and its corresponding classification model and predicate selection rate in the execution plan set, generate a model update sample based on the feedback parameters of the data query, and use the model update sample to update all classification models in the execution plan set.
[0026] In some implementations, the generation of a model update sample and the process of updating the model using the model update sample include:
[0027] For each data query, if the output result corresponding to the data query is reusable, obtain the feedback parameters corresponding to the data query, and generate the model update sample based on the feedback parameters, wherein the feedback parameters include the query delay for executing the data query;
[0028] Comparing the query delay with a preset delay threshold, and determining positive and negative sample labels corresponding to the model update samples based on the comparison result;
[0029] The model is used to update the samples and their corresponding positive and negative sample labels, and supervised training is performed on the target classification model to complete the update of the target classification model.
[0030] In some implementations, comparing the query delay with a preset delay threshold, and determining the positive and negative sample labels corresponding to the model update samples based on the comparison result, includes:
[0031] In response to the query delay being greater than the preset delay threshold, marking the positive and negative sample labels corresponding to the model update samples as negative samples;
[0032] In response to the query delay being less than or equal to the preset delay threshold, the positive and negative sample labels corresponding to the model update samples are marked as positive samples.
[0033] In some embodiments, the database query method exemplified in this specification further includes:
[0034] For each data query, when the output result corresponding to the data query is not reusable and the new execution plan is not cached in the execution plan set, obtain the feedback parameters corresponding to the data query, and generate a model update sample based on the feedback parameters;
[0035] Marking the positive and negative sample labels corresponding to the model update samples as positive samples to perform update training on the first classification model, and marking the positive and negative sample labels corresponding to the model update samples as negative samples to perform update training on the second classification model;
[0036] The first classification model represents the classification model corresponding to the new execution plan generated for the data query, and the second classification model represents other classification models in the execution plan set.
[0037] In a second aspect, some embodiments of this specification provide a database query device, including:
[0038] A plan selection module is configured to obtain a data query instruction, and determine a target execution plan and a target classification model associated with the target execution plan from a pre-cached execution plan set according to the data query instruction; wherein the execution plan set includes one or more execution plans, and a classification model and a predicate selection rate associated with each execution plan;
[0039] a classification module configured to convert the data query instruction to obtain a predicate selection rate corresponding to the data query instruction, and input the predicate selection rate into the target classification model to obtain an output result of the target classification model, wherein the output result indicates whether the target execution plan is reusable;
[0040] A data query module is configured to execute a data query based on the data query instruction and the target execution plan to obtain a query result when the output result of the target classification model is reusable;
[0041] The model updating module is configured to generate a model updating sample according to the feedback parameters of the data query process, and use the model updating sample to update the target classification model.
[0042] In some implementations, the plan selection module is configured to:
[0043] Determine a query template required for data query according to the data query instruction, and determine a target execution plan set associated with the query template from a plurality of pre-cached execution plan sets;
[0044] Converting the data query instruction to obtain a predicate selection rate corresponding to the data query instruction;
[0045] The predicate selection rate corresponding to the data query instruction is matched with the predicate selection rate of each execution plan cached in the target execution plan set, and the target execution plan and the target classification model are determined according to the matching result.
[0046] In some implementations, the model updating module is configured to:
[0047] In the case where the execution plan set is an empty set, calling a query optimizer of the database to generate a new execution plan based on the data query instruction;
[0048] Execute data query based on the new execution plan to obtain query results;
[0049] Acquire the classification model and predicate selection rate associated with the new execution plan, and cache the new execution plan and its associated classification model and predicate selection rate in an execution plan set;
[0050] A model update sample is generated according to the feedback parameter of the data query, and all classification models in the execution plan set are updated using the model update sample.
[0051] In some implementations, the data query module is configured to:
[0052] In the case where the output result of the target classification model is reusable, the variables of the query template in the target execution plan are updated using the data query instruction, and the data query is executed based on the updated target execution plan to obtain the query result.
[0053] In some implementations, the model updating module is configured to:
[0054] In the case where the output result of the target classification model is not reusable, calling the query optimizer of the database to generate a new execution plan based on the data query instruction, and executing the data query based on the new execution plan to obtain the query result;
[0055] Determine whether the new execution plan has been cached in the execution plan set;
[0056] If the new execution plan has been cached in the execution plan set, generating a model update sample according to the feedback parameter of the data query, and using the model update sample to update the target classification model;
[0057] If the new execution plan is not cached in the execution plan set, obtain the classification model and predicate selection rate corresponding to the new execution plan, cache the new execution plan and its corresponding classification model and predicate selection rate in the execution plan set, generate a model update sample based on the feedback parameters of the data query, and use the model update sample to update all classification models in the execution plan set.
[0058] In some implementations, the model updating module is configured to:
[0059] For each data query, if the output result corresponding to the data query is reusable, obtain the feedback parameters corresponding to the data query, and generate the model update sample based on the feedback parameters, wherein the feedback parameters include the query delay for executing the data query;
[0060] Comparing the query delay with a preset delay threshold, and determining positive and negative sample labels corresponding to the model update samples based on the comparison result;
[0061] The model is used to update the samples and their corresponding positive and negative sample labels, and supervised training is performed on the target classification model to complete the update of the target classification model.
[0062] In some implementations, the model updating module is configured to:
[0063] In response to the query delay being greater than the preset delay threshold, marking the positive and negative sample labels corresponding to the model update samples as negative samples;
[0064] In response to the query delay being less than or equal to the preset delay threshold, the positive and negative sample labels corresponding to the model update samples are marked as positive samples.
[0065] In some implementations, the model updating module is configured to:
[0066] For each data query, when the output result corresponding to the data query is not reusable and the new execution plan is not cached in the execution plan set, obtain the feedback parameters corresponding to the data query, and generate a model update sample based on the feedback parameters;
[0067] Marking the positive and negative sample labels corresponding to the model update samples as positive samples to perform update training on the first classification model, and marking the positive and negative sample labels corresponding to the model update samples as negative samples to perform update training on the second classification model;
[0068] The first classification model represents the classification model corresponding to the new execution plan generated for the data query, and the second classification model represents other classification models in the execution plan set.
[0069] In a third aspect, some embodiments of this specification provide a database system, including:
[0070] processor;
[0071] A memory storing computer instructions, wherein the computer instructions are used to enable a processor to execute the method described in any embodiment of the first aspect.
[0072] In a fourth aspect, some embodiments of this specification provide a storage medium storing computer instructions, wherein the computer instructions are used to enable a computer to execute the method described in any embodiment of the first aspect.
[0073] In a fifth aspect, some embodiments of the present specification provide a computer program product, which, when executed, implements the steps of the method described in any embodiment of the first aspect.
[0074] The database query method of the implementation mode of this specification includes determining the target execution plan and the corresponding target classification model from the execution plan set according to the data query instruction, and using the target classification model to evaluate whether the target execution plan is reusable, performing data query based on the target execution plan if it is reusable, and performing online learning and updating of the target classification model according to the feedback parameters of the data query process. In the implementation mode of this specification, by introducing a classification model for each cached execution plan, the classification model is used to determine whether the execution plan is suitable for reuse in the actual query, thereby reducing the risk of inappropriate execution plans slowing down the query process, and the classification model can be dynamically updated in combination with feedback during the data query process, so that the model is continuously optimized through online learning, effectively responding to changes in workload, and improving the stability and efficiency of data query. BRIEF DESCRIPTION OF THE DRAWINGS
[0075] Figure 1 It is a flowchart of a database query method in some implementation modes of this specification.
[0076] Figure 2 It is a flowchart of the database query method in some implementation modes of this specification when the execution plan set is an empty set.
[0077] Figure 3 It is a flowchart of a database query method for determining a target execution plan in some implementation modes of this specification.
[0078] Figure 4 It is a flowchart of online learning of the target classification model of the database query method in some implementation modes of this specification.
[0079] Figure 5 It is a flowchart of the database query method in some implementation modes of this specification when the output results are not reusable.
[0080] Figure 6 It is an online learning flowchart of the database query method classification model in some implementation methods of this specification.
[0081] Figure 7 It is a structural block diagram of a database query device in some implementation modes of this specification.
[0082] Figure 8 It is a structural block diagram of the database system in some implementation methods of this specification. DETAILED DESCRIPTION
[0083] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this manual are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0084] A database is an application system used to store, manage and retrieve data. It can save a large amount of information in a structured way and can support multiple data models, such as relational model, document model, etc. The database can usually be used together with a database management system (DMBS, Digital Measuring Borescope System) to provide efficient storage, query and management of data.
[0085] Parameterized query is a form of database data query, which is characterized by using parameters (also called variables) to replace the coded values in the query statement. These parameters are used as placeholders, and only when the data query is executed will the actual user input data replace these parameters. Compared with ordinary SQL queries, in parameterized queries, even if there is an attacker injecting malicious SQL code, the system will only treat the malicious code as an ordinary string, and will not be executed as an SQL command, thereby achieving the purpose of preventing SQL injection attacks.
[0086] In addition, parameterized queries make it possible to reuse query execution plans. A query execution plan is a set of operation instructions generated by the system's query optimizer to determine how to execute SQL query statements, including the order in which data is accessed, the use of indexes, whether to perform a full table scan, etc.
[0087] When the system receives a query request, the query optimizer analyzes the query statement and considers multiple possible execution strategies. It estimates the costs of different execution strategies through, for example, a cost model, and selects the execution strategy with the lowest cost as the execution plan created for this query.
[0088] Once an execution plan is created, it can be cached for reuse in subsequent identical or similar queries. For example, when the same or similar query is received again, the system will detect whether there is an available cached execution plan suitable for this query. Even if the query parameter values are different, the cached execution plan can be reused. You only need to pass the new query parameters to the cached execution plan to complete the query. The reuse of execution plans means that the system does not need to repeatedly call the optimizer to generate a new plan when facing the same or similar queries, saving database resources and overhead and improving query efficiency.
[0089] In order to achieve efficient reuse of execution plans, the caching and management of execution plans are crucial. For example, if only a single or a small number of types of execution plans are cached, when faced with dynamically changing workloads, there are fewer reusable execution plans, and a large number of queries still need to fall back to the query optimizer to generate new execution plans. In addition, inappropriate reuse can easily lead to high query latency and reduce data query efficiency. If all execution plans are cached, not only will a large amount of storage resources be occupied, but the latency of matching execution plans will be high, resulting in reduced query efficiency. Therefore, caching and management of execution plans are crucial for database systems.
[0090] In the related technology, some solutions adopt the method of fixed cache plan set. This type of solution presets the distribution of workload and pre-caches all the execution plans that may be used in the preset scenario. The characteristic is that in the current work scenario, all queries have appropriate execution plans that have been cached, so the cached execution plan is fixed and unchanged. The reuse of the execution plan is to select the appropriate execution plan from the fixed cache plan set. However, this solution cannot be applied to dynamically changing workload scenarios. Since the cached execution plan is fixed, when the workload changes, the execution plan cached for the past workload may not be able to adapt to the new load scenario. It is impossible to adaptively adjust and update the cache according to the changes in workload, and there is a lack of effective cache maintenance and management mechanism.
[0091] Based on this, the embodiments of this specification provide a database query method, device, database system, storage medium and computer program product. By introducing a classification model that can be learned online, the availability evaluation of cached execution plans is achieved, reducing the risk of inappropriate execution plans slowing down the query process. The classification model can also be dynamically updated based on feedback during the data query process, so that the model can continuously learn and optimize, effectively respond to changes in workload, and improve the stability and efficiency of data queries.
[0092] First, for the convenience of understanding and the following description, some technical terms appearing in the following implementation methods are explained here:
[0093] 1) Query Parameter
[0094] Query parameters are the variable parts of a parameterized query, usually used to replace the encoded values in the query string. These parameters will be replaced by the values of the data query instructions actually entered by the user before the query is executed.
[0095] 2) Query Instance
[0096] A query instance is a specific query request, which is usually based on a query template and filled with specific query parameters. The query instance contains enough information to perform an actual database query operation.
[0097] 3) Query Template
[0098] A query template is a framework of a query structure, which protects one or more query parameters. By replacing the query parameters in the query template, the corresponding query instance can be generated.
[0099] 4) Predicate Selectivity
[0100] Predicate selectivity is a concept in database query optimization, which indicates the ratio of data records that can be filtered out by a filter condition (also called predicate) to the total data records. For example, in an example, suppose there is a data table in the database, which contains 10,000 user records, and the data table contains the "age" field. When executing a query "find all users older than 30 years old", in this example, the predicate is "age>30 years old". Assuming that a total of 6,000 users older than 30 years old are screened out, the predicate selectivity is 6000 / 10000=0.6. Predicate selectivity is usually used in query optimizers to predict the efficiency of different query execution plans.
[0101] Figure 1A flowchart of a database query method in some embodiments of this specification is shown below. Figure 1 Provide explanation.
[0102] like Figure 1 As shown, in some embodiments, the database query method exemplified in this specification includes:
[0103] S110: Obtain a data query instruction, and determine a target execution plan and a target classification model associated with the target execution plan from a set of pre-cached execution plans according to the data query instruction.
[0104] In the implementation manner of this specification, the database system needs to maintain a storage space, and the storage space is used to cache the execution plan set, and the execution plan set is used to cache the execution plan generated in the historical query.
[0105] In some implementations, all execution plans may be cached in one execution plan set, that is, the system only needs to maintain and manage one execution plan set.
[0106] In other embodiments, considering the various types of queries for large databases or cluster data, an execution plan set can be configured for each query template, and the execution plan set corresponding to each query template is used to cache various execution plans similar to the query template. This is described in the following embodiments of this specification.
[0107] In the implementation of this specification, in addition to caching execution plans, it is also necessary to configure a classification model associated with each execution plan. The role of the classification model is to evaluate whether the current data query is suitable for the cached execution plan associated with it. That is, in actual query, when the system selects a cached execution plan, it does not directly reuse the execution plan for the current data query, but uses the classification model associated with the execution plan to evaluate and determine whether the execution plan can be reused.
[0108] If the classification model determines that its associated execution plan can be reused, it means that the execution plan is suitable for the current query, and the execution plan can be reused to execute the data query. On the contrary, if the classification model determines that its associated execution plan cannot be reused, it means that the execution plan is not suitable for the current query, and reusing the execution plan will slow down the query process, so it is necessary to fall back to calling the query optimizer to create a new execution plan.
[0109] The purpose of doing so is to effectively cope with dynamic changes in workload. It is understandable that the execution plans in the cache plan set are generated during the historical query process. As the workload changes, the historical cached execution plans may no longer be suitable for the current query. If the execution plans are directly reused, not only will the query efficiency not be improved, but it may reduce the query efficiency. Therefore, in the implementation of this specification, the classification model can be used to determine whether the execution plan can be reused, and different strategies can be executed based on the results of the classification model.
[0110] In the implementation manner of this specification, the classification model can be a binary classification model, whose input can be the predicate selectivity of the data query instruction conversion of the current data query, and the output is a binary classification result of "yes" or "no", "yes" means that the execution plan can be reused, and "no" means that the execution plan cannot be reused. In the following implementation manner of this specification, the execution plan cache and the construction process of the classification model are explained.
[0111] In the implementation mode of this specification, a data query instruction refers to input data input by a user for querying data. The data query instruction may include one or more query conditions, each of which is a predicate. Therefore, one or more predicate selectivity rates may be converted according to the data query instruction. In an example, assuming that there is a users table in the database, and it is desired to find all male users older than 30 years old from the users table, the data query instruction may represent "age>30 years old, gender: male", where the conditions "age>30 years old" and "gender: male" are two predicate conditions.
[0112] During actual query, when the database system receives a data query instruction, it can select a cached execution plan that is closest to the current query from multiple execution plans included in a pre-cached execution plan set according to the data query instruction. This execution plan is the target execution plan, and the classification model associated with the target execution plan is the target classification model.
[0113] In some implementations, in addition to caching the execution plan and the classification model associated with each execution plan, the execution plan set also records the predicate selectivity corresponding to each execution plan. The predicate selectivity can be calculated when the execution plan is generated historically, and then cached together with the execution plan. Therefore, during actual query, the predicate selectivity of the current query can be calculated based on the data query instruction, and then the predicate selectivity is matched with the predicate selectivity of each execution plan in the execution plan set, and the execution plan with the closest predicate selectivity is determined as the target execution plan. This process is explained in the following implementation of this specification.
[0114] In some embodiments, the database system can determine the query template required for the current query based on the received data query instruction, and then select an execution plan set corresponding to the query template, and select a corresponding target execution plan from the execution plan set. This is explained in the following embodiments of this specification.
[0115] In the implementation manner of this specification, since the execution plans cached in the execution plan set are generated along with the data query tasks, the execution plan set may be empty when there are fewer data query tasks. During actual data query, if the execution plan set is an empty set, it means that there is no reusable cached execution plan in the execution plan set, and you can directly fall back to calling the query optimizer to generate the execution plan, and execute the data query process to obtain the query results. At the same time, the newly generated execution plan can be cached in the execution plan set according to the method process described below in this specification, thereby realizing dynamic caching of the execution plans in the execution plan set, which is explained in the implementation manner below in this specification.
[0116] In some implementations, considering that in some scenarios the user may only need to perform a small number of data query tasks and is not sensitive to the time delay of a single data query, the user may be provided with permission to choose whether to allow the reuse of the cached execution plan. If the user chooses not to allow the reuse of the execution plan, then there is no need to follow the implementation method of this specification, and the query optimizer can be directly called to generate a new execution plan and execute the data query. If the user chooses to allow the reuse of the execution plan, then it can be executed according to the implementation method of this specification. Those skilled in the art will undoubtedly understand this, and this specification will not be repeated.
[0117] S120 , performing data conversion on the data query instruction to obtain a predicate selectivity corresponding to the data query instruction, and inputting the predicate selectivity into a target classification model to obtain an output result of the target classification model.
[0118] As can be seen from the foregoing, the input of the classification model is the predicate selectivity. Therefore, in the implementation manner of this specification, the database system can convert the received data query instruction to obtain the predicate selectivity corresponding to the data query instruction.
[0119] For example, in the previous example, suppose there is a users table in the database, and it is desired to find all male users older than 30 years old from the users table, so that the data query instruction can be expressed as "age>30 years old, gender: male", where the conditions "age>30 years old" and "gender: male" are two predicate conditions. Then the query optimizer can determine the predicate selectivity corresponding to each predicate condition based on these two predicate conditions. The calculation process of the predicate selectivity has been described above, and this field can be understood by referring to the above, so it will not be repeated here. From the above examples, it can be seen that according to the different number of conditions in the data query instruction, the predicate selectivity obtained after conversion can be a single value or an array consisting of multiple element values.
[0120] After the predicate selectivity is obtained through conversion, the predicate selectivity is input into the target classification model obtained above. The target classification model outputs the corresponding binary classification result according to the prediction, which is the output result described in this specification. The output result indicates whether the target execution plan can be reused.
[0121] S130: When the output result of the target classification model is reusable, execute data query based on the data query instruction and the target execution plan to obtain the query result.
[0122] Combined with the above, it can be seen that if the output result of the target classification model is reusable, it means that the currently selected target execution plan is suitable for the current data query, so the target execution plan can be reused to execute this data query without calling the query optimizer to regenerate a new execution plan. In this case, the query parameters of the data query instruction can be passed to the target execution plan, and then the data query can be executed according to the target execution plan to obtain the corresponding query results, and the query results are returned to the user to complete the data query process.
[0123] In some implementations, during the parameterized query process, the input parameters of the current data query may not be exactly the same as the parameters of the target execution plan, but the target execution plan can also be reused. Specifically, the query template corresponding to the target execution plan can be determined first, and then the variables in the query template can be replaced and updated using the parameters in the data query instruction to update the target execution plan, and then the data query is executed according to the updated target execution plan to obtain the corresponding query result.
[0124] S140: Generate model update samples according to feedback parameters of the data query process, and use the model update samples to update the target classification model.
[0125] It should be noted that, in the implementation mode of this specification, each classification model in the execution plan set adopts the model optimization paradigm of online machine learning. It can be understood that online machine learning is different from traditional batch learning. Batch learning is to train and test the model on a fixed data set, while online machine learning needs to continuously update the model to adapt to new observations. For example, in the implementation mode of this specification, as the data query task is continuously carried out, it is necessary to collect the feedback parameters of the data query task, and use the feedback parameters to perform online learning and update these classification models, so as to ensure that the classification model can always learn the latest workload characteristics, so as to adapt to the dynamic changes of the workload.
[0126] In some embodiments, the feedback parameters of the data query may include relevant parameters that can reflect the effect of this data query, such as query delay, resource consumption, etc. Query delay refers to the time taken to execute this data query. The higher the query delay, the worse the performance of this data query. Resource consumption refers to the resources occupied by executing this data query. Resources may include, for example, CPU, memory, I / O, etc. The higher the resource consumption, the worse the performance of this data query. Of course, those skilled in the art will understand that the feedback parameters may also be other parameters and are not limited to the above examples.
[0127] In an example, the feedback parameter takes query delay as an example. During each data query, the query delay of this data query can be collected and recorded, and the query delay can be compared with a preset threshold.
[0128] If the query delay is greater than the threshold, it means that the use of the target execution plan to execute data queries does not improve the query efficiency, that is, the output result of the target classification model does not meet expectations. Therefore, the model update sample generated based on the feedback parameters should be a "negative sample" for the target classification model. Then, the generated model update sample is used as a negative sample to optimize and update the target classification model.
[0129] If the query delay is less than or equal to the threshold, it means that the use of the target execution plan to execute data query has improved the query effect, that is, the output result of the target classification model meets expectations. Therefore, the model update sample generated based on the feedback parameters should be a "positive sample" for the target classification model. Then, the generated model update sample is used as a positive sample to optimize and update the target classification model.
[0130] From the above, it can be seen that in the implementation mode of this specification, the feedback parameters determine whether the generated model update samples are positive samples or negative samples for the classification model, that is, the positive and negative sample labels (Lable) of the model update samples, which are used to indicate the true value (Groundtruth) of the sample data.
[0131] In the implementation manner of this specification, the model update sample needs to include at least the predicate selectivity of this data query as the input of the classification model. In some implementations, the model update sample used to update the classification model can be a six-tuple, which is represented by {predicate selectivity; target execution plan identifier; reuse judgment result; query optimizer call identifier; whether the generated plan has been cached; feedback parameter}. Among them, the predicate selectivity represents the predicate selectivity of this data query, which can be a numerical value or an array. The target execution plan identifier refers to the identifier corresponding to the target execution plan selected by the aforementioned S110, which is used to uniquely identify the target execution plan. The reuse judgment result is the output result of the target classification model, indicating whether the target execution plan can be reused. The query optimizer call identifier refers to whether the query optimizer is called to generate a new execution plan. Whether the generated plan has been cached refers to whether the newly generated execution plan has been cached in the execution plan set when the query optimizer is called to generate a new execution plan. The feedback parameter is the aforementioned query delay.
[0132] In the above data query execution process, each element in the six-tuple can be obtained by the system, so that a model update sample represented by the six-tuple can be constructed. In addition, in combination with the above process, the positive and negative sample labels of the model update sample can be determined according to the feedback parameters. Then, the target classification model can be optimized and updated using the model update sample, completing an online learning process for the target classification model.
[0133] In the following implementation of this specification, the online learning process of the classification model will be further explained, which is only described here.
[0134] From the above, it can be seen that in the implementation mode of this specification, by introducing a classification model for each cached execution plan, the classification model is used to determine whether the execution plan is suitable for reuse in the actual query, thereby reducing the risk of inappropriate execution plans slowing down the query process. In addition, the classification model can be dynamically updated in combination with feedback during the data query process, so that the model can continuously learn and optimize online, effectively respond to changes in workload, and improve the stability and efficiency of data queries.
[0135] In some implementations, the execution plan set may be configured according to the type of query template, that is, a corresponding execution plan set is configured for each query template, and each execution plan set is used to record the execution plan and the classification model and predicate selectivity associated with the execution plan. In some examples, the execution plan set described in this specification may be shown in Table 1 below:
[0136] Table 1
[0137]
[0138] In the example of Table 1, the execution plan set corresponding to query template 1 includes n (n is a positive integer greater than 3) records, the execution plan set corresponding to query template 2 includes 2 records, and the execution plan set corresponding to query template 3 includes 1 record. Each of them includes an execution plan, a classification model, and a predicate selectivity.
[0139] It can be understood that the execution plan is an execution plan generated by the query optimizer during the historical data query process, and the predicate selectivity can also be obtained during the data query process. Those skilled in the art can understand it by referring to the foregoing, and this specification will not go into details. The following describes the construction process of the classification model of each execution plan.
[0140] In some example implementations of this specification, the classification model adopts a binary classification model that can be learned online. The specific online learning model adopted can be an SRP (Streaming Random Patches) integrated model. The SRP model is an integrated learning model designed for data stream environments. Since the load and execution time of database queries are a dynamic and continuously changing process, SRP is more suitable as the classification model of this specification due to its characteristics of learning and quickly adapting to new data.
[0141] In the SRP integrated model, the selected base classifier can be, for example, an EFDT (Extremely Fast Decision Tree) model. EFDT is a decision tree model suitable for data streams. It has extremely high training speed and good classification performance. It can process and adapt to new data at a very fast speed, making it particularly suitable for online learning scenarios and reducing the maintenance overhead of the model.
[0142] As for the specific network results and principles of the SRP integrated model and the EFDT base classifier, those skilled in the art can understand and fully implement them by referring to the relevant technologies, and this specification will not elaborate on them.
[0143] Figure 2 The process of caching a newly generated execution plan when the execution plan set is an empty set is shown in the embodiment of this specification. Figure 2 Provide explanation.
[0144] like Figure 2 As shown, in some embodiments, the database query method exemplified in this specification includes:
[0145] S210: When the execution plan set is an empty set, call the query optimizer of the database to generate a new execution plan based on the data query instruction.
[0146] It can be understood that in the actual query process, when the system receives a data query instruction, it can determine the query template required for this data query according to the data query instruction, and then search from the pre-established execution plan set shown in Table 1. If the execution plan set corresponding to the query template is an empty set, it means that there is no reusable execution plan in the current execution plan set. In this case, it is necessary to fall back to calling the query optimizer to generate a new execution plan according to the data query instruction.
[0147] It is worth noting that the process and principle of the database to generate an execution plan through a query optimizer are all recorded and explained in the existing related technologies, and this manual will not repeat them.
[0148] S220: Execute data query based on the new execution plan to obtain query results.
[0149] After the database system calls the query optimizer to generate a new execution plan, the newly generated execution plan can be executed to complete the data query, obtain the corresponding query results and feed them back to the user.
[0150] S230: Obtain the classification model and predicate selection rate associated with the new execution plan, and cache the new execution plan and its associated classification model and predicate selection rate into an execution plan set.
[0151] In the implementation manner of this specification, the data query has been completed through the newly generated execution plan. At the same time, the execution plan needs to be cached so that when the same or similar queries come later, the execution plan can be directly reused.
[0152] As shown in Table 1 above, the content that needs to be cached includes the new execution plan, classification model, and predicate selection rate. Therefore, in the implementation of this specification, based on the model architecture described above, a classification model associated with the new execution plan can be built, and the predicate selection rate can be calculated through the above method process. This process can be referred to in the above text and will not be repeated here.
[0153] Then, the new execution plan, the generated classification model, and the predicate selection rate can be combined into a record and cached in the execution plan set to obtain a data structure such as that shown in Table 1.
[0154] S240: Generate model update samples according to feedback parameters of the data query, and use the model update samples to update all classification models in the execution plan set.
[0155] In the implementation manner of the present specification, each data query task may collect corresponding feedback parameters, the feedback parameters may be, for example, the aforementioned query delay, and then the aforementioned six-tuple is constructed in combination with the feedback parameters as a model update sample.
[0156] However, it is worth noting that for different classification models, the number of positive and negative sample labels for the same model update sample may be different.
[0157] For example, assuming that the newly generated execution plan by the query optimizer is execution plan A, the model update sample A is obtained by collecting the feedback parameters of the query process of execution plan A. This model update sample A is a "positive sample" for execution plan A, because execution plan A itself is generated for the current data query, so the classification model of execution plan A can definitely reuse the same query task. However, this model update sample A is a "negative sample" for a cached execution plan B, because execution plan B is not applicable to the current query and cannot be reused when the same query arrives.
[0158] Therefore, when using model update sample A to update and optimize all classification models, it is necessary to divide them into the following two categories for discussion:
[0159] 1) When using the newly generated model update sample A to train the classification model of the newly generated execution plan A, it is necessary to mark the model update sample A as a “positive sample” for online learning optimization;
[0160] 2) When using the newly generated model update sample A to train other classification models in the execution plan set, the model update sample A needs to be marked as a "negative sample" for online learning optimization.
[0161] Through the above process, the new execution plan is cached and all cached classification models are updated through online learning using new data query tasks.
[0162] Figure 3 The process of determining the target execution plan from the execution plan set in some embodiments of this specification is shown below. Figure 3 Provide explanation.
[0163] like Figure 3 As shown, in some implementations, the process of determining the target execution plan in the database query method exemplified in this specification includes:
[0164] S310: Determine a query template required for data query according to the data query instruction, and determine a target execution plan set corresponding to the query template from a plurality of pre-cached execution plan sets.
[0165] S320 , performing data conversion on the data query instruction to obtain a predicate selection rate corresponding to the data query instruction.
[0166] S330: Match the predicate selection rate corresponding to the data query instruction with the predicate selection rate of each execution plan cached in the target execution plan set, and determine the target execution plan and the target classification model according to the matching result.
[0167] In the implementation mode of this specification, during actual data query, the system receives the data query instruction input by the user, and then determines the query template required for the current data query based on the data query instruction, and then determines the execution plan set corresponding to the query template from the multiple execution plan sets shown in Table 1. This execution plan set is the target execution plan set described in this specification.
[0168] As can be seen from Table 1, the target execution plan set may be an empty set. If it is an empty set, refer to the above Figure 2 If it is not an empty set, the target execution plan set includes one or more execution plans, and the target execution plan needs to be determined from the one or more execution plans. In the implementation of this specification, the target execution plan can be determined by matching the predicate selectivity.
[0169] For example, in one example, the predicate selection rate of the current data query can be obtained by converting the data query instruction through the aforementioned method process, which is defined as the first predicate selection rate. Then, combined with Table 1, it can be seen that each execution plan in the target execution plan set records its corresponding predicate selection rate, which is defined as the second predicate selection rate.
[0170] Afterwards, the similarity between the first predicate selectivity and each second predicate selectivity can be calculated respectively. For example, in one example, the similarity can be expressed as the Euclidean distance. The Euclidean distance between the first predicate selectivity and each second predicate selectivity is calculated as the similarity. The execution plan with the highest similarity is selected as the target execution plan, and the classification model associated with the target execution plan is the target classification model.
[0171] Of course, those skilled in the art can understand that the method of matching predicate selectivity is not limited to the Euclidean distance for calculating predicate selectivity in the above example, and various methods such as mean square error can also be used, which is not limited in this specification.
[0172] Figure 4 In some embodiments of this specification, the process of online updating and optimizing the target classification model is shown in the case where the output result of the target classification model is reusable. Figure 4 Provide explanation.
[0173] like Figure 4 As shown, in some embodiments, the database query method exemplified in this specification, the online learning process of the target classification model includes:
[0174] S410: For each data query, if the output result corresponding to the data query is reusable, obtain the feedback parameter corresponding to the data query, and generate a model update sample based on the feedback parameter.
[0175] Take any data query as an example, combined with Figure 1 As can be seen from the implementation method, when the output result of the target classification model is reusable, it means that there is no need to call the query optimizer to generate a new execution plan. The target execution plan can be directly reused to complete the data query process. For this process, see Figure 1 The implementation method is sufficient and will not be elaborated here.
[0176] After the data query is completed, it is necessary to collect feedback parameters during the data query process. In the example of this manual, the feedback parameter still takes query delay as an example. By calculating the total time spent on the data query, the corresponding query delay can be obtained. Then, combined with the above, it can be known that parameters such as predicate selection rate, target execution plan identifier, reuse judgment result, query optimizer call identifier, and whether the generated plan has been cached can be further collected. Combined with the feedback parameters, a six-tuple {predicate selection rate; target execution plan identifier; reuse judgment result; query optimizer call identifier; whether the generated plan has been cached; feedback parameter} is formed. This six-tuple is a model update sample.
[0177] S420: Compare the query delay with a preset delay threshold, and determine the positive and negative sample labels corresponding to the model update samples based on the comparison result.
[0178] Combining the relevant technologies of model supervised training, it can be understood that during model training, the model updates samples as input to obtain output results, calculates the loss between the output results and the true labels by constructing a loss function, and then backpropagates and optimizes the model parameters based on the loss to achieve model iterative training.
[0179] In the implementation of this specification, the positive and negative sample labels are the ground truth of the model update sample, which indicates whether a model update sample is a positive sample or a negative sample for the target classification model. In the implementation of this specification, the query delay in the data query process is used to determine the positive and negative sample labels.
[0180] In some implementations, a preset delay threshold may be set by staff based on prior knowledge, and the threshold represents the critical value of the time taken for a certain data query. For a certain data query, the query delay of this data query may be compared with the preset delay threshold. If the query delay is greater than the preset delay threshold, it means that although the cached target execution plan is reused, it does not bring about an improvement in data query efficiency, indicating that the effect of the target classification model is not as expected. Therefore, the generated model update sample should be a "negative sample" for the target classification model, that is, the positive and negative sample labels of the model update sample can be marked as "negative samples". On the contrary, if the query delay is less than or equal to the preset delay threshold, it means that reusing the cached target execution plan brings about an improvement in query efficiency, indicating that the effect of the target classification model is as expected. Therefore, the generated model update sample should be a "positive sample" for the target classification model, that is, the positive and negative sample labels of the model update sample can be marked as "positive samples".
[0181] S430: Use the model update samples and their corresponding positive and negative sample labels to perform supervised training on the target classification model to complete the update of the target classification model.
[0182] It can be understood that after obtaining the model update samples and the positive and negative sample labels, the target classification model can be supervised trained. Specifically, the model update samples are input as sample data into the target classification model to obtain the output result of the target classification model prediction output, and then the loss between the output result and the positive and negative sample labels is calculated according to the pre-constructed loss function. After that, the parameters of the target classification model are back-propagated and optimized according to the loss to realize online learning update of the target classification model.
[0183] It is worth noting that when the output of the target classification model is reusable, the above Figure 4 The method process only performs online learning updates on the target classification model, and does not update other classification models in the execution plan set. This is because when a target execution plan is reused, the data query process is mainly affected by the effect of the target classification model and is not affected by other classification models. Therefore, only the target classification model needs to be trained.
[0184] Figure 5 A flowchart of a database query method when the output result of the target classification model is not reusable is shown in some embodiments of this specification. Figure 5 Provide explanation.
[0185] like Figure 5 As shown, in some embodiments, the database query method exemplified in this specification includes:
[0186] S510: When the output result of the target classification model is not reusable, the query optimizer of the database is called to generate a new execution plan based on the data query instruction, and the data query is executed based on the new execution plan to obtain the query result.
[0187] Referring to the aforementioned S110 to S120, if the output result of the target classification model is not reusable, it means that the selected target execution plan is not applicable to the current data query process. The possible reason is that the current workload has changed dynamically, and the historical execution plan is no longer applicable to the latest load scenario.
[0188] In this case, the system needs to call the query optimizer to generate a new execution plan for the current data query. Specifically, the query optimizer can obtain multiple query strategies based on the data query instructions, and evaluate the cost of each query strategy through a cost model, and select the query strategy with the lowest cost as the new execution plan.
[0189] After the database system calls the query optimizer to generate a new execution plan, the newly generated execution plan can be executed to complete the data query, obtain the corresponding query results and feed them back to the user.
[0190] S520, determine whether the new execution plan has been cached in the execution plan set, if so, execute S530, if not, execute S540.
[0191] S530: Generate model update samples according to feedback parameters of data query, and use the model update samples to update the target classification model.
[0192] S540, obtain the classification model and predicate selection rate corresponding to the new execution plan, cache the new execution plan and its corresponding classification model and maintenance selection rate into the execution plan set, generate model update samples according to the feedback parameters of the data query, and use the model update samples to update all classification models in the execution plan set.
[0193] In the implementation manner of this specification, for a newly generated execution plan, feedback parameters when executing the new execution plan can be collected, and a model update sample can be generated by constructing a six-tuple in the above manner.
[0194] In some embodiments, the new execution plan and its corresponding classification model and predicate selectivity can be cached in the execution plan set through the aforementioned method process, and then all the classification models in the execution plan set can be updated through online learning using the model update samples. However, it can be understood from the above that for the classification model of the new execution plan, the positive and negative sample labels of the model update samples are "positive samples", while for other classification models, the positive and negative sample labels of the model update samples are "negative samples", which will not be elaborated in this specification.
[0195] In other implementations, after obtaining the model update sample of the new execution plan, instead of using the model update sample to perform online update optimization on all classification models, it is determined whether the new execution plan has been cached in the execution plan set.
[0196] It is understandable that since the output result of the target classification model is not reusable, the system will call the query optimizer to generate a new execution plan. If the new execution plan has been cached in the execution plan set, it means that the screened target execution plan is similar to or the same as the newly generated execution plan, and should actually be reusable, which means that the output result of the target classification model deviates and does not meet expectations.
[0197] In this case, there is no need to cache the new execution plan repeatedly, but the target classification model needs to be updated and optimized online based on the model update samples. At this time, the model update samples should be "positive samples" for the target classification model, and the positive and negative sample labels of the model update samples can be marked as "positive samples" to train and optimize the target classification model. It can be understood that at this time, only the target classification model needs to be trained, and no other classification models need to be trained.
[0198] If the new execution plan is not cached in the execution plan set, it means that the new execution plan is a brand new plan, and there is no identical or similar execution plan in the historical execution plan set. In this case, according to the aforementioned method process, a new classification model can be generated for the new execution plan, the corresponding predicate selection rate can be calculated, and then cached according to the data results shown in Table 1.
[0199] After the new execution plan is cached, the generated model update samples can be used to perform online learning updates on all classification models in the execution plan set. For the classification model associated with the new execution plan, the positive and negative sample labels of the model update samples are marked as "positive samples", and for other classification models, the positive and negative sample labels of the model update samples are marked as "negative samples" to train all classification models.
[0200] From the above, it can be seen that in the implementation mode of this specification, when a new execution plan is generated, by determining whether the new execution plan has been cached in the execution plan set, repeated caching of the same or similar execution plans is avoided, which wastes storage space, and at the same time, simple and efficient management and maintenance of the execution plan cache is achieved.
[0201] like Figure 6 As shown, in some embodiments, the database query method exemplified in this specification includes:
[0202] S610: For each data query, when the output result corresponding to the data query is not reusable and the new execution plan is not cached in the execution plan set, obtain the feedback parameters corresponding to the data query, and generate a model update sample based on the feedback parameters.
[0203] S620: Mark the positive and negative sample labels corresponding to the model update samples as positive samples to perform update training on the first classification model, and mark the positive and negative sample labels corresponding to the model update samples as negative samples to perform update training on the second classification model.
[0204] Taking any data query as an example, if the output result of the target classification model is not repeatable, the query optimizer is called to generate a new execution plan, and it is further determined that the new execution plan is not cached in the execution plan set, that is, the situation described in the aforementioned S540. In this case, the data query is completed by executing the new execution plan, and the new execution plan and its corresponding classification model and predicate selectivity are cached in the execution plan set through the aforementioned method. At the same time, the corresponding feedback parameters and other parameters can be collected, and the six-tuple is constructed according to the feedback parameters and other parameters through the aforementioned method process to obtain the model update sample.
[0205] From the above, we can see that in this case, it is necessary to perform online update optimization on all classification models in the cache plan set based on the model update samples. However, combined with the above, for the classification models in the execution plan set, the positive and negative sample labels corresponding to the model update samples may also be different.
[0206] In the implementation manner of this specification, the classification model corresponding to the new execution plan is defined as the first classification model, and the other classification models are defined as the second classification models. For the first classification model, the positive and negative sample labels of the model update samples are marked as "positive samples", and for the second classification model, the positive and negative sample labels of the model update samples are marked as "negative samples", so as to train all classification models.
[0207] The specific process of model training is the same as the supervised training process mentioned above. Please refer to the above implementation process and will not be repeated here.
[0208] From the above, it can be seen that in the implementation of this specification, by introducing a classification model for each cached execution plan, the classification model is used to determine whether the execution plan is suitable for reuse in the actual query, thereby reducing the risk of inappropriate execution plans slowing down the query process, and the classification model can be dynamically updated in combination with feedback during the data query process, so that the model can continuously learn and optimize online, effectively respond to changes in workload, and improve the stability and efficiency of data queries. Moreover, when calling query optimization to generate a new execution plan, by determining whether the new execution plan has been cached in the execution plan set, repeated caching of the same or similar execution plans is avoided, which wastes storage space, and at the same time achieves simple and efficient management and maintenance of the execution plan cache.
[0209] In some embodiments, this specification provides a database query device, such as Figure 7 As shown, the device comprises:
[0210] The plan selection module 10 is configured to obtain a data query instruction, and determine a target execution plan and a target classification model associated with the target execution plan from a pre-cached execution plan set according to the data query instruction; wherein the execution plan set includes one or more execution plans, and a classification model and a predicate selection rate associated with each execution plan;
[0211] The classification module 20 is configured to convert the data query instruction to obtain a predicate selection rate corresponding to the data query instruction, and input the predicate selection rate into the target classification model to obtain an output result of the target classification model, wherein the output result indicates whether the target execution plan is reusable;
[0212] The data query module 30 is configured to execute data query based on the data query instruction and the target execution plan to obtain a query result when the output result of the target classification model is reusable;
[0213] The model updating module 40 is configured to generate a model updating sample according to the feedback parameters of the data query process, and use the model updating sample to update the target classification model.
[0214] In some implementations, the plan selection module 10 is configured to:
[0215] Determine a query template required for data query according to the data query instruction, and determine a target execution plan set associated with the query template from a plurality of pre-cached execution plan sets;
[0216] Converting the data query instruction to obtain a predicate selection rate corresponding to the data query instruction;
[0217] The predicate selection rate corresponding to the data query instruction is matched with the predicate selection rate of each execution plan cached in the target execution plan set, and the target execution plan and the target classification model are determined according to the matching result.
[0218] In some implementations, the model updating module 40 is configured to:
[0219] In the case where the execution plan set is an empty set, calling a query optimizer of the database to generate a new execution plan based on the data query instruction;
[0220] Execute data query based on the new execution plan to obtain query results;
[0221] Acquire the classification model and predicate selection rate associated with the new execution plan, and cache the new execution plan and its associated classification model and predicate selection rate in an execution plan set;
[0222] A model update sample is generated according to the feedback parameter of the data query, and all classification models in the execution plan set are updated using the model update sample.
[0223] In some implementations, the data query module 30 is configured to:
[0224] In the case where the output result of the target classification model is reusable, the variables of the query template in the target execution plan are updated using the data query instruction, and the data query is executed based on the updated target execution plan to obtain the query result.
[0225] In some implementations, the model updating module 40 is configured to:
[0226] In the case where the output result of the target classification model is not reusable, calling the query optimizer of the database to generate a new execution plan based on the data query instruction, and executing the data query based on the new execution plan to obtain the query result;
[0227] Determine whether the new execution plan has been cached in the execution plan set;
[0228] If the new execution plan has been cached in the execution plan set, generating a model update sample according to the feedback parameter of the data query, and using the model update sample to update the target classification model;
[0229] If the new execution plan is not cached in the execution plan set, obtain the classification model and predicate selection rate corresponding to the new execution plan, cache the new execution plan and its corresponding classification model and predicate selection rate in the execution plan set, generate a model update sample based on the feedback parameters of the data query, and use the model update sample to update all classification models in the execution plan set.
[0230] In some implementations, the model updating module 40 is configured to:
[0231] For each data query, if the output result corresponding to the data query is reusable, obtain the feedback parameters corresponding to the data query, and generate the model update sample based on the feedback parameters, wherein the feedback parameters include the query delay for executing the data query;
[0232] Comparing the query delay with a preset delay threshold, and determining positive and negative sample labels corresponding to the model update samples based on the comparison result;
[0233] The model is used to update the samples and their corresponding positive and negative sample labels, and supervised training is performed on the target classification model to complete the update of the target classification model.
[0234] In some implementations, the model updating module 40 is configured to:
[0235] In response to the query delay being greater than the preset delay threshold, marking the positive and negative sample labels corresponding to the model update samples as negative samples;
[0236] In response to the query delay being less than or equal to the preset delay threshold, the positive and negative sample labels corresponding to the model update samples are marked as positive samples.
[0237] In some implementations, the model updating module 40 is configured to:
[0238] For each data query, when the output result corresponding to the data query is not reusable and the new execution plan is not cached in the execution plan set, obtain the feedback parameters corresponding to the data query, and generate a model update sample based on the feedback parameters;
[0239] Marking the positive and negative sample labels corresponding to the model update samples as positive samples to perform update training on the first classification model, and marking the positive and negative sample labels corresponding to the model update samples as negative samples to perform update training on the second classification model;
[0240] The first classification model represents the classification model corresponding to the new execution plan generated for the data query, and the second classification model represents other classification models in the execution plan set.
[0241] In some embodiments, this specification provides a database system, including:
[0242] processor;
[0243] A memory stores computer instructions, wherein the computer instructions are used to enable a processor to execute the method described in any of the above embodiments.
[0244] In some embodiments, the present specification provides a storage medium storing computer instructions, wherein the computer instructions are used to enable a computer to execute the method described in any of the above embodiments.
[0245] In some embodiments, the present specification provides a computer program product, which implements the steps of the method described in any of the above embodiments when executed.
[0246] Figure 8 is a schematic diagram of a database system provided by an exemplary embodiment. Figure 8 At the hardware level, the device includes a processor 702, an internal bus 704, a network interface 706, a memory 708, and a non-volatile memory 710, and may also include hardware required for other functions. One or more embodiments of this specification may be implemented based on software, such as the processor 702 reading the corresponding computer program from the non-volatile memory 710 into the memory 708 and then running it. Of course, in addition to the software implementation, one or more embodiments of this specification do not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
Claims
1. A database query method, comprising: Obtaining a data query instruction, and determining a target execution plan and a target classification model associated with the target execution plan from a pre-cached execution plan set according to the data query instruction; wherein the execution plan set includes one or more execution plans, and a classification model and a predicate selection rate associated with each execution plan; Converting the data query instruction to obtain a predicate selection rate corresponding to the data query instruction, and inputting the predicate selection rate into the target classification model to obtain an output result of the target classification model, wherein the output result indicates whether the target execution plan is reusable; In the case where the output result of the target classification model is reusable, executing data query based on the data query instruction and the target execution plan to obtain a query result; A model update sample is generated according to the feedback parameters of the data query process, and the target classification model is updated using the model update sample.
2. The method according to claim 1, wherein determining a target execution plan from a set of pre-cached execution plans according to the data query instruction, and a target classification model associated with the target execution plan, comprises: Determine a query template required for data query according to the data query instruction, and determine a target execution plan set associated with the query template from a plurality of pre-cached execution plan sets; Converting the data query instruction to obtain a predicate selection rate corresponding to the data query instruction; The predicate selection rate corresponding to the data query instruction is matched with the predicate selection rate of each execution plan cached in the target execution plan set, and the target execution plan and the target classification model are determined according to the matching result.
3. The method according to claim 1, further comprising: In the case where the execution plan set is an empty set, calling a query optimizer of the database to generate a new execution plan based on the data query instruction; Execute data query based on the new execution plan to obtain query results; Acquire the classification model and predicate selection rate associated with the new execution plan, and cache the new execution plan and its associated classification model and predicate selection rate in an execution plan set; A model update sample is generated according to the feedback parameter of the data query, and all classification models in the execution plan set are updated using the model update sample.
4. The method according to claim 1, wherein when the output result of the target classification model is reusable, executing the data query based on the data query instruction and the target execution plan to obtain the query result comprises: In the case where the output result of the target classification model is reusable, the variables of the query template in the target execution plan are updated using the data query instruction, and the data query is executed based on the updated target execution plan to obtain the query result.
5. The method according to claim 1, further comprising: In the case where the output result of the target classification model is not reusable, calling the query optimizer of the database to generate a new execution plan based on the data query instruction, and executing the data query based on the new execution plan to obtain the query result; Determine whether the new execution plan has been cached in the execution plan set; If the new execution plan has been cached in the execution plan set, generating a model update sample according to the feedback parameter of the data query, and using the model update sample to update the target classification model; If the new execution plan is not cached in the execution plan set, obtain the classification model and predicate selection rate corresponding to the new execution plan, cache the new execution plan and its corresponding classification model and predicate selection rate in the execution plan set, generate a model update sample based on the feedback parameters of the data query, and use the model update sample to update all classification models in the execution plan set.
6. The method according to any one of claims 1 to 5, wherein the generation of the model update sample and the process of updating the model using the model update sample comprises: For each data query, if the output result corresponding to the data query is reusable, obtain the feedback parameters corresponding to the data query, and generate the model update sample based on the feedback parameters, wherein the feedback parameters include the query delay for executing the data query; Comparing the query delay with a preset delay threshold, and determining positive and negative sample labels corresponding to the model update samples based on the comparison result; The model is used to update the samples and their corresponding positive and negative sample labels, and supervised training is performed on the target classification model to complete the update of the target classification model.
7. The method according to claim 6, comparing the query delay with a preset delay threshold, and determining the positive and negative sample labels corresponding to the model update samples based on the comparison result, comprising: In response to the query delay being greater than the preset delay threshold, marking the positive and negative sample labels corresponding to the model update samples as negative samples; In response to the query delay being less than or equal to the preset delay threshold, the positive and negative sample labels corresponding to the model update samples are marked as positive samples.
8. The method according to claim 6, further comprising: For each data query, when the output result corresponding to the data query is not reusable and the new execution plan is not cached in the execution plan set, obtain the feedback parameters corresponding to the data query, and generate a model update sample based on the feedback parameters; Marking the positive and negative sample labels corresponding to the model update samples as positive samples to perform update training on the first classification model, and marking the positive and negative sample labels corresponding to the model update samples as negative samples to perform update training on the second classification model; The first classification model represents the classification model corresponding to the new execution plan generated for the data query, and the second classification model represents other classification models in the execution plan set.
9. A database query device, comprising: A plan selection module is configured to obtain a data query instruction, and determine a target execution plan and a target classification model associated with the target execution plan from a pre-cached execution plan set according to the data query instruction; wherein the execution plan set includes one or more execution plans, and a classification model and a predicate selection rate associated with each execution plan; a classification module configured to convert the data query instruction to obtain a predicate selection rate corresponding to the data query instruction, and input the predicate selection rate into the target classification model to obtain an output result of the target classification model, wherein the output result indicates whether the target execution plan is reusable; A data query module is configured to execute a data query based on the data query instruction and the target execution plan to obtain a query result when the output result of the target classification model is reusable; The model updating module is configured to generate a model updating sample according to the feedback parameters of the data query process, and use the model updating sample to update the target classification model.
10. A database system comprising: processor; A memory storing computer instructions, wherein the computer instructions are used to enable a processor to execute the method according to any one of claims 1 to 8.
11. A storage medium storing computer instructions, wherein the computer instructions are used to enable a computer to execute the method according to any one of claims 1 to 8.
12. A computer program product, wherein when the computer program product is executed, the steps of the method according to any one of claims 1 to 8 are implemented.