Relational database SQL (Structured Query Language) generation method based on large model fine tuning
Through large-model fine-tuning technology, SQL query statements are semantic embedding encoding and optimization, and query strategies are dynamically adjusted, which solves the performance degradation of traditional optimizers in data changes and complex scenarios, and realizes flexible and efficient SQL query optimization.
Patent Information
- Application Number
- CN202411327346.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-23
- Publication Date
- 2024-12-20
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Traditional SQL query statement optimizers rely on pre-collected statistical information and cannot be updated in time, resulting in a degradation of query performance when data distribution changes. Fixed rules cannot adapt to complex and changeable practical application scenarios, especially in high concurrency or multi-user environments. It is difficult to make optimal resource allocation decisions.
Using a relational database SQL generation method based on large model fine-tuning, the initial SQL query statement is obtained through syntax parsing, semantic embedding encoding is performed, and the semantic query features are used to filter the network and the tree-shaped length and short-term memory network, and dynamically adjust the query Optimize strategy and generate optimized SQL query statements.
It realizes dynamic adjustment of query optimization strategies based on the current data distribution and query mode, adapts to complex scenarios and variable logic, provides flexible and personalized optimization solutions, improves query performance and efficiency, and avoids waste of resources.
Smart Images

Figure CN119166668A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data query, and more specifically, to a relational database SQL generation method based on large model fine-tuning. Background Art
[0002] In the modern big data environment, with the explosive growth of data volume and the increase in business complexity, database performance often becomes the key bottleneck of the overall system performance. Efficient query processing can not only speed up data retrieval, but also significantly reduce server resource consumption and improve system response time and stability. Optimizing SQL query statements is an important means to alleviate this bottleneck. It can help reduce unnecessary database load, avoid resource waste, and improve query efficiency and data processing capabilities, thereby directly improving the end-user experience.
[0003] However, traditional SQL query optimization usually relies on the query optimizer built into the database management system (DBMS). Specifically, the optimizer usually relies on pre-collected statistical information to determine the best execution plan. However, in actual applications, data distribution may change due to frequent data insertion, deletion, or update. If these statistical information is not updated in time, the optimizer will make suboptimal decisions based on outdated information, resulting in poor query performance. In addition, optimizers usually work based on a set of fixed rules and strategies, and such a design is not flexible enough when facing complex and changing actual application scenarios. In other words, fixed rules may not be able to fully take into account various special situations. For example, in a high-concurrency or multi-user environment, there may be complex interaction effects between different query requests. In this case, the optimizer may not be able to make the best resource allocation decision, resulting in the execution efficiency of some queries being affected.
[0004] Therefore, an optimized relational database SQL generation method is desired. Summary of the invention
[0005] In view of the shortcomings of the prior art, the present application provides a relational database SQL generation method based on large model fine-tuning.
[0006] According to one aspect of the present application, a method for generating SQL for a relational database based on large model fine-tuning is provided, which includes:
[0007] Get the initial SQL query statement entered by the user;
[0008] Performing syntax analysis on the initial SQL query statement to obtain an initial SQL query abstract syntax tree;
[0009] Performing semantic embedding coding on each node and each edge in the initial SQL query abstract syntax tree to obtain a semantic representation of the initial SQL query abstract syntax tree, wherein the semantic representation of the initial SQL query abstract syntax tree includes a set of node semantic embedding vectors and a set of edge semantic embedding vectors;
[0010] Inputting the set of node semantic embedding vectors into a feature filtering network based on pseudo anchor center contribution semantic query to obtain an optimized set of node semantic embedding vectors;
[0011] Replacing the set of node semantic embedding vectors in the initial SQL query abstract syntax tree semantic representation with the set of optimized node semantic embedding vectors to obtain an optimized initial SQL query abstract syntax tree semantic representation;
[0012] Inputting the optimized initial SQL query abstract syntax tree semantic representation into a syntax tree semantic encoder to obtain an initial SQL query statement semantic encoding feature vector;
[0013] Based on the semantic encoding feature vector of the initial SQL query statement, an optimized SQL query statement is obtained.
[0014] In the above-mentioned relational database SQL generation method based on large model fine-tuning, the set of node semantic embedding vectors is input into a feature filtering network based on pseudo-anchor center contribution semantic query to obtain a set of optimized node semantic embedding vectors, including: clustering analysis is performed on the set of node semantic embedding vectors to obtain node semantic embedding cluster center representation vectors as node semantic pseudo-anchor centers; the semantic contribution representation matrix of each node semantic embedding vector in the set of node semantic embedding vectors relative to the node semantic pseudo-anchor center is calculated to obtain a set of node semantic contribution representation matrices; each node semantic contribution representation matrix in the set of node semantic contribution representation matrices is input into a contribution pseudo-masked sparse module based on a random inactivation mechanism to obtain a set of node masked sparse semantic contribution representation matrices; each node masked sparse semantic contribution representation matrix in the set of node masked sparse semantic contribution representation matrices is used as a modulation matrix, and the matrix product between it and each node semantic embedding vector is calculated respectively to obtain the set of optimized node semantic embedding vectors.
[0015] In the above-mentioned relational database SQL generation method based on large model fine-tuning, a cluster analysis is performed on the set of node semantic embedding vectors to obtain the node semantic embedding cluster center representation vector as the node semantic pseudo anchor center, including: calculating the mean vector of the set of node semantic embedding vectors as the node semantic pseudo anchor center.
[0016] In the above-mentioned relational database SQL generation method based on large model fine-tuning, the semantic contribution representation matrix of each node semantic embedding vector in the set of node semantic embedding vectors relative to the node semantic pseudo-anchor center is calculated to obtain a set of node semantic contribution representation matrices, including: calculating the semantic association matrix between each node semantic embedding vector in the set of node semantic embedding vectors and the node semantic pseudo-anchor center to obtain a set of node semantic association matrices; activating the set of node semantic association matrices to obtain the set of node semantic contribution representation matrices.
[0017] In the above-mentioned relational database SQL generation method based on large model fine-tuning, the semantic association matrix between each node semantic embedding vector in the set of node semantic embedding vectors and the node semantic pseudo-anchor center is calculated to obtain a set of node semantic association matrices, including: calculating the product between each node semantic embedding vector and the transposed vector of the node semantic pseudo-anchor center to obtain a set of node semantic interaction matrices; dividing each node semantic interaction matrix in the set of node semantic interaction matrices by the bi-norm of the node semantic pseudo-anchor center by position to obtain the set of node semantic association matrices.
[0018] In the above-mentioned relational database SQL generation method based on large model fine-tuning, the set of node semantic association matrices is activated to obtain the set of node semantic contribution representation matrices, including: inputting the set of node semantic association matrices into a softmax function for activation processing to obtain the set of node semantic contribution representation matrices.
[0019] In the above-mentioned relational database SQL generation method based on large model fine-tuning, the optimized initial SQL query abstract syntax tree semantic representation is input into a syntax tree semantic encoder to obtain the initial SQL query statement semantic encoding feature vector, including: inputting the optimized initial SQL query abstract syntax tree semantic representation into a syntax tree semantic encoder based on a tree-shaped long short-term memory network to obtain the initial SQL query statement semantic encoding feature vector.
[0020] In the above-mentioned relational database SQL generation method based on large model fine-tuning, an optimized SQL query statement is obtained based on the semantic encoding feature vector of the initial SQL query statement, including: inputting the semantic encoding feature vector of the initial SQL query statement into a SQL statement optimizer to obtain the optimized SQL query statement.
[0021] In the above-mentioned relational database SQL generation method based on large model fine-tuning, the semantic encoding feature vector of the initial SQL query statement is input into the SQL statement optimizer to obtain the optimized SQL query statement, including: inputting the semantic encoding feature vector of the initial SQL query statement into the decoder-based SQL statement optimizer to obtain the optimized SQL query statement.
[0022] This application has significant technical effects due to the adoption of the above technical solutions:
[0023] The SQL generation method for a relational database based on large model fine-tuning provided by the present application adopts artificial intelligence-based syntax analysis and optimization technology to embed and encode each node and edge in the syntax tree obtained by syntax parsing of the initial SQL query statement, and captures the key feature information between the embedded semantics of each node, and uses this key feature information as an optimization feature to replace and optimize the original SQL query abstract syntax tree semantic representation, so as to intelligently obtain the optimized SQL query statement based on the syntactic dependency and structural dependency relationship in the optimized SQL query abstract syntax tree semantic representation information. In this way, the query optimization strategy can be dynamically adjusted according to the current data distribution and query mode, and it can more easily adapt to complex query scenarios and changing business logic, providing a more flexible and personalized optimization solution. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] By describing the embodiments of the present application in more detail in conjunction with the accompanying drawings, the above and other purposes, features and advantages of the present application will become more apparent. The accompanying drawings are used to provide a further understanding of the embodiments of the present application and constitute a part of the specification. Together with the embodiments of the present application, they are used to explain the present application and do not constitute a limitation of the present application. In the accompanying drawings, the same reference numerals generally represent the same components or steps.
[0025] Figure 1 The present invention is a flowchart of a relational database SQL generation method based on large model fine-tuning according to an embodiment of the present application.
[0026] Figure 2 The data flow diagram of the relational database SQL generation method based on large model fine-tuning according to an embodiment of the present application.
[0027] Figure 3 In the relational database SQL generation method based on large model fine-tuning according to an embodiment of the present application, the set of node semantic embedding vectors is input into a feature filtering network based on pseudo-anchor center contribution semantic query to obtain a flow chart of an optimized set of node semantic embedding vectors.
[0028] Figure 4The present invention is a flowchart of a method for generating SQL for a relational database based on large model fine-tuning according to an embodiment of the present application, which calculates the semantic contribution representation matrix of each node semantic embedding vector in the set of node semantic embedding vectors relative to the node semantic pseudo-anchor center to obtain a set of node semantic contribution representation matrices.
[0029] Figure 5 The present invention provides a flowchart for calculating the semantic association matrix between each node semantic embedding vector in the set of node semantic embedding vectors and the node semantic pseudo-anchor center in the relational database SQL generation method based on large model fine-tuning according to an embodiment of the present application to obtain a set of node semantic association matrices. DETAILED DESCRIPTION
[0030] Below, the exemplary embodiments according to the present application will be described in detail with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments of the present application, and it should be understood that the present application is not limited to the exemplary embodiments described here.
[0031] In today's big data era, database performance is crucial to the overall performance of the system. With the surge in data volume and the complexity of business needs, the query processing capability of the database is directly related to the speed of data retrieval, the utilization efficiency of server resources, and the response speed and stability of the system. Therefore, it is particularly important to optimize SQL query statements, which can not only reduce the burden on the database and avoid waste of resources, but also improve the efficiency of data processing and ultimately enhance the user experience.
[0032] Although database management systems (DBMS) often have built-in query optimizers to automatically optimize SQL queries, the effectiveness of these optimizers is limited by the accuracy and timeliness of the statistical information they rely on. Frequent changes in data may cause statistical information to become outdated, which in turn affects the quality of optimizer decisions and reduces query performance. In addition, optimizers usually follow a set of fixed rules and strategies, which may not be flexible enough when dealing with complex and changing actual application scenarios. Especially in high-concurrency or multi-user environments, it may be difficult for optimizers to fully consider the interaction effects between different queries, resulting in uneven resource allocation and affecting the execution efficiency of some queries.
[0033] It should be understood that a large model refers to a machine learning model with large-scale parameters and complex computational structures. These models are usually built with deep neural networks and have billions or even hundreds of billions of parameters. The purpose of designing a large model is to improve the expressiveness and predictive performance of the model, so that it can handle more complex tasks and data. A relational database is a database based on a relational model. It stores data in the form of tables. Each row in the table represents a record. Each record has a unique identifier (key), and the columns are used to store the attributes of the data. The query language of a relational database is SQL, which allows users to specify the required data content and optimize query performance through mechanisms such as indexes. The large model can automatically optimize SQL query statements based on its understanding of them, thereby improving user query efficiency and helping users better utilize data resources, thereby achieving good interaction between users and databases.
[0034] Based on this, the present application proposes a relational database SQL generation method based on large model fine-tuning, which obtains the initial SQL query statement input by the user, and performs syntax parsing on the initial SQL query statement to obtain the initial SQL query abstract syntax tree, and uses artificial intelligence-based syntax analysis and optimization technology to embed and encode each node and edge in the syntax tree, and captures the key feature information between the embedded semantics of each node, and uses this key feature information as an optimization feature to replace and optimize the original SQL query abstract syntax tree semantic representation, so as to intelligently obtain the optimized SQL query statement based on the syntactic dependency and structured dependency in the semantic representation information of the optimized SQL query abstract syntax tree. In this way, the current semantics of the query statement can be captured more accurately, instead of relying on statistical information that may be outdated, and the query optimization strategy can be dynamically adjusted according to the current data distribution and query mode to adapt to changes in data and changes in query requirements. And compared with traditional optimizers, artificial intelligence-based methods can more easily adapt to complex query scenarios and changing business logic, providing more flexible and personalized optimization solutions.
[0035] Figure 1 The present invention is a flowchart of a relational database SQL generation method based on large model fine-tuning according to an embodiment of the present application. Figure 2 Schematic diagram of data flow of a relational database SQL generation method based on large model fine-tuning according to an embodiment of the present application. Figure 1 and Figure 2As shown, according to the embodiment of the present application, the SQL generation method for a relational database based on large model fine-tuning includes: S110, obtaining an initial SQL query statement input by a user; S120, performing syntax parsing on the initial SQL query statement to obtain an initial SQL query abstract syntax tree; S130, performing semantic embedding encoding on each node and each edge in the initial SQL query abstract syntax tree to obtain a semantic representation of the initial SQL query abstract syntax tree, wherein the semantic representation of the initial SQL query abstract syntax tree includes a set of node semantic embedding vectors and a set of edge semantic embedding vectors; S140, encoding the node semantic embedding vectors A set of quantities is input into a feature filtering network based on pseudo-anchor center contribution semantic query to obtain a set of optimized node semantic embedding vectors; S150, replacing the set of node semantic embedding vectors in the initial SQL query abstract syntax tree semantic representation with the set of optimized node semantic embedding vectors to obtain an optimized initial SQL query abstract syntax tree semantic representation; S160, inputting the optimized initial SQL query abstract syntax tree semantic representation into a syntax tree semantic encoder to obtain an initial SQL query statement semantic encoding feature vector; S170, obtaining an optimized SQL query statement based on the initial SQL query statement semantic encoding feature vector.
[0036] In step S110, the initial SQL query statement input by the user is obtained. It should be understood that the initial SQL query statement input by the user contains the user's query intention and data operation requirements, specifically including the query table name, field name, conditional expression, connection operation and other information. By performing semantic analysis and optimization processing on the initial SQL query statement, an optimized SQL query statement that contains the original user's query intention but significantly improves query performance and efficiency can be obtained.
[0037] In step S120, the initial SQL query statement is parsed to obtain an initial SQL query abstract syntax tree. Accordingly, considering that the initial SQL query statement contains the structure and semantics of the query information, in order to enable the model to better understand and analyze the structure in these statements, and at the same time to detect syntax errors in the initial SQL query statement, such as missing keywords, incorrect symbol usage, etc., in the technical solution of the present application, the initial SQL query statement is parsed to obtain an initial SQL query abstract syntax tree. That is, syntax parsing can convert the initial SQL query statement from a text form into a structured initial SQL query abstract syntax tree. In particular, the abstract syntax tree is a tree structure that can clearly express the structure and logic of the query statement. Specifically, the initial SQL query abstract syntax tree not only contains all the components of the query statement, but also reflects the hierarchical relationship and logical order between these components, which is crucial for subsequent query optimization and execution plan generation. In a specific implementation method of the embodiment of the present application, parsing the initial SQL query statement to obtain an initial SQL query abstract syntax tree includes: a. first decomposing the string of the initial SQL query statement into lexical units, which may include keywords (such as SELECT, FROM, WHERE), identifiers (such as table names, column names), literals (such as numbers, strings) and operators (such as +, =, <), etc.; b. based on the lexical analysis, the syntax analyzer will perform syntax analysis on the obtained lexical units, and the syntax analyzer will check whether the sequence of lexical units conforms to the syntax rules of the SQL language, such as checking whether all brackets are correctly matched, whether keywords are used properly, and whether the correct statement structure is followed; c. in the process of syntax analysis, whenever a syntax structure is identified, a corresponding tree structure node is constructed in the memory, and these nodes are connected by edges to form a tree reflecting the structure and logic of the query statement, namely, the initial SQL query abstract syntax tree.
[0038] In step S130, semantic embedding coding is performed on each node and each edge in the initial SQL query abstract syntax tree to obtain a semantic representation of the initial SQL query abstract syntax tree, wherein the semantic representation of the initial SQL query abstract syntax tree includes a set of node semantic embedding vectors and a set of edge semantic embedding vectors. Accordingly, considering that the initial SQL query abstract syntax tree is composed of multiple nodes and multiple edges, and each node and edge contains deep semantic information in the SQL query statement, such as each node may contain the type, structure, conditional expression, etc. in the data table, and each edge contains the hierarchical relationship between different parts. Based on this, in the technical solution of the present application, semantic embedding coding is performed on each node and each edge in the initial SQL query abstract syntax tree to obtain a semantic representation of the initial SQL query abstract syntax tree, wherein the semantic representation of the initial SQL query abstract syntax tree includes a set of node semantic embedding vectors and a set of edge semantic embedding vectors, so that these rich semantic information can be further captured and expressed to provide support for further processing and optimization of SQL queries.
[0039] In step S140, the set of node semantic embedding vectors is input into a feature filtering network based on pseudo-anchor center contribution semantic query to obtain a set of optimized node semantic embedding vectors. It should be understood that each node semantic embedding vector in the set of node semantic embedding vectors has different semantic contributions and influences in the entire set. Therefore, in order to enhance the semantic features of important nodes while suppressing less critical node features, thereby optimizing the quality of semantic representation, in the technical solution of the present application, a feature filtering network based on pseudo-anchor center contribution semantic query is introduced to optimize the semantic contribution of the set of node semantic embedding vectors to obtain a set of optimized node semantic embedding vectors. In particular, the feature filtering network based on pseudo-anchor center contribution semantic query is an innovative feature optimization and screening method, which aims to improve the quality of feature vectors by using clustering analysis and semantic contribution evaluation.
[0040] Specifically, first, the set of node semantic embedding vectors is processed by implementing cluster analysis to identify and construct cluster centers as pseudo anchor centers of node semantics, which helps to reveal the potential patterns and layouts of the semantics of each node. In particular, the pseudo anchor center here serves as a reference point for the entire set, which helps to analyze and understand the semantic association and related trends between each node semantic embedding vector and the overall center of node semantics. Next, the semantic contribution matrix between each node semantic embedding vector and the pseudo anchor center of node semantics is calculated to measure the semantic similarity or association strength between each node semantic embedding vector and the pseudo anchor center of node semantics to obtain a set of node mask sparse semantic contribution representation matrices. That is, by calculating the semantic contribution matrix between the two, the weight and importance of each node embedding vector in the overall semantic structure can be determined, providing a basis for feature selection and optimization. Subsequently, each node mask sparse semantic contribution representation matrix is input into a contribution pseudo mask sparse module based on a random inactivation mechanism for feature pseudo sparse processing based on random inactivation to obtain a set of node mask sparse semantic contribution representation matrices corresponding to the node semantic embedding vector. It should be understood that the random dropout mechanism is a commonly used regularization technique, which prevents model overfitting and enhances the generalization ability of the model by randomly "turning off" or "deactivating" some unimportant features. The sparse processing helps to automatically select features, highlight important and critical features, and suppress unimportant or noise features, thereby improving the prediction performance of the model. Finally, the sparse semantic contribution representation matrix of each node mask is used as a modulation matrix to perform matrix product on the semantic embedding vector of each node to obtain the final set of optimized node semantic embedding vectors. In this way, the semantic feature representation of the key node embedding vector can be enhanced, the influence of noise and unimportant features can be suppressed, and the optimized embedding vector can better reflect the semantic role and importance of the node in the query statement.
[0041] Specifically, Figure 3 The present invention is a flowchart of a method for generating SQL for a relational database based on large model fine-tuning according to an embodiment of the present application, in which the set of node semantic embedding vectors is input into a feature filtering network based on pseudo anchor center contribution semantic query to obtain an optimized set of node semantic embedding vectors. Figure 3As shown, the set of node semantic embedding vectors is input into a feature filtering network based on pseudo-anchor center contribution semantic query to obtain a set of optimized node semantic embedding vectors, including: S141, clustering analysis is performed on the set of node semantic embedding vectors to obtain node semantic embedding cluster center representation vectors as node semantic pseudo-anchor centers; S142, the semantic contribution representation matrix of each node semantic embedding vector in the set of node semantic embedding vectors relative to the node semantic pseudo-anchor center is calculated to obtain a set of node semantic contribution representation matrices; S143, each node semantic contribution representation matrix in the set of node semantic contribution representation matrices is input into a contribution pseudo-mask sparse module based on a random inactivation mechanism to obtain a set of node mask sparse semantic contribution representation matrices; S144, each node mask sparse semantic contribution representation matrix in the set of node mask sparse semantic contribution representation matrices is used as a modulation matrix, and the matrix product between it and each node semantic embedding vector is calculated respectively to obtain the set of optimized node semantic embedding vectors.
[0042] More specifically, in an embodiment of the present application, a cluster analysis is performed on the set of node semantic embedding vectors to obtain a node semantic embedding cluster center representation vector as a node semantic pseudo anchor center, including: calculating the mean vector of the set of node semantic embedding vectors as the node semantic pseudo anchor center.
[0043] More specifically, Figure 4 The present invention is a flowchart of calculating the semantic contribution representation matrix of each node semantic embedding vector in the set of node semantic embedding vectors relative to the node semantic pseudo anchor center in the relational database SQL generation method based on large model fine-tuning according to an embodiment of the present application to obtain a set of node semantic contribution representation matrices. Figure 4 As shown, the semantic contribution representation matrix of each node semantic embedding vector in the set of node semantic embedding vectors relative to the node semantic pseudo-anchor center is calculated to obtain a set of node semantic contribution representation matrices, including: S1421, calculating the semantic association matrix between each node semantic embedding vector in the set of node semantic embedding vectors and the node semantic pseudo-anchor center to obtain a set of node semantic association matrices; S1422, activating the set of node semantic association matrices to obtain the set of node semantic contribution representation matrices.
[0044] More specifically, Figure 5 The present invention is a flowchart of calculating the semantic association matrix between each node semantic embedding vector in the set of node semantic embedding vectors and the node semantic pseudo anchor center in the relational database SQL generation method based on large model fine-tuning according to an embodiment of the present application to obtain a set of node semantic association matrices. Figure 5 As shown, the semantic association matrix between each node semantic embedding vector in the set of node semantic embedding vectors and the node semantic pseudo-anchor center is calculated to obtain a set of node semantic association matrices, including: S14211, calculating the product between each node semantic embedding vector and the transposed vector of the node semantic pseudo-anchor center to obtain a set of node semantic interaction matrices; S14212, dividing each node semantic interaction matrix in the set of node semantic interaction matrices by the bi-norm of the node semantic pseudo-anchor center by position to obtain the set of node semantic association matrices.
[0045] More specifically, in an embodiment of the present application, the set of node semantic association matrices is activated to obtain a set of node semantic contribution representation matrices, including: inputting the set of node semantic association matrices into a softmax function for activation processing to obtain a set of node semantic contribution representation matrices.
[0046] In an embodiment of the present application, the set of node semantic embedding vectors is input into a feature filtering network based on pseudo anchor center contribution semantic query to obtain an optimized set of node semantic embedding vectors, including: inputting the set of node semantic embedding vectors into a feature filtering network based on pseudo anchor center contribution semantic query, and processing with the following semantic query to obtain the optimized set of node semantic embedding vectors; wherein the semantic query formula is:
[0047] X={x1,x2,...,x i ,...,x n}
[0048]
[0049] Where X is the set of node semantic embedding vectors, x1, x2, ..., x i ,...,x n is the first, second, ..., i-th, ..., n-th node semantic embedding vector in the set of node semantic embedding vectors, n is the number of vectors in the set of node semantic embedding vectors, x c is the pseudo anchor center of the node semantics, x c T is x c The transposed vector of ||·||2 is the bi-norm of the calculated vector, Softmax(·) is the Softmax function, dropout(·) is the random inactivation process, WF i is the node mask sparse semantic contribution representation matrix corresponding to the i-th node semantic embedding vector, x i' is the i-th optimized node semantic embedding vector in the set of optimized node semantic embedding vectors.
[0050] In step S150, the set of node semantic embedding vectors in the initial SQL query abstract syntax tree semantic representation is replaced with the set of optimized node semantic embedding vectors to obtain an optimized initial SQL query abstract syntax tree semantic representation. Accordingly, considering that the optimized node semantic embedding vectors usually contain richer and more accurate semantic information, this information can better understand the true intention of the query statement, thereby generating an execution plan that is closer to user needs. Based on this, in order to more clearly and deeply understand the semantic information of each node and edge in the syntax tree semantic representation, in the technical solution of the present application, the set of node semantic embedding vectors in the initial SQL query abstract syntax tree semantic representation is replaced with the set of optimized node semantic embedding vectors to obtain an optimized initial SQL query abstract syntax tree semantic representation.
[0051] In step S160, the optimized initial SQL query abstract syntax tree semantic representation is input into a syntax tree semantic encoder to obtain an initial SQL query statement semantic encoding feature vector. Specifically, in an embodiment of the present application, the optimized initial SQL query abstract syntax tree semantic representation is input into a syntax tree semantic encoder to obtain an initial SQL query statement semantic encoding feature vector, including: inputting the optimized initial SQL query abstract syntax tree semantic representation into a syntax tree semantic encoder based on a tree-shaped long short-term memory network to obtain the initial SQL query statement semantic encoding feature vector. It should be understood that there are syntactic dependencies and structural dependencies between each node and edge in the optimized initial SQL query abstract syntax tree semantic representation. The tree-shaped long short-term memory network is a neural network architecture specially designed to process tree-structured data, which can capture the hierarchical relationship and dependency relationship between nodes, so as to more deeply understand the semantics of SQL statements. Therefore, in the technical solution of the present application, the optimized initial SQL query abstract syntax tree semantic representation is input into a syntax tree semantic encoder based on a tree-shaped long short-term memory network to obtain an initial SQL query statement semantic encoding feature vector. In particular, unlike traditional LSTM, the input of the tree-shaped LSTM network is not a simple sequence, but data with a hierarchical structure, usually represented as a tree. This structure enables the tree-shaped LSTM network to better process data such as grammar analysis trees. In other words, the tree-shaped LSTM network can consider the contextual information of each node in the tree, including the relationship between parent nodes, child nodes, and sibling nodes, so that it can more accurately and deeply understand the complex structure and nested clauses in SQL queries.
[0052] In step S170, an optimized SQL query statement is obtained based on the semantic encoding feature vector of the initial SQL query statement. Specifically, in an embodiment of the present application, an optimized SQL query statement is obtained based on the semantic encoding feature vector of the initial SQL query statement, including: inputting the semantic encoding feature vector of the initial SQL query statement into a SQL statement optimizer to obtain the optimized SQL query statement. More specifically, in an embodiment of the present application, inputting the semantic encoding feature vector of the initial SQL query statement into a SQL statement optimizer to obtain the optimized SQL query statement, including: inputting the semantic encoding feature vector of the initial SQL query statement into a decoder-based SQL statement optimizer to obtain the optimized SQL query statement. That is, the semantic encoding feature vector of the initial SQL query statement obtained by semantic encoding using the semantic representation of the optimized initial SQL query abstract syntax tree is decoded to intelligently obtain the optimized SQL query statement. In this way, the current semantics of the query statement can be captured more accurately, rather than relying on statistical information that may be outdated, and the query optimization strategy can be dynamically adjusted according to the current data distribution and query pattern to adapt to changes in data and changes in query requirements. And compared with traditional optimizers, AI-based methods can more easily adapt to complex query scenarios and changing business logic, providing more flexible and personalized optimization solutions.
[0053] In particular, since the set of optimized node semantic embedding vectors respectively represents the filtering query semantics based on the embedded semantic pseudo-central contribution of each node, when the optimized initial SQL query abstract syntax tree semantic representation obtained therefrom is input into the syntax tree semantic encoder based on the tree-shaped long short-term memory network, the node semantic filtering query difference will have different semantic encoding weights based on the tree-shaped long short-term memory association. Therefore, the initial SQL query statement semantic encoding feature vector will also have a diversified set expression distribution of node-based semantic aggregation features. Therefore, it is expected to improve the balance between the regression mapping accuracy and completeness when the initial SQL query statement semantic encoding feature vector is input into the decoder-based SQL statement optimizer for decoding regression, thereby improving the semantic accuracy of the optimized SQL query statement.
[0054] In a preferred example, inputting the initial SQL query statement semantic coding feature vector into the decoder-based SQL statement optimizer to obtain an optimized SQL query statement includes: determining the initial SQL query statement semantic coding maximum eigenvalue and the initial SQL query statement semantic coding minimum eigenvalue of the initial SQL query statement semantic coding feature vector; calculating the initial SQL query statement semantic coding mean and the initial SQL query statement semantic coding standard deviation of the feature set of the initial SQL query statement semantic coding feature vector, and calculating the quotient of the initial SQL query statement semantic coding mean and the initial SQL query statement semantic coding standard deviation to obtain the initial SQL query statement semantic coding statistical normalization value; calculating the inverse of each eigenvalue of the initial SQL query statement semantic coding feature vector, and comparing it with the initial SQL query statement semantic coding maximum eigenvalue and the initial SQL query statement semantic coding standard deviation. After multiplying the difference of the minimum eigenvalues of the semantic encoding of the initial SQL query statement, the difference is subtracted from the statistical normalized value of the semantic encoding of the initial SQL query statement to obtain an initial SQL query statement semantic encoding distribution approximation vector; an exponential function with the natural constant e as the base and each eigenvalue of the initial SQL query statement semantic encoding distribution approximation vector as the exponent is calculated to obtain an initial SQL query statement semantic encoding distribution class approximation vector; the initial SQL query statement semantic encoding distribution class approximation vector and the initial SQL query statement semantic encoding statistical normalized value are dot-added, and the base-two logarithm of the absolute value of each eigenvalue of the dot-added vector is calculated to obtain an optimized initial SQL query statement semantic encoding feature vector; the optimized initial SQL query statement semantic encoding feature vector is input into the decoder-based SQL statement optimizer to obtain an optimized SQL query statement.
[0055] The optimized representation of the semantic encoding feature vector of the initial SQL query statement is:
[0056] V'=log|η⊕V e |
[0057]
[0058] δ=v max -v min
[0059] Wherein, V is the semantic encoding feature vector of the initial SQL query statement, μ and σ are the mean value and standard deviation of the semantic encoding of the initial SQL query statement, respectively, and v max and v minare the maximum eigenvalue of the semantic encoding of the initial SQL query statement and the minimum eigenvalue of the semantic encoding of the initial SQL query statement, respectively; η is the statistical normalization value of the semantic encoding of the initial SQL query statement; δ is the difference between the maximum eigenvalue of the semantic encoding of the initial SQL query statement and the minimum eigenvalue of the semantic encoding of the initial SQL query statement; log is the logarithm with base 2; exp represents the natural exponential function; ⊙ represents the point multiplication by position; Indicates point-by-point subtraction, V e represents the semantic encoding distribution approximate vector of the initial SQL query statement, V ⊙-1 To calculate the inverse of each eigenvalue of the semantic encoding feature vector of the initial SQL query statement, ⊕ represents point-by-point addition, and V' is the optimized semantic encoding feature vector of the initial SQL query statement.
[0060] Here, by performing random statistical normalization on the diverse feature set of the semantic encoding feature vector of the initial SQL query statement, the confidence space constructed based on the overall feature value of the semantic encoding feature vector of the initial SQL query statement is approximated by the standardized continuous probability density distribution relative to the response hypothesis test of each feature value of the semantic encoding feature vector of the initial SQL query statement, thereby establishing the target reachability of the diverse feature distribution of the semantic encoding feature vector of the initial SQL query statement to the unified regression target, so as to achieve the balanced executableness between mapping accuracy and mapping completeness in the decoding regression process based on the diverse feature distribution of the semantic encoding feature vector of the initial SQL query statement, and improve the semantic accuracy of the optimized SQL query statement obtained by the semantic encoding feature of the initial SQL query statement input to the decoder-based SQL statement optimizer. In this way, the current semantics of the query statement can be captured more accurately, instead of relying on statistical information that may be outdated, and the query optimization strategy can be dynamically adjusted according to the current data distribution and query mode to adapt to changes in data and changes in query requirements. And compared with traditional optimizers, the artificial intelligence-based method can more easily adapt to complex query scenarios and changing business logic, providing a more flexible and personalized optimization solution.
[0061] In summary, the SQL generation method for a relational database based on large model fine-tuning according to the embodiment of the present application is explained, which uses artificial intelligence-based syntax analysis and optimization technology to embed and encode each node and edge in the syntax tree obtained by syntax parsing of the initial SQL query statement, and captures the key feature information between the embedded semantics of each node, and uses this key feature information as an optimization feature to replace and optimize the original SQL query abstract syntax tree semantic representation, so as to intelligently obtain the optimized SQL query statement according to the syntactic dependency and structured dependency relationship in the optimized SQL query abstract syntax tree semantic representation information. In this way, the query optimization strategy can be dynamically adjusted according to the current data distribution and query mode, and it can more easily adapt to complex query scenarios and changing business logic, providing a more flexible and personalized optimization solution.
[0062] It should be noted that in the method of the present application, each step can be decomposed and / or recombined. These decompositions and / or recombinations should be regarded as equivalent solutions of the present application.
[0063] The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use the present application. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other aspects without departing from the scope of the present application. Therefore, the present application is not intended to be limited to the aspects shown herein, but rather to the widest scope consistent with the principles and novel features of the present application.
[0064] The above description has been given for the purpose of illustration and description. In addition, this description is not intended to limit the embodiments of the present application to the forms disclosed herein. Although multiple example aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, changes, additions and sub-combinations thereof.
Claims
1. A method for generating SQL statements for relational databases based on large model fine-tuning. It is characterized in that include: Get the initial SQL query statement entered by the user; Performing syntax analysis on the initial SQL query statement to obtain an initial SQL query abstract syntax tree; Performing semantic embedding coding on each node and each edge in the initial SQL query abstract syntax tree to obtain a semantic representation of the initial SQL query abstract syntax tree, wherein the semantic representation of the initial SQL query abstract syntax tree includes a set of node semantic embedding vectors and a set of edge semantic embedding vectors; Inputting the set of node semantic embedding vectors into a feature filtering network based on pseudo anchor center contribution semantic query to obtain an optimized set of node semantic embedding vectors; Replacing the set of node semantic embedding vectors in the initial SQL query abstract syntax tree semantic representation with the set of optimized node semantic embedding vectors to obtain an optimized initial SQL query abstract syntax tree semantic representation; Inputting the optimized initial SQL query abstract syntax tree semantic representation into a syntax tree semantic encoder to obtain an initial SQL query statement semantic encoding feature vector; Based on the semantic encoding feature vector of the initial SQL query statement, an optimized SQL query statement is obtained.
2. According to the relational database SQL generation method based on large model fine-tuning according to claim 1, It is characterized in that Inputting the set of node semantic embedding vectors into a feature filtering network based on pseudo anchor center contribution semantic query to obtain an optimized set of node semantic embedding vectors, including: Performing cluster analysis on the set of node semantic embedding vectors to obtain node semantic embedding cluster center representation vectors as node semantic pseudo anchor centers; Calculating a semantic contribution representation matrix of each node semantic embedding vector in the set of node semantic embedding vectors relative to the node semantic pseudo anchor center to obtain a set of node semantic contribution representation matrices; Inputting each node semantic contribution representation matrix in the set of node semantic contribution representation matrices into a contribution pseudo-mask sparse module based on a random dropout mechanism to obtain a set of node mask sparse semantic contribution representation matrices; Each node mask sparse semantic contribution representation matrix in the set of node mask sparse semantic contribution representation matrices is used as a modulation matrix, and the matrix product between it and each node semantic embedding vector is calculated respectively to obtain the set of optimized node semantic embedding vectors.
3. The relational database SQL generation method based on large model fine-tuning according to claim 2, It is characterized in that Cluster analysis is performed on the set of node semantic embedding vectors to obtain node semantic embedding cluster center representation vectors as node semantic pseudo anchor centers, including: calculating the mean vector of the set of node semantic embedding vectors as the node semantic pseudo anchor center.
4. The relational database SQL generation method based on large model fine-tuning according to claim 3, It is characterized in that Calculating the semantic contribution representation matrix of each node semantic embedding vector in the set of node semantic embedding vectors relative to the node semantic pseudo anchor center to obtain a set of node semantic contribution representation matrices, including: Calculating a semantic association matrix between each node semantic embedding vector in the set of node semantic embedding vectors and the node semantic pseudo anchor center to obtain a set of node semantic association matrices; The set of node semantic association matrices is activated to obtain the set of node semantic contribution representation matrices.
5. According to claim 4, the relational database SQL generation method based on large model fine-tuning, It is characterized in that Calculating a semantic association matrix between each node semantic embedding vector in the set of node semantic embedding vectors and the node semantic pseudo anchor center to obtain a set of node semantic association matrices, including: Calculating the product between the semantic embedding vector of each node and the transposed vector of the semantic pseudo anchor center of the node to obtain a set of node semantic interaction matrices; Each node semantic interaction matrix in the set of node semantic interaction matrices is divided by the bi-norm of the node semantic pseudo anchor center by position to obtain the set of node semantic association matrices.
6. The relational database SQL generation method based on large model fine-tuning according to claim 5, It is characterized in that The set of node semantic association matrices is activated to obtain the set of node semantic contribution representation matrices, including: inputting the set of node semantic association matrices into a softmax function for activation processing to obtain the set of node semantic contribution representation matrices.
7. The method for generating SQL for a relational database based on large model fine-tuning according to claim 6, It is characterized in that Inputting the optimized initial SQL query abstract syntax tree semantic representation into a syntax tree semantic encoder to obtain the initial SQL query statement semantic encoding feature vector, including: inputting the optimized initial SQL query abstract syntax tree semantic representation into a syntax tree semantic encoder based on a tree-shaped long short-term memory network to obtain the initial SQL query statement semantic encoding feature vector.
8. The relational database SQL generation method based on large model fine-tuning according to claim 7, It is characterized in that Based on the semantic encoding feature vector of the initial SQL query statement, an optimized SQL query statement is obtained, including: inputting the semantic encoding feature vector of the initial SQL query statement into a SQL statement optimizer to obtain the optimized SQL query statement.
9. The method for generating SQL for a relational database based on large model fine-tuning according to claim 8, It is characterized in that Inputting the semantic encoding feature vector of the initial SQL query statement into a SQL statement optimizer to obtain the optimized SQL query statement includes: inputting the semantic encoding feature vector of the initial SQL query statement into a decoder-based SQL statement optimizer to obtain the optimized SQL query statement.
Citation Information
Cited By
Soil remediation technology evaluation method and system
CN119990811A
Precision injection mold surface defect visual identification system and method
CN120088182A
