Structured query statement optimization method and device, electronic equipment and storage medium
Through the artificial intelligence-driven structured query statement optimization method, SQL statements are detected and optimized in real time, which solves the problems of optimization lag and inefficiency in existing technologies, achieves more efficient and accurate SQL statement optimization, and improves system security and stability.
Patent Information
- Application Number
- CN202411668303.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-20
- Publication Date
- 2025-10-10
- Estimated Expiration
- 2044-11-20
AI Technical Summary
Existing technologies are lagging and passive when optimizing structured query statements, and are unable to detect high-risk SQL statements in a timely manner, resulting in low optimization accuracy and efficiency.
An artificial intelligence-based structured query statement optimization method is adopted. By combining structured statement detection agents, optimization agents and verification agents, SQL statements can be detected and optimized in real time, including obtaining target structured script files, performing statement content detection, risk type determination, optimization and verification, and generating optimized explanation text and structured statements.
It improves the optimization accuracy and efficiency of structured query statements, can discover and solve potential problems in the development stage, reduce risks in the production environment, and improve system security and stability.
Smart Images

Figure CN119621747B_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 thus enhance overall database performance. For example, in the fintech claims scenario, by setting SQL statement optimization methods in the claims system, SQL statements generated during user operations can be optimized to improve data query efficiency. However, high-risk SQL statements can easily lead to system security issues such as data leakage, data corruption, and system performance degradation. Therefore, optimizing high-risk SQL statements is one way to improve the security and stability of related systems.
[0003] The related technology for optimizing SQL statements usually involves first capturing log information, obtaining the execution script of the SQL statement from the log information, and comparing the analyzed SQL statement execution plan with the pre-set high-risk SQL rules based on the execution script. If a match is found, an alarm message is issued, and the developer is asked to perform manual optimization. However, this method has a certain degree of lag and passivity. The system needs to first trigger the script execution of the SQL statement, and then use the relevant analysis tools to analyze the script execution results of the SQL statement in the log. 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 also reducing 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 objectives, a first aspect of an embodiment of the present application provides a method for optimizing structured query statements, the method comprising:
[0006] Obtaining a target structured script file, wherein the target structured script file includes target structured statement content;
[0007] 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, wherein the statement detection data includes statement detection sub-data of the target structured statement content;
[0008] determining a sentence risk type of the target structured sentence content based on the sentence detection sub-data;
[0009] 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, wherein the candidate statement optimization data includes candidate optimization interpretation text and candidate structured statements, wherein the candidate optimization interpretation text is used to indicate the difference between the candidate structured statement and the target structured statement content;
[0010] 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, wherein the statement execution score is used to indicate the accuracy of the execution of the candidate structured statement;
[0011] Performing sentence adjustment on the candidate structured sentence based on the sentence execution score to obtain a target optimized structured sentence;
[0012] The candidate optimized interpretation texts are adjusted based on the target optimized structured statement to obtain a 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] Obtaining a semantic structure rule knowledge base associated with the structured sentence detection agent;
[0020] 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, 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 statement query data and the target statement query data to determine the statement execution score.
[0031] In some embodiments, performing sentence adjustment on 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 state, obtaining candidate resource consumption data of the candidate structured statement, wherein the accurate state is used to indicate that the amount of identical data in the candidate statement query data and the target statement query data is greater than or equal to a preset data amount 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 post-splitting resource consumption data of the split structured statements;
[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 adjusting the candidate structured statements based on the statement execution score to obtain a target optimized structured statement further includes:
[0039] If the statement execution status 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] Performing sentence content detection on the target structured script file based on the adjusted structured sentence detection agent 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, the candidate adjusted statement optimization data including candidate adjusted optimized interpretation text and candidate adjusted structured statements, the candidate adjusted optimized interpretation text being used to indicate the difference between the candidate adjusted structured statement and the target structured statement content;
[0043] The structured statement verification intelligent agent verifies the candidate adjusted structured statement based on the structured statement, and obtains an adjusted statement execution score, which indicates an accuracy degree of execution of the candidate adjusted structured statement.
[0044] The structured statement adjustment module adjusts the candidate structured statement based on the adjusted statement execution score, and obtains the target optimized structured statement.
[0045] To achieve the above object, a second aspect of the embodiment of the present application provides a structured query statement optimization device, which comprises:
[0046] The obtaining module is configured to obtain a target structured script file, wherein the target structured script file comprises target structured statement content.
[0047] The detection module is configured to perform statement content detection on the target structured script file based on a structured statement detection intelligent agent of a statement optimization model, and obtain statement detection data, wherein the statement detection data comprises statement detection sub-data of the target structured statement content.
[0048] The determination module is configured to determine a statement risk type of the target structured statement content based on the statement detection sub-data.
[0049] The optimization module is configured to perform statement content optimization on the statement risk type and the statement detection sub-data based on a structured statement optimization intelligent agent of the statement optimization model, and obtain candidate statement optimization data, wherein the candidate statement optimization data comprises a candidate optimized explanation text and a candidate structured statement, and the candidate optimized explanation text is used to indicate a difference between the candidate structured statement and the target structured statement content.
[0050] The verification module is configured to perform statement execution verification on the candidate structured statement based on a structured statement verification intelligent agent of the statement optimization model, and obtain a statement execution score, which is used to indicate an accuracy degree of execution of the candidate structured statement.
[0051] The statement adjustment module is configured to adjust the candidate structured statement based on the statement execution score, and obtain a target optimized structured statement.
[0052] The text adjustment module is configured to adjust the candidate optimized explanation text based on the target optimized structured statement, and obtain a target optimized explanation text.
[0053] To achieve the above object, a third aspect of the embodiments of the present application provides an electronic device, comprising a memory and a processor, the memory stores a computer program, and the processor implements the method of the first aspect when executing the computer program.
[0054] To achieve the above object, a fourth aspect of the embodiments of the present application provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the method of the first aspect.
[0055] The method and device for optimizing structured query statements, the electronic device, and the storage medium provided by the present application can effectively improve the flexibility of structured query statements by continuously detecting, optimizing, verifying, and adjusting the target structured script file through intelligent agents of different types in combination, and can better improve the optimization accuracy and efficiency of structured query statements through such continuous detection and optimization. BRIEF DESCRIPTION OF DRAWINGS
[0056] Figure 1 is a flowchart of the method for optimizing structured query statements provided by the embodiments of the present application;
[0057] Figure 2 is a framework schematic diagram of the optimization tool constructed based on the method for optimizing structured query statements provided by the embodiments 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.
[0064] Figure 9 This is a specific flow chart of the structured query statement optimization provided by the embodiment of the present application;
[0065] Figure 10 This is a schematic diagram of the structure of the structured query statement optimization device provided in the embodiment of the present application;
[0066] Figure 11 This is a hardware structure diagram of the electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0067] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.
[0068] It should be noted that although the device schematics illustrate functional module divisions and the flowcharts illustrate logical sequences, in certain circumstances, the steps shown or described may be performed in a sequence that differs from the module divisions in the device or the sequence in the flowcharts. The terms "first," "second," and so on, in the specification, claims, and drawings, are used to distinguish similar items and are not necessarily used to describe a specific sequence or precedence.
[0069] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application pertains. The terms used herein are for the purpose of describing the embodiments of this application only and are not intended to limit this application.
[0070] First, let’s analyze some of the terms used in this application:
[0071] Artificial Intelligence (AI) is a new technical discipline that studies and develops theories, methods, technologies, and application systems for simulating, extending, and expanding human intelligence. A branch of computer science, AI seeks to understand the essence of intelligence and create new intelligent machines that can respond in a manner similar to human intelligence. Research in this field includes robotics, speech recognition, image recognition, natural language processing, and expert systems. AI can simulate the information processes of human consciousness and thinking. It also encompasses theories, methods, technologies, and application systems that use digital computers or digital computer-controlled machines to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results.
[0072] Structured Query Language (SQL) is a standard programming language for managing and operating 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, including MySQL, PostgreSQL, Oracle, SQL Server, and SQLite.
[0073] A relational database management system (RDBMS) is a database management system that organizes data using a relational model (a two-dimensional table model). Data in a relational model is stored in tables, each consisting of rows (records) and columns (fields).
[0074] An agent is an entity that can perceive its 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 adapt to changes in the environment. In the field of artificial intelligence, an agent is a system that can simulate human intelligent behavior, such as chatbots, recommendation systems, or self-driving cars, that is, it can understand input, learn patterns, and make decisions based on them.
[0075] A SQL script file is a text file containing SQL statements, primarily used to interact with a database and automate complex database operations. SQL scripts can be used for tasks such as creating databases and tables, inserting and updating data, and generating reports. SQL scripts can be executed through command-line tools or the database management system's command-line interface, 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 thus enhance overall database performance. For example, in the fintech claims scenario, by setting SQL statement optimization methods in the claims system, SQL statements generated during user operations can be optimized to improve data query efficiency. However, high-risk SQL statements can easily lead to system security issues such as data leakage, data corruption, and system performance degradation. Therefore, optimizing high-risk SQL statements is one way to improve the security and stability of related systems.
[0077] The related technology for optimizing SQL statements usually involves first capturing log information, obtaining the execution script of the SQL statement from the log information, and comparing the analyzed SQL statement execution plan with the pre-set high-risk SQL rules based on the execution script. If a match is found, an alarm message is issued, and the developer is asked to perform manual optimization. However, this method has a certain degree of lag and passivity. The system needs to first trigger the script execution of the SQL statement, and then use the relevant analysis tools to analyze the script execution results of the SQL statement in the log. 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 also reducing 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, electronic device, and 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. 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 achieve optimal results.
[0080] Fundamental AI technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interaction systems, and mechatronics. AI software technologies primarily encompass computer vision, robotics, biometrics, speech processing, natural language processing, 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 a terminal, can be applied to a server side, or can be software running in a terminal or a 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 as a server cluster or distributed system composed of multiple physical servers, or 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, and the like. 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, and the like 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 via 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 embodiment 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 execution 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 such data will comply with relevant laws, regulations and standards. In addition, when the embodiment of the present application needs to obtain the sensitive personal information of the object, the separate permission or 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 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 This 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 statement optimization agent based on the statement optimization model optimizes the statement content based on the statement risk type and statement detection sub-data to obtain candidate statement 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 interpretation text of the candidate optimized interpretation text based on the target optimized structured statement to obtain the target optimized interpretation 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 subsequent embodiments. The structured query statement optimization method of the present application can also be packaged into an independent tool for users to use to ask statement questions, so as to facilitate the generation of optimized statements that meet user needs. For example, if 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; if 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 target structured statement content, which represents information related to the target structured statement, i.e., the specific content of the script file. The target structured statement content can be a specific statement or a description of the statement's execution effect. The target structured statement can be code, a query, or other form of instruction.
[0094] It's important to note that once a database system is connected to the tool, it can automatically retrieve the database connected to the system to obtain table data, structure, indexes, and other information for subsequent statement content detection. Furthermore, the tool can scan the system codebase to obtain target structured script files, such as SQL scripts.
[0095] In the above embodiment, compared to the related art that involves no tools and needs 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 independently 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 systems, etc., and asynchronous detection can be performed during the system development process and code base to detect whether there is high-risk SQL that affects the system. In addition, this application can also support SQL technical knowledge Q&A, 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 intelligent agent of the large model, and specifically can include a structured statement detection intelligent agent, a structured statement optimization intelligent agent and a structured statement verification intelligent agent.
[0097] It should be noted that this application uses a structured statement detection agent to perform statement content detection on target structured statements (such as multiple SQL statements) in a target structured script file to determine whether these statements contain high-risk SQL. Statement detection sub-data is used to represent the analysis results of each statement.
[0098] Please note that Figure 2 , Figure 2This is a schematic diagram of a framework of an optimization tool based on a structured query statement optimization method provided in 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 in this 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 for the tool to interact with the user. Because the optimization tool based on the structured query statement optimization method provided in this application can be used as an independent agent, it interacts with the user in the form of questions and answers by accessing a web page. The user sends the SQL script that needs to be analyzed and optimized, and the agent generates problems and optimization suggestions for the script online. At the same time, the tool can be connected to the system as a plug-in, offline analyze the problems existing in the SQL script code in the system and output optimization suggestions, and notify the system manager. 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 suggestions). 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 limitations.
[0099] See also Figure 3 , Figure 3 This 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 steps S310 and S320 of some embodiments, after obtaining the target structured script file, the present application can construct 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 structures, indexes, views, stored procedures, etc., and is the basis for constructing the virtual database. This virtual database is used to simulate real database operations without requiring 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, SQL statements in the target structured script file may be executed in the virtual database environment, and statement execution plan information for these statements may be obtained. Statement execution plan information includes the execution path of the SQL statement, used indexes, estimated execution time, and resource consumption, which is important for analyzing and optimizing the performance of SQL statements.
[0106] In some embodiments, step S340 can further include a structured statement detection agent that analyzes the target structured script file and statement execution plan information. Specifically, the structured statement detection agent analyzes the statements in the target structured script file and their execution plan information in the virtual database. The structured statement detection agent can analyze the logic, performance, and potential issues of the statements and generate statement detection data, which can include potential errors, performance bottlenecks, and optimization suggestions.
[0107] In the above embodiments, this application can identify and resolve potential issues in structured script files in advance through simulated 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 during the development phase, reducing the risk of problems in the production environment.
[0108] See also Figure 4 , Figure 4 This 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: performing sentence semantic structure analysis on the target structured sentence content based on the semantic structure rule knowledge base to obtain semantic structure analysis data;
[0111] Step S430: performing an 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 using a structured sentence detection agent to analyze sentence content, the present application may combine this with a pre-set semantic structure rule knowledge base to analyze the sentence semantic structure. The semantic structure rule knowledge base pre-stores a series of semantic structure rules that define how sentences should be constructed and the meaning expressed by each construction method. The semantic structure rule knowledge base can be associated with the structured sentence detection agent to facilitate flexible invocation 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. In other words, 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 that 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 some embodiments, in steps S440 and S450, the semantic structure analysis data and the statement execution analysis data may be further integrated to obtain statement detection sub-data for the target structured statement content. This provides a comprehensive perspective for subsequent intelligent agents, while considering both the semantic correctness and execution efficiency of the statement, thereby generating more accurate statement detection sub-data. Furthermore, the structured statement detection intelligent agent further merges the obtained multiple statement detection sub-data to aggregate the dispersed sub-data into a complete set of statement detection data for use in 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, thereby providing a prompt for subsequent structured sentence optimization agents to improve the accuracy of sentence content optimization. The sentence risk type can indicate high-risk issue types within the target structured sentence content, such as grammatical errors, logical errors, and performance issues.
[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 statement detection sub-data by a structured statement optimization agent of the statement optimization model to obtain candidate statement optimization data. The candidate statement optimization data is equivalent to a content optimization solution for the target structured script file and can include candidate optimization interpretation text and candidate structured statements. 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 5This 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 the structured statement optimization agent;
[0124] Step S520 , selecting and determining target optimization rule data from the optimization rule knowledge base based on the statement risk type;
[0125] Step S530 , performing sentence content optimization 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 utilizes a structured statement optimization agent to optimize 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 various 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 can include: (1) basic knowledge in the form of structured QA, including syntax, basic concepts, and usage scenario suggestions; (2) SQL development suggestions for various scenarios; (3) SQL optimization suggestion knowledge base based on syntax and scenario dimensions (i.e., optimization rule knowledge base); (4) SQL optimization knowledge base with user feedback (i.e., optimization rule knowledge base). 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, the present application may further 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 these optimization changes are accepted.
[0130] In step S150 of some embodiments, further, since the given candidate statement optimization data may not necessarily achieve the preset optimization effect, based on this, the present application may also use the structured statement verification agent of the statement optimization model to perform statement execution verification on the candidate structured statement to determine the accuracy and effectiveness of the statement. The verification result may be a statement execution score that indicates the accuracy of the execution of the candidate structured statement.
[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 statement detection agent of this application is used to output detection results, the structured statement optimization agent is mainly used to output optimization solutions, and the structured statement 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 This 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 steps S610 and 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 content of the target structured statement. 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 between the candidate statement query data and the target statement query data. If the total amount of data and the consistency of the data content queried by the candidate statement query data and the target statement query data are high, the corresponding statement execution score is high.
[0137] It's important to note that, generally, the query data is consistent, meaning the total amount and content of data returned by the candidate statement query data and the target statement query data are highly consistent. However, because optimization involves modifying query conditions, the order or scope of queries may change, resulting in undesirable query results despite the optimized SQL script. Based on this, the statement execution score can be used to determine whether the optimized candidate structured statement achieves the desired optimization effect.
[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 This 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 status is accurate, obtain 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 steps S710 and 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 meets the expected standard. If the score comparison result indicates that the statement execution score is greater than or equal to the preset execution score, the statement execution status can be determined to be an accurate state, and the accurate state is used to indicate that the amount of identical data in the candidate statement query data and the target statement query data is greater than or equal to the preset data amount corresponding to the preset execution score, that is, the statement accuracy requirement can be met.
[0147] In some embodiments, in step S730, if the statement execution status is accurate, candidate resource consumption data for the candidate structured statement is obtained. This candidate resource consumption data can represent the resources consumed by executing the candidate structured statement, namely, it can include CPU time, memory usage, disk I / O, etc., thereby determining whether the candidate structured statement has achieved an optimization effect. In other words, the resulting 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 may split 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, to decompose a complex query into multiple simple queries to achieve improved 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 can be judged whether the split statement has achieved 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 database and table sharding operations, and output a database sharding distribution plan, or create 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 several 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 scenario corresponding to the statement, so real-time background detection is required to update and supplement the detection data and optimization data of the missing scenario; (3) The content of the target structured statement is complex, which may be a complex scenario. That is, the target structured statement content or the optimized statement can be split and optimized through Java, C, Python and other code assistance implementations, 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, the latest large model should be replaced and the temperature parameter of the large model should be adjusted to make the output results more accurate.
[0151] See also Figure 8 , Figure 8 This 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 further include but is not limited to steps S810 to S860.
[0152] Step S810: If the statement execution state is inaccurate, adjust 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: Optimize the adjusted statement risk type and the adjusted statement detection sub-data based on the structured statement optimization agent to obtain candidate adjusted statement 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 : performing 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 amount of the same 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 some embodiments, in steps S820 to S860, 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 as step S120 above, the specific process of step S830 can be referred to as step S130 above, the specific process of step S840 can be referred to as step S140 above, the specific process of step S850 can be referred to as step S150 above, and the specific process of step S860 can be referred to as step S160 above. Only the input and output data are changed, which will not be described in detail 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 interpretation text of the candidate optimized interpretation text output by the structured statement optimization agent to obtain the target optimized interpretation text, so as to ensure that the target optimized interpretation text can accurately reflect the difference between the optimized target optimized structured statement and the original target structured statement content.
[0161] See also Figure 9 , Figure 9 This 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: Obtain the target structured script file to be analyzed.
[0163] When obtaining the target structured script file, a code library, a database, etc. can be combined.
[0164] Step S920: Use the structured statement detection agent to perform statement content detection on the target structured script file, and determine the statement risk type of the target structured statement content based on the statement 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 plan is equivalent to the candidate sentence optimization data, which includes the candidate optimization interpretation text and the candidate structured sentence. In addition, when optimizing the sentence content, the structured sentence optimization agent combines the optimization rule knowledge base associated with it.
[0168] In step S940, the candidate structured statements are verified 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 accurate, 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 executed again.
[0170] Step S950 , determining whether the candidate structured statement with the statement execution status being accurate has achieved the optimization effect, if so, executing step S960 , if not, executing step S920 again.
[0171] The process of determining whether the statement has achieved the optimization effect can be referred to above steps S730 to S760 and 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 interpretation text, 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's software tools or components that appear in the embodiments of this 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 actively obtains the script file that needs to be analyzed by connecting the code base and the database, 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. Moreover, 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 to output optimization suggestions based on the detection results. Moreover, it is possible to judge whether the optimization suggestion is effective and improve its own accuracy by simulating the execution of the SQL script corresponding to the optimization suggestion and then executing the original script for analysis. Therefore, the present application can effectively improve the flexibility of the structured query statement. And it can better improve the optimization accuracy and efficiency of the structured query statement by continuously detecting and optimizing the agent and the statement.
[0176] See also Figure 10 The present application also provides a structured query statement optimization device that can implement the above structured query statement optimization method. The device includes:
[0177] An acquisition module 1010 is configured to acquire a target structured script file, wherein the target structured script file includes target structured statement content;
[0178] A detection module 1020 is configured 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 is configured to determine a sentence risk type of the target structured sentence content based on the sentence detection sub-data;
[0180] Optimization module 1040 is configured to optimize the sentence content based on the sentence risk type and sentence detection sub-data of the sentence optimization model using the structured sentence optimization agent to obtain candidate sentence optimization data. The candidate sentence optimization data includes candidate optimization interpretation text and candidate structured sentences. The candidate optimization interpretation text indicates the difference between the candidate structured sentence and the target structured sentence.
[0181] Verification module 1050, 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, which indicates the accuracy of the execution of the candidate structured statement;
[0182] A statement adjustment module 1060 is configured 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 interpretation text of the candidate optimized interpretation text based on the target optimized structured statement to obtain the target optimized interpretation 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 embodiment of the structured query statement optimization method described above, and will not be repeated here.
[0185] The present application also provides an electronic device comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the above-described structured query statement optimization method when executing the computer program. The electronic device can be any smart terminal, including a tablet computer and an in-vehicle computer.
[0186] See also Figure 11 , Figure 11 The hardware structure of an electronic device according to another embodiment is shown. The electronic device includes:
[0187] The processor 1110 may be implemented as a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is configured 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 solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 1120 and is called by the processor 1110 to execute the structured query statement optimization method of the embodiments of this application.
[0189] Input / output interface 1130, used for information input and output;
[0190] Communication interface 1140, used to implement communication interaction between this device and other devices, which can be achieved through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WiFi, Bluetooth, etc.);
[0191] bus 1150 , which transmits information between 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 communicatively connected to each other within the device via a 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 arranged 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 this application are intended to more clearly illustrate the technical solutions of the embodiments of this application and do not constitute a limitation on the technical solutions provided by the embodiments of this 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 this application are also applicable to similar technical problems.
[0196] Those skilled in the art will understand 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. The units described as separate components may or may not be physically separate, i.e., they may be located in one place or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of this embodiment.
[0198] Those skilled in the art will appreciate that all or some of the steps in the methods, systems, and functional modules / units in the devices disclosed above may be implemented as software, firmware, hardware, or appropriate combinations 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 sequential order. 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 variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes 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 this 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 previous and next associated objects are in an "or" relationship. "At least one of the following items" or similar expressions refers to any combination of these items, including any combination of single items 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 this 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 merely schematic. For example, the division of the above-mentioned units is only a logical function division. In actual implementation, there may be other division methods, 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 separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0203] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or 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, which is stored in a storage medium and includes multiple instructions for enabling 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: various media that can store programs, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0205] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but are not intended to limit the scope of the present invention. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and essence of the present invention should be within the scope 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 statement detection agent based on the statement optimization model performs statement content detection on the target structured script file to obtain statement detection data, wherein the statement detection data includes statement detection sub-data of the target structured statement content; wherein 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: obtaining pre-configured database structure data; constructing a virtual database based on the database structure data; obtaining statement execution plan information of the target structured script file based on the virtual database; performing statement content analysis on the target structured script file and the statement execution plan information based on the structured statement detection agent to obtain the statement detection data; determining a sentence risk type of the target structured sentence content based on the sentence detection sub-data; 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, wherein the candidate statement optimization data includes candidate optimization interpretation text and candidate structured statements, wherein the candidate optimization interpretation text is used to indicate the difference between the candidate structured statement and the target structured statement content; 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, wherein the statement execution score is used to indicate the accuracy of the execution of the candidate structured statement; Performing sentence adjustment on the candidate structured sentence based on the sentence execution score to obtain a target optimized structured sentence; The candidate optimized interpretation texts are adjusted based on the target optimized structured statement to obtain a target optimized interpretation text.
2. The method according to claim 1, 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: Obtaining a semantic structure rule knowledge base associated with the structured sentence detection agent; 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, 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.
3. The method according to claim 1, characterized in that 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: 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.
4. The method according to any one of claims 1 to 3, 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 statement query data and the target statement query data to determine the statement execution score.
5. The method according to claim 4, 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 state, obtaining candidate resource consumption data of the candidate structured statement, wherein the accurate state is used to indicate that the amount of identical data in the candidate statement query data and the target statement query data is greater than or equal to a preset data amount 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 post-splitting resource consumption data of the split structured statements; 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.
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 further includes: If the statement execution status 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; Performing sentence content detection on the target structured script file based on the adjusted structured sentence detection agent 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, the candidate adjusted statement optimization data including candidate adjusted optimized interpretation text and candidate adjusted structured statements, the candidate adjusted optimized interpretation text being used to indicate the difference between the candidate adjusted structured statement and the target structured statement content; Performing statement execution verification on the candidate adjusted structured statement based on the structured statement verification agent 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.
7. A structured query statement optimization device, characterized in that: The device comprises: An acquisition module, configured to acquire a target structured script file, wherein the target structured script file includes target structured statement content; A detection module is configured to perform statement content detection on the target structured script file based on a structured statement detection agent of a statement optimization model to obtain statement detection data, wherein the statement detection data includes statement detection sub-data of the target structured statement content; wherein 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: obtaining pre-configured database structure data; constructing a virtual database based on the database structure data; obtaining statement execution plan information of the target structured script file based on the virtual database; and performing statement content analysis on the target structured script file and the statement execution plan information based on the structured statement detection agent to obtain the statement detection data; 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 perform sentence content optimization on 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 candidate optimization interpretation text and candidate structured sentences, 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 interpretation text of the candidate optimized interpretation text based on the target optimized structured statement to obtain the target optimized interpretation text.
8. An electronic device, characterized in that: The electronic device includes 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 6 when executing the computer program.
9. 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 6 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