An optimization method and device of a syntax tree
By using a neural network model to perform deep learning and reconstruction on the feature data of the syntax tree, the problem of insufficient performance evaluation of traditional physical execution plans is solved, and more efficient database query optimization is achieved.
Patent Information
- Application Number
- CN202111498126.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-09
- Publication Date
- 2026-02-13
- Estimated Expiration
- 2041-12-09
AI Technical Summary
Traditional physical execution plan performance evaluation cannot provide high-quality predictions, making it difficult to achieve optimal performance and affecting database query efficiency.
We employ a neural network model to perform deep learning on the feature data of the syntax tree. By extracting the feature data of node attributes, we reconstruct the syntax tree to optimize performance evaluation. We utilize long short-term memory networks and fully connected neural networks for performance evaluation and model training, and adjust the model parameters to improve evaluation accuracy.
It improves the accuracy of physical execution plan performance evaluation, optimizes syntax tree performance results, is applicable to various database types, and improves database query efficiency.
Smart Images

Figure CN114168625B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of database, in particular, to a syntax tree optimization method and device. BACKGROUND
[0002] In the field of database, various database services can be implemented based on the database. Taking database query as an example, the query condition text input by the user is parsed, a syntax tree for database query is generated based on the parsing result, a computing engine maps the syntax tree into a physical execution plan, and searches in the database according to the physical execution plan to obtain the query result.
[0003] In order to improve the efficiency of the service, the database needs to be optimized. In the field of database optimization, the performance of the physical execution plan is crucial to the service optimization, for example, cost evaluation for measuring the consumption of CPU, memory, network and other resources, and cardinality evaluation for measuring the list data volume, maximum / minimum value of each column, storage size occupied by each column value and other information. Different syntax trees are mapped into different physical execution plans, and the performance evaluation results of different physical execution plans are different.
[0004] The traditional performance evaluation of the physical execution plan cannot provide high-quality estimation, which leads to the difficulty in obtaining a physical execution plan with better performance. SUMMARY
[0005] The present application provides a syntax tree optimization method and device to obtain a physical execution plan with better performance.
[0006] The present application provides a syntax tree optimization method, comprising:
[0007] obtaining a first syntax tree for a database service,
[0008] extracting feature data of the current first syntax tree for representing node attributes,
[0009] using a neural network model to perform deep learning on the feature data, obtaining a representation vector of the first syntax tree and a performance evaluation result of the first syntax tree,
[0010] in the case where the performance evaluation result reaches a set evaluation threshold, obtaining a second syntax tree mapped by the current representation vector to obtain an optimization result of the first syntax tree;
[0011] If the performance evaluation result does not reach the set evaluation threshold, the first syntax tree is reconstructed based on the current representation vector of the first syntax tree so that the feature data of at least one node attribute of the first syntax tree is updated, and the step of extracting the feature data of the first syntax tree to represent the node attributes is returned to be executed until the number of reconstructed first syntax trees reaches the set exhaustive threshold.
[0012] Preferably, the method further includes,
[0013] If the performance evaluation result does not reach the evaluation threshold, and the number of reconstructed first syntax trees reaches the exhaustive threshold,
[0014] The current neural network model is trained using sample data from the aforementioned database service.
[0015] Adjust the model parameters of the neural network model based on the training results until the training results of the neural network model reach the set prediction results, and save the current model parameters.
[0016] Return to the step of processing the feature data using the neural network model.
[0017] Preferably, the extraction of feature data from the first syntax tree includes,
[0018] Extract feature data for each node in the first syntax tree. The feature data includes operation type features, predicate features, and metadata features.
[0019] Preferably, the neural network model includes a long short-term memory network and a fully connected neural network connected to the output of the long short-term memory network.
[0020] in,
[0021] The Long Short-Term Memory network is used to learn the representation vector of the first syntax tree based on the feature data.
[0022] The fully connected neural network is used to evaluate the performance of the first syntax tree based on the representation vector.
[0023] Preferably, the step of using a neural network model to perform deep learning on the feature data to obtain the representation vector of the first syntax tree and the performance evaluation result of the first syntax tree includes,
[0024] Based on the feature data of each node, the feature vector of each node is obtained.
[0025] inputting the feature vector of each node into the current neural network model one by one, obtaining the representation vector of each node from the output of the long short-term memory network one by one, and obtaining the evaluation result of the cost and / or cardinality of each node from the output of the fully connected neural network one by one,
[0026] obtaining the evaluation result of the cost and / or cardinality of the first syntax tree according to the evaluation result of the cost and / or cardinality of all nodes.
[0027] The reconstruction of the first syntax tree according to the current representation vector of the first syntax tree, so that the feature data of at least one node attribute of the first syntax tree is updated, comprises:
[0028] selecting at least one node for reconstructing the syntax tree,
[0029] updating the node attribute according to the current representation vector of the selected node, so that at least one of the operation type feature data, the predicate feature data, and the metadata feature data of the node is updated.
[0030] Preferably, the feature vector of each node is obtained based on the feature data of each node, which comprises:
[0031] In the case where there are a first node and a second node belonging to the same parent node, the feature vector of the first node and the feature vector of the second node are updated to the average of the feature vector of the first node and the feature vector of the second node, respectively.
[0032] Preferably, the evaluation result of the cost and / or cardinality of each node from the output of the fully connected neural network one by one further comprises:
[0033] In the case where the node is a child node, the evaluation result of the child node is cached.
[0034] Preferably, the second syntax tree mapped by the current representation vector is obtained in the case where the evaluation result reaches a set evaluation threshold, which comprises:
[0035] In the case where the performance evaluation result reaches the minimum performance evaluation result among all previous performance evaluation results, the second syntax tree is determined based on the current representation vector of each node according to the node relationship between nodes in the first syntax tree.
[0036] The application also provides an optimization device of a syntax tree, which comprises:
[0037] a first obtaining module configured to obtain a first syntax tree for a database service,
[0038] a feature extraction module configured to extract feature data of a current first syntax tree for representing node attributes,
[0039] a neural network model module configured to perform deep learning on the feature data to obtain a representation vector of the first syntax tree and a performance evaluation result of the first syntax tree,
[0040] a second obtaining module configured to, in a case where the performance evaluation result reaches a set evaluation threshold, obtain a second syntax tree mapped by the current representation vector to obtain an optimization result of the first syntax tree; and in a case where the performance evaluation result does not reach the set evaluation threshold, reconstruct the first syntax tree according to the current representation vector of the first syntax tree, so that feature data of at least one node attribute of the first syntax tree is updated, and provide the reconstructed first syntax tree to the feature extraction module until a quantity of the reconstructed first syntax trees reaches a set exhaustion threshold.
[0041] The application further provides a neural network model for syntax tree optimization, which is configured to perform deep learning on feature data of a syntax tree for database services to obtain a representation vector of the syntax tree and a performance evaluation result of the syntax tree.
[0042] Preferably, the neural network model comprises a long short-term memory network and a fully connected neural network connected to an output of the long short-term memory network,
[0043] wherein,
[0044] the long short-term memory network is configured to learn the representation vector of the syntax tree based on the feature data,
[0045] and the fully connected neural network is configured to perform the performance evaluation of the syntax tree based on the representation vector.
[0046] The application further provides a computer readable storage medium, wherein a computer program is stored in the storage medium, and the computer program is executed by a processor to implement any of the syntax tree optimization methods.
[0047] The syntax tree optimization method provided in the application uses a neural network model to perform deep learning on feature data of a syntax tree, obtains a representation vector of the syntax tree and a performance evaluation result of the syntax tree, thereby realizing performance estimation of the syntax tree, improving the performance of a physical execution plan, and improving the accuracy of the performance evaluation result. In the case where the performance evaluation result does not reach a set evaluation threshold, the feature data of the syntax tree is updated by reconstructing the syntax tree, and the input data of the current neural network model is adjusted, thereby obtaining a syntax tree with multiple node attributes, improving the optimization result of the syntax tree, and further training the current neural network model to adjust model parameters, so that the neural network model is optimized, and the representation vector of the syntax tree is gradually optimized by using the optimized neural network model, thereby obtaining a better and better performance evaluation result of the syntax tree. The optimization method of the application is not limited by databases and data sources, and has strong applicability and versatility. BRIEF DESCRIPTION OF DRAWINGS
[0048] Figure 1 A flowchart of a syntax tree optimization method according to an embodiment of the application.
[0049] Figure 2 A flowchart of a syntax tree optimization method according to an embodiment of the application.
[0050] Figure 3 A schematic diagram of a neural network according to an embodiment of the application.
[0051] Figure 4 A schematic diagram of an LSTM unit in a long short-term memory network.
[0052] Figure 5 A schematic diagram of a syntax tree before optimization and a syntax tree after optimization.
[0053] Figure 6 A schematic diagram of an optimization device for a syntax tree according to an embodiment of the application.
[0054] Figure 7 Another schematic diagram of an optimization device for a syntax tree according to an embodiment of the application. DETAILED DESCRIPTION
[0055] In order to make the purpose, technical means and advantages of the application more clear and explicit, the application is further described in detail below with reference to the drawings.
[0056] The optimization method for a syntax tree provided in the application uses a neural network model to perform deep learning on feature data of a syntax tree, obtains a representation vector of the syntax tree and a performance evaluation result of the syntax tree, adjusts the input data of the current neural network model through syntax tree reconstruction, thereby optimizing the representation vector and the performance evaluation result of the syntax tree.
[0057] Referring to Figure 1 as shown, Figure 1 is a flowchart of a syntax tree optimization method according to an embodiment of the present application. The method comprises,
[0058] In step 101, a first syntax tree for a database service is obtained,
[0059] In step 102, feature data of the current first syntax tree is extracted,
[0060] In step 103, a neural network model is used to perform deep learning on the feature data, to obtain a representation vector of the first syntax tree and a performance evaluation result of the first syntax tree,
[0061] In step 104, it is determined whether the performance evaluation result reaches a set evaluation threshold,
[0062] In the case where the performance evaluation result reaches the set evaluation threshold, a second syntax tree mapped by the current representation vector is obtained, to obtain an optimization result of the first syntax tree.
[0063] In the case where the performance evaluation result does not reach the set evaluation threshold, the first syntax tree is reconstructed according to the current representation vector of the first syntax tree, so that feature data of at least one node attribute of the first syntax tree is updated, and the step 102 is returned until the reconstructed first syntax tree tends to be exhausted.
[0064] The embodiment learns the feature data of the syntax tree through the neural network model, to obtain a performance evaluation result and a representation vector based on the syntax tree, thereby improving the accuracy of performance evaluation of the syntax tree. The embodiment of the present application is not limited to a database and is not limited to a specific data source.
[0065] For ease of understanding, the following will be described in combination with a specific neural network model, and it should be understood that the present application is not limited thereto, and any neural network model capable of deep learning can be applicable.
[0066] Referring to Figure 2 as shown, Figure 2 is a flowchart of a syntax tree optimization method according to an embodiment of the present application. The method comprises,
[0067] In step 201, a first syntax tree for a database service is obtained,
[0068] As an example, in view of the fact that the database service is mainly query, the query condition text for database query is subjected to text analysis, and the first syntax tree is generated based on the text analysis result. The first syntax tree can include a plurality of nodes and node relationships between the nodes, wherein all the node relationship sets form a tree structure.
[0069] The database can be any type of database, including but not limited to, an SQL database, an HBase database, a Hive database, an Elasticsearch (ES) database, a Click House database, etc.
[0070] Step 202, extracting feature data for representing the attributes of each node in the first syntax tree,
[0071] In view of the three main factors affecting access performance, namely, operation type, predicate, and metadata information, they can represent the attributes of the node, wherein,
[0072] The operation type mainly includes a join operation type (Join), such as a hash join (Hash Join), a merge join (Merge Join), and a sorted merge join (Sorted Merge Join); a scan operation type (Scan); an aggregation operation type (Aggregation); a filter operation type (Filter), etc., which will determine the cost of accessing the database;
[0073] The predicate is composed of a column, a predicate type, and a filtering condition, and the predicate type mainly includes and / or / not, = / != / > / >= / < / <= / like / in. The execution of the predicate and whether the predicate can be pushed down in priority will affect the execution cost of the entire access;
[0074] The metadata information includes a data table, a column constituting the data table, an index of the column constituting the data table, and statistical information of the data table, etc., which is used to convert a logical plan into a physical execution plan, i.e., to map a syntax tree into a physical execution plan, and to combine the characteristics and statistical information of the data source to optimize the access;
[0075] Therefore, the operation type feature, the predicate feature, and the metadata feature of each node are extracted as the feature vector of the node.
[0076] Specifically, the operation type (Operation), the predicate (Predicate), and the metadata (Metadata) feature data of any node X are represented as OPx, PRx, and MEx, respectively.
[0077] Step 203, inputting the feature data into a neural network model to perform deep learning on the feature data by using the neural network model.
[0078] For ease of understanding, the following takes a long short-term memory network (LSTM) and a fully connected neural network connected to the output of the long short-term memory network as an example.
[0079] Referring to Figure 3 illustrated,Figure 3 Figure 1 is a schematic diagram of a neural network according to an embodiment of the present application. The neural network comprises a long short-term memory network (LSTM) for learning a representation vector of a syntax tree, and a fully connected neural network connected to an output of the long short-term memory network, wherein the fully connected neural network is configured to evaluate a cost and / or a cardinality based on the representation vector, and the fully connected neural network can comprise n layers of fully connected layers, for example, 2 layers of fully connected layers.
[0080] In step 2031, a feature vector of the node is obtained based on the feature data of the node,
[0081] Specifically, the feature data is weighted, then an offset is added, and then an activation function operation is performed, and the result of the activation function operation is taken as the feature vector.
[0082] For example, the feature vector of the node X is denoted as EX, W is denoted as a weight, and b is denoted as an offset. The obtained feature vector is as follows:
[0083] EX=[OP' x ,PR' x ,ME' x ]
[0084] OP' x =ReLU(W OP *OP x +b OP )
[0085] PR' x =ReLU(W PR *PR x +b PR )
[0086] ME' x =ReLU(W ME *ME x +b ME )
[0087] wherein ReLU denotes an activation function,
[0088] W OP is a first weight for obtaining an operation type feature vector, W PR is a second weight for obtaining a predicate feature vector, and W ME is a third weight for obtaining a metadata feature vector,
[0089] b OP is a first offset for obtaining an operation type feature vector, b PR is a second offset for obtaining a predicate feature vector, and b ME is a third offset for obtaining a metadata feature vector,
[0090] OP x For feature data of operation type, PR x For the feature data of predicates, ME x Feature data for metadata,
[0091] OP' x For the feature vector of the operation type, PR' x ME' is the feature vector of the predicate. x This is the feature vector of the metadata.
[0092] To avoid gradient vanishing, for the first and second nodes belonging to the same parent node, such as the left and right nodes, the average of the eigenvectors of the left and right nodes is used to update the eigenvectors of the left and right nodes respectively. This can be expressed mathematically as follows:
[0093] x' l t =x' r t =(x l t+ x r t ) / 2
[0094] Where, x' l t 、x' r t The updated feature vectors for the left and right nodes are input respectively, x. l t x r t These are the feature vectors of the left node and the right node before the update, respectively.
[0095] Step 2032: Input the feature vectors of each node into the current neural network model one by one. Utilize the neural network model to process the input feature vectors to learn the representation vector of each node in the first syntax tree. Then, evaluate the cost and / or cardinality of each node based on its representation vector.
[0096] See Figure 4 As shown, Figure 4 This is a schematic diagram of an LSTM unit in a Long Short-Term Memory (LSTM) network. In the diagram, A represents an LSTM unit. In any LSTM unit, such as the middle unit in the diagram, based on the relationships between the variables, we have:
[0097] F t =Sigmoid(W f *[H t-1 xt ]+b f )
[0098] I 1 t =Sigmoid(W k1 *[H t-1 ,x t ]+b k1 )
[0099] C’ t =tanh(W r *[H t-1 ,x t ]+b r )
[0100] I 2 t =Sigmoid(W k2 *[H t-1 ,x t ]+b k2 )
[0101] C t =F t *C t-1 +I 1 t *C’ t
[0102] H t =I 2 t *tanh(C t )
[0103] wherein,
[0104] F t represents a forget gate unit for controlling which information is discarded; W f is a weight for controlling the information discarded, b f is an offset for controlling the information discarded;
[0105] I 1 t represents which feature information is added to the long memory input channel; W k1 is a weight for adding feature information to the long memory input channel, b k1 is an offset for adding feature information to the long memory input channel;
[0106] I 2 t represents which feature information is added to the output channel; W k2 is a weight for adding feature information to the output channel, b k2an offset for the feature information added to the output channel;
[0107] C’ t denotes the temporary state of the feature information entering the candidate memory cell channel, W r is a weight for the temporary state of the feature information entering the candidate memory cell channel, b r is an offset for the temporary state of the feature information entering the candidate memory cell channel;
[0108] x t denotes the input node feature vector;
[0109] H t denotes the current output of the LSTM unit;
[0110] C t denotes the candidate memory cell channel.
[0111] As can be seen from the above relationship, as the input data continues to increase, the self-circulating LSTM unit structure passes the previous state to the current input, together as new input data for the current round of training and learning, until the input or training is completed, and finally the prediction result is obtained; the LSTM unit structure maintains a persistent cell state that is continuously passed down, used to determine which information to forget or continue to pass down.
[0112] In this way, after inputting the feature vector of each node to the LSTM, an output result H t , i.e., the representation vector of the node, is obtained; in the fully connected neural network layer, the current representation vector is activated using the ReLU activation function, and then the normalized cost and cardinality are predicted using the Sigmoid function, expressed mathematically as:
[0113] Cost’ = ReLU(W cost’ *H t +b cost’ )
[0114] Card’ = ReLU(W card’ *H t +b card’ )
[0115] Cost = Sigmoid(W cost *Cost’ + b cost )
[0116] Card = Sigmoid(W card’ *Card’ + b card )
[0117] wherein Cost', Card' represent the activation operation results of the cost and the cardinality respectively, Cost, Card represent the normalized cost results of the cost and the cardinality respectively, and W cost’ is a weight used for weighting the current representation vector when performing the activation function operation of the cost, card’ is a weight used for weighting the current representation vector when performing the activation function operation of the cardinality.
[0118] In this way, the evaluation results of the cost and / or the cardinality of each node can be obtained through the representation vector of each node, and the results can be expressed in the form of a tuple <Operation, Cost, Cardinality>.
[0119] In order to reduce the calculation amount of the neural network model, the evaluation results of the cost and / or the cardinality of the child nodes are cached to avoid repeated calculation for the evaluation of different combinations of the child nodes. For example, a SQL expression is (A, B, C, D), and the following results need to be calculated:
[0120] {A, B, C, D, (A, B), (B, C), (C, D), (A, (B, C)), ((A, B), C), ((B, C), D), (B, (C, D)), (A, B, C, D),...} and the like. When the evaluation result of (A, (B, C)) is needed, the previously calculated and cached A and the evaluation result of (B, C) can be directly used, without the need for re-calculation.
[0121] Step 2033: determining whether the feature vectors of all nodes have been evaluated,
[0122] If not, step 2032 is repeatedly executed until the feature vectors of all nodes have been evaluated.
[0123] If yes, the evaluation results of the cost and / or the cardinality of each node are accumulated to obtain the evaluation results of the cost and / or the cardinality of the first syntax tree.
[0124] Step 204: determining whether the current evaluation result reaches a set evaluation threshold, wherein the evaluation threshold can be the minimum value in the previous evaluations.
[0125] If yes, an optimized second syntax tree (optimized first syntax tree) is obtained according to the current representation vector, and the second syntax tree is mapped to a physical plan for execution. Specifically, the tree structure is determined according to the node relationship between the nodes in the first syntax tree, the feature data of each node is determined based on the current representation vector of each node, i.e., the operation type, the predicate and the metadata of the node are determined, so as to obtain the second syntax tree.
[0126] Otherwise, at least one node of the reconstructed syntax tree is selected, and the attribute of the selected node is updated according to the current representation vector of the selected node, so that at least one of the operation type feature data, the predicate feature data, and the metadata feature data of the selected node is updated, and the feature data of each node in the reconstructed syntax tree is extracted, and then the step 2031 is returned until the first syntax tree reaches a set exhaustion threshold, so that the reconstructed syntax tree is learned in depth based on the current neural network model, so that the syntax tree with better performance evaluation result among all possible syntax trees can be determined in a faster way. The exhaustion threshold can be determined according to the number of syntax trees with the same tree structure among all syntax trees for implementing the database service.
[0127] As an example, a node of the reconstructed syntax tree can be selected according to the current evaluation result of each node, for example, the current evaluation result of each node is sorted, and the node corresponding to the maximum cost and / or cardinality in the current evaluation result of each node is selected. According to the current representation vector of the selected node, the attribute of the selected node is adjusted, that is, one of the operation type, the predicate, and the metadata of the node is adjusted to reconstruct the node, so that the feature data of the node is updated, and the feature data of the node is extracted.
[0128] For the convenience of understanding, an example is given. In order to query the list of scores between 60 and 70, the query method can be: querying the list of scores between 60 and 65 and the list of scores between 65 and 70, and the corresponding node operation type is jion operation, the metadata is 60-65 and 65-70, and the predicate is and; another query method is: filtering out the list of scores below 60 and the list of scores above 70, and the corresponding node type is filter operation, the metadata is less than 60 and greater than 70, and the predicate is and; the operation type and the metadata in the node attributes corresponding to the two query methods are different, so the feature data of the nodes are different, and the score distribution is different, which will cause the cost and / or cardinality of the nodes with the two attributes to be different. Therefore, by reconstructing the syntax tree, the feature data of at least one node attribute of the first syntax tree is updated, and the input data of the current neural network model is adjusted, so that the performance evaluation results of different syntax trees for the same database service are obtained as much as possible.
[0129] Step 205: Using the sample data used to train the neural network model parameters, train the current neural network model. Adjust the model parameters based on the training results, i.e., adjust the aforementioned weight parameters and offsets, until the training result of the neural network model reaches the set prediction result. Then save the current model parameters and return to step 202 for the next optimization based on the current neural network model. Repeat this process of evaluation and adjustment of model parameters until the current evaluation result reaches the set evaluation threshold. Since the neural network model can output the performance evaluation result of the syntax tree through model parameter adjustment and deep learning utilizing node features, this neural network model can also be called a syntax tree performance evaluation model.
[0130] To improve the accuracy and versatility of the neural network model, a massive amount of existing business data from the database is used as samples. Operation type features, predicate features, and metadata features are extracted from these samples. During training, model parameters can be adjusted based on historical business operations.
[0131] The embodiments of this application will be described below with reference to a specific syntax tree. See also Figure 5 As shown in the figure, the unoptimized syntax tree on the left is transformed into the optimized syntax tree on the right using the optimization method of this application embodiment. The optimized syntax tree demonstrates that the aggregation operation of table 1 is first pushed down to the data source side based on the characteristics of the data source, and the sorting operation of table 2 is also pushed down to the data source side to fully utilize the underlying computing power. The filtering operation of table 1 is then pushed down to the data source side to reduce intermediate network data transmission. Finally, the join order of table 1 and table 2 is adjusted, thus transforming a hash join into a broadcast join. Through the above optimization method, the performance of the final physical execution plan is greatly improved.
[0132] It should be understood that after optimizing a syntax tree, the current neural network model can be used to optimize the next syntax tree. In other words, the model parameters of the current neural network model are used as the initial parameters of the neural network model when optimizing the next syntax tree.
[0133] The syntax tree optimization method of the embodiment can also cooperatively and alternately perform model parameter adjustment and input data adjustment of the neural network model by setting the exhaustive threshold and the evaluation threshold, for example, performing performance evaluation of the reconstruction trees in the first reconstruction tree set based on the neural network model with the first model parameter, and performing performance evaluation of the reconstruction trees in the second reconstruction tree set based on the neural network model with the second model parameter, wherein the first reconstruction tree set can be the same as the second reconstruction tree set, or the two sets have an intersection or no intersection, so as to quickly obtain a better optimization result and improve the stability and robustness of the optimization process.
[0134] The syntax tree optimization method of the embodiment is equivalent to introducing two feedbacks into the optimization process, one is the feedback of the input data of the neural network model to the reconstruction syntax tree, and the other is the feedback of the model parameter of the neural network model to the sample data, that is, the two feedbacks are used to select the syntax tree with the optimal performance evaluation result from all the syntax tree sets for realizing the same database service, which improves the optimization efficiency of the syntax tree and the optimization result.
[0135] Referring to Figure 6 as shown, Figure 6 is a schematic diagram of an optimization device for the syntax tree of the embodiment. The device comprises,
[0136] a first acquisition module configured to acquire a first syntax tree for a database service,
[0137] a feature extraction module configured to extract feature data of a node attribute of the first syntax tree,
[0138] a neural network model module configured to perform deep learning on the feature data to obtain a representation vector of the first syntax tree and a performance evaluation result of the first syntax tree,
[0139] a second acquisition module configured to, in a case where the performance evaluation result reaches a set evaluation threshold, acquire a second syntax tree mapped by a current representation vector to obtain an optimization result of the first syntax tree; and in a case where the performance evaluation result does not reach the set evaluation threshold, reconstruct the first syntax tree according to the current representation vector of the first syntax tree so that the feature data of at least one node attribute of the first syntax tree is updated, and return to perform the step of performing deep learning on the feature data by using the neural network model until the number of the reconstructed first syntax trees reaches a set exhaustive threshold.
[0140] The feature extraction module comprises,
[0141] an operation type feature extraction submodule configured to extract operation type feature data of a node of the first syntax tree,
[0142] a predicate feature extraction submodule configured to extract predicate feature data of the first syntax tree node,
[0143] a metadata feature submodule configured to extract metadata feature data of the first syntax tree node;
[0144] the neural network model module comprises,
[0145] an input layer configured to acquire a feature vector of each node based on the feature data of each node,
[0146] a long short-term memory network layer configured to learn a representation vector of the first syntax tree based on the feature data,
[0147] a fully connected neural network layer configured to perform performance evaluation of the first syntax tree based on the representation vector.
[0148] The apparatus further comprises,
[0149] a training module configured to, in a case where the performance evaluation result does not reach the evaluation threshold,
[0150] train the current neural network model by using sample data in the database service,
[0151] adjust model parameters of the neural network model according to a training result until the training result of the neural network model reaches a set prediction result, and save the current model parameters.
[0152] the second acquisition module comprises,
[0153] a syntax tree reconstruction submodule configured to, in a case where the performance evaluation result does not reach a set evaluation threshold, reconstruct the first syntax tree according to a current representation vector of the first syntax tree, so that feature data of at least one node attribute of the first syntax tree is updated, and the updated feature data is input to the feature extraction module.
[0154] a syntax tree mapping submodule configured to, in a case where the performance evaluation result reaches a set evaluation threshold, acquire a second syntax tree mapped by the current representation vector to obtain an optimization result of the first syntax tree.
[0155] Referring to Figure 7 shown, Figure 7 is another schematic view of an optimization apparatus for a syntax tree according to an embodiment of the present application. The apparatus comprises a processor and a memory, the memory storing a computer program, and the processor being configured to execute the computer program to implement the optimization method for a syntax tree according to an embodiment of the present application.
[0156] The memory can include a random access memory (RAM) and can also include a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory can also be at least one storage device located remotely from the aforementioned processor.
[0157] The aforementioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc., and can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic device, discrete gate or transistor logic device, discrete hardware component.
[0158] The embodiment of the present application further provides a computer readable storage medium, wherein the storage medium stores a computer program, and the computer program is executed by a processor to implement the syntax tree optimization method provided by the embodiment of the present application.
[0159] For the device / network side equipment / storage medium embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the related parts refer to the part of the method embodiment.
[0160] In this document, the terms "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply these entities or operations have any such actual relationship or order. Also, the terms "comprises", "comprising", or any other variations thereof are intended to cover non-exclusive inclusions, so that a process, method, article, or apparatus including a list of elements does not only include those elements, but also includes other elements not explicitly listed, or further includes elements inherent in such a process, method, article, or apparatus. Without more limitations, the element defined by the statement "comprises a" does not exclude the presence of additional identical elements in the process, method, article, or apparatus including the element.
[0161] The above only describes the preferred embodiments of the present application and is not intended to limit the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the scope of protection of the present application.
Claims
1. A method of optimizing a syntax tree, characterized by, The method comprises: obtaining a first syntax tree for a database service, extracting feature data of a node in the current first syntax tree for representing a node attribute, wherein the feature data comprises an operation type feature, a predicate feature, and metadata feature, and based on the extracted feature data of each node, a feature vector of each extracted node is obtained, wherein, the feature vector of the node comprises a feature vector of the operation type, a feature vector of the predicate, and a feature vector of the metadata, the feature vector of the operation type is an activation function operation result obtained by weighting the operation type feature data with a first weight for obtaining an operation type feature vector, accumulating a first offset for obtaining the operation type feature vector, and then performing an activation function operation, the feature vector of the predicate is an activation function operation result obtained by weighting the predicate feature data with a second weight for obtaining a predicate feature vector, accumulating a second offset for obtaining the predicate feature vector, and then performing an activation function operation, the feature vector of the metadata is an activation function operation result obtained by weighting the metadata feature data with a third weight for obtaining a metadata feature vector, accumulating a third offset for obtaining the metadata feature vector, and then performing an activation function operation, using a neural network model to perform deep learning on the feature vector of each extracted node to obtain a representation vector of the first syntax tree and a performance evaluation result of the first syntax tree, in a case where the performance evaluation result reaches a set evaluation threshold, obtaining a second syntax tree mapped by the current representation vector to obtain an optimization result of the first syntax tree, in a case where the performance evaluation result does not reach the set evaluation threshold, reconstructing the first syntax tree according to the current representation vector of the first syntax tree so that the feature data of at least one node attribute of the first syntax tree is updated, returning to perform the step of extracting the feature data of the node in the current first syntax tree for representing the node attribute until the number of reconstructed first syntax trees reaches a set exhaustion threshold; wherein, the reconstructing the first syntax tree according to the current representation vector of the first syntax tree so that the feature data of at least one node attribute of the first syntax tree is updated comprises: selecting at least one node for reconstructing the syntax tree, updating the node attribute according to the current representation vector of the selected node so that at least one of the operation type feature data, the predicate feature data, and the metadata feature data of the node is updated.
2. The optimization method of claim 1, wherein, The method further comprises, in a case where the performance evaluation result does not reach the evaluation threshold and the number of reconstructed first syntax trees reaches the exhaustion threshold, training the current neural network model using sample data in the database service, adjusting model parameters of the neural network model according to the training result until the training result of the neural network model reaches a set prediction result, and saving the current model parameters; returning to perform the step of processing the feature data using the neural network model.
3. The optimization method of claim 1, wherein, The extracting feature data of a node in the current first syntax tree for representing a node attribute, comprises, Extract feature data of each node in the current first syntax tree.
4. The optimization method of claim 1, wherein, The neural network model comprises a long short-term memory network and a fully connected neural network connected to an output of the long short-term memory network, wherein, the long short-term memory network is configured to learn a representation vector of the first syntax tree based on the feature data, the fully connected neural network is configured to perform performance evaluation of the first syntax tree based on the representation vector.
5. The optimization method of claim 4, wherein, The extracted feature vector of each node is input into the current neural network model one by one, and the representation vector of each node is obtained from the output of the long short-term memory network one by one, and the evaluation result of the cost and / or the base of each node is obtained from the output of the fully connected neural network one by one, According to the evaluation results of the cost and / or the base of all nodes, the evaluation results of the cost and / or the base of the first syntax tree are obtained. The feature vector of each node is obtained based on the feature data of each node, which comprises, 6. The optimization method of claim 5, wherein, In the case where there are a first node and a second node belonging to the same parent node, the feature vector of the first node and the feature vector of the second node are updated to the average of the feature vector of the first node and the feature vector of the second node, respectively. The evaluation result of the cost and / or the base of each node is obtained from the output of the fully connected neural network one by one, which further comprises, 7. The optimization method of claim 5, wherein, In the case where the node is a child node, the evaluation result of the child node is cached. In the case where the evaluation result reaches a set evaluation threshold, the second syntax tree mapped by the current representation vector is obtained, which comprises, 8. The optimization method of claim 1, wherein, In the case where the performance evaluation result reaches the minimum performance evaluation result among all previous performance evaluation results, the second syntax tree is determined based on the current representation vector of each node according to the node relationship between the nodes in the first syntax tree. The device comprises, 9. A syntax tree optimization device, characterized in that, a first obtaining module configured to obtain a first syntax tree for a database service, a feature extraction module configured to extract feature data of a node in the current first syntax tree, wherein the feature data comprises operation type features, predicate features, and metadata features, a feature vector of each node is obtained based on the feature data of each node, wherein, the feature vector of the node comprises an operation type feature vector, a predicate feature vector, and a metadata feature vector, the operation type feature vector is an activation function operation result obtained by weighting the operation type feature data using a first weight for obtaining an operation type feature vector, accumulating the first offset for obtaining the operation type feature vector, and then performing an activation function operation, the predicate feature vector is an activation function operation result obtained by weighting the predicate feature data using a second weight for obtaining a predicate feature vector, accumulating the second offset for obtaining the predicate feature vector, and then performing an activation function operation, The feature vector of the metadata is: the activation function operation result obtained by weighting the metadata feature data by the third weight used to obtain the metadata feature vector, accumulating, and then performing an activation function operation on the third offset used to obtain the metadata feature vector; a neural network model module configured to perform deep learning on the feature vector of each node extracted to obtain the representation vector of the first syntax tree and the performance evaluation result of the first syntax tree, The second obtaining module is configured to obtain a second syntax tree mapped by the current representation vector when the performance evaluation result reaches a set evaluation threshold to obtain an optimization result of the first syntax tree. When the performance evaluation result does not reach the set evaluation threshold, the first syntax tree is reconstructed according to the current representation vector of the first syntax tree, so that the feature data of at least one node attribute of the first syntax tree is updated, and the reconstructed first syntax tree is provided to the feature extraction module until the number of the reconstructed first syntax trees reaches a set exhaustion threshold. The method further includes: selecting at least one node used to reconstruct the syntax tree, updating the current representation vector of the selected node to update at least one of the operation type feature data, the predicate feature data, and the metadata feature data of the node.
10. A computer-readable storage medium, characterized in that, The storage medium stores a computer program, and the computer program is executed by the processor to implement the syntax tree optimization method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Data processing method and device based on database engine, terminal and medium
CN111522816A
Vectorization representation method and device for nodes in abstract syntax tree
CN112035099A
Automatic code generation quality evaluation method
CN112698831A