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

By adopting a QMIX architecture-based method in database query optimization, using GAT and Tree-LSTM for deep feature representation and connection state constraints, the problem of insufficient ability of reinforcement learning models in database connection sorting is solved, and more efficient query optimization is achieved.

CN119646000AActive Publication Date: 2025-03-18NINGXIA UNIVERSITY
View PDF 4 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

At this stage, when feature extraction or vectorization is performed, the vector form it forms can often only capture the semantic information and structural characteristics in shallow query statements, and it is difficult to provide effective state input information for the training of reinforcement learning models, resulting in poor ability of reinforcement learning models when adjusting database connections.

Method used

Using a method based on QMIX architecture, the feature state representation is performed through the attention mechanism graph neural network GAT, and a query tree is constructed in combination with the tree structure long and short-term memory network Tree-LSTM, and the deep optimization algorithm DFS is used to obtain the connection state between leaf nodes, and a multi-agent reinforcement learning model MARL is constructed, and training is performed to optimize connection sorting.

Benefits of technology

Through deep-level feature representation and connection state constraints, more effective state input information is provided, allowing the multi-agent reinforcement learning model to achieve stronger capabilities when adjusting database connections and improve the efficiency of query optimization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119646000A_ABST
    Figure CN119646000A_ABST
Patent Text Reader

Abstract

The invention discloses a QMIX architecture-based database connection sorting adjustment method, device and equipment, and relates to the technical field of database data processing. Feature state representation is performed on each attribute column in each node in a query graph by utilizing GAT, so that data information and data column information involved in a query statement are vectorized, and a query result is obtained; the method comprises the following steps: firstly, forming a feature vector of each node, constructing a query tree by utilizing a Tree-LSTM, recursively searching leaf nodes in the query tree by adopting a deep optimization algorithm DFS, and obtaining a connection state between the leaf nodes, so as to perform monotonicity constraint on state input information of a reinforcement learning model; in the process, semantic information and structural characteristics in deep query statements are captured, effective state input information is provided for training of a reinforcement learning model, and then input state information of an intelligent agent in the model is constrained by using a connection state between leaf nodes; therefore, the multi-agent reinforcement learning model has higher capability when the connection sorting adjustment of the database is carried out.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of database data processing, and in particular to a database connection sorting adjustment method, device, equipment and medium based on a QMIX architecture. Background Art

[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 face complex query spaces and huge data sizes, and efficiently selecting the optimal join order becomes increasingly prominent. Traditional static join order enumeration algorithms search for the optimal solution by thoroughly traversing the query space, but this method is often time-consuming and labor-intensive, and even becomes infeasible when faced with large-scale data sets and complex queries.

[0003] To solve the above problems, current query optimizers usually adopt a combination of heuristic algorithms and static methods. Heuristic algorithms can find a nearly optimal solution in a short time, but they cannot always guarantee the global optimal solution. In addition, such algorithms often lack feedback mechanisms on the quality of the resulting plans, which may cause the optimizer to repeatedly select the same inefficient execution plan, thereby missing out on better execution plans.

[0004] With the development of artificial intelligence technology, especially the rise of reinforcement learning, new ideas and methods have been provided for database connection sorting. Its learning optimizer uses machine learning models to predict and optimize connection sorting plans, making reinforcement learning widely used because it can handle long-term dependencies and delayed reward problems. In the reinforcement learning framework, the connection sorting problem is modeled as a process of interaction between a model and an environment (database system). The model needs to select the connection order according to the current state and obtain rewards by interacting with the environment. In order to train such a model, the query statement needs to be converted into a vector form that the machine model can understand. This process is called feature extraction or vectorization. At the same time, in the training process of reinforcement learning, the intelligent agent gradually learns which actions can bring higher rewards by constantly trying different actions and observing their results, which shows that the interaction between the model and the environment is crucial. However, at this stage, when performing feature extraction or vectorization, the vector form formed can often only capture the semantic information and structural characteristics in the shallow query statement, which is difficult to provide effective state input information for the training of the reinforcement learning model, resulting in the poor ability of the reinforcement learning model in adjusting the connection sorting of the database. Summary of the invention

[0005] The embodiments of the present invention provide a method, device and equipment for adjusting the sorting of database connections based on the QMIX architecture, which can solve the problem in the prior art that, when performing feature extraction or vectorization at the current stage, the vector form formed can often only capture the semantic information and structural characteristics in the shallow query statement, and it is difficult to provide effective state input information for the training of the reinforcement learning model.

[0006] An embodiment of the present invention provides a method for adjusting the database connection order based on the QMIX architecture, comprising the following steps:

[0007] According to the query statement SQL, multiple data tables in the database are obtained, the data tables are set as nodes of the graph, the connections between the data tables are set as edges of the graph, the query graph is constructed, and the column attributes of the data tables are constructed;

[0008] Based on the attention mechanism graph neural network GAT, each attribute column in each node in the query graph is characterized by its feature state; each attribute column after the feature state is represented is linearly mapped to a vector, and the vectors formed by each attribute column are concatenated to form a feature vector for 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, where the leaf nodes of the query tree are data tables or attribute columns in the data table, and a deep optimization algorithm DFS is used to recursively search the leaf nodes in the query tree to obtain the connection status between the leaf nodes;

[0009] Construct a multi-agent reinforcement learning model MARL based on QMIX, use a deep Q network to train the model, use the connection status between leaf nodes to constrain the agents to monotony during training, and obtain the trained multi-agent reinforcement learning model MARL;

[0010] The query statement SQL is input into the trained multi-agent reinforcement learning model MARL to obtain the query result after the connection order is adjusted.

[0011] Preferably, the constructing the column attributes of the data table includes:

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

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

[0014] A represents the data table, and c represents the attribute; type Occupies 3 positions, representing integers, floating-point numbers and strings respectively; c link Occupies 3 positions, representing the comparison methods of =, > and <; c only Represents the unique value ratio, occupies 3 positions, representing the intervals [0, 0.001), [0.001, 0.999] and (0.999, 1); c key Occupies a position, where 1 represents the primary key and 0 represents the non-primary key; c pkey Occupies a position, indicating whether the attribute is a foreign key attribute; c change 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 all column attributes in the data table into attribute column vectors R column .

[0016] Preferably, characterizing the characteristic state of each attribute column in each node in the query graph includes:

[0017] Each attribute column in 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, and each node forms a feature vector F′ of multiple dimensions;

[0018] Set the weight matrix W∈R F*F′ , characterize the characteristic state of each attribute column.

[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] Use N-aryTree-LSTM to build a connection tree, and 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 is composed of four nodes, namely Table0, Column0, Column1 and Table1. Table0 and Table1 represent the tables to be connected, Column0 and Column1 represent the attribute columns to be connected, and the connection units of all nodes are constructed;

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

[0023] The depth optimization algorithm DFS is used to start from the root node of the query tree, recursively traverse the nodes of the query tree along the depth of the tree, and obtain the connection status between the leaf nodes in the query tree.

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

[0025] Construct a multi-agent reinforcement learning model MARL based on the QMIX algorithm, and set two weight networks as hyper_w1 and hyper_w2, and two bias networks as hyper_b1 and hyper_b2; hyper_w1 and hyper_w2 dynamically generate weights for weighted summation according to state input; hyper_b1 is a fully connected layer for generating bias terms; hyper_b2 contains two fully connected layers and a ReLU activation function in the middle;

[0026] In the multi-agent reinforcement learning model MARL, the agents are trained using a deep Q network. During the training, the connection status between leaf nodes is used to perform 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 according to the constrained state input information to continuously optimize the total Q value of each agent and obtain the trained multi-agent reinforcement learning model MARL.

[0027] Preferably, the continuously optimizing the total Q value of each agent comprises:

[0028] Use the two networks hyper_w1 and hyper_b1 to dynamically generate the first set of weights w1 and bias b1 according to the constrained state input information, and add the weighted sum of the first set of weights w1 and the corresponding bias b1 to obtain the first set of Q values ​​of the agent;

[0029] Use the two networks hyper_w2 and hyper_b2 to dynamically generate the second set of weights w2 and bias b2 according to the constrained state input information, and add the corresponding bias b2 to the weighted sum of the second set of weights w2 to obtain the second set of Q values ​​of the agent;

[0030] The first set of Q-values ​​of the agent and the second set of Q-values ​​of the agent are continuously used to continuously optimize the total Q-value of each agent.

[0031] The embodiment of the present invention further provides a database connection sorting adjustment device based on the QMIX architecture, comprising:

[0032] A construction module is used to obtain multiple data tables in the database according to 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, build a query graph, and construct column attributes of the data tables;

[0033] The state representation module is used to represent the feature state of each attribute column in each node in the query graph based on the attention mechanism graph neural network GAT; each attribute column after the feature state representation is linearly mapped to a vector, and the vectors formed by each attribute column are spliced ​​to form a 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, and the leaf nodes of the query tree are data tables or attribute columns in the data table, and the deep optimization algorithm DFS is used to recursively search the leaf nodes in the query tree to obtain the connection status between the leaf nodes;

[0034] The model module is used to build a multi-agent reinforcement learning model MARL based on the QMIX form. The deep Q network is used to train the model. During the training, the connection status between leaf nodes is used to impose monotonicity constraints on the agents to obtain the trained multi-agent reinforcement learning model MARL.

[0035] The adjustment module is used to input the query statement SQL into the trained multi-agent reinforcement learning model MARL to obtain the query result after the connection order is adjusted.

[0036] An embodiment of the present invention further provides an electronic device, including a memory and a processor;

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

[0038] The processor is used to implement the steps of the database connection sorting adjustment method based on the QMIX architecture as described above when executing the computer program stored in the memory.

[0039] An embodiment of the present invention further provides a computer-readable storage medium for storing a computer program, wherein when the computer program is executed by a processor, the steps of the database connection sorting adjustment method based on the QMIX architecture are implemented as described above.

[0040] The embodiment of the present invention provides a method, device and apparatus for adjusting the database connection order based on the QMIX architecture. Compared with the prior art, the beneficial effects thereof are as follows:

[0041] The present invention uses an attention mechanism graph neural network GAT to characterize the feature state of each attribute column in each node in the query graph, so as to vectorize the data information and data column information involved in the query statement to form a feature vector of each node in the query graph, and then uses a tree structure long short-term memory network Tree-LSTM to build a query tree and adopts a deep optimization algorithm DFS to recursively search the leaf nodes in the query tree to obtain the connection state between the leaf nodes, so as to use the connection state between the leaf nodes to monotonically constrain the state input information of the reinforcement learning model. This process captures the semantic information and structural characteristics in the deep query statement, and provides effective state input information for the training of the reinforcement learning model. Then, the connection state between the leaf nodes is used to constrain the input state information of the agent in the multi-agent reinforcement learning model MARL, so that the multi-agent reinforcement learning model can achieve stronger capabilities when adjusting the connection sorting of the database. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0043] Figure 2 A query tree construction schematic diagram of a database connection sorting adjustment method based on the QMIX architecture provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0044] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific embodiments of the present invention are described in detail below in conjunction with the accompanying drawings. In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention can be implemented in many other ways different from those described herein, and those skilled in the art can make similar improvements without violating the connotation of the present invention, so the present invention is not limited by the specific embodiments disclosed below.

[0045] See also Figure 1 The embodiment of the present 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. The method to ensure quality is to select SQL sets of authoritative benchmarks in the database field, such as JOB, TPC-H, etc., and then divide S into training sets S according to the stratified sampling principle. t and the test set S v .

[0047] Step S2: Query plan representation; train the training set S tThe SQL query statement in is taken out, and the SQL query statement is constructed into a vector form Q, which includes the connection information of all tables.

[0048] Step S3: One-hot vectors are used to represent the designed attribute columns, which mainly include column attributes. Attribute column information is constructed according to the unique value ratio and other contents. The obtained attribute columns are used to characterize the query-designed data table using GAT.

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

[0050] Step S5: Use a QMIX-style multi-agent reinforcement learning architecture, set up a MixingNetwork network, and use global information to constrain the monotonicity of the agent so that the agent can find the optimal solution; its connection operator has three types: hashjoin, mergejoin, and nested loopjoin, so set up three DQN-style agents.

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

[0052] Specifically, step S2 includes:

[0053] Step S21: query the traditional database to obtain the number n of data tables 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 It represents the connection relationship between table i and table j. 1 means that there is a connection between the two, and 0 means that there is no connection between the two.

[0054] Step S22: Use the fully connected layer FC to convert the matrix m into a query plan expression R(Q) in vector form; put all the rows in the matrix m into the vector v to obtain m i,j =v i *n+j; at the same time, the vectorized expression of R(Q) is obtained by 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), b is a vector of shape (1,hs), and these two FC layers need to use the parameters learned by the training samples; 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 statement are regarded as nodes N of the graph, and the queries between tables are regarded as edges E of the graph; t Take out a SQL statement, define the data table in the statement as node N, and define the equivalent connection between nodes as edge E, then the query graph is expressed as G = (N, E).

[0058] Step S24: construct the query design data column through a 12-bit one-hot vector R column Characterize the column attributes; where c type Occupies 3 positions, representing integers, floating-point numbers and strings respectively; c link Occupies 3 positions, representing the comparison methods of =, > and <; c only Represents the unique value ratio, occupies 3 positions, representing the intervals [0, 0.001), [0.001, 0.999] and (0.999, 1). The unique value can be obtained from the system table of the traditional database system; for example, the pg_status table of Postgresql; c key Occupies a position, where 1 represents the primary key and 0 represents not the primary key; c pkey Occupies a position to represent whether the attribute is a foreign key attribute, which is 1 instead of 0; c change Occupies 1 position, the collected statistical data predicts whether the unique value count will increase, 1 represents increase, 0 represents no increase; assuming that the c attribute of table A is characterized, it can be expressed as:

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

[0060] Step S25: A table table having k attribute columns is represented by the query-related attribute column vector R generated in step S24. column ; Use GAT method to express k column attributes (R column (c1),R column (c2),...,Rcolumn (c k )), forming a vector representation of the data table.

[0061] Specifically, step S3 includes:

[0062] Step S31: The k column attribute expressions (R column (c1),R column (c2),...,R column (ck)) as the input information of GAT, and further obtain the data table representing R table ; For the single-layer graph attention mechanism network, the input is N nodes and the F-dimensional features of the nodes themselves. After GAT processing, multi-dimensional features F′ can be formed, and the size of F is the number of features of each node.

[0063] Step S31: Obtain the feature vector F′ in a higher-level feature space, which enhances the expression ability. In order to calculate the attention between nodes and obtain the structural information of the graph more effectively, define the weight matrix W∈R F*F′ Applied to each node N, the correlation coefficient is calculated through the shared attention mechanism.

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

[0065] Step S34: i The weighted output is the sum of the neighbors according to their attention. We further implement the attention mechanism with k heads and make an average output for the k heads. The data table vector of the node is represented as R table .

[0066] Specifically, step S4 includes:

[0067] Step S41: Build a connection tree. The leaf nodes of the tree are data tables or attribute column information. table With R column Vector representation; the middle node of the connection tree corresponds to a connection unit, which is composed of four nodes (Table0, Column0, Column1, Table1), marked as j; among them, Table0 and Table1 are the corresponding tables to be connected, and Column0 and Column1 are the corresponding attribute columns to be connected.

[0068] Step S42: Construct a connection unit Unit, and use g j Define its representation, using m jTo represent its storage unit, specifically including:

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

[0070] ②If node j is a leaf node representing a single column, then g j =R F ( j ), m j will be initialized to the 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 generated data table information R table In the initial stage, i is regarded as a tree node, that is, 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 trees in the initial state are unordered, and any tree can be connected; in order to further represent the process of merging trees into a forest, that is, connecting 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 in the state space to obtain a representation of the connection state. The pseudo code of the search algorithm is expressed as follows:

[0074]

[0075] Specifically, step S5 includes:

[0076] Step S51: Set up a reinforcement learning model of the DQN architecture; use DQN (Deep Q-Network) to train the model, and automatically learn the decision-making strategy through interaction with the environment, mainly including the DQN network and ReolayMemory; specifically:

[0077] 1. Define the DQN network. First, define all network layers; define the convolution layer, with N input channels, 1 output channel, n convolution kernels, and s step size; define the normalization layer, designed for the output channel to accelerate training and improve model stability; similarly, the subsequent convolution layers also need to be normalized; define the fully connected layer, map the output of the convolution layer to the output channel, and obtain the reward value of the execution.

[0078] 2. Define experience memory ReplayMemory; Experience replay stores the experience (state, action, next state, reward) gained by the agent when interacting with the environment, and samples can be randomly drawn from it to update the agent's strategy during training; define capacity, memory and position respectively; among them, 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, which is used to track the location 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 multiple key components and configuration parameters, which together define the structure and function of the network; among them, state_shape is used to define the dimension of the state input, that is, the size of the state information that the network needs to process; two_hyper_layers is a Boolean variable indicating whether a two-layer hypernetwork is used to generate weights. If true, the hypernetwork will contain more complexity and depth; hyper_hidden_dim sets the dimension of the hidden layer of the hypernetwork, while qmix_hidden_dim defines the dimension of the hidden layer of QMIX, and n_agents indicates the number of agents, which is an important parameter in a multi-agent system.

[0081] 2. In terms of hypernetwork, QMIXNET initializes two key weight networks: hyper_w1 and hyper_w2; the two networks dynamically generate weights for weighted summation according to the state input; if two_hyper_layers is configured to be true, then the two networks will each contain two fully connected layers and ReLU activation functions. This design enables the network to learn more complex feature representations and weight generation mechanisms; on the contrary, if two_hyper_layers is false, the 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; and hyper_b2 contains two fully connected layers and the ReLU activation function in the middle. This design makes the generation of bias also have a certain complexity and nonlinearity.

[0083] 4. During the forward propagation of the QMIX algorithm, the Q values ​​and state inputs of all agents are processed to calculate the total Q value of the team; receive 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, and its shape is (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 of each time step, and its shape is (episode_num, max_episode_len, state_shape), where state_shape represents the dimension of the state information; process these inputs so that they can adapt to the input requirements of the network; this usually involves reshaping q_values ​​and states so that they become the shape expected by the network.

[0084] 5. Use the two networks hyper_w1 and hyper_b1 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 by the configuration and network design. After generation, w1 and b1 need to be reshaped into appropriate shapes for subsequent calculations.

[0085] After having weights and biases, the q_values ​​are transformed for the first time. This transformation is achieved by weighted summation plus bias, that is, the Q value of each agent is weighted summed and then the corresponding bias is added. After completing this transformation, the ReLU activation function is used to activate the result to increase the nonlinear expression ability of the network.

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

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

[0088] like Figure 2 The following is a schematic diagram of query tree construction. The specific query tree construction process is as follows:

[0089] Set up query Q: Select*FromA,B,C,D WhereA;a1=B;b1 andB;b2=C;c1 and C;c2=D;d1 and D;d2=30.

[0090] When there is a query statement Q in the training set, the tables A, B, C and D in the query are constructed as nodes in the graph according to the equivalue connection relationship, and the query graph G = (N, E) is constructed; for example, each attribute column in table A is represented, R cloumn (A.a1) = (100, 100, 010, 1, 0, 1), the constructed vector is used as the attribute of node N, and information aggregation is performed to obtain the final R table The node vector.

[0091] After GAT processing, we get a vector, R tabel (A),R column (A.a1),R table (B),R cloumn (B.b1) constructs node j and stores node m as a leaf node j ; Perform a connection selection on the leaf node to generate a Unit unit that can be used for the next connection, and then the Unit unit is used for the next connection selection node to form the final h root .

[0092] The present invention adopts GAT (Graph Attention Network) to represent the query plan, and uses GAT to process the information involved in the query statement, such as data information, data column information, etc., into a vector form; then combines N-ary LSTM (N-ary Long Short-Term Memory) and Child-Sum Tree-LSTM to construct a query tree, and at the same time construct a representation of the query plan, and uses the constructed query plan and query content as training data for MARL, so that the trained model has the ability to adjust the database connection order, thereby achieving the purpose of connection order adjustment.

[0093] The above-mentioned embodiments only express several implementation methods of the present invention, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, and these all belong to the protection scope of the present invention. Therefore, the protection scope of the patent of the present invention shall be subject to the attached claims.

Claims

1. A database connection sorting adjustment method based on QMIX architecture, characterized in that: The following steps are involved: According to the query statement SQL, multiple data tables in the database are obtained, the data tables are set as nodes of the graph, the connections between the data tables are set as edges of the graph, the query graph is constructed, and the column attributes of the data tables are constructed; Based on the attention mechanism graph neural network GAT, each attribute column in each node in the query graph is characterized by its feature state; Each attribute column after the characteristic state is represented 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 data tables or attribute columns in the data table, and the deep optimization algorithm DFS is used to recursively search the leaf nodes in the query tree to obtain the connection status between the leaf nodes; Construct a multi-agent reinforcement learning model MARL based on QMIX, use a deep Q network to train the model, use the connection status between leaf nodes to constrain the agents to monotony during training, and obtain the trained multi-agent reinforcement learning model MARL; The query statement SQL is input into the trained multi-agent reinforcement learning model MARL to obtain the query result after the connection order is adjusted.

2. According to a method for adjusting database connection order based on QMIX architecture according to claim 1, it is characterized in that: The column attributes of the constructed data table include: Get the columns in each data table involved in the query, using a 12-bit one-hot vector R column The column attributes are represented as: R column (A.c)=(c type ,c link ,c key ,c only ,c key ,c pkey ,c change ) A represents the data table, and c represents the attribute; type Occupies 3 positions, representing integers, floating-point numbers and strings respectively; c link Occupies 3 positions, representing the comparison methods of =, > and <; c only Represents the unique value ratio, occupies 3 positions, representing the intervals [0, 0.001), [0.001, 0.999] and (0.999, 1); c key Occupies a position, where 1 represents the primary key and 0 represents the non-primary key; c pkey Occupies a position, indicating whether the attribute is a foreign key attribute; c change 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 all column attributes in the data table into attribute column vectors R column .

3. According to a method for adjusting database connection order based on QMIX architecture according to claim 1, it is characterized in that: The step of characterizing the characteristic state of each attribute column in each node in the query graph includes: Each attribute column in 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, and each node forms a feature vector F′ of multiple dimensions; Set the weight matrix W∈R F*F′ , characterize the characteristic state of each attribute column.

4. According to a method for adjusting database connection order based on QMIX architecture according to claim 1, it is characterized in that: The obtaining of the connection status between leaf nodes includes: The tree-structured long short-term memory network Tree-LSTM includes N-ary Tree-LSTM and Child-SumTree-LSTM; Use N-aryTree-LSTM to build a connection tree, and 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 is composed of four nodes, namely Table0, Column0, Column1 and Table1. Table0 and Table1 represent the tables to be connected, Column0 and Column1 represent the attribute columns to be connected, and the connection units of all nodes are constructed; The Child-Sum Tree-LSTM is used to aggregate the connection units of all constructed nodes to form a query tree; The depth optimization algorithm DFS is used to start from the root node of the query tree, recursively traverse the nodes of the query tree along the depth of the tree, and obtain the connection status between the leaf nodes in the query tree.

5. According to a method for adjusting database connection order based on QMIX architecture according to claim 1, it is characterized in that: The method of obtaining the trained multi-agent reinforcement learning model MARL includes: Construct a multi-agent reinforcement learning model MARL based on the QMIX algorithm, and set two weight networks as hyper_w1 and hyper_w2, and two bias networks as hyper_b1 and hyper_b2; hyper_w1 and hyper_w2 dynamically generate weights for weighted summation according to state input; hyper_b1 is a fully connected layer for generating bias terms; hyper_b2 contains two fully connected layers and a ReLU activation function in the middle; In the multi-agent reinforcement learning model MARL, the agents are trained using a deep Q network. During the training, the connection status between leaf nodes is used to perform 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 according to the constrained state input information to continuously optimize the total Q value of each agent and obtain the trained multi-agent reinforcement learning model MARL.

6. According to a method for adjusting database connection order based on QMIX architecture according to claim 5, it is characterized in that: The continuous optimization of the total Q value of each agent includes: Use the two networks hyper_w1 and hyper_b1 to dynamically generate the first set of weights w1 and bias b1 according to the constrained state input information, and add the weighted sum of the first set of weights w1 and the corresponding bias b1 to obtain the first set of Q values ​​of the agent; Use the two networks hyper_w2 and hyper_b2 to dynamically generate the second set of weights w2 and bias b2 according to the constrained state input information, and add the corresponding bias b2 to the weighted sum of the second set of weights w2 to obtain the second set of Q values ​​of the agent; The first set of Q-values ​​of the agent and the second set of Q-values ​​of the agent are continuously used to continuously optimize the total Q-value of each agent.

7. A database connection sorting adjustment device based on QMIX architecture, characterized in that: include: A construction module is used to obtain multiple data tables in the database according to 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, build a query graph, and construct the column attributes of the data tables; The state representation module is used to represent the feature state of each attribute column in each node in the query graph based on the attention mechanism graph neural network GAT; Each attribute column after the characteristic state is represented 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 data tables or attribute columns in the data table, and the deep optimization algorithm DFS is used to recursively search the leaf nodes in the query tree to obtain the connection status between the leaf nodes; The model module is used to build a multi-agent reinforcement learning model MARL based on the QMIX form. The deep Q network is used to train the model. During the training, the connection status between leaf nodes is used to impose monotonicity constraints on the agents to obtain the trained multi-agent reinforcement learning model MARL. The adjustment module is used to input the query statement SQL into the trained multi-agent reinforcement learning model MARL to obtain the query result after the connection order is adjusted.

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

9. 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 a QMIX architecture as described in any one of claims 1 to 6.

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

  • Distributed query service-oriented optimization method

    CN119003617A

  • Method for multi-agent dynamic path planning

    GB202209423D0