A database connection sorting adjustment method, device and equipment based on QMIX architecture

By using a QMIX-based approach, a query tree is constructed using GAT and Tree-LSTM, and a multi-agent reinforcement learning model is trained. This solves the problem of vectorizing shallow information in existing technologies and achieves stronger database connection sorting and adjustment capabilities.

CN119646000BActive Publication Date: 2025-10-28NINGXIA UNIVERSITY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411777665.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-05
Publication Date
2025-10-28
Estimated Expiration
2044-12-05

AI Technical Summary

Technical Problem

At present, when performing feature extraction or vectorization, the vector form in the query statement can only capture shallow semantic information and structural features, making it difficult to provide effective state input information for reinforcement learning models, resulting in poor database connection sorting and adjustment capabilities.

Method used

A method based on the QMIX architecture is adopted. By constructing a query graph, the attention mechanism graph neural network GAT is used to represent the feature state. The query tree is constructed by combining the tree structure long short-term memory network Tree-LSTM. The deep optimization algorithm DFS is used to obtain the connection state between leaf nodes. A multi-agent reinforcement learning model MARL is constructed and trained. Finally, the connection state between leaf nodes is used to impose monotonic constraints on the agents and optimize the connection ranking.

Benefits of technology

It captures semantic information and structural features in deep query statements, providing effective state input information for reinforcement learning models and improving the ability to adjust database connection order.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119646000B_ABST
    Figure CN119646000B_ABST
Patent Text Reader

Abstract

This invention discloses a database connection sorting adjustment method, apparatus, and device based on the QMIX architecture, relating to the field of database data processing technology. This invention utilizes GAT to characterize the feature states of each attribute column within each node of the query graph, vectorizing the data information and data column information involved in the query statement to form the feature vector of each node. Then, a query tree is constructed using Tree-LSTM, and the leaf nodes within the query tree are recursively searched using the Depth-First Search (DFS) algorithm to obtain the connection states between the leaf nodes. This allows for monotonicity constraints on the state input information of the reinforcement learning model. This process captures the semantic information and structural features of the deep-level query statement and provides effective state input information for the training of the reinforcement learning model. Finally, the connection states between the leaf nodes are used to constrain the input state information of the agents within the model, enabling the multi-agent reinforcement learning model to achieve stronger capabilities when adjusting the database connection sorting.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database data processing technology, and in particular to a database connection sorting adjustment method, apparatus, device, and medium based on the QMIX architecture. Background Technology

[0002] Join order selection is a key issue in database query optimization, which directly affects the efficiency of query execution. In practical applications, query optimizers need to deal with complex query spaces and huge data scales, making the efficient selection of the optimal join order increasingly important. Traditional static join order enumeration algorithms find the optimal solution by thoroughly traversing the query space, but this method is often time-consuming and labor-intensive, and may even become infeasible when faced with large-scale datasets and complex queries.

[0003] To address these issues, current query optimizers typically employ a combination of heuristic algorithms and static methods. Heuristic algorithms can find a near-optimal solution in a relatively short time, but they do not always guarantee finding the globally optimal solution. Furthermore, these algorithms often lack feedback mechanisms regarding the quality of the resulting execution plan, which may cause the optimizer to repeatedly select the same inefficient execution plan, thus missing out on better execution options.

[0004] With the development of artificial intelligence technology, especially the rise of reinforcement learning, new ideas and methods have been provided for database join ordering. Its learning optimizer utilizes machine learning models to predict and optimize join ordering plans, making reinforcement learning widely used because it can handle long-term dependencies and delayed reward problems. In the reinforcement learning framework, the join ordering problem is modeled as a process of interaction between the model and the environment (database system). The model needs to select the join order based on the current state and obtain rewards through interaction with the environment. To train such a model, the query statement first needs to be transformed into a vector form that the machine model can understand; this process is called feature extraction or vectorization. Simultaneously, during the training process of reinforcement learning, the agent gradually learns which actions bring higher rewards by continuously trying different actions and observing their results, thus demonstrating the crucial importance of interaction between the model and the environment. However, at present, the vector forms formed during feature extraction or vectorization often only capture the semantic information and structural features of the shallow query statement, making it difficult to provide effective state input information for the training of reinforcement learning models. This results in reinforcement learning models having poor capabilities when adjusting database join ordering. Summary of the Invention

[0005] This invention provides a database connection sorting adjustment method, apparatus, and device based on the QMIX architecture. It can solve the problem in the prior art that, at the current stage, when performing feature extraction or vectorization, the resulting vector form can often only capture the semantic information and structural features of shallow query statements, making it difficult to provide effective state input information for the training of reinforcement learning models.

[0006] This invention provides a database connection sorting adjustment method based on the QMIX architecture, comprising the following steps:

[0007] Retrieve multiple data tables from the database based on the SQL query statement, set the data tables as nodes of the graph, set the connections between the data tables as edges of the graph, construct the query graph, and construct the column attributes of the data tables.

[0008] Based on the attention mechanism graph neural network GAT, each attribute column in each node of the query graph is represented by a feature state. Each attribute column after feature state representation is linearly mapped into a vector, and the vectors formed by each attribute column are concatenated to form the feature vector of each node in the query graph. Based on the feature vector of each node in the query graph, a query tree is constructed using a tree-structured long short-term memory network Tree-LSTM. The leaf nodes of the query tree are the data table or the attribute columns in the data table. The depth optimization algorithm DFS is used to recursively search the leaf nodes in the query tree to obtain the connection state between the leaf nodes.

[0009] A multi-agent reinforcement learning model (MARL) based on QMIX is constructed. The model is trained using a deep Q-network. During training, the connection states between leaf nodes are used to constrain the monotonicity of the agents, thus obtaining the trained multi-agent reinforcement learning model (MARL).

[0010] Input the SQL query into the trained multi-agent reinforcement learning model MARL to obtain the query results after connection sorting adjustment.

[0011] Preferably, the column attributes of the constructed data table include:

[0012] Retrieve columns from each data table involved in the query using a 12-bit one-hot vector R. column The column attributes are represented as follows:

[0013] R column (Ac)=(c type c link c key c only c key c pkey c change )

[0014] Where A represents the data table, and c represents the attribute; c type Occupying 3 positions, representing integers, floating-point numbers, and strings respectively; c link Occupying 3 positions, representing the comparison methods =, >, and < respectively; c only This represents the proportion of unique values, occupying three positions, representing the intervals [0, 0.001), [0.001, 0.999], and (0.999, 1); c key Occupy one position, where 1 represents a primary key and 0 represents a non-primary key; c pkey Occupying one position indicates whether the attribute is a foreign key attribute; c change It occupies 1 position and is used to predict whether the unique value count will increase; 1 means it will increase and 0 means it will not.

[0015] Construct an attribute column vector R from all column attributes in the data table. column .

[0016] Preferably, the step of characterizing the feature state of each attribute column within each node of the query graph includes:

[0017] Each attribute column within each node of the query graph is input into the attention mechanism graph neural network GAT, which includes N nodes in the query graph and each corresponding F-dimensional feature. Each node forms a multi-dimensional feature vector F′.

[0018] Set the weight matrix W∈R F*F′ Each attribute column is characterized by its feature state.

[0019] Preferably, obtaining the connection status between leaf nodes includes:

[0020] The tree-structured long short-term memory network Tree-LSTM includes N-ary Tree-LSTM and Child-SumTree-LSTM;

[0021] Construct a connection tree using N-aryTree-LSTM, where the leaf nodes of the connection tree are data tables R. table Or the attribute column R in the data table column The middle node of the connection tree corresponds to a connection unit, which consists of four nodes: Table0, Column0, Column1, and Table1. Table0 and Table1 represent the tables that need to be connected, and Column0 and Column1 represent the attribute columns that need to be connected. This forms the connection unit for all nodes.

[0022] The Child-Sum Tree-LSTM is used to aggregate the connection units of all the constructed nodes to form a query tree;

[0023] The Depth-First Search (DFS) algorithm is used to recursively traverse the query tree from the root node along the depth of the tree to obtain the connection state between the leaf nodes in the query tree.

[0024] Preferably, obtaining the trained multi-agent reinforcement learning model (MARL) includes:

[0025] A multi-agent reinforcement learning model (MARL) based on the QMIX algorithm is constructed. Two weight networks, hyper_w1 and hyper_w2, and two bias networks, hyper_b1 and hyper_b2, are set. Hyper_w1 and hyper_w2 dynamically generate weights for weighted summation based on the state input. Hyper_b1 is a fully connected layer used to generate bias terms. Hyper_b2 contains two fully connected layers and an intermediate ReLU activation function.

[0026] In the multi-agent reinforcement learning model MARL, agents are trained using a deep Q-network. During training, the connection states between leaf nodes are used to impose monotonicity constraints on the state input information of the agents. Hyper_w1, Hyper_w2, Hyper_b1, and Hyper_b2 are used to dynamically generate two sets of weights and biases based on the constrained state input information to continuously optimize the total Q value of each agent, thus obtaining the trained multi-agent reinforcement learning model MARL.

[0027] Preferably, the continuous optimization of the total Q value of each agent includes:

[0028] The first set of weights w1 and bias b1 is dynamically generated using two networks, hyper_w1 and hyper_b1, based on the constrained state input information. The first set of weights w1 is then weighted and summed, and the corresponding bias b1 is added to obtain the first set of Q values ​​of the agent.

[0029] The second set of weights w2 and bias b2 is dynamically generated using two networks, hyper_w2 and hyper_b2, based on the constrained state input information. The second set of weights w2 is then weighted and summed, and the corresponding bias b2 is added to obtain the agent's second set of Q values.

[0030] The total Q value of each agent is continuously optimized by using the first set of Q values ​​and the second set of Q values ​​of the agents.

[0031] This invention also provides a database connection sorting adjustment device based on the QMIX architecture, comprising:

[0032] The module is used to retrieve multiple data tables from the database based on the query statement SQL, set the data tables as nodes of the graph, set the connections between the data tables as edges of the graph, construct the query graph, and construct the column attributes of the data tables.

[0033] The state representation module is used to represent the feature state of each attribute column within each node in the query graph based on the attention mechanism graph neural network GAT. Each attribute column after feature state representation is linearly mapped into a vector, and the vectors formed by each attribute column are concatenated to form the feature vector of each node in the query graph. Based on the feature vector of each node in the query graph, a query tree is constructed using a tree-structured long short-term memory network Tree-LSTM. The leaf nodes of the query tree are the data table or the attribute columns within the data table. The depth optimization algorithm DFS is used to recursively search the leaf nodes in the query tree to obtain the connection state between the leaf nodes.

[0034] The model module is used to construct a multi-agent reinforcement learning model (MARL) based on the QMIX form. The model is trained using a deep Q-network. During training, the connection states between leaf nodes are used to constrain the monotonicity of the agents, resulting in the trained multi-agent reinforcement learning model (MARL).

[0035] The adjustment module is used to input the SQL query statement into the trained multi-agent reinforcement learning model (MARL) to obtain the query results after connection sorting adjustment.

[0036] This invention also provides an electronic device, including a memory and a processor;

[0037] The memory is used to store computer programs;

[0038] When the processor executes the computer program stored in the memory, it implements the steps of the database connection sorting adjustment method based on the QMIX architecture as described above.

[0039] This invention also provides a computer-readable storage medium for storing a computer program, which, when executed by a processor, implements the steps of a database connection sorting adjustment method based on a QMIX architecture as described above.

[0040] This invention provides a database connection sorting adjustment method, apparatus, and device based on the QMIX architecture. Compared with the prior art, its advantages are as follows:

[0041] This invention utilizes a graph neural network (GAT) with an attention mechanism to represent the feature state of each attribute column within each node of the query graph. This vectorizes the data information and data column information involved in the query statement, forming a feature vector for each node in the query graph. Then, a tree-structured long short-term memory network (Tree-LSTM) is used to construct the query tree, and a deep search algorithm (DFS) is used to recursively search the leaf nodes within the query tree to obtain the connection states between the leaf nodes. These connection states are then used to impose monotonicity constraints on the state input information of the reinforcement learning model. This process captures the semantic information and structural features of the deep-level query statement and provides effective state input information for the training of the reinforcement learning model. Finally, the connection states between the leaf nodes are used to constrain the input state information of the agents in the multi-agent reinforcement learning model (MARL), enabling the MARL to achieve stronger capabilities when adjusting the connection sorting of the database. Attached Figure Description

[0042] Figure 1 A schematic diagram of the overall process of a database connection sorting adjustment method based on QMIX architecture provided in an embodiment of the present invention;

[0043] Figure 2 This is a schematic diagram of query tree construction for a database connection sorting adjustment method based on QMIX architecture provided in an embodiment of the present invention. Detailed Implementation

[0044] To make the above-mentioned objects, features, and advantages of the present invention more apparent and understandable, specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. Many specific details are set forth in the following description to provide a thorough understanding of the present invention. However, the present invention can be practiced in many other ways different from those described herein, and those skilled in the art can make similar modifications without departing from the spirit of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.

[0045] See Figure 1 This invention provides a database connection sorting adjustment method based on the QMIX architecture, comprising the following steps:

[0046] Step S1: Select a batch of high-quality SQL statements and construct them into a set S. To ensure quality, select authoritative benchmarks in the database domain, such as SQL sets from JOB and TPC-H, and then divide S into training sets S'' based on stratified sampling principles. t and test set S v .

[0047] Step S2: Query the plan representation; use the training set S tExtract the SQL query statement from the table and construct it into a vector Q, which includes the join information of all tables.

[0048] Step S3: Represent the design attribute columns using one-hot vectors. The main attributes are column attributes. Attribute column information is constructed based on the proportion of unique values, etc. The obtained attribute columns are then used to represent the data table of the query design using GAT.

[0049] Step S4: After the query statement is processed by the above steps, it is transformed into a vector, and a query tree is constructed by combining N-ary Tree-LSTM and Child-Sum Tree-LSTM; at the same time, DFS (Depth-First Search) is used to search the query space to obtain the representation of the connection state.

[0050] Step S5: A multi-agent reinforcement learning architecture in the form of QMIX is adopted, and a MixingNetwork is set up. Global information is used to impose monotonicity constraints on the agents so that the agents can find the optimal solution. Its connection operators have three modes: hashjoin, mergejoin, and nested loopjoin. Therefore, three agents in the form of DQN are set up.

[0051] Step S6: When using the query, start the trained model, input the original query statement, and obtain the query results.

[0052] Specifically, step S2 includes:

[0053] Step S21: Query the traditional database to obtain the number of data tables n in the database, and obtain the representation of each data table from 0 to n-1; create a matrix m of size n*n, m i,j This represents the connection between table i and table j, where 1 indicates that there is a connection between them, and 0 indicates that there is no connection between them.

[0054] Step S22: Use a fully connected layer (FC) to convert matrix m into a vector form of the query plan expression R(Q); put all rows of matrix m into vector v to obtain m i,j =v i *n+j; and the vectorized expression of R(Q) is obtained through the following formula.

[0055] R(Q)=FC(v)=σ(vW+b)

[0056] Where: σ represents a sigmoid activation function in the neural network; W is a matrix of shape (n*n, hs), and b is a vector of shape (1, hs), which are the parameters that need to be learned using training samples in these two FC layers; h is the size of the hidden layer in the neural network; R(Q) is a vector of shape (1, hs), representing the query Q.

[0057] Step S23: Define a query graph G, where the data tables in the SQL statements are considered as nodes N, and the queries between tables are considered as edges E; use the training set S... t If we extract an SQL statement, define the data table in the statement as node N, and define the equi-connections between nodes as edges E, then the query graph is represented as G = (N, E).

[0058] Step S24: Construct the data columns for the query design using a 12-bit one-hot vector R. column Characterize the column attributes; where c type Occupying 3 positions, representing integers, floating-point numbers, and strings respectively; c link Occupying 3 positions, representing the comparison methods =, >, and < respectively; c only This represents the proportion of unique values, occupying three positions, representing the intervals [0, 0.001), [0.001, 0.999], and (0.999, 1). Unique values ​​can be obtained from system tables in traditional database systems; for example, the pg_status table in PostgreSQL. key This occupies one position, where 1 represents a primary key and 0 represents a non-primary key; c pkey Occupying a position indicates whether the attribute is a foreign key attribute; 1 indicates it is, 0 indicates it is. change Occupying one position, the collected statistical data predicts whether the unique value count will increase; 1 represents an increase, and 0 represents no increase. Assuming we characterize attribute c of table A, it can be represented as:

[0059] R column (Ac)=(c type c link c key c only c key c pkey c change )

[0060] Step S25: For a table `table` with k attribute columns, express `R` using the attribute column vector generated in step S24 that relates to the query. column The GAT method is used to express the k column attributes (R). column (c1),R column (c2),...,Rcolumn (c k This forms a vector representation of the data table.

[0061] Specifically, step S3 includes:

[0062] Step S31: Express the k column attributes of the attribute column vector generated above (R column (c1),R column (c2),...,R column (ck) is used as input information for GAT to further obtain the data table representation R. table The input to a single-layer graph attention mechanism network consists of N nodes and the F-dimensional features of each node itself. After GAT processing, it can form a multi-dimensional feature F′, where the size of F is the number of features of each node.

[0063] Step S31: Obtain the feature vector F′ in the higher-level feature space, which enhances the expressive power and facilitates the calculation of attention between nodes. To more effectively obtain the structural information of the graph, define the weight matrix W∈R. F*F′ The correlation coefficient is calculated for each node N through a shared attention mechanism.

[0064] Step S33: In the attention calculation, normalization is performed on each node in the graph and its neighbors. When calculating attention, the vectors after linear mapping between nodes are concatenated together.

[0065] Step S34: h i The weighted output is the sum of the neighbors based on their attention levels. Further, an attention mechanism with k heads is implemented, and the average output of the k heads is calculated to obtain the node's data table vector representation as R. table .

[0066] Specifically, step S4 includes:

[0067] Step S41: Construct a connection tree, where the leaf nodes are data tables or attribute column information generated in the previous step. table With R column Vector representation; the middle node of the connection tree corresponds to a connection unit, which consists of four nodes (Table0, Column0, Column1, Table1), labeled j; where Table0 and Table1 are the tables to be connected, and Column0 and Column1 are the attribute columns to be connected.

[0068] Step S42: Construct a connection unit (Unit). For a node j in the connection tree, use g... j Define its representation, using m jTo represent its storage unit, specifically including:

[0069] ① If node j represents a leaf node of the table, then g j =R F ( j ), m j It will be initialized to a zero vector.

[0070] ②If node j is a leaf node representing a single column, then g j =R F ( j ), m j It will be initialized to a zero vector.

[0071] ③ For the tree node j representing the connection, it has four child nodes (Table0, Column0, Column1, Table1). In the representation of these four child nodes, Unit is used to represent j and m. j .

[0072] Step S43: Generate the data table information R table In the initial stage, i is considered as a tree node, thus obtaining the state forest F = {R}. tabel1 R table2 , ..., R tablen}(n data tables involved in the query), the number of tables in the initial forest is equal to the number of tables in the query; in the forest, the initial trees are unordered, and any trees can be joined; to further represent the process of merging trees into a forest, that is, joining all tables, the root node is used to represent the forest h. root =F; Different connection tree construction processes can produce different connection plans.

[0073] Step S44: Use the DFS algorithm to recursively search the state space to obtain the representation of the connected states. The pseudocode of the search algorithm is as follows:

[0074]

[0075] Specifically, step S5 includes:

[0076] Step S51: Set up a reinforcement learning model with a DQN architecture; use DQN (Deep Q-Network) for model training, automatically learning decision-making strategies through interaction with the environment, mainly including the DQN network and Reolaly Memory; specifically:

[0077] 1. Define the DQN network. First, define all network layers; define convolutional layers with N input channels, 1 output channel, n kernels, and s stride; define normalization layers designed for the output channels to accelerate training and improve model stability; similarly, normalization operations are also needed for subsequent convolutional layers; define fully connected layers to map the output of the convolutional layers to the output channels and obtain the reward value for execution.

[0078] 2. Define Experience Memory (ReolayMemory); Experience replay stores the experiences (states, actions, next state, rewards) gained by the agent when interacting with the environment. During training, samples can be randomly drawn from this memory to update the agent's policy. Define capacity, memory, and position respectively; where capacity is the maximum capacity of the replay memory, memory is the list of stored experiences, and position is the index of the current storage position, used to track the position of the next stored value.

[0079] Step S52: Construct the MixingNet network by performing class initialization and forward propagation; specifically:

[0080] 1. In the QMIX algorithm, the initialization process of the QMIXNET class involves several key components and configuration parameters, which together define the network's structure and function. Among them, `state_shape` defines the dimension of the state input, i.e., the size of the state information that the network needs to process; `two_hyper_layers` is a boolean variable indicating whether to use two hypernetworks to generate weights. If true, the hypernetwork will contain more complexity and depth; `hyper_hidden_dim` sets the dimension of the hypernetwork's hidden layers, while `qmix_hidden_dim` defines the dimension of the QMIX hidden layers; and `n_agents` specifies the number of agents, which is an important parameter in multi-agent systems.

[0081] 2. Regarding the hypernetwork, QMIXNET initializes two key weight networks: hyper_w1 and hyper_w2. These two networks dynamically generate weights for weighted summation based on the state input. If two_hyper_layers is configured to true, then each of these two networks will contain two fully connected layers and a ReLU activation function. This design allows the network to learn more complex feature representations and weight generation mechanisms. Conversely, if two_hyper_layers is false, these two networks will be simplified to a single fully connected layer to generate weights in a more concise way.

[0082] 3. In addition to the weight network, QMIXNET also initializes two bias networks: hyper_b1 and hyper_b2; hyper_b1 is a simple fully connected layer used to generate bias terms; while hyper_b2 contains two fully connected layers and an intermediate ReLU activation function. This design makes the generation of biases more complex and nonlinear.

[0083] 4. During the forward propagation of the QMIX algorithm, the Q-values ​​and state inputs of all agents are processed to calculate the team's total Q-value. It receives two main inputs: q_values ​​and states. q_values ​​is a three-dimensional tensor containing the Q-values ​​of all agents at each time step, with a shape of (episode_num, max_episode_len, n_agents), where episode_num represents the number of rounds, max_episode_len represents the maximum number of time steps per round, and n_agents represents the number of agents. states is also a three-dimensional tensor containing the state information at each time step, with a shape of (episode_num, max_episode_len, state_shape), where state_shape represents the dimension of the state information. These inputs are processed to adapt to the network's input requirements. This typically involves reshaping q_values ​​and states to the desired shape for the network.

[0084] 5. Use the hyper_w1 and hyper_b1 networks to generate the first set of weights w1 and biases b1. These two networks will dynamically generate weights and biases based on the state input states. Their size and shape will be determined according to the configuration and network design. After generation, w1 and b1 need to be reshaped into appropriate shapes for subsequent calculations.

[0085] After the weights and biases are established, the q_values ​​undergo their first transformation. This transformation is achieved by weighted summation plus the bias, i.e., by weighted summation of the Q-values ​​of each agent and then adding the corresponding bias. After this transformation, the ReLU activation function is used to activate the result, thereby increasing the nonlinear expressive power of the network.

[0086] 6. Use the hyper_w2 and hyper_b2 networks to generate the second set of weights w2 and biases b2; similarly, these two networks will also dynamically generate weights and biases based on the state input states and reshape them appropriately.

[0087] 7. The second set of weights and biases obtained in the previous step are transformed a second time. This transformation is also achieved by weighted summation plus the bias, resulting in the team's total Q value q_total. q_total is a three-dimensional tensor with the shape (episode_num, -1, 1), where -1 represents the number of time steps in each round (in actual calculation, the size of this dimension is determined by max_episode_len), and 1 indicates that a single Q value is obtained, representing the team's total value at that time step.

[0088] like Figure 2 The diagram illustrates the construction of a query tree. The specific process for constructing a query tree is as follows:

[0089] Set the query Q: Select * From A, B, C, D Where A; a1 = B; b1 and B; b2 = C; c1 and C; c2 = D; d1 and D; d2 = 30.

[0090] Given a query statement Q in the training set, tables A, B, C, and D in the query are constructed as nodes in the graph based on equi-join relationships, forming a query graph G = (N, E); if each attribute column in table A is represented, R... cloumn (A.a1) = (100, 100, 010, 1, 0, 1), and the constructed vector is used as the attribute of node N. Information is aggregated to obtain the final R. table Node vectors.

[0091] After GAT processing, a vector is obtained, and R is... tabel (A),R column (A.a1),R table (B),R cloumn (B.b1) is used as a leaf node to construct node j and store node m. j Perform a connection selection on the leaf nodes to generate Unit elements that can be used for the next connection. These Unit elements are then used for the next connection selection, forming the final h. root .

[0092] This invention employs GAT (Graph Attention Network) for query plan representation. Information related to the query statement, such as data information and data column information, is processed into vector form using GAT. Then, a query tree is constructed by combining N-ary LSTM (N-ary Long Short-Term Memory) and Child-Sum Tree-LSTM, simultaneously constructing a representation of the query plan. The constructed query plan and query content are used as training data for MARL, enabling the trained model to adjust the database connection order, thereby achieving the goal of connection order adjustment.

[0093] The embodiments described above are merely illustrative of several implementations of the present invention, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these all fall within the protection scope of the present invention. Therefore, the protection scope of this invention patent should be determined by the appended claims.

Claims

1. A database connection sorting adjustment method based on QMIX architecture, characterized in that, Includes the following steps: Retrieve multiple data tables from the database based on the SQL query statement, set the data tables as nodes of the graph, set the connections between the data tables as edges of the graph, construct the query graph, and construct the column attributes of the data tables. Based on the attention mechanism graph neural network GAT, each attribute column in each node of the query graph is represented by a feature state. Each attribute column after being characterized by its feature state is linearly mapped to a vector, and the vectors formed by each attribute column are concatenated to form the feature vector of each node in the query graph. Based on the feature vector of each node in the query graph, a query tree is constructed using a tree-structured long short-term memory network Tree-LSTM. The leaf nodes of the query tree are the data table or the attribute columns within the data table. The depth optimization algorithm DFS is used to recursively search the leaf nodes in the query tree to obtain the connection state between the leaf nodes. A multi-agent reinforcement learning model (MARL) based on the QMIX algorithm is constructed. Two weight networks, hyper_w1 and hyper_w2, and two bias networks, hyper_b1 and hyper_b2, are set. Hyper_w1 and hyper_w2 dynamically generate weights for weighted summation based on the state input. Hyper_b1 is a fully connected layer used to generate bias terms. Hyper_b2 contains two fully connected layers and an intermediate ReLU activation function. In the multi-agent reinforcement learning model MARL, agents are trained using a deep Q-network. During training, the connection states between leaf nodes are used to impose monotonicity constraints on the state input information of the agents. Hyper_w1, Hyper_w2, Hyper_b1, and Hyper_b2 are used to dynamically generate two sets of weights and biases based on the constrained state input information to continuously optimize the total Q value of each agent, thus obtaining the trained multi-agent reinforcement learning model MARL. Input the SQL query statement into the trained multi-agent reinforcement learning model MARL to obtain the query results after connection sorting adjustment. The column attributes of the constructed data table include: Retrieve columns from each data table involved in the query using a 12-bit one-hot vector R. column The column attributes are represented as follows: R column (A.c)= (c type ,c link ,c key ,c only ,c key ,c pkey ,c change ) Where A represents the data table, and c represents the attribute; c type Occupying 3 positions, representing integers, floating-point numbers, and strings respectively; c link Occupying 3 positions, representing the comparison methods =, >, and < respectively; c only This represents the proportion of unique values, occupying three positions, representing the intervals [0, 0.001), [0.001, 0.999], and (0.999, 1); c key Occupy one position, where 1 represents a primary key and 0 represents a non-primary key; c pkey Occupying one position indicates whether the attribute is a foreign key attribute; c change It occupies 1 position and is used to predict whether the unique value count will increase; 1 means it will increase and 0 means it will not. Construct an attribute column vector R from all column attributes in the data table. column .

2. The database connection sorting adjustment method based on QMIX architecture according to claim 1, characterized in that, The step of characterizing the feature state of each attribute column within each node of the query graph includes: Each attribute column within each node of the query graph is input into the attention mechanism graph neural network GAT, which includes N nodes in the query graph and each corresponding F-dimensional feature. Each node forms a multi-dimensional feature vector F′. Set the weight matrix W∈R F*F′ Each attribute column is characterized by its feature state.

3. The database connection sorting adjustment method based on QMIX architecture according to claim 1, characterized in that, The step of obtaining the connection status between leaf nodes includes: The tree-structured long short-term memory network Tree-LSTM includes N-ary Tree-LSTM and Child-Sum Tree-LSTM; Construct a connection tree using N-ary Tree-LSTM, where the leaf nodes of the connection tree are data tables R. table Or the attribute column R in the data table column The middle node of the connection tree corresponds to a connection unit, which consists of four nodes: Table0, Column0, Column1, and Table1. Table0 and Table1 represent the tables that need to be connected, and Column0 and Column1 represent the attribute columns that need to be connected. This forms the connection unit for all nodes. The Child-Sum Tree-LSTM is used to aggregate the connection units of all the constructed nodes to form a query tree; The Depth-First Search (DFS) algorithm is used to recursively traverse the query tree from the root node along the depth of the tree to obtain the connection state between the leaf nodes in the query tree.

4. The database connection sorting adjustment method based on QMIX architecture according to claim 1, characterized in that, The continuous optimization of the total Q value for each agent includes: The first set of weights w1 and bias b1 is dynamically generated using two networks, hyper_w1 and hyper_b1, based on the constrained state input information. The first set of weights w1 is then weighted and summed, and the corresponding bias b1 is added to obtain the first set of Q values ​​of the agent. The second set of weights w2 and bias b2 is dynamically generated using two networks, hyper_w2 and hyper_b2, based on the constrained state input information. The second set of weights w2 is then weighted and summed, and the corresponding bias b2 is added to obtain the agent's second set of Q values. The total Q value of each agent is continuously optimized by using the first set of Q values ​​and the second set of Q values ​​of the agents.

5. A database connection sorting adjustment device based on QMIX architecture, characterized in that, include: The module is used to retrieve multiple data tables from the database based on the query statement SQL, set the data tables as nodes of the graph, set the connections between the data tables as edges of the graph, construct the query graph, and construct the column attributes of the data tables. The state representation module is used to perform feature state representation on each attribute column in each node of the query graph based on the attention mechanism graph neural network GAT. Each attribute column after being characterized by its feature state is linearly mapped to a vector, and the vectors formed by each attribute column are concatenated to form the feature vector of each node in the query graph. Based on the feature vector of each node in the query graph, a query tree is constructed using a tree-structured long short-term memory network Tree-LSTM. The leaf nodes of the query tree are the data table or the attribute columns within the data table. The depth optimization algorithm DFS is used to recursively search the leaf nodes in the query tree to obtain the connection state between the leaf nodes. The model module is used to construct a multi-agent reinforcement learning model (MARL) based on the QMIX algorithm. It sets up two weight networks, hyper_w1 and hyper_w2, and two bias networks, hyper_b1 and hyper_b2. hyper_w1 and hyper_w2 dynamically generate weights for weighted summation based on the state input. hyper_b1 is a fully connected layer used to generate bias terms. hyper_b2 contains two fully connected layers and an intermediate ReLU activation function. In the multi-agent reinforcement learning model MARL, agents are trained using a deep Q-network. During training, the connection states between leaf nodes are used to impose monotonicity constraints on the state input information of the agents. Hyper_w1, Hyper_w2, Hyper_b1, and Hyper_b2 are used to dynamically generate two sets of weights and biases based on the constrained state input information to continuously optimize the total Q value of each agent, thus obtaining the trained multi-agent reinforcement learning model MARL. The adjustment module is used to input the SQL query statement into the trained multi-agent reinforcement learning model MARL to obtain the query result after connection sorting adjustment. The column attributes of the constructed data table include: Retrieve columns from each data table involved in the query using a 12-bit one-hot vector R. column The column attributes are represented as follows: R column (A.c)= (c type ,c link ,c key ,c only ,c key ,c pkey ,c change ) Where A represents the data table, and c represents the attribute; c type Occupying 3 positions, representing integers, floating-point numbers, and strings respectively; c link Occupying 3 positions, representing the comparison methods =, >, and < respectively; c only This represents the proportion of unique values, occupying three positions, representing the intervals [0, 0.001), [0.001, 0.999], and (0.999, 1); c key Occupy one position, where 1 represents a primary key and 0 represents a non-primary key; c pkey Occupying one position indicates whether the attribute is a foreign key attribute; c change It occupies 1 position and is used to predict whether the unique value count will increase; 1 means it will increase and 0 means it will not. Construct an attribute column vector R from all column attributes in the data table. column .

6. An electronic device, characterized in that, include: Memory and processor; The memory is used to store computer programs; When the processor executes the computer program stored in the memory, it implements the steps of the database connection sorting adjustment method based on the QMIX architecture as described in any one of claims 1 to 4.

7. A computer-readable storage medium, characterized in that, Used to store a computer program, which, when executed by a processor, implements the steps of a database connection sorting adjustment method based on the QMIX architecture as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Database query optimization method based on reinforcement learning and graph attention network

    CN112328578A

  • Asynchronous SQL connection query optimization method based on reinforcement learning DQN algorithm

    CN113836174A