Structured query statement optimization method and device, electronic equipment and storage medium
By using agents for real-time detection, optimization and verification in structured query statement optimization, the problems of optimization lag and low efficiency in the existing technology are solved, and more efficient and accurate SQL statement optimization is achieved.
Patent Information
- Application Number
- CN202411668303.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-20
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2044-11-20
AI Technical Summary
The prior art has lag and passiveness when optimizing structured query statements, and cannot effectively improve the optimization accuracy and efficiency of SQL statements.
By obtaining the target structured script file, the agent in the statement optimization model uses the agent to detect statement content, determine risk type, optimize content, and perform checks and adjustments, real-time optimization of structured query statements is achieved.
It improves the optimization accuracy and efficiency of structured query statements, reduces the risks of data leakage and system performance degradation, and enhances the security and stability of the system.
Smart Images

Figure CN119621747A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of financial technology, and in particular to a structured query statement optimization method and device, electronic device, and storage medium. Background Art
[0002] Structured Query Language (SQL) statement optimization refers to the process of using technical means to improve the execution efficiency of SQL statement queries, reduce query response time, and improve overall database performance. For example, in the claims scenario of financial technology, by setting SQL statement optimization methods in the claims system, the SQL statements generated during user operations can be optimized to improve data query efficiency. However, high-risk SQL statements are prone to system security issues such as data leakage, data corruption, and system performance degradation. Therefore, optimizing high-risk SQL statements is a way to improve the security and stability of related systems.
[0003] The related technology for the optimization process of SQL statements usually first captures log information, obtains the execution script of the SQL statement from the log information, and compares the execution plan of the analyzed SQL statement with the pre-set high-risk SQL rules based on the execution script. If they match, an alarm message is issued and the developer is asked to perform manual optimization. However, this method has certain lag and passivity. The system needs to trigger the script execution of the SQL statement first, and then analyze the script execution results of the SQL statement in the log through relevant analysis tools. Because this method does not establish a connection with the database, the analysis tool cannot provide reasonable optimization suggestions, thereby reducing the optimization accuracy of the SQL statement and the statement optimization efficiency. Therefore, how to propose a method that can improve the optimization accuracy and efficiency of structured query statements has become a technical problem that needs to be solved urgently. Summary of the invention
[0004] The main purpose of the embodiments of the present application is to propose a structured query statement optimization method and device, electronic device, and storage medium, aiming to improve the optimization accuracy and efficiency of structured query statements.
[0005] To achieve the above-mentioned purpose, a first aspect of an embodiment of the present application proposes a structured query statement optimization method, the method comprising:
[0006] Obtaining a target structured script file, wherein the target structured script file includes target structured statement content;
[0007] The structured sentence detection agent based on the sentence optimization model performs sentence content detection on the target structured script file to obtain sentence detection data, wherein the sentence detection data includes sentence detection sub-data of the target structured sentence content;
[0008] Determining a sentence risk type of the target structured sentence content based on the sentence detection sub-data;
[0009] The structured sentence optimization agent based on the sentence optimization model performs sentence content optimization on the sentence risk type and the sentence detection sub-data to obtain candidate sentence optimization data, wherein the candidate sentence optimization data includes a candidate optimization interpretation text and a candidate structured sentence, wherein the candidate optimization interpretation text is used to indicate the difference between the candidate structured sentence and the target structured sentence content;
[0010] The structured statement checking agent based on the statement optimization model performs statement execution checking on the candidate structured statement to obtain a statement execution score, wherein the statement execution score is used to indicate the accuracy of execution of the candidate structured statement;
[0011] Performing statement adjustment on the candidate structured statement based on the statement execution score to obtain a target optimized structured statement;
[0012] The candidate optimized interpretation text is adjusted based on the target optimized structured sentence to obtain the target optimized interpretation text.
[0013] In some embodiments, the structured statement detection agent based on the statement optimization model performs statement content detection on the target structured script file to obtain statement detection data, including:
[0014] Get pre-configured database structure data;
[0015] Building a virtual database based on the database structure data;
[0016] Acquire statement execution plan information of the target structured script file based on the virtual database;
[0017] Based on the structured statement detection agent, statement content analysis is performed on the target structured script file and the statement execution plan information to obtain the statement detection data.
[0018] In some embodiments, the structured statement detection agent performs statement content analysis on the target structured script file and the statement execution plan information to obtain the statement detection data, including:
[0019] Acquire a semantic structure rule knowledge base associated with the structured sentence detection agent;
[0020] Based on the semantic structure rule knowledge base, a sentence semantic structure analysis is performed on the target structured sentence content to obtain semantic structure analysis data, wherein the semantic structure analysis data is used to characterize the matching between the target structured sentence content and the semantic structure rules preset in the semantic structure rule knowledge base;
[0021] Performing an execution plan analysis on the statement execution plan information to obtain statement execution analysis data;
[0022] Performing data integration on the semantic structure analysis data and the sentence execution analysis data to obtain the sentence detection sub-data of the target structured sentence content;
[0023] The sentence detection sub-data are merged to obtain the sentence detection data.
[0024] In some embodiments, the structured statement optimization agent based on the statement optimization model performs statement content optimization on the statement risk type and the statement detection sub-data to obtain candidate statement optimization data, including:
[0025] Obtaining an optimization rule knowledge base associated with the structured statement optimization agent;
[0026] Selecting and determining target optimization rule data from the optimization rule knowledge base based on the statement risk type;
[0027] Sentence content optimization is performed based on the target optimization rule data and the sentence detection sub-data to obtain the candidate sentence optimization data.
[0028] In some embodiments, the structured statement verification agent based on the statement optimization model performs statement execution verification on the candidate structured statement to obtain a statement execution score, including:
[0029] Acquire candidate sentence query data of the candidate structured sentence, and acquire target sentence query data of the target structured sentence content;
[0030] Query data matching is performed based on the candidate sentence query data and the target sentence query data to determine the sentence execution score.
[0031] In some embodiments, the sentence adjustment of the candidate structured sentence based on the sentence execution score to obtain a target optimized structured sentence includes:
[0032] Comparing the statement execution score with a preset execution score to obtain a score comparison result;
[0033] Determining a statement execution state of the candidate structured statement based on the score comparison result;
[0034] If the statement execution status is an accurate status, obtaining candidate resource consumption data of the candidate structured statement, wherein the accurate status is used to indicate that the same amount of data in the candidate statement query data and the target statement query data is greater than or equal to a preset amount of data corresponding to the preset execution score;
[0035] If the candidate resource consumption data is greater than a preset optimization consumption threshold, the candidate structured statement is split to obtain a split structured statement;
[0036] Obtaining the split resource consumption data of the split structured statement;
[0037] If the resource consumption data after the split is less than or equal to the preset optimization consumption threshold, the structured statement after the split is used as the target optimized structured statement.
[0038] In some embodiments, the step of performing statement adjustment on the candidate structured statement based on the statement execution score to obtain a target optimized structured statement further includes:
[0039] If the statement execution state is an inaccurate state, adjusting parameters of the structured statement detection agent to obtain an adjusted structured statement detection agent, wherein the inaccurate state is used to indicate that the amount of identical data in the candidate statement query data and the target statement query data is less than a preset amount of data corresponding to the preset execution score;
[0040] Based on the adjusted structured sentence detection agent, the target structured script file is subjected to sentence content detection to obtain adjusted sentence detection data, wherein the adjusted sentence detection data includes adjusted sentence detection sub-data of the target structured sentence content;
[0041] determining an adjusted statement risk type of the target structured statement content based on the adjusted statement detection sub-data;
[0042] Based on the structured statement optimization agent, the adjusted statement risk type and the adjusted statement detection sub-data are optimized for statement content to obtain candidate adjusted statement optimization data, wherein the candidate adjusted statement optimization data includes a candidate adjusted optimized explanation text and a candidate adjusted structured statement, wherein the candidate adjusted optimized explanation text is used to indicate the difference between the candidate adjusted structured statement and the target structured statement content;
[0043] Based on the structured statement verification agent, the candidate adjusted structured statement is verified for statement execution to obtain an adjusted statement execution score, wherein the adjusted statement execution score is used to indicate the accuracy of execution of the candidate adjusted structured statement;
[0044] The candidate adjusted structured statement is adjusted based on the adjusted statement execution score to obtain the target optimized structured statement.
[0045] To achieve the above-mentioned purpose, a second aspect of an embodiment of the present application proposes a structured query statement optimization device, the device comprising:
[0046] An acquisition module, used for acquiring a target structured script file, wherein the target structured script file includes target structured statement content;
[0047] A detection module, configured to perform sentence content detection on the target structured script file based on a structured sentence detection agent of a sentence optimization model to obtain sentence detection data, wherein the sentence detection data includes sentence detection sub-data of the target structured sentence content;
[0048] A determination module, configured to determine a statement risk type of the target structured statement content based on the statement detection sub-data;
[0049] An optimization module, configured to optimize the sentence content of the sentence risk type and the sentence detection sub-data based on the structured sentence optimization agent of the sentence optimization model to obtain candidate sentence optimization data, wherein the candidate sentence optimization data includes a candidate optimization interpretation text and a candidate structured sentence, wherein the candidate optimization interpretation text is used to indicate the difference between the candidate structured sentence and the target structured sentence content;
[0050] A verification module, configured to perform statement execution verification on the candidate structured statement based on the structured statement verification agent of the statement optimization model to obtain a statement execution score, wherein the statement execution score is used to indicate the accuracy of execution of the candidate structured statement;
[0051] A statement adjustment module, configured to adjust the candidate structured statements based on the statement execution score to obtain a target optimized structured statement;
[0052] The text adjustment module is used to adjust the explanation text of the candidate optimization explanation text based on the target optimization structured sentence to obtain the target optimization explanation text.
[0053] To achieve the above objectives, a third aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the method described in the first aspect is implemented.
[0054] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application proposes a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in the first aspect is implemented.
[0055] The present application proposes a structured query statement optimization method and device, electronic device, and storage medium, which obtain a target structured script file, wherein the target structured script file includes target structured sentence content; a structured sentence detection agent based on a sentence optimization model performs sentence content detection on the target structured script file to obtain sentence detection data, wherein the sentence detection data includes sentence detection sub-data of the target structured sentence content; further, based on the sentence detection sub-data, a sentence risk type of the target structured sentence content is determined; and based on the sentence detection sub-data, a structured sentence optimization agent based on the sentence optimization model performs sentence content optimization on the sentence risk type and the sentence detection sub-data to obtain a candidate sentence. Sentence optimization data, the candidate sentence optimization data includes candidate optimization interpretation text and candidate structured sentences, the candidate optimization interpretation text is used to indicate the difference between the candidate structured sentence and the target structured sentence content; further, the structured sentence verification agent based on the sentence optimization model performs sentence execution verification on the candidate structured sentence to obtain a sentence execution score, and the sentence execution score is used to indicate the accuracy of the execution of the candidate structured sentence; further, the candidate structured sentence is adjusted based on the sentence execution score to obtain the target optimized structured sentence; and the candidate optimized interpretation text is adjusted based on the target optimized structured sentence to obtain the target optimized interpretation text. Compared with the related art that needs to trigger the script execution first and then analyze the script results, the present application can adopt a combination of different types of large model agents, and the target structured script file is continuously detected, optimized, verified and adjusted by different types of agents, which can effectively improve the flexibility of structured query statements. And through this continuous detection and optimization, the optimization accuracy and efficiency of structured query statements can be better improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] Figure 1 It is a flow chart of the structured query statement optimization method provided by the embodiment of the present application;
[0057] Figure 2 It is a schematic diagram of a framework of an optimization tool constructed based on a structured query statement optimization method provided in an embodiment of the present application;
[0058] Figure 3 yes Figure 1 A flowchart of step S120 in FIG.
[0059] Figure 4 yes Figure 3 A flowchart of step S340 in FIG.
[0060] Figure 5 yes Figure 1 A flowchart of step S140 in FIG.
[0061] Figure 6 yes Figure 1 A flowchart of step S150 in FIG.
[0062] Figure 7 yes Figure 1 A flowchart of step S160 in FIG.
[0063] Figure 8 yes Figure 1 Another flowchart of step S160 in FIG. 1 ;
[0064] Fig. 9 It is a specific flow chart of the structured query statement optimization provided by the embodiment of the present application;
[0065] Fig.10 It is a structural schematic diagram of a structured query statement optimization device provided in an embodiment of the present application;
[0066] Fig.11 It is a hardware structure diagram of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION
[0067] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0068] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0069] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0070] First, some nouns involved in this application are analyzed:
[0071] Artificial Intelligence (AI): It is a new technical science that studies and develops theories, methods, technologies and application systems for simulating, extending and expanding human intelligence. AI is a branch of computer science. AI attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Research in this field includes robots, language recognition, image recognition, natural language processing and expert systems. AI can simulate the information process of human consciousness and thinking. AI is also a theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0072] Structured Query Language (SQL) is a standard programming language used to manage and operate relational database management systems (RDBMS). SQL can be used to perform various database operations, including querying, inserting, updating, and managing data. SQL is widely used in various database systems, such as MySQL, PostgreSQL, Oracle, SQL Server, and SQLite.
[0073] Relational Database Management System (RDBMS): A database management system that organizes data by using a relational model (i.e., a two-dimensional table model). Data in a relational model is stored in the form of tables, and each table consists of rows (records) and columns (fields).
[0074] Agent: refers to an entity that can perceive the environment and make decisions to achieve a specific goal. In computer science, an agent can be a software program or system that can autonomously perform tasks such as searching for information, detecting system status, or interacting with users, that is, it can make adaptive responses according to environmental changes. In the field of artificial intelligence, an agent refers to a system that can simulate human intelligent behavior, such as a chatbot, recommendation system, or self-driving car, that is, it can understand input, learn patterns, and make decisions based on them.
[0075] SQL script files are text files containing SQL statements, which are mainly used to interact with the database and automate complex database operations. SQL script files can be used for tasks such as creating databases and tables, inserting and updating data, and generating reports. SQL script files can be executed through command line tools or the command line interface of the database management system, providing automation, portability, version control, and documentation.
[0076] Structured Query Language (SQL) statement optimization refers to the process of using technical means to improve the execution efficiency of SQL statement queries, reduce query response time, and improve overall database performance. For example, in the claims scenario of financial technology, by setting SQL statement optimization methods in the claims system, the SQL statements generated during user operations can be optimized to improve data query efficiency. However, high-risk SQL statements are prone to system security issues such as data leakage, data corruption, and system performance degradation. Therefore, optimizing high-risk SQL statements is a way to improve the security and stability of related systems.
[0077] The related technology for the optimization process of SQL statements usually first captures log information, obtains the execution script of the SQL statement from the log information, and compares the execution plan of the analyzed SQL statement with the pre-set high-risk SQL rules based on the execution script. If they match, an alarm message is issued and the developer is asked to perform manual optimization. However, this method has certain lag and passivity. The system needs to trigger the script execution of the SQL statement first, and then analyze the script execution results of the SQL statement in the log through relevant analysis tools. Because this method does not establish a connection with the database, the analysis tool cannot provide reasonable optimization suggestions, thereby reducing the optimization accuracy of the SQL statement and the statement optimization efficiency. Therefore, how to propose a method that can improve the optimization accuracy and efficiency of structured query statements has become a technical problem that needs to be solved urgently.
[0078] Based on this, the embodiments of the present application provide a structured query statement optimization method and device, an electronic device, and a storage medium, which can improve the optimization accuracy and efficiency of structured query statements.
[0079] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0080] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0081] The structured query statement optimization method provided in the embodiment of the present application relates to the field of artificial intelligence technology. The structured query statement optimization method provided in the embodiment of the present application can be applied to the terminal, can also be applied to the server side, and can also be software running in the terminal or the server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or it can be configured as a server cluster or a distributed system composed of multiple physical servers, and can also be configured as a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the structured query statement optimization method, etc., but is not limited to the above forms.
[0082] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0083] It should be noted that in each specific implementation of the present application, when it comes to the need to perform relevant processing on data related to the identity or characteristics of the object, such as queries and statement executions based on database tables constructed based on object information, the permission or consent of the object will be obtained first, and the collection, use and processing of these data will comply with relevant laws, regulations and standards. In addition, when the embodiment of the present application needs to obtain sensitive personal information of the object, the separate permission or separate consent of the object will be obtained through a pop-up window or by jumping to a confirmation page. After clearly obtaining the separate permission or separate consent of the object, the necessary user-related data for the normal operation of the embodiment of the present application will be obtained.
[0084] See also Figure 1 , Figure 1 is an optional flow chart of the structured query statement optimization method provided in the embodiment of the present application. In some embodiments of the present application, Figure 1 The method may specifically include but is not limited to steps S110 to S170.
[0085] Step S110, obtaining a target structured script file;
[0086] Step S120, the structured sentence detection agent based on the sentence optimization model performs sentence content detection on the target structured script file to obtain sentence detection data;
[0087] Step S130, determining the sentence risk type of the target structured sentence content based on the sentence detection sub-data;
[0088] Step S140, the structured sentence optimization agent based on the sentence optimization model performs sentence content optimization on the sentence risk type and sentence detection sub-data to obtain candidate sentence optimization data;
[0089] Step S150, the structured statement verification agent based on the statement optimization model performs statement execution verification on the candidate structured statement to obtain a statement execution score;
[0090] Step S160, adjusting the candidate structured statements based on the statement execution score to obtain a target optimized structured statement;
[0091] Step S170, adjusting the explanation text of the candidate optimized explanation text based on the target optimized structured sentence to obtain the target optimized explanation text.
[0092] In step S110 of some embodiments, the structured query statement optimization method of the present application can be packaged into a plug-in tool, which can be connected to the database system for optimizing the code statements in the database system. The plug-in tool may include the statement optimization model of the present application, and the specific structure of the statement optimization model will be described in detail in the subsequent embodiments. The structured query statement optimization method of the present application can also be packaged into an independent tool for users to ask statement questions, so as to facilitate the generation of optimized statements that meet user needs. For example, when the SQL script has been developed, the user sends the SQL to the page window of the tool and can ask how it can be optimized; when the SQL has not been developed, the user can use the tool to ask for development suggestions for the SQL script and how to encode the script for optimal performance.
[0093] It should be noted that the target structured script file includes the target structured statement content, which is used to represent information related to the target structured statement, that is, the specific content of the script file. The target structured statement content can be a specific statement or a description of the execution effect of the statement. The target structured statement can be a code, query or other form of instruction.
[0094] It should be noted that after the database system is connected to the tool, it can automatically obtain the database connected to the system to obtain table data, structure, index and other information for subsequent statement content detection. At the same time, the tool can scan the system code library to obtain the target structured script file, such as SQL script file.
[0095] In the above embodiments, compared to the related technologies that involve no tools and need to be coupled into the system to be used, the structured query statement optimization method mentioned in this application can exist independently in the form of a tool, so that it can be used alone and connected to the system, thereby improving the flexibility of structured query statements. Specifically, it can be applied to insurance policy issuance systems, standard verification tools, claims settlement systems, etc., and asynchronous detection is performed during the system development process and in the code base to detect whether there is a high-risk SQL that affects the system. In addition, this application can also support SQL technical knowledge questions and answers, and automatically generate the SQL required by the user or similar case scenarios based on the scenarios and needs entered by the user.
[0096] In step S120 of some embodiments, the statement detection data includes statement detection sub-data of the target structured statement content, and the statement detection sub-data may include analysis of information such as the script file content, execution plan, system consumption and time consumption of the target structured statement content. The statement optimization model of the present application is used to detect and optimize the input target structured script file to output the detection results and optimization plan. The statement optimization model of the present application can be constructed based on the agent of the large model, and specifically can include a structured statement detection agent, a structured statement optimization agent and a structured statement verification agent.
[0097] It should be noted that the present application uses a structured statement detection agent to perform statement content detection on the target structured statement content (such as multiple SQL statements) in the target structured script file to determine whether these statements contain high-risk SQL. The statement detection sub-data is used to characterize the analysis results of each statement.
[0098] Please note that Figure 2 , Figure 2It is a framework diagram of an optimization tool based on a structured query statement optimization method provided by an embodiment of the present application. Among them, the overall framework of the high-risk SQL detection and optimization tool based on a large model provided by the present application may specifically include an application layer, a service layer, a data layer, and a basic model layer. The application layer refers to the structure in which the tool interacts with the user. Because the optimization tool based on the structured query statement optimization method provided by the present application can be used as an independent Agent, it interacts with the user in the form of a question and answer by accessing a Web page, and the user sends the SQL script that needs to be analyzed and optimized, and the Agent generates the problems and optimization suggestions of the script online. At the same time, the tool can be accessed into the system as a plug-in, and the problems existing in the SQL script code in the system are analyzed offline and the optimization suggestions are output, and the person in charge of the system is notified. The service layer mainly includes a structured statement detection agent (i.e., a high-risk SQL detection agent), a structured statement optimization agent (i.e., a high-risk SQL optimization agent), and a structured statement verification agent (i.e., an SQL accuracy verification agent, used to detect the accuracy of the optimization suggestion). At the same time, the optimization tool also includes a database connection tool, a semantic structure rule knowledge base (i.e., a high-risk SQL rule knowledge base) and an optimization rule knowledge base (i.e., a SQL optimization professional knowledge base). The database connection tool is used to connect to the system database to read the table structure and index and other related information in the database, the semantic structure rule knowledge base is used to assist the high-risk SQL detection agent to improve its accuracy; the optimization rule knowledge base is used to assist the SQL accuracy verification agent to improve its accuracy, etc. The data layer mainly includes the databases connected to the system, including Mysql, Oracle, PgSql and other databases, as well as the file scripts and code libraries that need to be analyzed. The basic model layer mainly includes the current large model framework (such as LangChain), and can integrate a variety of current mainstream large models, such as ChatGLM, QianWen-72B, Vicuna-13B, Fauxpilot, etc., without specific limitation.
[0099] See also Figure 3 , Figure 3 It is a specific flow chart of step S120 provided in an embodiment of the present application. In some embodiments of the present application, step S120 may specifically include but is not limited to steps S310 to S340.
[0100] Step S310, obtaining pre-configured database structure data;
[0101] Step S320, constructing a virtual database based on the database structure data;
[0102] Step S330, obtaining statement execution plan information of the target structured script file based on the virtual database;
[0103] Step S340, based on the structured statement detection agent, the target structured script file and statement execution plan information are analyzed for statement content to obtain statement detection data.
[0104] In step S310 and step S320 of some embodiments, after obtaining the target structured script file, the present application can build a virtual database based on pre-configured database structure data for executing the target structured script file. The database structure data may include database architecture information, such as table structure, index, view, stored procedure, etc., which is the basis for building a virtual database. This virtual database is used to simulate real database operations without the need for actual data. The virtual database allows query optimization, performance testing, and script debugging without affecting the production environment.
[0105] In step S330 of some embodiments, in the virtual database environment, the SQL statements in the target structured script file can be executed, and the statement execution plan information of these statements can be obtained. The statement execution plan information includes the execution path of the SQL statement, the index used, the estimated execution time and resource consumption, etc., which is important for analyzing and optimizing the performance of the SQL statement.
[0106] In step S340 of some embodiments, further, the target structured script file and statement execution plan information can be analyzed based on the structured statement detection agent, that is, the statements in the target structured script file and the statement execution plan information of these statements in the virtual database are analyzed. And this structured statement detection agent can analyze the logic, performance and potential problems of the statement, and generate statement detection data, and the statement detection data can include potential errors, performance bottlenecks, optimization suggestions, etc. of the statement.
[0107] In the above embodiments, the present application can discover and solve possible problems in structured script files in advance through simulation execution and analysis without affecting the actual database, thereby improving the execution efficiency and stability of the script. In this way, SQL statements can be optimized in the development stage to reduce the risk of problems in the production environment.
[0108] See also Figure 4 , Figure 4 It is a specific flow chart of step S340 provided in an embodiment of the present application. In some embodiments of the present application, step S340 may specifically include but is not limited to steps S410 to S450.
[0109] Step S410, obtaining a semantic structure rule knowledge base associated with the structured sentence detection agent;
[0110] Step S420, based on the semantic structure rule knowledge base, performing sentence semantic structure analysis on the target structured sentence content to obtain semantic structure analysis data;
[0111] Step S430, performing execution plan analysis on the statement execution plan information to obtain statement execution analysis data;
[0112] Step S440, integrating the semantic structure analysis data and the sentence execution analysis data to obtain sentence detection sub-data of the target structured sentence content;
[0113] Step S450: merge the sentence detection sub-data to obtain sentence detection data.
[0114] In step S410 of some embodiments, when the present application uses the structured sentence detection agent to perform sentence content analysis, it can combine the pre-set semantic structure rule knowledge base to perform sentence semantic structure analysis. Among them, the semantic structure rule knowledge base pre-stores a series of semantic structure rules, which define how the sentence should be constructed and the meaning of each construction method. The semantic structure rule knowledge base can be associated with the structured sentence detection agent to facilitate the flexible call of the agent.
[0115] In step S420 of some embodiments, the semantic structure analysis data is used to characterize the matching of the target structured sentence content with the semantic structure rules preset in the semantic structure rule knowledge base. That is, the structured sentence detection agent of the present application can use the semantic structure rule knowledge base to analyze the target structured sentence content to determine whether the sentence conforms to the preset semantic structure rules, and generate semantic structure analysis data, which can characterize the matching of the target structured sentence content with the semantic structure rules preset in the knowledge base.
[0116] In step S430 of some embodiments, the obtained statement execution plan information can be further analyzed in depth, that is, the execution logic and performance of the statements and how these statements affect the operation of the database are understood to generate statement execution analysis data, which can provide information about statement execution efficiency and potential problems.
[0117] In step S440 and step S450 of some embodiments, the semantic structure analysis data and the statement execution analysis data may be further integrated to obtain statement detection sub-data of the target structured statement content, so that a comprehensive perspective can be provided to the subsequent intelligent agent, while considering the semantic correctness and execution efficiency of the statement, thereby generating more accurate statement detection sub-data. In addition, the structured statement detection intelligent agent further merges the obtained multiple statement detection sub-data to aggregate the scattered sub-data into a complete statement detection data for evaluating the overall quality and performance of the statements in the target structured script file.
[0118] In step S130 of some embodiments, the sentence risk type is used to indicate the risk level of the target structured sentence content, so as to serve as an optimization direction prompt for the subsequent structured sentence optimization agent to improve the accuracy of sentence content optimization. The sentence risk type can indicate the type of problem with a higher risk level in the target structured sentence content, such as grammatical errors, logical errors, performance issues, etc.
[0119] In step S140 of some embodiments, after determining the statement risk type, the statement content can be optimized based on the statement risk type and the statement detection sub-data by the structured statement optimization agent of the statement optimization model to obtain candidate statement optimization data. The candidate statement optimization data is equivalent to the content optimization scheme for the target structured script file, and can include candidate optimization interpretation text and candidate structured statements, and the candidate optimization interpretation text is used to indicate the difference between the candidate structured statement and the target structured statement content. It is understandable that the candidate optimization interpretation text is used to indicate the specific details of the target structured statement content that can be optimized, and the candidate structured statement is equivalent to a reference statement.
[0120] For example, the target structured statement content is "select*from agent_a where blike concat(1,'%')", the corresponding statement detection sub-data is "detection found that b has an index but the index is not used", and the statement risk type is a logical error. After the structured statement optimization agent, the output candidate optimization explanation text is "specify the index type when indexing b", and the candidate structured statement "select*from agent_a where b like'1'||'%'" gives a sql script modification suggestion.
[0121] It should be noted that the output candidate sentence optimization data may include only candidate optimization interpretation texts, or may include both candidate optimization interpretation texts and candidate structured sentences, without specific limitation.
[0122] See also Figure 5 , Figure 5It is a specific flow chart of step S140 provided in an embodiment of the present application. In some embodiments of the present application, step S140 may specifically include but is not limited to steps S510 to S530.
[0123] Step S510, obtaining an optimization rule knowledge base associated with a structured statement optimization agent;
[0124] Step S520, selecting and determining target optimization rule data from an optimization rule knowledge base based on the statement risk type;
[0125] Step S530, optimizing the sentence content based on the target optimization rule data and the sentence detection sub-data to obtain candidate sentence optimization data.
[0126] In step S510 of some embodiments, when the present application uses a structured statement optimization agent to optimize the statement content, it can combine a pre-set optimization rule knowledge base to perform statement optimization analysis. The optimization rule knowledge base can pre-store basic SQL development language concepts, code refactoring, query optimization, logic simplification guidelines, SQL development application templates for a variety of different scenarios, etc. The optimization rule knowledge base is not just a knowledge base in the form of questions and answers, but also includes the performance consumption and usage scenarios of each SQL syntax, as well as SQL scenario applications, SQL development suggestions and optimization suggestions for each scenario, and also distinguishes between data volumes, that is, SQL usage suggestions and optimization suggestions for different data volumes are inconsistent.
[0127] It should be noted that the construction of the optimization rule knowledge base may include: (1) basic knowledge in the form of structured QA, including grammar, basic concepts, usage scenario suggestions, etc.; (2) SQL development suggestions in various scenarios; (3) SQL optimization suggestion knowledge base (i.e., optimization rule knowledge base) with grammar and scenario as dimensions; (4) SQL optimization knowledge base (i.e., optimization rule knowledge base) with user feedback. In addition, the above data can be stored in the database and file system as structured and unstructured data respectively.
[0128] In step S520 of some embodiments, further, the present application may select corresponding optimization rules from the optimization rule knowledge base based on the determined statement risk type, that is, match the most suitable target optimization rule data to solve a specific type of risk or problem.
[0129] In step S530 of some embodiments, statement content optimization is further performed based on the target optimization rule data and statement detection sub-data, that is, the original statement content can be modified and adjusted according to the target optimization rule data to improve its performance, readability or maintainability, and candidate statement optimization data is obtained. At this time, the candidate statement optimization data represents the optimized statement version, and further evaluation and testing are required to determine whether to accept these optimization changes.
[0130] In step S150 of some embodiments, further, since the given candidate sentence optimization data may not necessarily achieve the preset optimization effect, based on this, the present application can also perform sentence execution verification on the candidate structured sentence through the structured sentence verification agent of the sentence optimization model to determine the accuracy and validity of the sentence. The verification result can be a sentence execution score, which is used to indicate the accuracy of the execution of the candidate structured sentence.
[0131] It should be noted that the statement execution verification of the present application may include simulating execution, testing or analyzing the execution logic of the statement to determine the accuracy and validity of the statement.
[0132] It should be noted that the structured sentence detection agent of the present application is used to output detection results, the structured sentence optimization agent is mainly used to output optimization solutions, and the structured sentence verification agent is used to output verification results. Each Agent supports dynamic expansion of the scenarios it supports, and also supports dynamic increase of its knowledge base to enhance its professional capabilities.
[0133] See also Figure 6 , Figure 6 It is a specific flow chart of step S150 provided in an embodiment of the present application. In some embodiments of the present application, step S150 may specifically include but is not limited to steps S610 to S620.
[0134] Step S610, obtaining candidate sentence query data of the candidate structured sentence, and obtaining target sentence query data of the target structured sentence content;
[0135] Step S620: performing query data matching based on the candidate statement query data and the target statement query data to determine a statement execution score.
[0136] In step S610 and step S620 of some embodiments, the candidate statement query data refers to the data results that can be obtained by querying data in the virtual database based on the candidate structured statement, and the target statement query data refers to the data results that can be obtained by querying data in the virtual database based on the target structured statement content. The statement execution score determined in this application is used to evaluate the accuracy of the output script, that is, it can be judged based on the query data results. For example, the statement execution score is the data matching percentage of the candidate statement query data and the target statement query data. If the consistency of the total amount of data and the data content queried by the candidate statement query data and the target statement query data is high, the corresponding statement execution score is high.
[0137] It should be noted that, in general, there will be no errors in the queried data, that is, the total amount of data and the data content of the candidate statement query data and the target statement query data are highly consistent. However, because the optimization involves the modification of the query conditions, it is possible to change the order or scope of the query, resulting in the SQL script being optimized but the query result is not what you want. Based on this, you can further judge whether the optimized candidate structured statement can achieve the optimization effect based on the statement execution score.
[0138] In step S160 of some embodiments, the present application may further perform statement adjustments on candidate structured statements based on statement execution scores to obtain target optimized structured statements with more accurate optimization and better optimization effects.
[0139] See also Figure 7 , Figure 7 It is a specific flow chart of step S160 provided in an embodiment of the present application. In some embodiments of the present application, step S150 may specifically include but is not limited to steps S710 to S760.
[0140] Step S710, comparing the statement execution score with the preset execution score to obtain a score comparison result;
[0141] Step S720, determining the statement execution status of the candidate structured statement based on the score comparison result;
[0142] Step S730, if the statement execution state is an accurate state, obtaining candidate resource consumption data of the candidate structured statement;
[0143] Step S740: if the candidate resource consumption data is greater than a preset optimization consumption threshold, the candidate structured statement is split to obtain a split structured statement;
[0144] Step S750, obtaining the split resource consumption data of the split structured statement;
[0145] Step S760: If the resource consumption data after the split is less than or equal to the preset optimization consumption threshold, the structured statement after the split is used as the target optimized structured statement.
[0146] In step S710 and step S720 of some embodiments, the present application may first compare the statement execution score of the candidate structured statement with a preset execution score (equivalent to a reference standard score) to evaluate whether the performance of the candidate statement has reached the expected standard. If the score comparison result indicates that the statement execution score is greater than or equal to the preset execution score, it can be determined that the statement execution state is an accurate state, and the accurate state is used to indicate that the same amount of data in the candidate statement query data and the target statement query data is greater than or equal to the preset amount of data corresponding to the preset execution score, that is, the accuracy requirement of the statement can be met.
[0147] In step S730 of some embodiments, if the statement execution state is an accurate state, the candidate resource consumption data of the candidate structured statement is obtained. The candidate resource consumption data can characterize the resources consumed by executing the candidate structured statement, that is, it can include CPU time, memory usage, disk I / O, etc., so as to determine whether the candidate structured statement has achieved the optimization effect. In other words, the obtained target optimized structured statement has better execution performance and lower resource consumption than the original target structured statement content.
[0148] In step S740 of some embodiments, if the candidate resource consumption data is greater than a preset optimization consumption threshold, that is, the currently optimized candidate structured statement does not achieve the preset optimization effect, the present application can perform statement splitting on the candidate structured statement to obtain multiple split structured statements. The purpose of splitting is to reduce the resource consumption of a single statement, that is, a complex query can be decomposed into multiple simple queries to improve the optimization efficiency.
[0149] In step S750 and step S760 of some embodiments, further, the post-splitting resource consumption data of each split structured statement can be obtained, and based on the comparison between the post-splitting resource consumption data and the preset optimization consumption threshold, it is judged whether the split statement achieves the preset optimization effect. The post-splitting resource consumption data can characterize the resources required to execute multiple split structured statements, wherein, if the post-splitting resource consumption data is less than or equal to the preset optimization consumption threshold, it means that the split statement can achieve the preset optimization effect while meeting the performance standard, then multiple split structured statements can be used as target optimized structured statements. If the post-splitting resource consumption data is still greater than the preset optimization consumption threshold, the user can be advised to perform library and table sharding operations, and output the library sharding distribution plan, or build a partition table, or adjust the model parameters of the structured statement optimization agent, etc., without specific limitation.
[0150] It should be noted that there may be multiple reasons why the optimized statement does not achieve the preset optimization effect: (1) The detection result of the structured statement detection agent may be inaccurate. In this case, the agent should be optimized to output accurate detection results, which will be transmitted to the structured statement optimization agent and output optimization suggestions; the semantic structure rule knowledge base or the optimization rule knowledge base does not involve the scene corresponding to the statement, so the background real-time detection is required to update and supplement the detection data and optimization data of the missing scene; (3) The content of the target structured statement is complex, which may be a complex scene. That is, the target structured statement content or the optimized statement can be split and optimized through Java, C, Python and other code assistance, and the split SQL script is output; (4) The data volume is huge. At this time, no matter how to optimize, the database performance consumption is very high. It can be recommended that users perform database and table sharding operations and output the database sharding distribution plan, or create partition tables, etc.; (5) The output results of the statement optimization model itself are too general or inaccurate. In this case, replace the latest large model and adjust the temperature parameter of the large model to make its output more accurate.
[0151] See also Figure 8 , Figure 8 It is another specific flow chart of step S160 provided in an embodiment of the present application. In some embodiments of the present application, after step S720, step S160 may also include but not limited to steps S810 to S860.
[0152] Step S810, if the statement execution state is an inaccurate state, adjusting the parameters of the structured statement detection agent to obtain an adjusted structured statement detection agent;
[0153] Step S820, based on the adjusted structured sentence detection agent, the target structured script file is subjected to sentence content detection to obtain adjusted sentence detection data;
[0154] Step S830, determining the adjusted statement risk type of the target structured statement content based on the adjusted statement detection sub-data;
[0155] Step S840, based on the structured sentence optimization agent, sentence content optimization is performed on the adjusted sentence risk type and the adjusted sentence detection sub-data to obtain candidate adjusted sentence optimization data;
[0156] Step S850, performing statement execution verification on the candidate adjusted structured statement based on the structured statement verification agent to obtain an adjusted statement execution score;
[0157] Step S860: perform statement adjustment on the candidate adjusted structured statement based on the adjusted statement execution score to obtain a target optimized structured statement.
[0158] In step S810 of some embodiments, if the statement execution status is an inaccurate state, the present application can adjust the parameters of the structured statement detection agent to obtain an adjusted structured statement detection agent, and the inaccurate state is used to indicate that the same amount of data in the candidate statement query data and the target statement query data is less than the preset data amount corresponding to the preset execution score.
[0159] In steps S820 to S860 of some embodiments, the adjusted statement detection data includes the adjusted statement detection sub-data of the target structured statement content, and the specific process of step S820 performing statement content detection on the target structured script file can be referred to in the above step S120, the specific process of step S830 can be referred to in the above step S130, the specific process of step S840 can be referred to in the above step S140, the specific process of step S850 can be referred to in the above step S150, and the specific process of step S860 can be referred to in the above step S160, only the input and output data are changed, which will not be repeated here. Among them, the candidate adjusted statement optimization data includes the candidate adjusted optimized interpretation text and the candidate adjusted structured statement, and the candidate adjusted optimized interpretation text is used to indicate the difference between the candidate adjusted structured statement and the target structured statement content.
[0160] In step S170 of some embodiments, after determining the target optimized structured statement, the present application can simultaneously adjust the explanation text of the candidate optimized explanation text output by the structured statement optimization agent to obtain the target optimized explanation text, so as to ensure that the target optimized explanation text can accurately reflect the difference between the optimized target optimized structured statement and the original target structured statement content.
[0161] See also Fig. 9 , Fig. 9 It is a specific flow chart of the structured query statement optimization provided by the embodiment of the present application. In some embodiments of the present application, the specific execution process of the structured query statement optimization may include but is not limited to steps S910 to S960.
[0162] Step S910, obtaining the target structured script file to be analyzed.
[0163] Among them, when obtaining the target structured script file, the code library, database, etc. can be combined.
[0164] Step S920: Use the structured sentence detection agent to perform sentence content detection on the target structured script file, and determine the sentence risk type of the target structured sentence content based on the sentence detection sub-data.
[0165] Among them, the structured sentence detection agent can combine the semantic structure rule knowledge base associated with it when performing sentence content detection.
[0166] Step S930, use the structured statement optimization agent to optimize the statement content of the statement risk type and statement detection sub-data to obtain a statement optimization solution.
[0167] The sentence optimization scheme is equivalent to the candidate sentence optimization data, including the candidate optimization interpretation text and the candidate structured sentence. In addition, when the structured sentence optimization agent optimizes the sentence content, it combines the optimization rule knowledge base associated with it.
[0168] Step S940, perform statement execution verification on the candidate structured statements based on the structured statement verification agent. If the verification result indicates that the data obtained after the execution of the current candidate structured statement and the data obtained after the execution of the original statement can meet the preset execution status requirements, that is, the statement execution status is an accurate state, execute step S950, otherwise, re-execute step S930.
[0169] The verification result is a statement execution status determined based on the statement execution score. If the statement execution status is accurate, step S950 is executed. If the statement execution status is inaccurate, step S930 is re-executed.
[0170] Step S950, determining whether the candidate structured statement whose statement execution status is accurate has achieved the optimization effect, if so, executing step S960, if not, re-executing step S920.
[0171] The process of determining whether the statement has achieved the optimization effect may refer to the above steps S730 to S760, which will not be described in detail here.
[0172] Step S960, output the detection results and optimization plan.
[0173] The optimization plan includes target optimization structured statements and target optimization explanation texts, and the detection results are used to indicate problems existing in the original target structured script file.
[0174] It should be noted that the non-Company software tools or components appearing in the embodiments of the present application are merely examples and do not represent actual use.
[0175] The structured query statement optimization method provided in the embodiment of the present application, by connecting the code base and the database, actively obtains the script file that needs to be analyzed, and analyzes the input script file in combination with the semantic structure rule knowledge base of high-risk SQL and the structured statement detection agent, so that the analysis result is more efficient and accurate. In addition, compared with the related art that does not output the optimization plan or the output optimization plan has low accuracy, the present application can also combine the optimization rule knowledge base and the structured statement optimization agent, and output the optimization suggestion according to the detection result. In addition, the SQL script corresponding to the optimization suggestion can be simulated and executed, and then the original script is analyzed to determine whether the optimization suggestion is effective and improve its own accuracy. Therefore, the present application can effectively improve the flexibility of the structured query statement. And the optimization accuracy and efficiency of the structured query statement can be better improved by continuously detecting and optimizing the agent and the statement.
[0176] See also Fig.10 The embodiment of the present application also provides a structured query statement optimization device, which can implement the above structured query statement optimization method, and the device includes:
[0177] An acquisition module 1010 is used to acquire a target structured script file, where the target structured script file includes target structured statement content;
[0178] A detection module 1020 is used to perform sentence content detection on a target structured script file based on a structured sentence detection agent of a sentence optimization model to obtain sentence detection data, wherein the sentence detection data includes sentence detection sub-data of the target structured sentence content;
[0179] A determination module 1030, configured to determine a sentence risk type of a target structured sentence content based on the sentence detection sub-data;
[0180] An optimization module 1040 is used to optimize the sentence content of the sentence risk type and the sentence detection sub-data based on the structured sentence optimization agent of the sentence optimization model to obtain candidate sentence optimization data, wherein the candidate sentence optimization data includes a candidate optimization interpretation text and a candidate structured sentence, wherein the candidate optimization interpretation text is used to indicate the difference between the candidate structured sentence and the target structured sentence content;
[0181] Verification module 1050, used to perform statement execution verification on the candidate structured statement based on the structured statement verification agent of the statement optimization model to obtain a statement execution score, where the statement execution score is used to indicate the accuracy of the execution of the candidate structured statement;
[0182] A statement adjustment module 1060 is used to adjust the candidate structured statements based on the statement execution score to obtain a target optimized structured statement;
[0183] The text adjustment module 1070 is used to adjust the explanation text of the candidate optimization explanation text based on the target optimization structured sentence to obtain the target optimization explanation text.
[0184] The specific implementation of the structured query statement optimization device of the embodiment of the present application is basically the same as the specific implementation of the structured query statement optimization method described above, and will not be repeated here.
[0185] The embodiment of the present application also provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the above structured query statement optimization method when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.
[0186] See also Fig.11 , Fig.11 The hardware structure of an electronic device of another embodiment is illustrated, and the electronic device includes:
[0187] The processor 1110 may be implemented by a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;
[0188] The memory 1120 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 1120 can store an operating system and other application programs. When the technical solution provided in the embodiments of this specification is implemented by software or firmware, the relevant program code is stored in the memory 1120, and the processor 1110 calls and executes the structured query statement optimization method of the embodiment of the present application;
[0189] Input / output interface 1130, used to implement information input and output;
[0190] The communication interface 1140 is used to realize the communication interaction between the device and other devices. The communication can be realized through a wired manner (such as USB, network cable, etc.) or a wireless manner (such as mobile network, WIFI, Bluetooth, etc.);
[0191] bus 1150 , which transmits information between the various components of the device (e.g., processor 1110 , memory 1120 , input / output interface 1130 , and communication interface 1140 );
[0192] The processor 1110 , the memory 1120 , the input / output interface 1130 , and the communication interface 1140 are connected to each other in communication within the device via the bus 1150 .
[0193] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the above-mentioned structured query statement optimization method is implemented.
[0194] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0195] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0196] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.
[0197] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0198] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.
[0199] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, 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 "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0200] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0201] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0202] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0203] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0204] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.
[0205] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.
Claims
1. A structured query statement optimization method, characterized in that: The method comprises: Obtaining a target structured script file, wherein the target structured script file includes target structured statement content; The structured sentence detection agent based on the sentence optimization model performs sentence content detection on the target structured script file to obtain sentence detection data, wherein the sentence detection data includes sentence detection sub-data of the target structured sentence content; Determining a sentence risk type of the target structured sentence content based on the sentence detection sub-data; The structured sentence optimization agent based on the sentence optimization model performs sentence content optimization on the sentence risk type and the sentence detection sub-data to obtain candidate sentence optimization data, wherein the candidate sentence optimization data includes a candidate optimization interpretation text and a candidate structured sentence, wherein the candidate optimization interpretation text is used to indicate the difference between the candidate structured sentence and the target structured sentence content; The structured statement checking agent based on the statement optimization model performs statement execution checking on the candidate structured statement to obtain a statement execution score, wherein the statement execution score is used to indicate the accuracy of execution of the candidate structured statement; Performing statement adjustment on the candidate structured statement based on the statement execution score to obtain a target optimized structured statement; The candidate optimized interpretation text is adjusted based on the target optimized structured sentence to obtain the target optimized interpretation text.
2. The method according to claim 1, characterized in that The structured sentence detection agent based on the sentence optimization model performs sentence content detection on the target structured script file to obtain sentence detection data, including: Get pre-configured database structure data; Building a virtual database based on the database structure data; Acquire statement execution plan information of the target structured script file based on the virtual database; Based on the structured statement detection agent, statement content analysis is performed on the target structured script file and the statement execution plan information to obtain the statement detection data.
3. The method according to claim 2, characterized in that The structured statement detection agent performs statement content analysis on the target structured script file and the statement execution plan information to obtain the statement detection data, including: Acquire a semantic structure rule knowledge base associated with the structured sentence detection agent; Based on the semantic structure rule knowledge base, a sentence semantic structure analysis is performed on the target structured sentence content to obtain semantic structure analysis data, wherein the semantic structure analysis data is used to characterize the matching between the target structured sentence content and the semantic structure rules preset in the semantic structure rule knowledge base; Performing an execution plan analysis on the statement execution plan information to obtain statement execution analysis data; Performing data integration on the semantic structure analysis data and the sentence execution analysis data to obtain the sentence detection sub-data of the target structured sentence content; The sentence detection sub-data are merged to obtain the sentence detection data.
4. The method according to claim 1, characterized in that: The structured sentence optimization agent based on the sentence optimization model performs sentence content optimization on the sentence risk type and the sentence detection sub-data to obtain candidate sentence optimization data, including: Obtaining an optimization rule knowledge base associated with the structured statement optimization agent; Selecting and determining target optimization rule data from the optimization rule knowledge base based on the statement risk type; Sentence content optimization is performed based on the target optimization rule data and the sentence detection sub-data to obtain the candidate sentence optimization data.
5. The method according to any one of claims 1 to 4, characterized in that: The structured statement verification agent based on the statement optimization model performs statement execution verification on the candidate structured statement to obtain a statement execution score, including: Acquire candidate sentence query data of the candidate structured sentence, and acquire target sentence query data of the target structured sentence content; Query data matching is performed based on the candidate sentence query data and the target sentence query data to determine the sentence execution score.
6. The method according to claim 5, characterized in that The step of adjusting the candidate structured statements based on the statement execution score to obtain a target optimized structured statement includes: Comparing the statement execution score with a preset execution score to obtain a score comparison result; Determining a statement execution state of the candidate structured statement based on the score comparison result; If the statement execution status is an accurate status, obtaining candidate resource consumption data of the candidate structured statement, wherein the accurate status is used to indicate that the same amount of data in the candidate statement query data and the target statement query data is greater than or equal to a preset amount of data corresponding to the preset execution score; If the candidate resource consumption data is greater than a preset optimization consumption threshold, the candidate structured statement is split to obtain a split structured statement; Obtaining the split resource consumption data of the split structured statement; If the resource consumption data after the split is less than or equal to the preset optimization consumption threshold, the structured statement after the split is used as the target optimized structured statement.
7. The method according to claim 6, characterized in that The step of adjusting the candidate structured statements based on the statement execution score to obtain a target optimized structured statement further includes: If the statement execution state is an inaccurate state, adjusting parameters of the structured statement detection agent to obtain an adjusted structured statement detection agent, wherein the inaccurate state is used to indicate that the amount of identical data in the candidate statement query data and the target statement query data is less than a preset amount of data corresponding to the preset execution score; Based on the adjusted structured sentence detection agent, the target structured script file is subjected to sentence content detection to obtain adjusted sentence detection data, wherein the adjusted sentence detection data includes adjusted sentence detection sub-data of the target structured sentence content; determining an adjusted statement risk type of the target structured statement content based on the adjusted statement detection sub-data; Based on the structured statement optimization agent, the adjusted statement risk type and the adjusted statement detection sub-data are optimized for statement content to obtain candidate adjusted statement optimization data, wherein the candidate adjusted statement optimization data includes a candidate adjusted optimized explanation text and a candidate adjusted structured statement, wherein the candidate adjusted optimized explanation text is used to indicate the difference between the candidate adjusted structured statement and the target structured statement content; Based on the structured statement verification agent, the candidate adjusted structured statement is verified for statement execution to obtain an adjusted statement execution score, wherein the adjusted statement execution score is used to indicate the accuracy of execution of the candidate adjusted structured statement; The candidate adjusted structured statement is adjusted based on the adjusted statement execution score to obtain the target optimized structured statement.
8. A structured query statement optimization device, characterized in that: The device comprises: An acquisition module, used for acquiring a target structured script file, wherein the target structured script file includes target structured statement content; A detection module, configured to perform sentence content detection on the target structured script file based on a structured sentence detection agent of a sentence optimization model to obtain sentence detection data, wherein the sentence detection data includes sentence detection sub-data of the target structured sentence content; A determination module, configured to determine a statement risk type of the target structured statement content based on the statement detection sub-data; An optimization module, configured to optimize the sentence content of the sentence risk type and the sentence detection sub-data based on the structured sentence optimization agent of the sentence optimization model to obtain candidate sentence optimization data, wherein the candidate sentence optimization data includes a candidate optimization interpretation text and a candidate structured sentence, wherein the candidate optimization interpretation text is used to indicate the difference between the candidate structured sentence and the target structured sentence content; A verification module, configured to perform statement execution verification on the candidate structured statement based on the structured statement verification agent of the statement optimization model to obtain a statement execution score, wherein the statement execution score is used to indicate the accuracy of execution of the candidate structured statement; A statement adjustment module, configured to adjust the candidate structured statements based on the statement execution score to obtain a target optimized structured statement; The text adjustment module is used to adjust the explanation text of the candidate optimization explanation text based on the target optimization structured sentence to obtain the target optimization explanation text.
9. An electronic device, characterized in that: The electronic device comprises a memory and a processor, the memory stores a computer program, and the processor implements the method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Automatic optimization method and device for structured query statements, medium and electronic equipment
CN110716949A
Automatic method and system for realizing database SQL optimization execution based on artificial intelligence
CN113505141A
Data query strategy optimization method and device, terminal equipment and storage medium
CN117609288A
Intelligent SQL query generation method and system based on large language model
CN118861081A
Translation of natural language questions and requests to a structured query format
US20180095962A1