Database self-adaptive mixed data partitioning method and system based on reinforcement learning
Based on the method of strengthening learning, the data partition scheme of the database dynamically adjusts the database, the problem of querying the load access to the redundant data in the existing technology, and the adaptive data partition of the dynamic workload, which improves the database query efficiency.
Patent Information
- Application Number
- CN202411519197.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-29
- Publication Date
- 2025-01-24
- Estimated Expiration
- 2044-10-29
AI Technical Summary
Existing data partitioning schemes still require access to a large amount of redundant data when querying load execution, and cannot implement adaptive data partitioning for dynamic workloads.
A database adaptive hybrid data partitioning method based on reinforcement learning is adopted. By collecting database table information and historical query workload information, a reinforcement learning model and query workload prediction model are established, and the data partitioning scheme is dynamically adjusted to reduce redundant data access.
It effectively reduces the amount of data that needs to be accessed when executing query loads, realizes adaptive data partitioning for dynamic workloads, and improves database query efficiency.
Smart Images

Figure CN119357239A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of artificial intelligence, and in particular relates to a database adaptive hybrid data partitioning method and system based on reinforcement learning. Background Art
[0002] The queries in the database query load are usually only related to part of the data. The purpose of database partitioning is to skip as much data as possible that is not related to the query when the load is executed. Existing data partitioning schemes include horizontal partitioning schemes, vertical partitioning schemes, and horizontal-vertical hybrid partitioning schemes. However, under these data partitioning strategies, a large amount of redundant data still needs to be accessed when the query load is executed, and adaptive data partitioning for dynamic query workloads cannot be achieved.
[0003] Therefore, in order to solve the problem that under the existing data partitioning scheme, query load still needs to access a large amount of redundant data when executing, and cannot automatically perform adaptive data partitioning for dynamic workloads, it is necessary to propose a new database adaptive hybrid data partitioning method. Summary of the invention
[0004] The purpose of the present invention is to solve the problem that under the existing data partitioning scheme, a large amount of redundant data needs to be accessed when executing the query load and the data cannot be automatically adaptively partitioned according to the dynamic workload. A database adaptive hybrid data partitioning method and system based on reinforcement learning is proposed.
[0005] The technical solution adopted by the present invention to solve the above technical problems is:
[0006] According to one aspect of the present invention, a method for adaptive hybrid data partitioning of a database based on reinforcement learning comprises the following steps:
[0007] Step 1: Collect information of each table in the database, historical query workload information, and data partitioning scheme corresponding to the historical query workload information;
[0008] Step 2: Use the table information and historical query workload information in the database as the state of the reinforcement learning model agent, use the table information and historical query workload information collected in step 1 to train the reinforcement learning model agent, and use the data partitioning scheme corresponding to the historical query workload information as the label for agent training;
[0009] Step 3: Establish a query workload prediction model, and use historical query workload information to train the established query workload prediction model;
[0010] Step 4: According to the number of times each type of query workload appears in the current time step and the number of times each type of query workload appears in p-1 historical time steps, time series data of the number of times each type of query workload appears as a function of the time step are obtained;
[0011] Then, the time series data corresponding to various types of query workloads are respectively input into the trained query workload prediction model, and the trained query workload prediction model outputs the predicted frequencies of various types of query workloads in the next time step, and the query workload type i' corresponding to the predicted maximum frequency is obtained; at the start time of the next time step, the data partitioning scheme is initialized to the data partitioning scheme corresponding to the query workload type i';
[0012] Step 5: Initialize k=1;
[0013] Step 6: Determine whether the k-th query workload arriving in the next time step is of the same type as the query workload corresponding to the current data partitioning scheme;
[0014] If they are the same, use the current data partitioning scheme to query directly, and then execute step 7;
[0015] If they are not the same, the kth query workload is input into the trained reinforcement learning model, and the query is performed again after the trained agent outputs the new data partitioning scheme, and then step seven is continued;
[0016] Step 7: Determine whether the next time step is over;
[0017] If the next time step has not ended, set k=k+1 and return to step 6;
[0018] If the next time step ends, return to step 4.
[0019] According to another aspect of the present invention, a database adaptive hybrid data partitioning system based on reinforcement learning, the system includes an information collection module, a reinforcement learning model, a query workload prediction model and a data partitioning module, wherein:
[0020] The information collection module is used to collect information of each table in the database, historical query workload information, and data partitioning scheme corresponding to the historical query workload information;
[0021] The historical query workload information includes each query statement and the execution time of each query statement;
[0022] The reinforcement learning model is trained according to the information collected by the information collection module, and the intelligent agent of the trained reinforcement learning model is used to output the data partitioning scheme;
[0023] The action of the agent is: after the query statement is input, the agent takes the action of adding rows, adding columns, deleting rows, deleting columns, merging partitions, splitting partitions or deleting partitions on the current state; the reward obtained by the agent after performing the action is:
[0024]
[0025] Among them, reward t is the reward obtained by the agent after executing the action at the current time t; cost t is the size of the partition where the query result is located after entering the query statement under the data partitioning scheme at the current time t; cost t-1 It is the size of the partition where the query result is located after the query statement is entered under the data partitioning scheme at time t-1;
[0026] The query workload prediction model is trained based on the historical query workload information collected by the information collection module, and the trained query workload prediction model is used to predict the future occurrence frequency of various types of query workloads;
[0027] The working process of the query workload prediction model is as follows:
[0028] Step 1: Set the time step T, and then count the number of times each type of historical query workload appears in each time step. The number of times the i-th type of historical query workload appears in the j-th time step is recorded as a ij , i = 1, 2, ..., I, j = 1, 2, ..., J, I is the number of types of historical query workloads, and J is the total number of time steps;
[0029] Then, for each type of historical query workload, time series data of the number of occurrences of the query workload changing with the time step is obtained;
[0030] Step 2: Cluster the time series data corresponding to various types of historical query workloads to obtain the time series data in each cluster;
[0031] For a cluster that contains only one set of time series data, there is no need to process the time series data in the cluster, that is, the time series data in the cluster is directly used as the fitting time series data of the cluster;
[0032] For clusters containing two or more groups of time series data, each group of time series data in a cluster is fitted into one group of time series data, and the time series data obtained by fitting is used as the fitting time series data of the cluster;
[0033] Step 3: For the kth cluster, the number of occurrences of the query workload corresponding to the 1st time step to the pth time step on the fitting time series data corresponding to the kth cluster is used as a training sample, and the number of occurrences of the query workload corresponding to the p+1th time step on the fitting time series data corresponding to the kth cluster is used as the label of the training sample;
[0034] Where k = 1, 2, ..., K, K is the total number of categories obtained by clustering;
[0035] Step 4: Use all the training samples obtained in step 3 to train the query workload prediction model;
[0036] In the query workload prediction model, the training samples are passed through the DLinear model and the Transformer model respectively, and then the output of the DLinear model and the output of the Transformer model are fused, and the fusion result is used as the query workload prediction result;
[0037] Then, the loss is calculated based on the prediction results and labels, and the training is stopped when the loss converges to obtain the trained query workload prediction model.
[0038] The data partitioning module is used to generate a data partitioning scheme according to the prediction results of the query workload prediction model and the intelligent agent of the trained reinforcement learning model.
[0039] The beneficial effects of the present invention are:
[0040] The present invention proposes an adaptive hybrid data partitioning technology based on reinforcement learning. The database data partitioning problem is established as a Markov decision process. The reinforcement learning model is trained using Q learning. At the same time, a query workload prediction model is constructed to find the frequency of various types of queries in the query workload in the next time period, and intelligently recommend appropriate data partitioning schemes.
[0041] 1. Establish a workload prediction model to predict the frequency of various queries in the database query workload in the future based on historical workload, so as to facilitate subsequent calls.
[0042] 2. The hybrid data partitioning problem is modeled as a Markov decision process, and the agent states, actions, and rewards are defined. The trained reinforcement learning model can adaptively recommend a suitable hybrid data partitioning scheme for the incoming query workload, reducing the amount of data that needs to be accessed when executing the query workload. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Figure 1 is a flow chart of the method of the present invention. DETAILED DESCRIPTION
[0044] Specific implementation method 1: Combination Figure 1 The present embodiment describes a method for adaptive hybrid data partitioning of a database based on reinforcement learning, and the method specifically comprises the following steps:
[0045] Step 1: Collect information of each table in the database, historical query workload information, and data partitioning scheme corresponding to the historical query workload information;
[0046] Step 2: Model the data partitioning process as a Markov decision process, use the table information and historical query workload information in the database as the state of the reinforcement learning model (DDQN) agent, use the table information and historical query workload information collected in step 1 to train the agent of the reinforcement learning model, and use the data partitioning scheme corresponding to the historical query workload information as the label of the agent training;
[0047] The agent is a deep neural network that fits the Q function. The Q function describes the expected total reward for executing action a in a certain state s, so that the best action can be selected in the current state. In each round of iterative training, the agent will choose to execute an action. According to the reward function, the reward value for the executed action can be generated, thereby generating the corresponding loss value and optimizing the parameters of the agent. The trained agent can be used to generate a data partitioning scheme.
[0048] Step 3: Establish a query workload prediction model, and use historical query workload information to train the established query workload prediction model;
[0049] Step 4: According to the number of times each type of query workload appears in the current time step and the number of times each type of query workload appears in p-1 historical time steps, time series data of the number of times each type of query workload appears as a function of the time step are obtained;
[0050] Then, the time series data corresponding to various types of query workloads are respectively input into the trained query workload prediction model, and the trained query workload prediction model outputs the predicted frequencies of various types of query workloads in the next time step, and the query workload type i' corresponding to the predicted maximum frequency is obtained; at the start time of the next time step, the data partitioning scheme is initialized to the data partitioning scheme corresponding to the query workload type i';
[0051] Step 5: Initialize k=1;
[0052] Step 6: Determine whether the k-th query workload arriving in the next time step is of the same type as the query workload corresponding to the current data partitioning scheme;
[0053] If they are the same, use the current data partitioning scheme to query directly, and then execute step 7;
[0054] If they are not the same, the kth query workload is input into the trained reinforcement learning model, and the query is performed again after the trained agent outputs the new data partitioning scheme, and then step seven is continued;
[0055] If the types of query workloads that have arrived before are the same as the query workload type i', there is no need to update the current data partitioning scheme temporarily. When a different type of load arrives, the data partitioning scheme is updated and the load type corresponding to the updated data partitioning scheme is compared with the newly arrived load type. If they are consistent, there is no need to update the data partitioning scheme this time. Otherwise, the data partitioning scheme continues to be updated.
[0056] Step 7: Determine whether the next time step is over;
[0057] If the next time step has not ended, set k=k+1 and return to step 6;
[0058] If the next time step ends, the latest time step is used as the current time step, and then return to step 4.
[0059] The database of the present invention can adaptively perform hybrid data partitioning according to the query workload, and at the same time, by predicting the frequency of each type of query in the query workload of the next time step, and judging whether the query workload has undergone a significant change, it is determined whether the data partitioning scheme needs to be regenerated. This not only avoids the training overhead and re-layout overhead caused by the frequent generation of data partitions, but also generates the corresponding data partitioning scheme before the new query workload arrives, thereby improving the database query efficiency.
[0060] Specific implementation method 2: This implementation method is different from specific implementation method 1 in that the information of each table in the database includes the size of the table, the number of tuples, the number of attributes and the size of each attribute.
[0061] The other steps and parameters are the same as those in the first embodiment.
[0062] Specific implementation method three: This implementation method is different from specific implementation methods one or two in that the historical query workload information includes each query statement and the execution time of each query statement.
[0063] The other steps and parameters are the same as those in the first or second embodiment.
[0064] Specific implementation method 4: This implementation method is different from any one of specific implementation methods 1 to 3 in that the data partitioning scheme is the partitioning result of each table in the database.
[0065] The other steps and parameters are the same as those in Specific Embodiments 1 to 3.
[0066] Specific implementation method 5: This implementation method is different from the specific implementation methods 1 to 4 in that the
[0067] The actions of the agent are: after the query statement is entered, the agent takes the following actions on the current state: add rows, add columns, delete rows, delete columns, merge partitions, split partitions, or delete partitions.
[0068] The other steps and parameters are the same as those in Specific Embodiments 1 to 4.
[0069] Specific implementation method 6: This implementation method is different from any one of the specific implementation methods 1 to 5 in that the reward obtained by the agent after performing an action in the reinforcement learning model is:
[0070]
[0071] Among them, reward t is the reward obtained by the agent after executing the action at the current time t; cost t is the size of the partition where the query result is located after entering the query statement under the data partitioning scheme at the current time t; cost t-1 It is the size of the partition where the query result is located after the query statement is entered under the data partitioning scheme at time t-1.
[0072] The other steps and parameters are the same as those in Specific Implementation Methods 1 to 5.
[0073] Specific implementation method seven: This implementation method is different from any one of specific implementation methods one to six in that the query workload prediction model includes a DLinear model and a Transformer model.
[0074] The other steps and parameters are the same as those in Specific Embodiments 1 to 6.
[0075] Specific implementation eight: This implementation differs from specific implementations one to seven in that the specific process of step three is as follows:
[0076] Step 3: Set the time step T, and then count the number of times each type of historical query workload appears in each time step. The number of times the i-th type of historical query workload appears in the j-th time step is recorded as a ij , i = 1, 2, ..., I, j = 1, 2, ..., J, I is the number of types of historical query workloads, and J is the total number of time steps;
[0077] For example, the time from 0 to T is taken as the first time step, the time from T to 2T is taken as the second time step, and so on;
[0078] Then, for each type of historical query workload, time series data of the number of occurrences of the query workload changing with the time step is obtained;
[0079] That is, each time step corresponds to I values, and the I values are the number of times each type of historical query workload appears in a time step. For a query workload, the number of times this type of query workload appears in each time step constitutes a set of time series data of the change of this type of query workload with the time step;
[0080] Step 32: Cluster the time series data corresponding to various types of historical query workloads to obtain the time series data in each cluster; that is, cluster the time series data with similar change trends and data at each time point into one category;
[0081] For a cluster that contains only one set of time series data, there is no need to process the time series data in the cluster, that is, the time series data in the cluster is directly used as the fitting time series data of the cluster;
[0082] For clusters containing two or more groups of time series data, each group of time series data in a cluster is fitted into one group of time series data, and the time series data obtained by fitting is used as the fitting time series data of the cluster;
[0083] Step 33: For the kth cluster, the number of occurrences of the query workload corresponding to the 1st time step to the pth time step on the fitting time series data corresponding to the kth cluster is used as a training sample, and the number of occurrences of the query workload corresponding to the p+1th time step on the fitting time series data corresponding to the kth cluster is used as the label of the training sample;
[0084] Where k = 1, 2, ..., K, K is the total number of categories obtained by clustering;
[0085] It should be noted that the value of p can be set according to actual conditions. For example, when p = 10, the number of occurrences of the query workload corresponding to the 1st time step to the 10th time step can be used as a training sample, and the number of occurrences of the query workload corresponding to the 11th time step can be used as a label. Then, using a sliding window method, the number of occurrences of the query workload corresponding to the 2nd time step to the 11th time step can be used as a training sample, and the number of occurrences of the query workload corresponding to the 12th time step can be used as a label; and so on.
[0086] Step 34: train the query workload prediction model using all the training samples obtained in step 33;
[0087] In the query workload prediction model, the training samples are passed through the DLinear model and the Transformer model respectively, and then the output of the DLinear model and the output of the Transformer model are fused, and the fusion result is used as the query workload prediction result;
[0088] The loss is then calculated based on the prediction results and labels, and the training is stopped when the loss converges to obtain a trained query workload prediction model.
[0089] The other steps and parameters are the same as those in Specific Embodiments 1 to 7.
[0090] The hybrid partitioning strategy proposed in the present invention is compared with the partitioning strategies obtained by other classic algorithms under different data sets and workloads. A large number of comparative experiments prove that the method proposed in the present invention has good performance. Compared with the most advanced methods, its running time is shortened by an average of 35.67% and the scanning size is reduced by an average of 46.67%.
[0091] Specific implementation method 9: A database adaptive hybrid data partitioning system based on reinforcement learning described in this implementation method includes an information collection module, a reinforcement learning model, a query workload prediction model and a data partitioning module, wherein:
[0092] The information collection module is used to collect information of each table in the database, historical query workload information, and data partitioning scheme corresponding to the historical query workload information;
[0093] The historical query workload information includes each query statement and the execution time of each query statement;
[0094] The reinforcement learning model is trained according to the information collected by the information collection module, and the intelligent agent of the trained reinforcement learning model is used to output the data partitioning scheme;
[0095] The action of the agent is: after the query statement is input, the agent takes the action of adding rows, adding columns, deleting rows, deleting columns, merging partitions, splitting partitions or deleting partitions on the current state; the reward obtained by the agent after performing the action is:
[0096]
[0097] Among them, reward t is the reward obtained by the agent after executing the action at the current time t; cost tis the size of the partition where the query result is located after entering the query statement under the data partitioning scheme at the current time t; cost t-1 It is the size of the partition where the query result is located after the query statement is entered under the data partitioning scheme at time t-1;
[0098] The query workload prediction model is trained based on the historical query workload information collected by the information collection module, and the trained query workload prediction model is used to predict the future occurrence frequency of various types of query workloads;
[0099] The working process of the query workload prediction model is as follows:
[0100] Step 1: Set the time step T, and then count the number of times each type of historical query workload appears in each time step. The number of times the i-th type of historical query workload appears in the j-th time step is recorded as a ij , i = 1, 2, ..., I, j = 1, 2, ..., J, I is the number of types of historical query workloads, and J is the total number of time steps;
[0101] Then, for each type of historical query workload, time series data of the number of occurrences of the query workload changing with the time step is obtained;
[0102] Step 2: Cluster the time series data corresponding to various types of historical query workloads to obtain the time series data in each cluster;
[0103] For a cluster that contains only one set of time series data, there is no need to process the time series data in the cluster, that is, the time series data in the cluster is directly used as the fitting time series data of the cluster;
[0104] For clusters containing two or more groups of time series data, each group of time series data in a cluster is fitted into one group of time series data, and the time series data obtained by fitting is used as the fitting time series data of the cluster;
[0105] Step 3: For the kth cluster, the number of occurrences of the query workload corresponding to the 1st time step to the pth time step on the fitting time series data corresponding to the kth cluster is used as a training sample, and the number of occurrences of the query workload corresponding to the p+1th time step on the fitting time series data corresponding to the kth cluster is used as the label of the training sample;
[0106] Where k = 1, 2, ..., K, K is the total number of categories obtained by clustering;
[0107] Step 4: Use all the training samples obtained in step 3 to train the query workload prediction model;
[0108] In the query workload prediction model, the training samples are passed through the DLinear model and the Transformer model respectively, and then the output of the DLinear model and the output of the Transformer model are fused, and the fusion result is used as the query workload prediction result;
[0109] Then, the loss is calculated based on the prediction results and labels, and the training is stopped when the loss converges to obtain the trained query workload prediction model.
[0110] The data partitioning module is used to generate a data partitioning scheme according to the prediction results of the query workload prediction model and the intelligent agent of the trained reinforcement learning model.
[0111] Specific implementation method ten: This implementation method is different from specific implementation method nine in that the working process of the data partition module is as follows:
[0112] Step 1: According to the number of times each type of query workload appears in the current time step and the number of times each type of query workload appears in p-1 historical time steps, time series data of the number of times each type of query workload appears as a function of the time step are obtained;
[0113] Then, the time series data corresponding to various types of query workloads are respectively input into the trained query workload prediction model, and the trained query workload prediction model outputs the predicted frequencies of various types of query workloads in the next time step, and the query workload type i' corresponding to the predicted maximum frequency is obtained; at the start time of the next time step, the data partitioning scheme is initialized to the data partitioning scheme corresponding to the query workload type i';
[0114] Step 2: Initialize k=1;
[0115] Step 3: Determine whether the k-th query workload arriving in the next time step is of the same type as the query workload corresponding to the current data partitioning scheme;
[0116] If they are the same, use the current data partitioning scheme to query directly, and then execute step 4;
[0117] If they are not the same, the kth query workload is input into the trained reinforcement learning model, and the query is performed again after the trained agent outputs the new data partitioning scheme, and then step 4 is continued;
[0118] Step 4: Determine whether the next time step is over;
[0119] If the next time step has not ended, set k = k + 1 and return to step 3;
[0120] If the next time step ends, return to step 1.
[0121] The other steps and parameters are the same as those in the ninth embodiment.
[0122] Example
[0123] In the field of IoT, sensors and devices collect a large amount of data such as machine status, production line operation, temperature, humidity, and vibration. For example, device status data (each device reports status information once a minute, including temperature, vibration value, energy consumption, etc.) and environmental monitoring data (sensors record ambient temperature, humidity, and air pressure information every 5 seconds). These data are large in volume, frequently updated, and have time series characteristics, which puts high demands on storage and scheduling. These data are stored in the database. When the device status needs to be detected abnormally, the data in the database needs to be queried.
[0124] Taking device status data as an example, the data partitioning scheme for device status data query is as follows:
[0125] Step 1: The database stores device status data. First, collect information of each table in the database, historical query workload information, and data partitioning scheme corresponding to the historical query workload information; wherein:
[0126] The information of each table in the database includes the size of the table, the number of tuples, the number of attributes, and the size of each attribute.
[0127] The historical query workload information includes each query statement and the execution time of each query statement.
[0128] The data partition scheme is the partition result of each table in the database.
[0129] Step 2: Model the data partitioning process as a Markov decision process, use the table information and historical query workload information in the database as the state of the reinforcement learning model (DDQN) agent, use the table information and historical query workload information collected in step 1 to train the agent of the reinforcement learning model, and use the data partitioning scheme corresponding to the historical query workload information as the label of the agent training;
[0130] The agent is a deep neural network that fits the Q function. The Q function describes the expected total reward for executing action a in a certain state s, so that the best action can be selected in the current state. In each round of iterative training, the agent will choose to execute an action. According to the reward function, the reward value for the executed action can be generated, thereby generating the corresponding loss value and optimizing the parameters of the agent. The trained agent can be used to generate a data partitioning scheme.
[0131] The actions of the agent are: after the query statement is entered, the agent takes the following actions on the current state: add rows, add columns, delete rows, delete columns, merge partitions, split partitions, or delete partitions.
[0132] The reward the agent gets after performing the action is:
[0133]
[0134] Among them, reward t is the reward obtained by the agent after executing the action at the current time t; cost t is the size of the partition where the query result is located after entering the query statement under the data partitioning scheme at the current time t; cost t-1 It is the size of the partition where the query result is located after the query statement is entered under the data partitioning scheme at time t-1.
[0135] Step 3: Establish a query workload prediction model, and use historical query workload information to train the established query workload prediction model;
[0136] The query workload prediction model includes the DLinear model and the Transformer model. The training process of the query workload prediction model is as follows:
[0137] Step 3: Set the time step T, and then count the number of times each type of historical query workload appears in each time step. The number of times the i-th type of historical query workload appears in the j-th time step is recorded as a ij , i = 1, 2, ..., I, j = 1, 2, ..., J, I is the number of types of historical query workloads, and J is the total number of time steps;
[0138] For example, the time from 0 to T is taken as the first time step, the time from T to 2T is taken as the second time step, and so on;
[0139] Then, for each type of historical query workload, time series data of the number of occurrences of the query workload changing with the time step is obtained;
[0140] That is, each time step corresponds to I values, and the I values are the number of times each type of historical query workload appears in a time step. For a query workload, the number of times this type of query workload appears in each time step constitutes a set of time series data of the change of this type of query workload with the time step;
[0141] Step 32: Cluster the time series data corresponding to various types of historical query workloads to obtain the time series data in each cluster; that is, cluster the time series data with similar change trends and data at each time point into one category;
[0142] For a cluster that contains only one set of time series data, there is no need to process the time series data in the cluster, that is, the time series data in the cluster is directly used as the fitting time series data of the cluster;
[0143] For clusters containing two or more groups of time series data, each group of time series data in a cluster is fitted into one group of time series data, and the time series data obtained by fitting is used as the fitting time series data of the cluster;
[0144] Step 33: For the kth cluster, the number of occurrences of the query workload corresponding to the 1st time step to the pth time step on the fitting time series data corresponding to the kth cluster is used as a training sample, and the number of occurrences of the query workload corresponding to the p+1th time step on the fitting time series data corresponding to the kth cluster is used as the label of the training sample;
[0145] Where k = 1, 2, ..., K, K is the total number of categories obtained by clustering;
[0146] It should be noted that the value of p can be set according to actual conditions. For example, when p = 10, the number of occurrences of the query workload corresponding to the 1st time step to the 10th time step can be used as a training sample, and the number of occurrences of the query workload corresponding to the 11th time step can be used as a label. Then, using a sliding window method, the number of occurrences of the query workload corresponding to the 2nd time step to the 11th time step can be used as a training sample, and the number of occurrences of the query workload corresponding to the 12th time step can be used as a label; and so on.
[0147] Step 34: train the query workload prediction model using all the training samples obtained in step 33;
[0148] In the query workload prediction model, the training samples are passed through the DLinear model and the Transformer model respectively, and then the output of the DLinear model and the output of the Transformer model are fused, and the fusion result is used as the query workload prediction result;
[0149] The loss is then calculated based on the prediction results and labels, and the training is stopped when the loss converges to obtain a trained query workload prediction model.
[0150] Step 4: According to the number of times each type of query workload appears in the current time step and the number of times each type of query workload appears in p-1 historical time steps, time series data of the number of times each type of query workload appears as a function of the time step are obtained;
[0151] Then, the time series data corresponding to various types of query workloads are respectively input into the trained query workload prediction model, and the trained query workload prediction model outputs the predicted frequencies of various types of query workloads in the next time step, and the query workload type i' corresponding to the predicted maximum frequency is obtained; at the start time of the next time step, the data partitioning scheme is initialized to the data partitioning scheme corresponding to the query workload type i';
[0152] Step 5: Initialize k=1;
[0153] Step 6: Determine whether the k-th query workload arriving in the next time step is of the same type as the query workload corresponding to the current data partitioning scheme;
[0154] If they are the same, use the current data partitioning scheme to query directly, and then execute step 7;
[0155] If they are not the same, the kth query workload is input into the trained reinforcement learning model, and the query is performed again after the trained agent outputs the new data partitioning scheme, and then step seven is continued;
[0156] If the types of query workloads that have arrived before are the same as the query workload type i', there is no need to update the current data partitioning scheme temporarily. When a different type of load arrives, the data partitioning scheme is updated and the load type corresponding to the updated data partitioning scheme is compared with the newly arrived load type. If they are consistent, there is no need to update the data partitioning scheme this time. Otherwise, the data partitioning scheme continues to be updated.
[0157] Step 7: Determine whether the next time step is over;
[0158] If the next time step has not ended, set k=k+1 and return to step 6;
[0159] If the next time step ends, the latest time step is used as the current time step, and then return to step 4.
[0160] The above calculation examples of the present invention are only used to explain the calculation model and calculation process of the present invention in detail, and are not intended to limit the implementation methods of the present invention. For ordinary technicians in the relevant field, other different forms of changes or modifications can be made based on the above description. It is impossible to list all the implementation methods here. All obvious changes or modifications derived from the technical solution of the present invention are still within the scope of protection of the present invention.
Claims
1. A database adaptive hybrid data partitioning method based on reinforcement learning, characterized in that: The method specifically comprises the following steps: Step 1: Collect information of each table in the database, historical query workload information, and data partitioning scheme corresponding to the historical query workload information; Step 2: Use the table information and historical query workload information in the database as the state of the reinforcement learning model agent, use the table information and historical query workload information collected in step 1 to train the reinforcement learning model agent, and use the data partitioning scheme corresponding to the historical query workload information as the label for agent training; Step 3: Establish a query workload prediction model, and use historical query workload information to train the established query workload prediction model; Step 4: According to the number of times each type of query workload appears in the current time step and the number of times each type of query workload appears in p-1 historical time steps, time series data of the number of times each type of query workload appears as a function of the time step are obtained; Then, the time series data corresponding to various types of query workloads are respectively input into the trained query workload prediction model, and the trained query workload prediction model outputs the predicted frequencies of various types of query workloads in the next time step, and the query workload type i' corresponding to the predicted maximum frequency is obtained; at the start time of the next time step, the data partitioning scheme is initialized to the data partitioning scheme corresponding to the query workload type i'; Step 5: Initialize k=1; Step 6: Determine whether the k-th query workload arriving in the next time step is of the same type as the query workload corresponding to the current data partitioning scheme; If they are the same, use the current data partitioning scheme to query directly, and then execute step 7; If they are not the same, the kth query workload is input into the trained reinforcement learning model, and the query is performed again after the trained agent outputs the new data partitioning scheme, and then step seven is continued; Step 7: Determine whether the next time step is over; If the next time step has not ended, set k=k+1 and return to step 6; If the next time step ends, return to step 4.
2. According to the method of claim 1, wherein the method comprises: The information of each table in the database includes the size of the table, the number of tuples, the number of attributes and the size of each attribute.
3. According to the method of adaptive hybrid data partitioning of a database based on reinforcement learning in claim 2, it is characterized in that: The historical query workload information includes each query statement and the execution time of each query statement.
4. According to the method of adaptive hybrid data partitioning of a database based on reinforcement learning in claim 3, it is characterized in that: The data partitioning scheme is the partitioning result of each table in the database.
5. According to the method of adaptive hybrid data partitioning of a database based on reinforcement learning in claim 4, it is characterized in that: The action of the agent is: after the query statement is input, the agent takes the operation of adding rows, adding columns, deleting rows, deleting columns, merging partitions, splitting partitions or deleting partitions on the current state.
6. The method for adaptive hybrid data partitioning of a database based on reinforcement learning according to claim 5, characterized in that: The reward obtained by the agent after performing an action in the reinforcement learning model is: Among them, reward t is the reward obtained by the agent after executing the action at the current time t; cost t is the size of the partition where the query result is located after entering the query statement under the data partitioning scheme at the current time t; cost t-1 It is the size of the partition where the query result is located after the query statement is entered under the data partitioning scheme at time t-1.
7. The method for adaptive hybrid data partitioning of a database based on reinforcement learning according to claim 6, characterized in that: The query workload prediction model includes a DLinear model and a Transformer model.
8. The method for adaptive hybrid data partitioning of a database based on reinforcement learning according to claim 7, characterized in that: The specific process of step three is: Step 3: Set the time step T, and then count the number of times each type of historical query workload appears in each time step. The number of times the i-th type of historical query workload appears in the j-th time step is recorded as a ij , i = 1, 2, ..., I, j = 1, 2, ..., J, I is the number of types of historical query workloads, and J is the total number of time steps; Then, for each type of historical query workload, time series data of the number of occurrences of the query workload changing with the time step is obtained; Step 32: Cluster the time series data corresponding to various types of historical query workloads, and obtain the time series data in each cluster; For a cluster that contains only one set of time series data, there is no need to process the time series data in the cluster, that is, the time series data in the cluster is directly used as the fitting time series data of the cluster; For clusters containing two or more groups of time series data, each group of time series data in a cluster is fitted into one group of time series data, and the time series data obtained by fitting is used as the fitting time series data of the cluster; Step 33: For the kth cluster, the number of occurrences of the query workload corresponding to the 1st time step to the pth time step on the fitting time series data corresponding to the kth cluster is used as a training sample, and the number of occurrences of the query workload corresponding to the p+1th time step on the fitting time series data corresponding to the kth cluster is used as the label of the training sample; Where k = 1, 2, ..., K, K is the total number of categories obtained by clustering; Step 34: train the query workload prediction model using all the training samples obtained in step 33; In the query workload prediction model, the training samples are passed through the DLinear model and the Transformer model respectively, and then the output of the DLinear model and the output of the Transformer model are fused, and the fusion result is used as the query workload prediction result; The loss is then calculated based on the prediction results and labels, and the training is stopped when the loss converges to obtain a trained query workload prediction model.
9. A database adaptive hybrid data partitioning system based on reinforcement learning, characterized in that: The system includes an information collection module, a reinforcement learning model, a query workload prediction model and a data partitioning module, wherein: The information collection module is used to collect information of each table in the database, historical query workload information, and data partitioning scheme corresponding to the historical query workload information; The historical query workload information includes each query statement and the execution time of each query statement; The reinforcement learning model is trained according to the information collected by the information collection module, and the intelligent agent of the trained reinforcement learning model is used to output the data partitioning scheme; The action of the agent is: after the query statement is input, the agent takes the action of adding rows, adding columns, deleting rows, deleting columns, merging partitions, splitting partitions or deleting partitions on the current state; the reward obtained by the agent after performing the action is: Among them, reward t is the reward obtained by the agent after executing the action at the current time t; cost t is the size of the partition where the query result is located after entering the query statement under the data partitioning scheme at the current time t; cost t-1 It is the size of the partition where the query result is located after the query statement is entered under the data partitioning scheme at time t-1; The query workload prediction model is trained based on the historical query workload information collected by the information collection module, and the trained query workload prediction model is used to predict the future occurrence frequency of various types of query workloads; The working process of the query workload prediction model is as follows: Step 1: Set the time step T, and then count the number of times each type of historical query workload appears in each time step. The number of times the i-th type of historical query workload appears in the j-th time step is recorded as a ij , i = 1, 2, ..., I, j = 1, 2, ..., J, I is the number of types of historical query workloads, and J is the total number of time steps; Then, for each type of historical query workload, time series data of the number of occurrences of the query workload changing with the time step is obtained; Step 2: Cluster the time series data corresponding to various types of historical query workloads to obtain the time series data in each cluster; For a cluster that contains only one set of time series data, there is no need to process the time series data in the cluster, that is, the time series data in the cluster is directly used as the fitting time series data of the cluster; For clusters containing two or more groups of time series data, each group of time series data in a cluster is fitted into one group of time series data, and the time series data obtained by fitting is used as the fitting time series data of the cluster; Step 3: For the kth cluster, the number of occurrences of the query workload corresponding to the 1st time step to the pth time step on the fitting time series data corresponding to the kth cluster is used as a training sample, and the number of occurrences of the query workload corresponding to the p+1th time step on the fitting time series data corresponding to the kth cluster is used as the label of the training sample; Where k = 1, 2, ..., K, K is the total number of categories obtained by clustering; Step 4: Use all the training samples obtained in step 3 to train the query workload prediction model; In the query workload prediction model, the training samples are passed through the DLinear model and the Transformer model respectively, and then the output of the DLinear model and the output of the Transformer model are fused, and the fusion result is used as the query workload prediction result; Then, the loss is calculated based on the prediction results and labels, and the training is stopped when the loss converges to obtain the trained query workload prediction model. The data partitioning module is used to generate a data partitioning scheme according to the prediction results of the query workload prediction model and the intelligent agent of the trained reinforcement learning model.
10. The database adaptive hybrid data partitioning system based on reinforcement learning according to claim 9, characterized in that: The working process of the data partition module is as follows: Step 1: According to the number of times each type of query workload appears in the current time step and the number of times each type of query workload appears in p-1 historical time steps, time series data of the number of times each type of query workload appears as a function of the time step are obtained; Then, the time series data corresponding to various types of query workloads are respectively input into the trained query workload prediction model, and the trained query workload prediction model outputs the predicted frequencies of various types of query workloads in the next time step, and the query workload type i' corresponding to the predicted maximum frequency is obtained; at the start time of the next time step, the data partitioning scheme is initialized to the data partitioning scheme corresponding to the query workload type i'; Step 2: Initialize k=1; Step 3: Determine whether the k-th query workload arriving in the next time step is of the same type as the query workload corresponding to the current data partitioning scheme; If they are the same, use the current data partitioning scheme to query directly, and then execute step 4; If they are not the same, the kth query workload is input into the trained reinforcement learning model, and the query is performed again after the trained agent outputs the new data partitioning scheme, and then step 4 is continued; Step 4: Determine whether the next time step is over; If the next time step has not ended, set k = k + 1 and return to step 3; If the next time step ends, return to step 1.
Citation Information
Patent Citations
Automatic database partitioning method and system based on depth map compression algorithm
CN116226281A
Dynamic database partitioning using artificial intelligence techniques
US20240346325A1
Cited By
Intelligent archive storage and distribution method and system
CN121412236A
Intelligent file storage allocation method and system
CN121412236B