Database query statement generation method and device, electronic equipment and storage medium
By acquiring natural language query requirements and using a query statement generation model to generate and optimize database query statements, the problem of low execution efficiency is solved, achieving efficient structured query transformation and improved user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-24
- Publication Date
- 2026-04-10
AI Technical Summary
Existing technologies generate database query statements with low execution efficiency, leading to a decline in database system performance.
By acquiring query demand information described in natural language, an initial structured query statement is generated using a query statement generation model. Feedback adjustments are made based on the statement execution time to optimize the generation strategy and improve execution efficiency.
It achieves intelligent conversion from natural language to structured queries, reduces the learning cost for users, improves the convenience and efficiency of data query, adapts to the query needs of different industries and user groups, and provides flexibility and support for a wide range of application scenarios.
Smart Images

Figure CN121833737A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of data management and database technology, in particular to a database query statement generation method and device, an electronic device and a storage medium. BACKGROUND
[0002] In the field of data management and database technology, there are multiple technical challenges in converting natural language queries into database query languages. Currently, the statement generation model in the related art can assist in generating database query statements, but it shows obvious limitations in specific field applications. The generated database query statements have a large amount of redundancy or inefficient expression, resulting in a long execution time of the generated database query statements and affecting the performance of the database system. Therefore, the execution efficiency of the database query statements generated in the related art is low. SUMMARY
[0003] The embodiments of the present application provide a database query statement generation method and device, an electronic device and a storage medium to at least solve the problem of low execution efficiency of the database query statements generated in the related art.
[0004] According to an embodiment of the present application, a database query statement generation method is provided, including: obtaining query requirement information, wherein the query requirement information is used to represent a requirement for querying a target database in natural language; inputting the query requirement information into a query statement generation model, and generating an initial structured query statement using the query statement generation model; determining a statement execution time of the initial structured query statement, wherein the statement execution time is the time for executing the initial structured query statement on the target database; inputting the statement execution time into the query statement generation model, and generating a target structured query statement using the query statement generation model.
[0005] Optionally, inputting the query requirement information into the query statement generation model and generating the initial structured query statement using the query statement generation model includes: using a natural language parsing module in the query statement generation model to parse the query requirement information to obtain a structured query instruction set; using a historical data analysis module in the query statement generation model to perform historical query data matching on the structured query instruction set to obtain a historical table connection order, wherein the historical table connection order is used to represent the connection order of the database tables used to execute a historical query statement matching the structured query instruction set; and generating the initial structured query statement based on the structured query instruction set and the historical table connection order.
[0006] Optionally, the natural language parsing module in the query statement generation model is used to parse the query requirement information to obtain a structured query instruction set, including: using a pre-trained language model in the natural language parsing module to perform text feature extraction on the query requirement information to obtain query text features; identifying the query text features to obtain database entities and database operations, wherein the database entities include at least one of the following: a table name, a column name, and a value range, and the database operations include at least one of the following: a statistical operation, a filtering operation, and a sorting operation; and generating the structured query instruction set based on the database entities and the database operations.
[0007] Optionally, based on the structured query instruction set and the historical table connection sequence, an initial structured query statement is generated, including: using a long short-term memory network in the query statement generation model to encode the structured query instruction set to obtain a query continuous vector; using an attention mechanism in the query statement generation model to decode the query continuous vector to obtain a first structured query statement; and obtaining the initial structured query statement based on the first structured query statement, the historical table connection sequence, and a predefined structured query statement template.
[0008] Optionally, the statement execution time is input to the query statement generation model, and the query statement generation model is used to generate a target structured query statement, including: constructing a target reward function based on the statement execution time; adjusting a first generation strategy of the query statement generation model based on the target reward function to obtain a second generation strategy; and generating the target structured query statement based on the second generation strategy and the query statement generation model.
[0009] Optionally, based on the statement execution time, a target reward function is constructed, including: evaluating the initial structured query statement to obtain the grammatical correctness and the result accuracy of the initial structured query statement; and constructing the target reward function based on the statement execution time, the grammatical correctness, and the result accuracy.
[0010] Optionally, based on the statement execution time, the grammatical correctness, and the result accuracy, a target reward function is constructed, including: constructing a negative exponential function based on the statement execution time, a first positive exponential function based on the grammatical correctness, and a second positive exponential function based on the result accuracy; and constructing the target reward function based on the negative exponential function, the first positive exponential function, and the second positive exponential function.
[0011] According to another aspect of the embodiments of the present application, a database query statement generation apparatus is further provided, comprising: an acquisition module configured to acquire query requirement information of a user, wherein the query requirement information is used to represent a requirement for querying a target database in a natural language; a first generation module configured to input the query requirement information into a query statement generation model, and generate an initial structured query statement by using the query statement generation model; a determination module configured to determine a statement execution time of the initial structured query statement, wherein the statement execution time is a time for executing the initial structured query statement on the target database; and a second generation module configured to input the statement execution time into the query statement generation model, and generate a target structured query statement by using the query statement generation model.
[0012] Optionally, the first generation module is further configured to parse the query requirement information by using a natural language parsing module in the query statement generation model, to obtain a structured query instruction set; match the structured query instruction set with historical query data by using a historical data analysis module in the query statement generation model, to obtain a historical table connection order, wherein the historical table connection order is used to represent a connection order of database tables used for executing a historical query statement matched with the structured query instruction set; and generate the initial structured query statement based on the structured query instruction set and the historical table connection order.
[0013] Optionally, the first generation module is further configured to extract text features of the query requirement information by using a pre-training language model in the natural language parsing module, to obtain query text features; identify the query text features, to obtain database entities and database operations, wherein the database entities include at least one of a table name, a column name and a value range, and the database operations include at least one of a statistical operation, a filtering operation and a sorting operation; and generate the structured query instruction set based on the database entities and the database operations.
[0014] Optionally, the first generation module is further configured to encode the structured query instruction set by using a long short-term memory network in the query statement generation model, to obtain a query continuous vector; decode the query continuous vector by using an attention mechanism in the query statement generation model, to obtain a first structured query statement; and obtain the initial structured query statement based on the first structured query statement, the historical table connection order and a pre-defined structured query statement template.
[0015] Optionally, the second generation module is further configured to construct a target reward function based on the statement execution time; adjust a first generation strategy of the query statement generation model based on the target reward function, to obtain a second generation strategy; and generate the target structured query statement based on the second generation strategy and the query statement generation model.
[0016] Optionally, the second generating module is further configured to evaluate the initial structured query statement to obtain syntax correctness and result accuracy of the initial structured query statement; and construct the target reward function based on the statement execution time, the syntax correctness and the result accuracy.
[0017] Optionally, the first generating module is further configured to construct a negative exponential function based on the statement execution time, construct a first positive exponential function based on the syntax correctness, and construct a second positive exponential function based on the result accuracy; and construct the target reward function based on the negative exponential function, the first positive exponential function and the second positive exponential function.
[0018] According to another aspect of the embodiments of the present application, a computer readable storage medium is provided, and the computer readable storage medium stores a computer program. The computer program is configured to perform the database query statement generation method when being executed.
[0019] According to another aspect of the embodiments of the present application, an electronic device is provided, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. The processor performs the database query statement generation method by executing the computer program.
[0020] According to another aspect of the embodiments of the present application, a computer program product is provided, which includes a computer program. The computer program performs the database query statement generation method when being executed by a processor.
[0021] In the embodiments of the present application, first, query requirement information is obtained, the query requirement information is used to represent a requirement for querying a target database in a natural language; then, the query requirement information is input into a query statement generation model, and an initial structured query statement is generated by using the query statement generation model; then, a statement execution time of the initial structured query statement is determined, wherein the statement execution time is a time for executing the initial structured query statement on the target database; finally, the statement execution time is input into the query statement generation model, and a target structured query statement is generated by using the query statement generation model.
[0022] In the above process, the query requirement information is obtained, the intelligent conversion from natural language to structured query can be realized, and the user experience is significantly improved. The user does not need to learn complex structured query statement syntax and can only need to describe the query requirement in natural language. After automatic recognition and understanding, the query is converted into a structured query statement executable by the database. Through the application of natural language processing and deep learning technology, the intelligent structured query statement generation can adapt to the query requirements of different industries and user groups, providing high flexibility and extensive application scenario support. The user can only need to describe the query requirement in natural language without learning complex structured query statement syntax. The query requirement information described in natural language is converted into an initial structured query statement, which reduces the learning cost of the user, improves the convenience of data query, and enhances the user experience. The structured query statement generation can adapt to the query requirements of different industries and user groups, providing high flexibility and extensive application scenario support. The execution time of the initial structured query statement is evaluated, the efficiency of the generated structured query statement is quantitatively considered, and direct feedback signals are provided for the improvement of the structured query statement. The execution time of the statement is fed back to the query statement generation model. This closed-loop design allows the query statement generation model to adjust and improve itself based on the real-time feedback of the efficiency of the structured query statement execution in subsequent generation, and promotes the generation of more efficient target structured query statements, solving the problem of low execution efficiency of the generated database query statements in the related art. BRIEF DESCRIPTION OF DRAWINGS
[0023] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and serve to explain the principles of the present application together with the specification.
[0024] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the accompanying drawings needed to be used in the embodiments or prior art description will be briefly introduced. Obviously, for those skilled in the art, other drawings can also be obtained without creative labor based on these drawings.
[0025] Figure 1 is a flowchart of a database query statement generation method according to an embodiment of the present application;
[0026] Figure 2 is a schematic diagram of an optional database query statement generation process according to an embodiment of the present application;
[0027] Figure 3 is a schematic diagram of a database query statement generation device according to an embodiment of the present application. DETAILED DESCRIPTION
[0028] In the following, the technical solutions in the embodiments of the present application will be described clearly and completely in conjunction with the drawings in the embodiments of the present application, so that those skilled in the art can better understand the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work should fall within the scope of the present application.
[0029] It should be noted that the terms "first", "second", and the like in the specification and claims of the present application and the above-described drawings are used to distinguish similar objects, and do not necessarily have to describe a specific order or a sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, device or device including a series of steps or units does not have to be limited to those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to these processes, methods, devices or devices.
[0030] According to an embodiment of the present application, a method for generating a database query statement is provided. It should be noted that the steps shown in the flowchart of the drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described herein can be executed in an order different from that shown herein.
[0031] Figure 1 is a flowchart of a method for generating a database query statement according to an embodiment of the present application, as shown in Figure 1 The method comprises the following steps:
[0032] Step S102, obtaining query requirement information.
[0033] The query requirement information is used to represent the requirement for querying the target database in natural language.
[0034] The above-mentioned target database can refer to a database system that accepts query operations. The type of target database can include a relational database, a graph database, etc., which can be determined according to actual needs.
[0035] The query requirement information can be a data query request or a question in natural language form proposed by the user. For example, display products with high sales, or list customers who have purchased more than 10 times in the past year. The query requirement information can include the data content that the user needs to obtain from the database, can include entities, operations, and filtering conditions, and the query requirement information can be used as a basis for understanding and generating a suitable query statement.
[0036] In an optional embodiment, the query requirement information is obtained, and the natural language query of the user is converted into a machine-understandable requirement representation. This step can be implemented using natural language processing techniques, which can include semantic understanding and entity recognition. The user inputs the query requirement information in natural language form, which provides a basis for subsequent structured query statement generation. To improve the accuracy and comprehensiveness of the query requirement information, multi-modal understanding capabilities can be integrated, combining the user's historical query behavior, database schema information, and domain knowledge, to more accurately understand the user's query intent through the combined application of deep learning and rule engines. For example, the user's data query pattern can be inferred from historical query data, providing additional context information during entity recognition and intent classification, and enhancing the accuracy of understanding.
[0037] In the above process, obtaining the query requirement information enables intelligent conversion from natural language to structured queries, significantly improving user experience. Users do not need to learn complex structured query statement syntax and can only need to describe query requirements in natural language. After automatic recognition and understanding, the query is converted into a structured query statement executable by the database. Through the application of natural language processing and deep learning techniques, intelligent structured query statement generation can adapt to the query requirements of different industries and user groups, providing high flexibility and extensive application scenario support.
[0038] In step S104, the query requirement information is input into the query statement generation model, and an initial structured query statement is generated using the query statement generation model.
[0039] The query statement generation model can be a model responsible for converting natural language query requirement information into a structured query statement. The query statement generation model can be based on deep learning techniques such as sequence-to-sequence models, long short-term memory networks, and attention mechanisms. The query statement generation model can include multiple sub-modules that can generate an initial structured query statement based on understanding and parsing the query requirement information, and further generate a target structured query statement through subsequent steps.
[0040] The initial structured query statement can refer to a statement result generated by a query statement generation model, and the structured query statement capable of expressing the query intent is constructed based on the query requirement information provided by the user and through natural language analysis and historical data assistance.
[0041] In an optional embodiment, the query requirement information can be input into the query statement generation model, and the initial structured query statement can be generated by using the model. Specifically, after obtaining the query requirement information, the query requirement information can be input into the query statement generation model. The query statement generation model can be a deep learning model, such as a model based on a sequence-to-sequence framework, which can convert natural language into structured data. After receiving the query requirement information, the query statement generation model can encode the query requirement information into a continuous vector representation, and the continuous vector representation contains semantic features of the query. The decoder of the query statement generation model can decode the encoded continuous vector representation to generate a structured query statement. In order to generate a higher-quality initial structured query statement, the following techniques can be used to enhance the ability of the query statement generation model. During the training phase of the query statement generation model, auxiliary tasks of grammar checking and semantic parsing can be introduced, so that the query statement generation model can learn the grammar and semantic constraints while generating the statement, thereby improving the accuracy of the generated statement. The query statement generation model can be pre-trained and fine-tuned on a large amount of data in a specific field, so that the query statement generation model can understand the domain-specific vocabulary and query patterns, and generate more accurate and domain-specific structured query statements.
[0042] In the above process, the natural language query can be accurately and efficiently converted into a structured query statement, which reduces the learning cost of the user, improves the convenience of data query, enhances the user experience, and promotes the efficient use and management of data.
[0043] In step S106, the statement execution time of the initial structured query statement is determined.
[0044] The statement execution time is the time for executing the initial structured query statement on the target database.
[0045] The statement execution time can be the time required for executing the initial structured query statement on the target database, and can be used to evaluate the performance of the initial structured query statement and reflect the efficiency of the query. The performance evaluation module can execute the initial structured query statement and measure the execution time, so as to judge the efficiency of the initial structured query statement and further guide the improvement of the query statement. The statement execution time can be used as part of the reward signal to encourage the query statement generation model to generate a more optimal structured query statement.
[0046] In an optional embodiment, the initial structured query statement generated by the query statement generation model can be sent to the target database management system to trigger the data query operation. After receiving the initial structured query statement, the target database management system can parse and execute the statement to retrieve the required data from the target database. During the execution of the initial structured query statement by the target database management system, the timestamps of the start and completion of the statement execution can be recorded, and the time required for executing the initial structured query statement can be calculated to obtain the statement execution time. The statement execution time can evaluate the statement execution efficiency and reflect the response speed and resource consumption of the statement in the target database environment. In order to more accurately control and improve the statement execution time, additional performance monitoring and optimization mechanisms can also be introduced to analyze the query execution plan generated by the database, understand the improvement points of the structured query statement such as index usage, table scan order, etc., and provide strategy suggestions for subsequent statement improvement. According to different query requirements and database load conditions, the acceptable execution time threshold can also be dynamically adjusted to ensure that high-efficiency structured query statements can also be generated in high-load environments.
[0047] In the above process, feedback can be obtained from the target database environment to evaluate the execution efficiency of the generated initial structured query statement. By measuring the statement execution time, the performance of the query statement generation model can be quantified to provide a basis for subsequent model improvement and strategy adjustment. The statement execution time can be used as a factor to build a target reward function, which can guide the reinforcement learning module to dynamically adjust the generation strategy and prompt the query statement generation model to generate efficient structured query statements.
[0048] In step S108, the statement execution time is input into the query statement generation model, and the target structured query statement is generated by the query statement generation model.
[0049] The above target structured query statement can refer to the structured query statement generated after multiple iterations of improvement by the query statement generation model. Through the intervention of the reinforcement learning mechanism, the statement execution time can be used as the improvement target of the structured query statement, and the generated target structured query statement can significantly improve the query efficiency and reduce resource consumption while maintaining the query intent, thereby achieving higher performance and higher efficiency standards.
[0050] In an optional embodiment, the statement execution time can be input as a feedback signal into the query statement generation model for evaluating the performance of the query statement generation model. The query statement generation model can adjust the generation strategy through an internal reinforcement learning mechanism using the statement execution time. The query statement generation model can use the reward function constructed according to the statement execution time as the main reward, and gradually improve the way of generating structured query statements through trial and error learning, in order to reduce the execution time of the subsequently generated structured query language. To effectively utilize the statement execution time feedback, the reinforcement learning module can design a reasonable state space and action space. The state space can include the current state of the structured query statement, the schema of the database, historical execution data, etc.; the action space can include the choices that the query statement generation model can make when generating the structured query statement, such as table join order, condition filtering method, etc. Through a deep network, the query statement generation model can establish a connection between the state and the action pair, learn to take better actions in a specific state, and achieve the goal of minimizing the execution time of the structured statement.
[0051] In the above process, the feedback of the statement execution time is introduced to realize the closed-loop improvement of the generation of the structured query statement. Under the reinforcement learning framework, the generation strategy can be dynamically adjusted through continuous learning from actual execution, so as to promote the query statement generation model to generate structured query statements with high execution efficiency. Through continuous learning and improvement, the query statement generation model can better adapt to different database environments and query patterns, and improve the generalization ability and robustness of the generated statements. The improvement mechanism based on the statement execution time feedback can improve the performance of the intelligent structured query statement generation tool, and provide technical support for big data query and analysis.
[0052] In the above process, the query requirement information is obtained, which can realize intelligent conversion from natural language to structured query, and significantly improve user experience. Users do not need to learn complex structured query statement syntax, and can only need to describe the query requirement in natural language. After automatic recognition and understanding, the query is converted into a structured query statement executable by the database. Through the application of natural language processing and deep learning technology, the intelligent structured query statement generation can adapt to the query requirements of different industries and user groups, providing high flexibility and extensive application scenario support. Users can only need to describe the query requirement in natural language, without learning complex structured query statement syntax. The query requirement information described in natural language is converted into an initial structured query statement, which reduces the learning cost of users, improves the convenience of data query, and improves the user experience. The structured query statement generation can adapt to the query requirements of different industries and user groups, providing high flexibility and extensive application scenario support. The execution time of the initial structured query statement is evaluated, which introduces quantitative consideration of the execution efficiency of the generated structured query statement, providing direct feedback signal for the improvement of the structured query statement. The execution time of the statement is fed back to the query statement generation model, which allows the query statement generation model to adjust and improve itself based on the real-time feedback of the structured query statement execution efficiency in subsequent generation, and to generate more efficient target structured query statement, solving the problem of low execution efficiency of the generated database query statement in related technologies.
[0053] Optionally, the query requirement information is input into the query statement generation model, and an initial structured query statement is generated by using the query statement generation model, including: using a natural language parsing module in the query statement generation model to parse the query requirement information to obtain a structured query instruction set; using a historical data analysis module in the query statement generation model to perform historical query data matching on the structured query instruction set to obtain a historical table connection order, wherein the historical table connection order is used to represent the connection order of the database tables used to execute a historical query statement matched with the structured query instruction set; and generating the initial structured query statement based on the structured query instruction set and the historical table connection order.
[0054] The natural language parsing module described above can be used to convert the query requirement information described in natural language input by the user into a structured form understandable by machines to obtain a structured query instruction set. The natural language parsing module can understand the meaning of the query requirement information based on natural language processing techniques such as morphological analysis, syntactic analysis and semantic analysis, can identify specific database entities such as table names, column names and value ranges, determine the type of user query such as statistical, filtering or sorting operation, and can organize the parsing results into semantic representations convenient for subsequent processing, such as constructing a tree or graph structure to represent the logical relationship of the query.
[0055] The structured query instruction set described above can refer to a series of instructions generated by the natural language parsing module for constructing a structured query statement. The structured query instruction set can include but is not limited to information about the tables and columns that need to be queried, the operations applied such as aggregation, filtering, and sorting, and conditional statements such as value range, keyword matching.
[0056] The historical data analysis module described above can refer to a module used to match historical query data, learn query patterns and optimal query paths from it, and assist in generating improved structured query statements. The historical data analysis module can extract useful patterns from historical queries, such as the order of query operations, the number and type of filtering conditions, the use of indexes, etc. Clustering algorithms can be used to classify the extracted features and find the commonalities of similar queries, thereby refining the optimal query strategy. The structure of the structured query statement that has performed efficiently in the past can be learned, including how to effectively join tables and how to reasonably apply filtering conditions, etc.
[0057] The historical table connection order described above can refer to a table connection order learned from historical query data that is more efficient for a specific type or similar type of query. In database queries, complex queries involving multiple table joins, the connection order of tables has a significant impact on query efficiency. The historical table connection order can be derived based on the execution plans and efficiency indicators of past queries, reflecting the optimal connection strategy of the database in a specific scenario, such as which two tables to connect first, and then connect the third table, etc. The historical table connection order can be used as a reference when generating a structured query statement, helping to construct a more efficient query statement.
[0058] In an optional embodiment, the query requirement information can be sent to the natural language parsing module of the query statement generation model, and the natural language parsing module can parse the query requirement information, extract entity, operation, and value range information from the query requirement information, and construct a structured query instruction set. The structured query instruction set can clearly describe the user's query intent and details, providing a basis for generating a structured query statement. The structured query instruction set can be passed to the historical data analysis module. The historical data analysis module can identify query patterns and table connection orders that match the structured query instruction set through analysis of historical query data, and obtain a historical table connection order. The historical table connection order can be derived based on the optimal performance records exhibited in historical queries, can reflect the query logic, and also takes into account the physical structure and data distribution of the database, thereby facilitating the generation of more efficient and optimal structured query statements. Then, an initial structured query statement can be generated based on the structured query instruction set and the historical table connection order. In the generation process, the optimal path provided by the historical table connection order can be considered, and an efficient table connection order can be used, while combining the specific requirements and intentions of the user to generate an initial structured query statement.
[0059] In the above process, the user's query requirements can be accurately understood, and the initial structured query statement can be generated by using historical query data. The natural language parsing module ensures accurate extraction of query intent, and the historical data analysis module introduces experience from previous queries, improving the practicality and efficiency of the structured query statement, which helps to speed up the data retrieval and analysis process, and improves user query satisfaction.
[0060] Optionally, the natural language parsing module in the query statement generation model is used to parse the query requirement information to obtain a structured query instruction set, including: using a pre-trained language model in the natural language parsing module to extract text features of the query requirement information to obtain query text features; identifying the query text features to obtain database entities and database operations, wherein the database entities include at least one of the following: table name, column name and value range, and the database operations include at least one of the following: statistical operation, filtering operation and sorting operation; and generating the structured query instruction set based on the database entities and the database operations.
[0061] The pre-trained language model mentioned above can be a deep learning model pre-trained on a large-scale text data, which can be used to learn the general representation of language. When the user submits the natural language query requirement information, the pre-trained language model can extract the text features of the input information to obtain the query text features. The pre-trained language model can be designed or fine-tuned to recognize specific database entities such as table name, column name and value range, and database operations such as statistics, filtering and sorting, which helps to generate effective structured query statements.
[0062] The query text features mentioned above can be semantic feature vectors extracted by the pre-trained language model after processing the query requirement information. The query text features provide a basis for subsequent database entity and operation recognition. The feature extraction stage can consider the contribution of each relevant vocabulary and generate query text features through the comprehensive influence of the context, which helps the query statement generation model to understand more complex query intent.
[0063] The database entity mentioned above can refer to a database object referenced in a database query statement, which can include table name, column name and value range. The table name can be the table name in the database, and each table can contain information or data of a specific topic; the column name can be the field or column title in the database table, which can represent a specific attribute or data type; the value range can refer to the data value or value interval involved in the query, which can be used for filtering, comparison or constraint of query results.
[0064] The database operations described above can refer to specific operations used in structured query statements, which can be used to instruct the database management system on how to process data. The database operations can include, but are not limited to, statistical operations, filtering operations, and sorting operations. The statistical operations can include operations for calculating the sum, average, or count of numerical attributes, etc. The filtering operations can be used to limit the query results by excluding records that do not meet certain conditions. The sorting operations can be used to sort the results according to the values of one or more columns. Identifying the database operations can help build the correct structure of the structured query statement, ensuring that the query results meet the user's query intent.
[0065] In an optional embodiment, the query requirement information can be processed by a pre-trained language model. The pre-trained language model utilizes rich language understanding capabilities to convert the query requirement information into dense vector representations, i.e., query text features. The query text features encode the semantic information of the text, including the intent, entities, and relationships of the query, providing a foundation for subsequent entity recognition and operation parsing. Next, the extracted query text features can be analyzed to identify database-related database entities, such as table names, column names, value ranges, and database operations, such as statistics, filtering, and sorting. This identification process can include multiple sub-tasks, such as named entity recognition, locating and classifying database entities, and sequence labeling, which are used to identify the positions of operation instructions. After identifying the relevant database entities and database operations, the database entities and database operations are organized into a structured query instruction set, which lists the operations and entities required for the query.
[0066] In the above process, the pre-trained language model provides strong text understanding capabilities, ensuring accurate parsing of the query requirement information, which helps to efficiently generate a structured query language that meets the user's requirements, improving the efficiency of data retrieval and analysis, and also ensuring the accuracy and reliability of the query results.
[0067] Optionally, based on the structured query instruction set and the historical table connection order, an initial structured query statement is generated, including: using a long short-term memory network in the query statement generation model to encode the structured query instruction set to obtain a query continuous vector; using an attention mechanism in the query statement generation model to decode the query continuous vector to obtain a first structured query statement; and based on the first structured query statement, the historical table connection order, and a predefined structured query statement template, an initial structured query statement is obtained.
[0068] The query continuous vector can refer to a vector representation obtained by encoding the structured query instruction set through a long short-term memory network, which realizes the conversion of the information of the structured query instruction set into a continuous vector form. As a special recurrent neural network, the long short-term memory network can process sequence data and solve the problems of gradient disappearance and gradient explosion in long sequences, so that it can capture long-distance dependencies. Based on the long short-term memory network processing the structured query instruction set, the semantic information of the structured query instruction set is encoded into a high-dimensional query continuous vector, which can be used as the basis for decoding to generate a structured query statement in the next stage.
[0069] The first structured query statement can refer to a structured query statement generated by decoding through an attention mechanism based on the query continuous vector. The attention mechanism can focus on different parts of the input sequence during the decoding process, thereby better processing long sequence data and improving the accuracy of the generated statement. During the decoding process, the attention mechanism can determine which vector elements of the query continuous vector should be given higher weights when generating each part of the structured query statement based on the information in the query continuous vector, to ensure that the generated structured query statement accurately reflects the query requirement information.
[0070] The predefined structured query statement template can refer to a structured query statement framework pre-set for each query type and pattern. The predefined structured query statement template can be induced based on historical query data and can include various query structures and patterns. When generating a structured query statement, the first structured query statement can be mapped to these predefined structured query statement templates to ensure that the generated structured query statement conforms to the pattern of the database query in structure, and also facilitates subsequent performance evaluation and improvement.
[0071] In an optional embodiment, the structured query instruction set can be input into a long short-term memory network in the query sentence generation model. The long short-term memory network can process sequence data and remember long-term dependencies. In this stage, the long short-term memory network can convert each entity and operation in the structured query instruction set into a corresponding vector representation, taking into account the relevance between entities and the order of operations, to form a query continuous vector representing the query requirements. The obtained query continuous vector can be sent to a decoder, which uses an attention mechanism to enhance the decoding process. The attention mechanism allows the decoder to focus on the part of the query continuous vector that is more relevant to the current generation task when generating each part of the structured query sentence, thereby improving the accuracy and efficiency of generation. For example, the attention mechanism can focus on entities and operations that specify filtering conditions to ensure that the generated structured query sentence correctly reflects the user's query intent. Then, the first structured query sentence can be integrated with the historical table connection order provided by the historical data analysis module, which provides an efficient query path, and the pre-defined structured query sentence template, which ensures the grammatical correctness and structural rationality of the generated sentence, so that the generated initial structured query sentence can accurately express the user's query intent.
[0072] In the above process, through the processing of the query sentence generation model, efficient and automatic conversion from the structured query instruction set to the structured query sentence is achieved. The combination of the long short-term memory network and the attention mechanism takes into account the semantic logic of the query and can effectively handle complex dependencies in the instruction set, improving the accuracy and efficiency of generating structured query sentences. Considering the historical table connection order and the pre-defined structured query sentence template ensures that when processing complex queries, structured query sentences that are semantically correct and have high execution efficiency can be generated, significantly improving the flexibility and response speed of data queries.
[0073] Optionally, the sentence execution time is input to the query sentence generation model, and the target structured query sentence is generated by using the query sentence generation model, including: based on the sentence execution time, constructing a target reward function; based on the target reward function, adjusting the first generation strategy of the query sentence generation model to obtain a second generation strategy; based on the second generation strategy and the query sentence generation model, generating the target structured query sentence.
[0074] The above-mentioned target reward function can refer to a reward function used to guide the decision-making and behavior improvement of the query sentence generation model in reinforcement learning. Based on the target reward function, the sentence execution time of the structured query sentence can be used as the target for improving the query sentence generation model. In addition to the sentence execution time, the target reward function can also consider factors such as grammatical correctness and result accuracy to comprehensively evaluate the quality of the generated structured query sentence.
[0075] The first generation strategy mentioned above can refer to a generation strategy adopted by the query statement generation model before reinforcement learning improvement.
[0076] The second generation strategy mentioned above can refer to a generation strategy obtained by reinforcement learning improvement based on the first generation strategy. When the query statement generation model executes the structured query statement and receives feedback based on the target reward function, the generation strategy can be adjusted to obtain a higher reward value in future generation and generate a structured query statement with higher execution efficiency. The parameters of the query statement generation model can be adjusted, such as through experience replay and target network synchronization mechanisms in deep learning to improve the behavior of the model, so that the query statement generation model tends to make generation decisions that can lead to better execution time.
[0077] In an optional embodiment, the target reward function can be constructed according to the statement execution time, and the target reward function can quantify the efficiency of structured query statement execution. The target reward function can be designed as a negative function of the statement execution time, such as a negative exponential function. The target reward function can ensure that the shorter the statement execution time, the higher the reward, which provides an improvement direction for the query statement generation model. After receiving feedback of the target reward function, the query statement generation model can adjust the first generation strategy, and this process can be implemented through a deep learning network. The deep learning network can predict the expected reward of each possible action according to the current state, including the structured query instruction set, the historical table connection order, the database schema, and the historical action, the generated structured query language fragment. Based on the target reward function, the query statement generation model can adjust the expected reward value and learn which actions, such as specific table connection orders and filter condition selections, can bring higher execution efficiency, thereby forming the second generation strategy. After obtaining the second generation strategy, the query statement generation model can generate structured query statements more intelligently. The query statement generation model can select an optimal action sequence according to the first generation strategy to generate a target structured query statement, and the target structured query statement can meet the query requirements and has been significantly improved in execution efficiency.
[0078] In the above process, by introducing the statement execution time as a reward signal, the query statement generation model can be guided to learn and generate structured query statements with higher execution efficiency. The query statement generation model can be adjusted and improved based on the execution time feedback, and the reinforcement learning strategy can better adapt to changes in the database environment, generate structured query statements with higher execution efficiency, and improve the performance of data query and analysis. This dynamic improvement mechanism can also gradually improve the intelligence of the query statement generation model as the use time increases, realize long-term performance improvement, and provide more efficient and accurate data query services for users.
[0079] Optionally, based on the statement execution time, a target reward function is constructed, including: evaluating the initial structured query statement to obtain the syntax correctness and result accuracy of the initial structured query statement; and constructing the target reward function based on the statement execution time, the syntax correctness and the result accuracy.
[0080] The syntax correctness can refer to a parameter for measuring whether the structured query statement conforms to the specifications and standards of the database query language at the syntax level. The structured query statement with correct syntax can be correctly parsed and executed by the database management system, and the syntax correctness can ensure that the structured query statement can be correctly and efficiently executed. Evaluating the syntax correctness can include checking whether the structure of the statement is complete, whether the use of keywords is appropriate, whether the reference of tables and columns exists, and whether the logical expression is reasonable.
[0081] The result accuracy can refer to a parameter for measuring whether the data result returned after the execution of the structured query statement conforms to the query requirement proposed by the user. The checking of the result accuracy can include the following aspects: whether the correct table and column are selected, whether the filtering rule is accurately applied, whether the aggregation function is correctly applied to the data set; whether the sorting, grouping and other operations are implemented according to the user's demand, and whether the number of returned rows and the data type are consistent with the query requirement.
[0082] In an optional embodiment, after the initial structured query statement is generated, the initial structured query statement can be checked by a structured query statement syntax checker. This process can include checking the integrity of the syntax structure, the correct use of keywords, the correct reference of table and column names, etc. The initial structured query statement can be executed on the target database, and the matching degree between the execution result and the expected query requirement information can be compared. A series of test cases can be designed and executed to cover various cases and edge conditions of the query. Based on the statement execution time, the syntax correctness and the result accuracy, a comprehensive target reward function can be constructed to guide the query statement generation model to generate more efficient and accurate structured query statements in the future. The design of the target reward function can include the three components of the statement execution time, the syntax correctness and the result accuracy. The reward for the statement execution time can be measured by using a negative exponential function to measure the execution efficiency. The reward for the syntax correctness can give a lower or negative reward value for the structured query statement with syntax error. The reward for the result accuracy can be punished for the statement that cannot return the correct result, so as to ensure the accuracy of the execution result of the generated structured query statement.
[0083] In the above process, the overall quality of the generated structured query statement is quantified more comprehensively by evaluating the syntax correctness and result accuracy of the initial structured query statement, and constructing a target reward function based on the execution time. Such a setting allows the reinforcement learning module to adjust the generation strategy based on the comprehensive evaluation results, pursue the improvement of execution efficiency, and also ensure the correctness of the syntax and the accuracy of the results. Considering the statement execution time, syntax correctness and result accuracy comprehensively helps to build a more robust and intelligent query statement generation model, and improves the overall performance of data query and user satisfaction.
[0084] Optionally, based on the statement execution time, the syntax correctness and the result accuracy, the target reward function is constructed, including: constructing a negative exponential function based on the statement execution time, constructing a first positive exponential function based on the syntax correctness, and constructing a second positive exponential function based on the result accuracy; and constructing the target reward function based on the negative exponential function, the first positive exponential function and the second positive exponential function.
[0085] The negative exponential function described above can refer to a function used to express the reward of the statement execution time in a mathematical form. The shorter the statement execution time, the higher the value of the negative exponential function, and the greater the reward; the longer the statement execution time, the greater the value of the negative exponential function, and the smaller the reward. Such a design reflects the pursuit of the execution efficiency of the structured query statement, that is, the smaller the statement execution time, the more rewards obtained, thereby encouraging the query statement generation model to generate structured query statements with higher execution efficiency.
[0086] The first positive exponential function described above can refer to a function used to quantify the syntax correctness of the structured query statement. The first positive exponential function can reward those statements without syntax errors. Syntax correctness can ensure that the structured statement can be correctly parsed and executed by the database management system. Structured query statements with correct syntax can obtain a larger value of reward, and statements with syntax errors will be punished. The specific design of the first positive exponential function can also be related to the syntax characteristics, error types and severity of the database.
[0087] The second positive exponential function can be a function for quantifying the result accuracy of the execution of the structured query statement. The result accuracy can reflect whether the execution of the structured query statement accurately expresses the query intention of the user. If the execution result of the generated structured query statement is close to the user's demand, the value of the second positive exponential function can be larger, thereby giving the query statement generation model a corresponding reward; if the execution result of the generated structured query statement deviates greatly from the user's demand, the value of the second positive exponential function can be relatively small, forming a punishment signal. The result accuracy evaluation can be realized by setting a reference standard or an expected result set, which can be a result obtained by manually writing a correct statement, or a test case based on the user's query intention. The design of the second positive exponential function considers the actual utility of the structured query statement and emphasizes the reliability of the result.
[0088] In an optional embodiment, a negative exponential function of the statement execution time can be constructed. The shorter the statement execution time, the higher the execution efficiency of the structured query statement. The negative exponential function of the statement execution time can be designed as part of the target reward function. The shorter the statement execution time, the higher the reward. A first positive exponential function of the syntax correctness can be constructed. The first positive exponential function can be designed to measure the syntax correctness. For a structured query statement with correct syntax, the reward value of the first positive exponential function can be larger. For a structured query statement with syntax errors, the reward value of the first positive exponential function can be smaller. The first positive exponential function can encourage the query statement generation model to generate structured query statements with correct syntax, avoiding the risk of execution failure. A second positive exponential function of the result accuracy can be constructed. The result accuracy can measure whether the structured query statement meets the user's query demand. The result accuracy can be evaluated by setting the second positive exponential function. The function value of the second positive exponential function can be determined according to the matching degree of the query result and the user's query demand information. This setting can ensure that the generated structured query statement can accurately return the information required by the user. Then, the target reward function can be constructed based on the negative exponential function, the first positive exponential function and the second positive exponential function. For example, the negative exponential function, the first positive exponential function and the second positive exponential function can be assigned respective corresponding weight coefficients and weighted summation to obtain the target reward function. The query statement generation model can adjust the generation strategy according to the target reward function to achieve an optimal structured statement generation effect.
[0089] In the above process, by constructing a target reward function based on execution time, grammatical correctness and result accuracy, the quality of generated structured query statements can be improved from multiple dimensions, promoting the query statement generation model to learn to improve execution efficiency while maintaining grammatical correctness and result accuracy. This comprehensive improvement strategy improves the response speed of data query and ensures the high quality of query results, thereby significantly improving user experience and data management efficiency. In complex query and real-time requirement scenarios, the design of this target reward function can help the query statement generation model quickly adapt in dynamic environments, generating efficient and accurate structured query statements, effectively avoiding resource waste and execution delay. The introduction of dynamic weight adjustment and punishment mechanism enhances the flexibility and robustness of structured query statements, which can cope with different query requirements and changes in database environment.
[0090] The technical solutions proposed in the present application are described below in conjunction with an optional embodiment. The present application proposes an intelligent structured query statement generation tool based on machine learning. The technical field involved mainly includes database management systems and the application of machine learning technology. The present application focuses on automatically generating database query statements using machine learning to improve the efficiency and accuracy of data query and analysis. The execution time is introduced as an explicit reward signal, and the performance indicators are integrated into the reinforcement learning reward mechanism, realizing the dual improvement of translation quality and execution efficiency.
[0091] The system architecture of the present application can be composed of a natural language parsing module, a historical data analysis module, a query statement generation model, a performance evaluation module and a reinforcement learning module. The natural language parsing module is responsible for parsing the user's natural language input and extracting entities, relationships and intentions. The historical data analysis module mines historical query data to assist the query statement generation model in learning common patterns and optimal paths. The query statement generation model generates an initial structured query statement based on the parsing results. The performance analysis module evaluates the execution efficiency of the generated initial structured query statement and provides feedback signals. The reinforcement learning module improves the structured query statement generation strategy through a deep Q network.
[0092] The specific process is as follows: the user inputs the query intent; the natural language parsing module can parse the user input and extract entities, relationships and intentions; the historical data analysis module can analyze historical data such as common query patterns and optimal structured query statement structures; the query statement generation model can generate an initial structured query statement based on the parsing results and historical data; the performance evaluation module can execute the initial structured query statement and measure the execution time; the reinforcement learning module can improve the generation strategy and improve the efficiency of the structured query statement; the output module can display the generated efficient target structured query statement.
[0093] Figure 2is a schematic diagram of an optional database query statement generation process according to an embodiment of the present application, as shown Figure 2 Based on the user input module, input query requirement information; based on the natural language analysis module, analyze the query requirement information to obtain a structured query instruction set; based on the historical data analysis module, perform historical query data matching to obtain a historical table connection order; based on the query statement generation module, generate an initial structured query statement based on the structured query instruction set and the historical table connection order; based on the performance evaluation module, determine the statement execution time; based on the deep learning module, construct a target reward function, update the generation strategy of the query statement generation model, and generate a target structured query statement; based on the output module, output the target structured query statement.
[0094] The detailed design of the system modules of the present application can include the following modules. The natural language analysis module can be responsible for converting the user's natural language query into a structured semantic representation, extracting key information such as entities, relationships, and intentions, and constructing a semantic graph. The natural language analysis module can ensure support for complex queries, such as multi-condition filtering, aggregation operations, and sorting. Entity recognition can be performed to identify database-related entities in the text, such as table names, column names, and value ranges. Intent classification can be performed to determine the user's query requirements, such as statistics, filtering, and sorting. Semantic graph construction can be performed to map natural language to a structured structured query statement semantic representation. Pre-trained language models can be used for text feature extraction, database entities can be extracted through start-internal-external labels, a multi-label classifier can be used to extract user intentions, and a semantic graph can be mapped and constructed. The historical data analysis module can be responsible for mining patterns and trends in historical data to assist the query statement generation model in learning common structured query statement structures and optimal paths.
[0095] The query statement generation model can generate an initial structured query statement by combining the structured information and the recommended table connection order transmitted by the natural language analysis module and the historical data analysis module, and combining the predefined structured query statement template. Syntax generation can be performed to convert the structured semantic representation into a legal structured query statement; context association can be performed to capture long-distance dependencies using an attention mechanism; dynamic adjustment can be performed according to the better practices analyzed by the historical data analysis module to dynamically adjust the order of table association. The technical implementation can be performed by a sequence-to-sequence model using a long short-term memory network to encode the structured semantic representation into a continuous vector representation, and then decode to generate the first structured query statement. In the decoding process, the context association is enhanced by the attention mechanism, so that the decoder can focus on important positions in the input when generating each structured query statement element. At the same time, dynamic adjustment can also be performed according to the predefined structured query statement template and the optimal table connection order given by the historical data analysis module. Then, the generated structured query statement is checked and repaired.
[0096] The performance evaluation module can be responsible for executing the generated structured query statement and measuring the efficiency, analyzing the query plan to identify bottlenecks, and obtaining the structured query statement query time and identifying inefficient operations such as full table scanning and lack of index.
[0097] The reinforcement learning module can improve the structured query statement generation strategy by using a deep Q network, introduce the statement execution time as a reward signal, dynamically adjust the generation strategy, and improve the execution efficiency of the generated structured query statement while ensuring grammatical correctness and semantic consistency. The module design, the state space can include the current generated structured query statement fragment, the database schema such as table name, column name, foreign key relationship, historical execution time feedback, etc. The action space, each action corresponds to a decision of structured query statement generation, such as selecting a specific query order, adding a filter condition, specifying an aggregation function, etc. The target reward function, the target reward function design subject is the statement execution time, while other indicators such as grammatical correctness and execution accuracy can also be considered. The target reward function can be designed as follows, the main reward can be a negative exponential function based on the statement execution time Rtime can be represented as follows:
[0098] Rtime=exp(-k·t);
[0099] Where t can be the statement execution time, k can be the adjustment coefficient, which can be used to control the reward decay rate.
[0100] The auxiliary reward, the syntax correctness, the first positive exponential function R syntax, if the syntax is wrong, a penalty is applied; the result accuracy, the second positive exponential function R accuracy, if the generated result does not match the expectation, a penalty is applied.
[0101] The target reward function R can be expressed as follows:
[0102] R = ω1·Rtime + ω2·Rsyntax + ω3·Raccuracy;
[0103] Wherein, ω1 can represent the weight coefficient of the negative exponential function Rtime, ω2 can represent the weight coefficient of the first positive exponential function Rsyntax, and ω3 can represent the weight coefficient of the second positive exponential function Raccuracy.
[0104] Implement experience replay, after each generation of structured query statement, store the current state, the selected action, the obtained reward, the next state and the end flag, periodically randomly draw a small batch of samples from the experience replay pool, calculate the target expected reward value and update the network parameters. Integrate the target network, which can provide stable expected reward value calculation, avoid policy shock caused by frequent updating of main network parameters, and realize the method by copying the parameters of the main network to the target network every certain number of training steps, that is, hard update, or gradually synchronized in proportion, that is, soft update. A loss function can be designed to realize the steps, encode the state, convert external input into a form suitable for neural network processing; network initialization, define the structure of the deep Q network, including input layer, hidden layer and output layer; experience storage, after each interaction, store the experience in the experience replay pool; experience sampling, randomly draw a small batch of sample data, calculate the target expected reward value; loss calculation, compare the predicted reward value with the target reward value, calculate the gradient; parameter update, improve the network weight by back propagation; target network synchronization, periodically synchronize the parameters of the main network and the target network.
[0105] The present application realizes the full-process automation from natural language input to structured query statement generation, to performance improvement, reduces the need for manual intervention, and such a closed-loop design improves efficiency and reduces the possibility of human error. Multiple data sources such as natural language, database schema, and historical execution data are integrated, and deep learning models are used to efficiently fuse cross-modal features. This multi-modal processing capability enables the generated structured query statement to meet semantic requirements and adapt to complex database environments. By introducing a reinforcement learning module, the scheme can dynamically adjust the generation strategy based on real-time feedback such as structured query statement execution time. This adaptive improvement mechanism significantly improves the execution efficiency of the generated structured query statement and performs better in the face of dynamic changes in the database environment. A modular design is adopted, and the coupling between components such as the natural language analysis module, the query statement generation model, and the reinforcement learning module is low, supporting horizontal expansion such as adding support for new database dialects and vertical improvement such as customized training for specific industries.
[0106] According to another aspect of the embodiments of the present application, a database query statement generation device is also provided. The device can execute the database query statement generation method of the above-mentioned embodiments, and the specific implementation method and preferred application scenarios are the same as those of the above-mentioned embodiments, which will not be repeated here.
[0107] Figure 3 is a schematic diagram of a database query statement generation device according to an embodiment of the present application, as shown in Figure 3 The device includes the following: an acquisition module 302, a first generation module 304, a determination module 306, and a second generation module 308.
[0108] The acquisition module 302 is configured to acquire query requirement information of a user, wherein the query requirement information is used to represent a requirement for querying a target database in natural language; the first generation module 304 is configured to input the query requirement information into a query statement generation model and generate an initial structured query statement using the query statement generation model; the determination module 306 is configured to determine a statement execution time of the initial structured query statement, wherein the statement execution is the time for executing the initial structured query statement on the target database; and the second generation module 308 is configured to input the statement execution time into the query statement generation model and generate a target structured query statement using the query statement generation model.
[0109] Optionally, the first generation module is further configured to parse the query requirement information by using a natural language parsing module in the query statement generation model to obtain a structured query instruction set; match the structured query instruction set with historical query data by using a historical data analysis module in the query statement generation model to obtain a historical table connection order, wherein the historical table connection order is used to represent a connection order of a database table used to execute a historical query statement matched with the structured query instruction set; and generate an initial structured query statement based on the structured query instruction set and the historical table connection order.
[0110] Optionally, the first generation module is further configured to extract text features of the query requirement information by using a pre-trained language model in the natural language parsing module to obtain query text features; identify the query text features to obtain database entities and database operations, wherein the database entities include at least one of a table name, a column name, and a value range, and the database operations include at least one of a statistical operation, a filtering operation, and a sorting operation; and generate the structured query instruction set based on the database entities and the database operations.
[0111] Optionally, the first generation module is further configured to encode the structured query instruction set by using a long short-term memory network in the query statement generation model to obtain a query continuous vector; decode the query continuous vector by using an attention mechanism in the query statement generation model to obtain a first structured query statement; and obtain the initial structured query statement based on the first structured query statement, the historical table connection order, and a predefined structured query statement template.
[0112] Optionally, the second generation module is further configured to construct a target reward function based on the statement execution time; adjust the first generation strategy of the query statement generation model based on the target reward function to obtain a second generation strategy; and generate a target structured query statement based on the second generation strategy and the query statement generation model.
[0113] Optionally, the second generation module is further configured to evaluate the initial structured query statement to obtain grammatical correctness and result accuracy of the initial structured query statement; and construct the target reward function based on the statement execution time, the grammatical correctness, and the result accuracy.
[0114] Optionally, the first generation module is further configured to construct a negative exponential function based on the statement execution time, construct a first positive exponential function based on the grammatical correctness, and construct a second positive exponential function based on the result accuracy; and construct the target reward function based on the negative exponential function, the first positive exponential function, and the second positive exponential function.
[0115] The embodiment of the application further provides an electronic device, comprising a memory storing an executable program; and a processor configured to execute the program, wherein the program is configured to execute the method in the embodiments of the application when executed.
[0116] The memory can be a device for storing data and programs inside a computer, and can include a memory, a hard disk, etc., wherein the memory can be used for temporarily storing programs and data being executed, the hard disk can be used for long-term storage of programs and data, the memory can be used for enabling the computer to read and write data and execute programs; the processor can be responsible for executing instructions in the computer program and processing data, and can be responsible for controlling and executing various operations, including arithmetic operations, logical operations, data transmission, etc.
[0117] The embodiment of the application further provides a computer readable storage medium, comprising a stored executable program, wherein the executable program is configured to control a device where the computer readable storage medium is located to execute the method in the embodiments of the application when executed.
[0118] The computer storage medium can be a medium for storing certain discontinuous physical quantities in a computer memory, and the computer storage medium mainly includes semiconductors, magnetic cores, magnetic drums, magnetic tapes, laser discs, etc.; the stored program included in the computer readable storage medium can be a set of instructions that can be recognized and executed by a computer, and can be an information tool running on an electronic computer and meeting certain needs of people.
[0119] The embodiment of the application further provides a computer program product, comprising a computer program, wherein the computer program is configured to implement the method in the embodiments of the application when executed by a processor.
[0120] The computer program product can be a software program that has been written, tested and released, and can run on a computer or other device; the computer program product can include application programs, operating systems, tool software, etc., and is used for implementing specific functions or solving specific problems.
[0121] The embodiment of the application further provides a computer program product, comprising a non-volatile computer readable storage medium, wherein the non-volatile computer readable storage medium is used for storing a computer program, and the computer program is configured to implement the method in the embodiments of the application when executed by a processor.
[0122] The non-volatile computer readable storage medium can be a medium for storing data, and the non-volatile computer readable storage medium can keep the data from being lost when power is off, and can be used for storing long-term saved data such as operating systems, application programs and user files; the non-volatile storage medium can include a hard disk drive, a solid state disk, an optical disc and a flash memory storage device, etc.
[0123] The embodiments of the present application further provide a computer program which, when executed by a processor, implements the method in each of the embodiments of the present application.
[0124] The computer program described above can refer to a set of instructions for telling a computer to perform a specific task or operation. The computer program can be written by a programmer using a specific programming language, and can include algorithms, data structures, logic and control flow, etc. The computer program can be used for various purposes, including application software, operating systems, etc.
[0125] Optionally, in the embodiment, the storage medium can include, but is not limited to, a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and various media that can store program codes.
[0126] Optionally, the specific examples in the embodiment can refer to the examples described in the above embodiments and optional implementation manners, and the embodiment will not be described here.
[0127] In the technical solutions of the present application, the collection, storage, use, processing, transmission, provision and disclosure of information such as financial data or user data comply with relevant laws and regulations and do not violate public order and good customs.
[0128] It should be noted that in the embodiments of the present application, some existing industry solutions, components, models, etc. may be mentioned, which should be considered as exemplary, and the purpose is only to illustrate the feasibility of the implementation of the technical solutions of the present application, but it does not mean that the applicant has or will necessarily use the solution.
[0129] Obviously, those skilled in the art should understand that the above-mentioned modules or steps of the present application can be realized by a general computing device, which can be concentrated on a single computing device or distributed on a network composed of multiple computing devices. Optionally, they can be realized by program codes executable by a computing device, so that they can be stored in a storage device and executed by a computing device, and in some cases, the steps shown or described can be executed in an order different from that described herein, or they can be manufactured into individual integrated circuit modules, or a plurality of modules or steps can be manufactured into a single integrated circuit module. Thus, the present application is not limited to any specific hardware and software combination.
[0130] The above merely describes the preferred embodiments of the present application, and it should be pointed out that, for those skilled in the art, some improvements and refinements can be made without departing from the principles of the present application, and these improvements and refinements should also be considered as the protection scope of the present application.
Claims
1. A method for generating database query statements, characterized in that, include: Obtain query requirement information, wherein the query requirement information is used to represent the requirement to query the target database in natural language; The query requirement information is input into the query statement generation model, and the initial structured query statement is generated using the query statement generation model. Determine the execution time of the initial structured query statement, wherein the execution time is the time taken for the target database to execute the initial structured query statement; The execution time of the statement is input into the query statement generation model, and the target structured query statement is generated using the query statement generation model.
2. The method for generating database query statements according to claim 1, characterized in that, The query requirement information is input into the query statement generation model, and the initial structured query statement is generated using the query statement generation model, including: The natural language parsing module in the query statement generation model is used to parse the query request information to obtain a structured query instruction set; The historical data analysis module in the query statement generation model is used to match the structured query instruction set with historical query data to obtain the historical table join order. The historical table join order is used to indicate the order in which the database tables are joined when executing historical query statements that match the structured query instruction set. The initial structured query statement is generated based on the structured query instruction set and the historical table join order.
3. The method for generating database query statements according to claim 2, characterized in that, The natural language parsing module in the query statement generation model is used to parse the query request information to obtain a structured query instruction set, including: Using the pre-trained language model in the natural language parsing module, text features are extracted from the query request information to obtain query text features; The features of the query text are identified to obtain database entities and database operations, wherein the database entities include at least one of the following: table name, column name and value range, and the database operations include at least one of the following: statistical operation, filtering operation and sorting operation; The structured query instruction set is generated based on the database entities and the database operations.
4. The method for generating database query statements according to claim 2, characterized in that, Based on the structured query instruction set and the historical table join order, the initial structured query statement is generated, including: The long short-term memory network in the query statement generation model is used to encode the structured query instruction set to obtain a continuous query vector; The attention mechanism in the query statement generation model is used to decode the continuous query vector to obtain the first structured query statement; The initial structured query statement is obtained based on the first structured query statement, the historical table join order, and the predefined structured query statement template.
5. The method for generating database query statements according to any one of claims 1 to 4, characterized in that, The execution time of the statement is input into the query statement generation model, and the target structured query statement is generated using the query statement generation model, including: Based on the execution time of the aforementioned statement, construct a target reward function; Based on the target reward function, the first generation strategy of the query statement generation model is adjusted to obtain the second generation strategy; Based on the second generation strategy and the query statement generation model, the target structured query statement is generated.
6. The method for generating database query statements according to claim 5, characterized in that, Based on the execution time of the aforementioned statement, a target reward function is constructed, including: The initial structured query statement is evaluated to obtain its syntactic correctness and result accuracy. The target reward function is constructed based on the statement execution time, the syntax correctness, and the result accuracy.
7. The method for generating database query statements according to claim 6, characterized in that, Based on the statement execution time, the syntax correctness, and the result accuracy, the target reward function is constructed, including: A negative exponential function is constructed based on the statement execution time, a first positive exponential function is constructed based on the syntax correctness, and a second positive exponential function is constructed based on the result accuracy. The target reward function is constructed based on the negative exponential function, the first positive exponential function, and the second positive exponential function.
8. A device for generating database query statements, characterized in that, include: The acquisition module is used to acquire the user's query requirement information, wherein the query requirement information is used to represent the user's query requirement for the target database, described in natural language. The first generation module is used to input the query requirement information into the query statement generation model and use the query statement generation model to generate an initial structured query statement. The determination module is used to determine the execution time of the initial structured query statement, wherein the statement execution refers to the time during which the initial structured query statement is executed in the target database; The second generation module is used to input the execution time of the statement into the query statement generation model, and use the query statement generation model to generate the target structured query statement.
9. The database query statement generation apparatus according to claim 8, characterized in that, The first generation module is further configured to: parse the query requirement information using the natural language parsing module in the query statement generation model to obtain a structured query instruction set; match the structured query instruction set with historical query data using the historical data analysis module in the query statement generation model to obtain a historical table join order, wherein the historical table join order indicates the order in which database tables were joined when executing historical query statements that match the structured query instruction set; and generate the initial structured query statement based on the structured query instruction set and the historical table join order.
10. An electronic device, characterized in that, include: Memory, which stores executable programs; A processor for running the program, wherein the program, when running, executes the method for generating database query statements according to any one of claims 1 to 7.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored executable program, wherein, when the executable program is executed, it controls the device on which the storage medium is located to execute the database query statement generation method according to any one of claims 1 to 7.
12. A computer program product, characterized in that, It includes computer instructions that, when executed by a processor, implement the method for generating database query statements according to any one of claims 1 to 7.