A SQL statement intelligent merging method and system

By constructing prediction trees and hierarchical clustering trees, extracting feature vectors and calculating merging probabilities, the problem of large SQL statement merging errors in the existing technology is solved, and more efficient SQL statement merging is achieved.

CN118363980BActive Publication Date: 2024-09-24CHANGAN COMM SCI & TECH CO LTD +1

Patent Information

Application Number
CN202410788650.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-19
Publication Date
2024-09-24
Estimated Expiration
2044-06-19

AI Technical Summary

Technical Problem

Existing SQL statement merging methods are difficult to accurately obtain the dependencies of SQL statements when querying across tables or systems, resulting in large errors in the merged results.

Method used

Using the SQL statement intelligent merging method, by obtaining the clauses and merged SQL sentence vectors in the historical database, we build a prediction tree structure and a hierarchical clustering tree, screen the optimal clustering layer, extract feature vectors, and calculate based on feature matching Merge probabilities for statement merging.

Benefits of technology

It improves the accuracy of SQL statement merging, reduces errors, and ensures the accuracy and reliability of the merging results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118363980B
    Figure CN118363980B
Patent Text Reader

Abstract

The present invention relates to the field of data processing technology, and in particular to a method and system for intelligently merging SQL statements, comprising: obtaining a clause vector and a sentence vector, and SQL statements to be merged in a historical database; using the clause as the bottom layer, constructing a prediction tree structure and a hierarchical clustering tree according to the similarity between any two sentence vectors; determining the optimal clustering layer according to the matching relationship between the prediction tree structure and the nodes in the hierarchical clustering tree; extracting features from cluster clusters in the optimal clustering layer to obtain a feature vector of each cluster cluster; performing feature matching based on the similarity between feature vectors, merging features, and determining a merged feature vector; calculating the merging probability between the SQL statements to be merged according to the feature matching between the SQL statements to be merged and the merged feature vector; merging the SQL statements to be merged based on the merging probability. The present invention can obtain a more accurate SQL statement merging result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data processing, and in particular to a method and system for intelligently merging SQL statements. Background Art

[0002] Merging SQL statements is an important means of database optimization. It can improve system performance, reduce resource consumption, simplify code logic, and help optimize the database query process, thereby improving the efficiency and response speed of the overall system. For example, when an application needs to send multiple SQL query statements, the database server needs to receive and process each statement, which will increase communication overhead. By merging SQL statements, multiple queries can be combined into one, thereby reducing the number of communications and network transmission costs.

[0003] At present, the existing methods for merging SQL statements mainly identify the dependencies and transaction boundaries in SQL statements, and use batch processing, transaction merging and statement rewriting technology to reduce network transmission and database operation times. However, due to the complexity of SQL queries, it is difficult to obtain the dependencies of each feature in the SQL statement when querying across tables or systems, which makes the results of merging statements prone to large errors. Summary of the invention

[0004] In order to solve the technical problem that the merging results obtained by the existing merging methods are prone to large errors, the purpose of the present invention is to provide a method and system for intelligent merging of SQL statements. The technical solutions adopted are as follows:

[0005] In a first aspect, the present invention provides a method for intelligently merging SQL statements, comprising:

[0006] Obtain the clause vector of each SQL clause in the historical database and the sentence vector of the merged SQL clause, and obtain the SQL clause to be merged; based on the similarity between any two sentence vectors, use the clause as the bottom layer to build a prediction tree structure; based on the similarity between different clause vectors, build a hierarchical clustering tree;

[0007] According to the matching relationship between each node in the prediction tree structure and each node in the hierarchical clustering tree, the layers in the hierarchical clustering tree are screened to determine the optimal clustering layer;

[0008] Extract features from the sentence vectors in each cluster in the optimal clustering layer to obtain the feature vector of each cluster; perform feature matching based on the similarity between the feature vectors of each two clusters, merge features, and determine each merged feature vector;

[0009] According to the feature matching between the SQL clauses to be merged and the merge feature vector, the merge probability between the SQL clauses to be merged is calculated; and the SQL clauses to be merged are merged based on the merge probability.

[0010] Preferably, the method of matching the features according to the similarity between the feature vectors of each two clusters and merging the features to determine each merged feature vector specifically includes:

[0011] For any two clusters, matching is performed based on the similarity between each feature vector in one cluster and each feature vector in another cluster, to determine a vector matching pair of the any two clusters;

[0012] Based on the coincidence of feature vectors in the vector matching pairs of all two arbitrary clustering clusters, a vector matching set of each feature vector in each clustering cluster is determined, wherein the elements in the vector matching set are feature vectors in different clustering clusters;

[0013] Based on the similarity of the vector matching pairs corresponding to the feature vectors in the vector matching set, the vector matching set is screened to determine the feature vector set; and each feature vector set is respectively merged to obtain each merged feature vector.

[0014] Preferably, the method for obtaining the vector matching pair of any two clusters is specifically as follows:

[0015] For any two clusters, each feature vector in one of the clusters is used as the left node in the KM algorithm, and each feature vector in the other cluster is used as the right node in the KM algorithm. The edge value between the left node and the right node is the similarity coefficient between the corresponding feature vectors of the left node and the right node. The KM matching algorithm is used to match the feature vectors in the any two clusters to obtain a vector matching pair.

[0016] Preferably, the screening of the vector matching set based on the similarity of the vector matching pairs corresponding to the feature vectors in the vector matching set to determine the feature vector set specifically includes:

[0017] When the similarity between the feature vectors in each vector matching pair in the vector matching set is greater than a preset similarity threshold, the vector matching set is used as a feature vector set.

[0018] Preferably, the step of extracting features from the sentence vectors in each cluster in the optimal clustering layer to obtain a feature vector for each cluster specifically includes:

[0019] For any cluster, a feature matrix is ​​constructed based on all sentence vectors in the cluster; the feature matrix is ​​subjected to feature decomposition to obtain the feature vector of the cluster.

[0020] Preferably, the method of screening the layers in the hierarchical clustering tree according to the matching relationship between each node in the prediction tree structure and each node in the hierarchical clustering tree to determine the optimal clustering layer specifically includes:

[0021] Based on the similarity between the nodes of each layer in the prediction tree structure and the nodes of each layer in the hierarchical clustering tree, feature matching is performed to determine a node matching pair, wherein the node matching pair includes two nodes belonging to different trees respectively; the layer in the hierarchical clustering tree where the node corresponding to the maximum value of the similarity between the two nodes in the node matching pair is located is taken as the optimal clustering layer.

[0022] Preferably, the performing feature matching based on the similarity between the nodes of each layer in the prediction tree structure and the nodes of each layer in the hierarchical clustering tree to determine the node matching pairs specifically includes:

[0023] Each node in the prediction tree structure is used as the left node in the KM algorithm, and each node in the hierarchical clustering tree is used as the right node in the KM algorithm. The mean of the similarities between the vector corresponding to the left node and all the vectors corresponding to the right node is used as the edge value between the left node and the right node, and feature matching is performed to obtain node matching pairs.

[0024] Preferably, the calculating the merging probability between the SQL clauses to be merged based on the feature matching between the SQL clauses to be merged and the merged feature vector specifically includes:

[0025] A matrix to be merged is constructed based on the SQL clauses to be merged, and the matrix to be merged is subjected to eigendecomposition to obtain vectors to be merged; the maximum value of the edge value of KM matching between each vector to be merged in the matrix to be merged and each merged eigenvector is taken as the merging probability between the SQL clauses to be merged.

[0026] Preferably, constructing a hierarchical clustering tree according to the similarities between different sentence vectors specifically includes: performing bottom-up hierarchical clustering on all sentence vectors based on the similarities between different sentence vectors to obtain a hierarchical clustering tree.

[0027] In a second aspect, the present invention provides a SQL statement intelligent merging system, comprising:

[0028] The preprocessing module is used to obtain the clause vectors and combined sentence vectors of different SQL statements in the database and the SQL clauses to be merged; based on the similarity between any two combined sentence vectors, the clauses are used as the bottom layer to build a prediction tree structure; based on the similarity between different clause vectors, a hierarchical clustering tree is built;

[0029] A screening module is used to screen the layers in the hierarchical clustering tree and determine the optimal clustering layer according to the matching relationship between each node in the prediction tree structure and each node in the hierarchical clustering tree;

[0030] The analysis module is used to extract features from the sentence vectors in each cluster in the optimal clustering layer to obtain the feature vector of each cluster; perform feature matching based on the similarity between the feature vectors of each two clusters, and perform feature merging to determine each merged feature vector;

[0031] The merging module is used to calculate the merging probability between the SQL sentences to be merged according to the feature matching between the SQL sentences to be merged and the merged feature vector; and merge the SQL sentences to be merged based on the merging probability.

[0032] The embodiments of the present invention have at least the following beneficial effects:

[0033] The present invention first collects the clauses and the combined sentences in the historical database, and the combined sentences are SQL combined sentences after the clauses are merged, and then the similarity between the combined sentences can be analyzed, and the clauses can be combined as the bottom nodes to construct a prediction tree structure, and the correlation relationship and the corresponding relationship between the clauses and the combined sentences can be expressed in the form of a tree structure, which can fully characterize the similarity between the combined sentences after the historical clauses are merged. At the same time, for the similarity between different clauses, a hierarchical clustering tree is constructed, that is, the clauses are clustered by hierarchical clustering, and clustering results with different similarity expressions can be obtained. Then, by analyzing the node matching relationship between the prediction tree structure and the hierarchical clustering tree, the layers in the hierarchical clustering tree are screened to obtain the optimal clustering layer. Each layer in the hierarchical clustering tree corresponds to a clustering result, and the screening operation of the clustering layer is performed through the matching relationship. The optimal clustering layer also characterizes the clustering result expression form with a larger correlation relationship between the clauses that have not been merged and the combined sentences that have been merged. Furthermore, feature extraction is performed on each cluster in the optimal clustering layer. The feature vector can represent a feature dimension of the cluster. By analyzing the matching results of similar situations between feature vectors of different clusters, feature merging operations are performed to obtain the common feature performance between different clusters under each feature dimension. Finally, by comparing the feature situations between the SQL clauses to be merged and the merged feature vectors, the merge probability is calculated, and it is possible to fully analyze whether there are common feature performances that can be merged between the SQL clauses to be merged, that is, the merged feature vectors. In this way, the final merge result has a higher accuracy and avoids the situation where large errors are prone to occur. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] In order to more clearly illustrate the technical solutions and advantages in the embodiments of the present invention or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0035] Figure 1 It is a flow chart of the steps of a method for intelligently merging SQL statements provided by the present invention;

[0036] Figure 2 is a sub-step flow chart of step S100 provided by the present invention;

[0037] Figure 3 is a flowchart of the steps of the method for obtaining the merged feature vector provided by the present invention;

[0038] Figure 4 It is a system block diagram of a SQL statement intelligent merging system provided by the present invention;

[0039] Figure 5 The present invention provides a schematic diagram of the structure of a computer device. DETAILED DESCRIPTION

[0040] In order to further explain the technical means and effects adopted by the present invention to achieve the predetermined invention purpose, the following is a detailed description of a method and system for intelligent merging of SQL statements proposed by the present invention, its specific implementation, structure, features and effects, in conjunction with the accompanying drawings and preferred embodiments. In the following description, different "one embodiment" or "another embodiment" does not necessarily refer to the same embodiment. In addition, specific features, structures or characteristics in one or more embodiments may be combined in any suitable form.

[0041] Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.

[0042] The specific scheme of the SQL statement intelligent merging method and system provided by the present invention is described in detail below with reference to the accompanying drawings.

[0043] See also Figure 1 , which shows a flowchart of a method for intelligently merging SQL statements provided by an embodiment of the present invention, the method comprising the following steps:

[0044] Step S100, obtaining the clause vector of each SQL clause in the historical database and the sentence vector of the merged SQL sentence, and obtaining the SQL clause to be merged; according to the similarity between any two sentence vectors, taking the clause as the bottom layer, constructing a prediction tree structure; according to the similarity between different clause vectors, constructing a hierarchical clustering tree.

[0045] The common features of different SQL statements that can be merged in the database have different degrees of expression. By analyzing the feature distribution between the merged SQL statements and the corresponding clauses in the historical data of the database, the common features between the clauses are characterized respectively, and the feature dependency relationship between the SQL clauses that can be merged can be effectively obtained. The common features that can be used for statement merging in the historical data are used as a reference to analyze the feature dependency relationship between the SQL statements to be merged. The distribution of the common features between the SQL statements can be fully considered, so that the accuracy of the merging result is guaranteed.

[0046] Based on this, it is necessary to first obtain historical data from the database, including the SQL statements that have been merged and the corresponding SQL clauses before the merge, and then perform two different forms of feature analysis on the historical data obtained. One is to build the association relationship between the merged SQL statements and the corresponding clauses, and the other is to build the similarity distribution relationship between different SQL clauses, which provides a data basis for subsequent feature comparison, that is, to build a prediction tree structure through the original data, and then compare it with the actual hierarchical tree structure obtained by vector similarity, which is helpful to obtain more accurate merging probability in the follow-up.

[0047] like Figure 2 As shown, step S100 can be implemented through steps S101 to S103.

[0048] Step S101, obtaining the sentence vector of each SQL sentence in the history database and the sentence vector of the merged SQL sentence, and obtaining the SQL sentence to be merged.

[0049] First, obtain the historical merge data in the historical database, that is, obtain each SQL clause from the historical database, and at the same time obtain the SQL statements that have a merge relationship and are merged. The format of each merged SQL statement can be expressed as, sentence 1: sentence 1, sentence 2, sentence 3. Among them, sentence 1 represents the SQL statement obtained by merging sentence 1, sentence 2, and sentence 3. The sentence refers to the SQL statement that can be merged, that is, sentence 1, sentence 2, and sentence 3 are merged to obtain sentence 1. According to this format, each SQL clause and the SQL sentence formed by merging multiple SQL clauses can be obtained. It can be understood that each SQL clause has a corresponding SQL sentence.

[0050] At the same time, it is necessary to obtain multiple SQL statements that need to be merged, which are recorded as SQL statements to be merged. Considering that the data type of each SQL statement is not conducive to data feature analysis, it is necessary to convert it into a data format that is easy to calculate. In this embodiment, the word vector model wors2vec is used to convert each SQL statement into a vector, that is, the sentence vector of each SQL statement, the sentence vector of each SQL sentence, and the vector of each SQL statement to be merged can be obtained. It should be noted that the vectors in this embodiment are all one-dimensional vectors, and the number of elements contained is equal, that is, the size of the vector can be 1×N, and N represents the number of elements contained in the vector.

[0051] Step S102, based on the similarity between any two sentence vectors, the clauses are used as the bottom layer to construct a prediction tree structure.

[0052] Specifically, the sentence vector of each sentence is used as the leaf node of the lowest layer, and the sentence vector corresponding to each sentence is used as the node of the previous layer of the sentence. Then, the nodes of other layers are obtained by calculating the similarity between the sentence vectors corresponding to any two sentences. The tree structure is constructed through multiple iterative calculations and recorded as the prediction tree structure. The similarity between vectors can be measured by methods such as cosine similarity or Pearson correlation coefficient.

[0053] The prediction tree structure can reflect the association between clauses and combined sentences, and also reflect the similarities between different combined sentences. The tree structure can more intuitively represent the association characteristics between SQL statements that can be merged.

[0054] Step S103: construct a hierarchical clustering tree according to the similarities between different sentence vectors.

[0055] Specifically, based on the similarity between different sentence vectors, all sentence vectors are hierarchically clustered from bottom to top to obtain a hierarchical clustering tree. In this embodiment, the similarity between different sentence vectors is measured by calculating the cosine similarity between different sentence vectors. In other embodiments, other suitable methods such as the Pearson correlation coefficient can also be used for measurement. The hierarchical clustering tree also reflects the distribution relationship of similar features between different sentences in the historical data.

[0056] It should be noted that for two SQL statements to be merged in actual data, it is necessary to calculate whether there are similarities between the SQL statements to be merged and the extracted clause features, and different clause features have different degrees of expression of the merging rules. Therefore, this embodiment simulates the similarity features between different clauses in actual data, measures the similarity between different clauses in historical data, and represents them in the form of a hierarchical clustering tree structure, so as to determine the best expression scale of the similarity relationship between different clauses in the historical database for subsequent analysis and prediction of the distribution correlation between the tree structure and the hierarchical clustering tree structure.

[0057] Step S200 , based on the matching relationship between each node in the prediction tree structure and each node in the hierarchical clustering tree, the layers in the hierarchical clustering tree are screened to determine the optimal clustering layer.

[0058] The prediction tree structure represents the correlation features between the clauses in the historical data and the combined clauses that have been merged, and the hierarchical clustering tree represents the similar features between different clauses in the historical data. Each layer in the hierarchical clustering tree corresponds to a clustering result. The best clustering result represents the clustering of similar features between different SQL clauses. In the clustering result, the more similar SQL clauses in each cluster can be represented as SQL clauses with common features. Therefore, by comparing the actual merged data structure, that is, the distribution of the prediction tree structure and the correlation between the hierarchical clustering tree, the clause clustering result that is closest to the sentence merging can be obtained. That is, it is necessary to analyze the matching relationship between the nodes in the prediction tree structure and the hierarchical clustering tree structure, and screen each clustering result of the hierarchical clustering tree to determine the layer with the best classification effect.

[0059] Based on this, feature matching is performed based on the similarity between the nodes of each layer in the prediction tree structure and the nodes of each layer in the hierarchical clustering tree to determine a node matching pair, wherein the node matching pair includes two nodes belonging to different trees respectively.

[0060] In this embodiment, the KM matching algorithm is used to obtain a one-to-one layer matching relationship between the nodes in the prediction tree structure and the hierarchical clustering tree structure. Specifically, each node in the prediction tree structure is used as the left node in the KM algorithm, and each node in the hierarchical clustering tree is used as the right node in the KM algorithm. There is an edge connection between each left node and each right point. The one-to-one matching relationship between the left node and the right node is obtained through KM matching, which is recorded as a node matching pair. A node matching pair contains two nodes and belongs to different trees respectively, that is, the node matching pair contains a node in the prediction tree structure and a node in the hierarchical clustering tree.

[0061] It can be understood that each node in the prediction tree structure can be a sentence vector or a clause vector, and each node in the hierarchical clustering tree can be a clause vector or a cluster composed of multiple clause vectors. The similarity between the nodes in the prediction tree structure and the nodes in the hierarchical clustering cluster can be measured by the cosine similarity between the vectors. Specifically, for any corresponding left node in the prediction tree structure and any corresponding right node in the hierarchical clustering tree, the cosine similarity between the vector corresponding to the left node and each vector in the right node is calculated, and the average of the cosine similarities between the vector corresponding to the left node and all the vectors corresponding to the right node is used as the edge value between the left node and the right node.

[0062] It should be noted that the left node and the right node are part of the KM matching algorithm, and are usually used to describe the node part in the bipartite graph. In the KM matching algorithm, the left node represents the source node to be matched, and the right node represents the target node to be matched. The optimal solution is found by continuously updating and iterating the matching status of the left node and the right node.

[0063] The matching results of the prediction tree structure and the hierarchical clustering tree, that is, the node matching pair represents the matching pair composed of two relatively similar nodes in the two tree structures. The greater the similarity between the two nodes in the node matching pair, the greater the similarity between all the sentence vectors belonging to the same cluster in the hierarchical clustering tree and a certain sentence vector in the prediction tree structure, which further indicates that the feature performance shared by all the sentence vectors in the cluster is better, and the possibility of sentence merging is greater.

[0064] Based on this, the layer in the hierarchical clustering tree corresponding to the maximum similarity between the two nodes in the node matching pair is taken as the optimal clustering layer. The node matching pair corresponding to the maximum similarity represents the maximum representation of the similarity between the sentence vector in the prediction structure tree and the cluster cluster where the sentence is located in the hierarchical clustering tree. Furthermore, the sentence vectors in the nodes belonging to the hierarchical clustering tree in the node matching pair reflect the most common features that can be merged. The optimal clustering layer also represents the layer with the best clustering effect in the hierarchical clustering tree. At the same time, the probability distribution that the sentence vectors of each cluster cluster can be merged in the clustering result corresponding to the optimal clustering layer is the largest, which can better represent the correlation between the sentence vectors and the common features.

[0065] Step S300, extracting features from the sentence vectors in each cluster in the optimal clustering layer to obtain the feature vector of each cluster; performing feature matching based on the similarity between the feature vectors of each two clusters, and merging features to determine each merged feature vector.

[0066] Considering that the classification of sentence vectors in the optimal clustering layer is closest to the ideal vector classification, that is, the greater the similarity between sentence vectors in the same clustering cluster, the greater the similarity between the sentence vectors and a certain sentence vector, indicating that there are common features with a large degree of expression between the sentence vectors in the same clustering cluster, and they can be merged. At the same time, considering that there may also be common features between sentence vectors of different clustering clusters in the optimal clustering layer, these common features can represent the same features that can be merged between different sentences. Therefore, it is necessary to extract features from each clustering cluster, and then compare the feature matching between different clustering clusters, so as to obtain the same feature representation vectors between different sentences, and then extract the common feature representation that can be merged between all SQL sentences in the historical database.

[0067] First, it is necessary to extract features from the sentence vectors in each cluster in the optimal clustering layer to obtain the feature vector of each cluster. That is, for any cluster, a feature matrix is ​​constructed based on all the sentence vectors in the cluster; the feature matrix is ​​decomposed to obtain the feature vector of the cluster.

[0068] SVD is a process of decomposing a matrix to obtain an eigenvector, which can represent certain characteristics of the matrix row data. In this embodiment, each sentence vector in each cluster is used as a row of the matrix to obtain a feature matrix, and the feature matrix of each cluster in the optimal clustering layer is decomposed by SVD to obtain a right singular matrix, and the column data of the right singular matrix is ​​used as the right singular vector, and each right singular vector is the eigenvector of each feature matrix.

[0069] It should be noted that the right singular matrix represents the changes in the row space of the original matrix, corresponding to the main patterns or features of the rows of the original data. Therefore, retaining the right singular vector as the feature vector can better characterize the main features of each sentence vector in each cluster.

[0070] Then, by analyzing the similarity between the feature vectors of each cluster in the optimal clustering layer, we can quantify the matching relationship between the features of the sentence vectors corresponding to different clusters, and find relatively similar feature vectors to represent the same features of the sentence vectors in different clusters. Figure 3 As shown, the method for obtaining the merged feature vector can be implemented by steps S301 to S303.

[0071] Step S301 : for any two clusters, matching is performed based on the similarity between each feature vector in one cluster and each feature vector in another cluster, to determine a vector matching pair of the any two clusters.

[0072] Specifically, take any two clusters in the optimal clustering layer as an example for explanation. For any two clusters, each feature vector in one of the clusters is used as a left node, and each feature vector in the other cluster is used as a right node. The edge value between the left node and the right node is the similarity coefficient between the feature vectors corresponding to the left node and the right node. The KM matching algorithm is used to match the feature vectors in the any two clusters to obtain a vector matching pair. It should be noted that the left node and the right node here are also node representations in the KM algorithm.

[0073] Among them, the similarity coefficient can be characterized by cosine similarity or Pearson correlation coefficient. Through KM matching, a one-to-one matching relationship between the feature vectors contained in two clusters can be obtained, which is recorded as a vector matching pair, that is, the vector matching pair contains two feature vectors, which belong to two different clusters. For example, in the optimal clustering layer, the feature vector a contained in cluster A and the feature vector b contained in cluster B constitute a vector matching pair.

[0074] Step S302 : determining a vector matching set of each feature vector in each cluster based on the coincidence of feature vectors in vector matching pairs of any two clusters, wherein the elements in the vector matching set are feature vectors in different clusters.

[0075] The vector matching pair corresponding to every two arbitrary clusters represents the feature vectors of the association and matching relationship between the two clusters. Then, taking the feature vector of any cluster in the best clustering layer as the target, through the overlap of the feature vectors of the vector matching pairs in the feature matching results, all feature vectors with certain association and matching relationships in the feature vector dimension can be obtained, and then the common features of all clusters in one dimension can be represented.

[0076] For example, a vector matches Including the feature vector a contained in cluster A and the feature vector b contained in cluster B, a vector matching pair Including the feature vector b contained in cluster B and the feature vector c contained in cluster C, a vector matching pair Including the feature vector c contained in cluster C and the feature vector d contained in cluster D, based on the coincidence of the feature vectors in these four vector matching pairs, the vector matching set of the feature vector a in cluster A can be obtained, which can be expressed as , there is an association relationship between feature vector a and feature vector b, and there is an association relationship between feature vector b and feature vector c, and there is an association relationship between feature vector c and feature vector d. Therefore, the vector matching set represents different feature vectors that have an association relationship or a matching relationship. It can be seen that each element in the vector matching set belongs to a feature vector of a different clustering cluster.

[0077] At the same time, it can be understood that due to the same matching relationship, the vector matching sets corresponding to all feature vectors in the same vector matching set are the same, that is, the vector matching set of feature vector b in cluster B, the vector matching set of feature vector c in cluster C, and the vector matching set of feature vector d in cluster D are all the same as the vector matching set of feature vector a in cluster A.

[0078] Step S303, based on the similarity of the vector matching pairs corresponding to the feature vectors in the vector matching set, the vector matching set is screened to determine a feature vector set; and features of each feature vector set are merged to obtain each merged feature vector.

[0079] The vector matching set represents the set of feature vectors with the same features or matching relationships in each cluster in the best clustering layer. By analyzing the similarities between feature vectors in the vector matching set, feature representations with greater similarities between different clusters can be screened out.

[0080] Specifically, when the similarity between the feature vectors in each vector matching pair in the vector matching set is greater than the preset similarity threshold, it indicates that the similarity between the feature vectors of different clusters with correlation relationships is relatively large, which further indicates that different clusters have a large degree of common features under the feature dimension corresponding to the feature vector, so the vector matching set is used as the feature vector set. The feature vector set also represents the feature vectors that have more common features belonging to different clusters.

[0081] Furthermore, each feature vector set represents a set representation of feature vectors that have many common features between different clusters under a feature dimension. By merging or fusing all feature vectors in each feature vector set, a unique vector representation under the feature dimension can be obtained.

[0082] That is, each feature vector set is merged to obtain each merged feature vector. In this embodiment, the mean of all feature vectors in each feature vector set is used as the merged feature vector of each feature vector set. In other embodiments, the implementer may choose other ways to merge feature vectors according to the specific implementation scenario. The merged feature vector also represents the vector representation of the common features between SQL clauses in the historical database. When the same common features exist between different SQL clauses at the same time, it means that these SQL clauses can be merged.

[0083] Step S400, calculating the merging probability between the SQL clauses to be merged according to the feature matching between the SQL clauses to be merged and the merged feature vector; and merging the SQL clauses to be merged based on the merging probability.

[0084] The merge feature vector represents the common features of SQL statements that can be merged. When performing merge analysis on the SQL statements to be merged, we can first obtain the feature correlation between the SQL statements to be merged and the common features in the historical data. The greater the feature correlation, the greater the probability that the SQL statements to be merged can be merged. Then, the merging operation process of the SQL statements to be merged can be judged according to the probability of the merging operation.

[0085] Specifically, before performing a merge operation judgment on the actually collected SQL sentences to be merged, the SQL sentences to be merged need to be converted into a vector representation. In this embodiment, the wors2vec method is still used to convert each SQL sentence to be merged into a sentence vector to be merged.

[0086] Then, the combined eigenvalue decomposition operation is performed on the clause vectors corresponding to the two or more SQL clauses to be merged that need to be merged, that is, a matrix to be merged is constructed based on the SQL clauses to be merged, and the clause vectors corresponding to each SQL clause to be merged are used as the rows of the matrix, so that the matrix to be merged corresponding to the multiple SQL clauses to be merged can be obtained. The vector to be merged is obtained by eigenvalue decomposition of the matrix to be merged.

[0087] The method for obtaining the vector to be merged can be analogous to the method for obtaining each feature vector in the optimal clustering layer, specifically, the SVD decomposition of the matrix to be merged is performed to obtain the right singular matrix to be merged, and each column data in the right singular matrix to be merged is used as the vector to be merged. Each vector to be merged can be regarded as the vector representation of multiple SQL clauses to be merged in each feature dimension, and then the correlation and similarity between the vector to be merged and the vector representation of the common features in the historical database that has been obtained can be further analyzed.

[0088] Specifically, KM matching is used to perform a one-to-one matching operation between the vectors to be merged and the merged feature vectors. The edge value is the similarity between each vector to be merged and each merged feature vector, which can be measured by cosine similarity or Pearson correlation coefficient. The maximum edge value of KM matching between each vector to be merged and each merged feature vector in the matrix to be merged is taken as the merge probability between the SQL clauses to be merged.

[0089] It should be noted that a matrix to be merged may correspond to multiple vectors to be merged, which represent the common features of multiple feature dimensions between multiple SQL clauses to be merged corresponding to the matrix to be merged. These common features are compared with the merged feature vectors in the historical database, and the vector to be merged with the greatest similarity is selected, which means that the vector to be merged has the greatest performance feature of the feature vector that can be merged.

[0090] When the value of the merge probability corresponding to the matrix to be merged is larger, it means that the possibility that the multiple SQL clauses to be merged constituting the matrix to be merged can be merged is larger, and the SQL clauses to be merged are merged based on the merge probability. Specifically, the relevant staff can verify the SQL clauses to be merged in order from large to small in terms of the merge probability, determine whether they need to be merged, and perform a merge operation on the clauses to be merged according to a common merge method, thereby completing the intelligent merging of SQL clauses.

[0091] like Figure 4 As shown, this embodiment also provides a SQL statement intelligent merging system, which includes:

[0092] The preprocessing module is used to obtain the clause vectors and combined sentence vectors of different SQL statements in the database and the SQL clauses to be merged; based on the similarity between any two combined sentence vectors, the clauses are used as the bottom layer to build a prediction tree structure; based on the similarity between different clause vectors, a hierarchical clustering tree is built;

[0093] A screening module is used to screen the layers in the hierarchical clustering tree and determine the optimal clustering layer according to the matching relationship between each node in the prediction tree structure and each node in the hierarchical clustering tree;

[0094] The analysis module is used to extract features from the sentence vectors in each cluster in the optimal clustering layer to obtain the feature vector of each cluster; perform feature matching based on the similarity between the feature vectors of each two clusters, and perform feature merging to determine each merged feature vector;

[0095] The merging module is used to calculate the merging probability between the SQL sentences to be merged according to the feature matching between the SQL sentences to be merged and the merged feature vector; and merge the SQL sentences to be merged based on the merging probability.

[0096] It should be noted that the system provided in the above embodiment is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the computer device is divided into different functional modules to complete all or part of the functions described above. In addition, the SQL statement intelligent merging system and the SQL statement intelligent merging method embodiment provided in the above embodiment belong to the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.

[0097] The present application also provides a computer device. Figure 5 , which shows a schematic diagram of the structure of a computer device provided by an embodiment of the present invention, the computer device includes a memory 501, a processor 502, and a computer program 503 stored in the memory 501 and running on the processor 502, wherein when the processor 502 executes the computer program 503, the computer device can execute any one of the SQL statement intelligent merging methods introduced above.

[0098] The embodiment of the present application also provides a computer program product. When the computer program product is run on a computer device, the computer device can execute any one of the SQL statement intelligent merging methods introduced above.

[0099] The embodiment of the present application also provides a computer-readable storage medium, in which a computer program code is stored. When the computer program code runs on a computer device, the computer device can execute any one of the SQL statement intelligent merging methods introduced above.

[0100] In the embodiments provided in the present application, it should be understood that the provided computer device, computer program product and computer-readable storage medium are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the methods provided above and will not be repeated here.

[0101] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A method for intelligently merging SQL statements, characterized in that: The method comprises the following steps: Obtain the clause vector of each SQL clause in the historical database and the sentence vector of the merged SQL clause, and obtain the SQL clause to be merged; based on the similarity between any two sentence vectors, use the clause as the bottom layer to build a prediction tree structure; based on the similarity between different clause vectors, build a hierarchical clustering tree; According to the matching relationship between each node in the prediction tree structure and each node in the hierarchical clustering tree, the layers in the hierarchical clustering tree are screened to determine the optimal clustering layer; Extract features from the sentence vectors in each cluster in the optimal clustering layer to obtain the feature vector of each cluster; perform feature matching based on the similarity between the feature vectors of each two clusters, merge features, and determine each merged feature vector; Calculating the merging probability between the SQL sentences to be merged according to the feature matching between the SQL sentences to be merged and the merged feature vector; merging the SQL sentences to be merged based on the merging probability; The method of screening the layers in the hierarchical clustering tree according to the matching relationship between each node in the prediction tree structure and each node in the hierarchical clustering tree to determine the optimal clustering layer specifically includes: Based on the similarity between the nodes of each layer in the prediction tree structure and the nodes of each layer in the hierarchical clustering tree, feature matching is performed to determine a node matching pair, wherein the node matching pair includes two nodes belonging to different trees respectively; the layer in the hierarchical clustering tree where the node corresponding to the maximum value of the similarity between the two nodes in the node matching pair is located is taken as the optimal clustering layer; The method of performing feature matching based on the similarity between the nodes of each layer in the prediction tree structure and the nodes of each layer in the hierarchical clustering tree to determine the node matching pairs specifically includes: Each node in the prediction tree structure is used as the left node in the KM algorithm, and each node in the hierarchical clustering tree is used as the right node in the KM algorithm. The mean of the similarity between the vector corresponding to the left node and all the vectors corresponding to the right node is used as the edge value between the left node and the right node, and feature matching is performed to obtain node matching pairs; The calculating the merging probability between the SQL clauses to be merged according to the feature matching between the SQL clauses to be merged and the merged feature vector specifically includes: A matrix to be merged is constructed based on the SQL clauses to be merged, and the matrix to be merged is subjected to eigendecomposition to obtain vectors to be merged; the maximum value of the edge value of KM matching between each vector to be merged in the matrix to be merged and each merged eigenvector is taken as the merging probability between the SQL clauses to be merged.

2. The method for intelligently merging SQL statements according to claim 1, characterized in that: The feature matching result based on the similarity between the feature vectors of each two clusters is performed, and the feature merging is performed to determine each merged feature vector, specifically including: For any two clusters, matching is performed based on the similarity between each feature vector in one cluster and each feature vector in another cluster, to determine a vector matching pair of the any two clusters; Based on the coincidence of feature vectors in the vector matching pairs of all two arbitrary clustering clusters, a vector matching set of each feature vector in each clustering cluster is determined, wherein the elements in the vector matching set are feature vectors in different clustering clusters; Based on the similarity of the vector matching pairs corresponding to the feature vectors in the vector matching set, the vector matching set is screened to determine the feature vector set; and each feature vector set is respectively merged to obtain each merged feature vector.

3. The method for intelligently merging SQL statements according to claim 2, characterized in that: The method for obtaining the vector matching pair of any two clusters is specifically as follows: For any two clusters, each feature vector in one of the clusters is used as the left node in the KM algorithm, and each feature vector in the other cluster is used as the right node in the KM algorithm. The edge value between the left node and the right node is the similarity coefficient between the corresponding feature vectors of the left node and the right node. The KM matching algorithm is used to match the feature vectors in the any two clusters to obtain a vector matching pair.

4. The method for intelligently merging SQL statements according to claim 2, characterized in that: The screening of the vector matching set based on the similarity of the vector matching pairs corresponding to the feature vectors in the vector matching set to determine the feature vector set specifically includes: When the similarity between the feature vectors in each vector matching pair in the vector matching set is greater than a preset similarity threshold, the vector matching set is used as a feature vector set.

5. The method for intelligently merging SQL statements according to claim 1, characterized in that: The feature extraction of the sentence vectors in each cluster in the optimal clustering layer to obtain the feature vector of each cluster specifically includes: For any cluster, a feature matrix is ​​constructed based on all sentence vectors in the cluster; the feature matrix is ​​subjected to feature decomposition to obtain the feature vector of the cluster.

6. The method for intelligently merging SQL statements according to claim 1, characterized in that: The step of constructing a hierarchical clustering tree according to the similarities between different sentence vectors specifically includes: performing bottom-up hierarchical clustering on all sentence vectors based on the similarities between different sentence vectors to obtain a hierarchical clustering tree.

7. An intelligent merging system for SQL statements, characterized in that: The system includes: The preprocessing module is used to obtain the sentence vector of each SQL sentence in the historical database and the sentence vector of the merged SQL sentence, and obtain the SQL sentence to be merged; according to the similarity between any two sentence vectors, the sentence is used as the bottom layer to build a prediction tree structure; according to the similarity between different sentence vectors, a hierarchical clustering tree is built; The screening module is used to screen the layers in the hierarchical clustering tree according to the matching relationship between each node in the prediction tree structure and each node in the hierarchical clustering tree, and determine the optimal clustering layer, specifically including: Based on the similarity between the nodes of each layer in the prediction tree structure and the nodes of each layer in the hierarchical clustering tree, feature matching is performed to determine a node matching pair, wherein the node matching pair includes two nodes belonging to different trees respectively; the layer in the hierarchical clustering tree where the node corresponding to the maximum value of the similarity between the two nodes in the node matching pair is located is taken as the optimal clustering layer; The method of performing feature matching based on the similarity between the nodes of each layer in the prediction tree structure and the nodes of each layer in the hierarchical clustering tree to determine the node matching pairs specifically includes: Each node in the prediction tree structure is used as the left node in the KM algorithm, and each node in the hierarchical clustering tree is used as the right node in the KM algorithm. The mean of the similarity between the vector corresponding to the left node and all the vectors corresponding to the right node is used as the edge value between the left node and the right node, and feature matching is performed to obtain node matching pairs; The analysis module is used to extract features from the sentence vectors in each cluster in the optimal clustering layer to obtain the feature vector of each cluster; perform feature matching based on the similarity between the feature vectors of each two clusters, merge features, and determine each merged feature vector; A merging module, used to calculate the merging probability between the SQL sentences to be merged according to the feature matching between the SQL sentences to be merged and the merged feature vector; and merge the SQL sentences to be merged based on the merging probability; The calculating of the merging probability between the SQL clauses to be merged specifically includes: A matrix to be merged is constructed based on the SQL clauses to be merged, and the matrix to be merged is subjected to eigendecomposition to obtain vectors to be merged; the maximum value of the edge value of KM matching between each vector to be merged in the matrix to be merged and each merged eigenvector is taken as the merging probability between the SQL clauses to be merged.

Citation Information

Patent Citations

  • Method and apparatus for constructing semantic hierarchy tree

    CN109033084A

  • Automatic method and system for realizing database SQL optimization execution based on artificial intelligence

    CN113505141A

  • Method and device for determining SQL execution plan

    CN114756578A

  • Information query method and device, storage medium and terminal

    CN114925179A

  • SQL statement optimization method and device

    CN116266182A

Cited By

  • Query optimization method and device for structured query language

    CN120448417A

  • A query optimization method and device for structured query language

    CN120448417B