SQL optimization method and device based on AI intelligent auditing and medium
By using AI-powered intelligent auditing to detect and optimize SQL statements, the problem of low efficiency in traditional manual optimization is solved, enabling fast and accurate SQL optimization and ensuring efficient database operation.
Patent Information
- Application Number
- CN202511298884.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-11
- Publication Date
- 2026-01-23
AI Technical Summary
Traditional SQL optimization relies on human experience, which is inefficient and difficult to meet the real-time optimization needs of massive amounts of SQL. It is also easily limited by the personal experience and knowledge gaps of database administrators, resulting in some performance issues being overlooked.
An AI-based intelligent review method is adopted, which performs syntax and performance testing through a pre-built detection mechanism, uses a pre-built language model to convert SQL statements into semantic vectors, combines historical case libraries and database metadata to generate optimization suggestions, and verifies and corrects the optimization process through testing.
Quickly identify basic syntax errors and potential performance issues, provide optimization suggestions that better align with actual business logic, continuously improve the accuracy and effectiveness of optimization solutions, and ensure efficient database operation.
Smart Images

Figure CN121387952A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application relates to the technical field of databases, in particular to an SQL optimization method and device based on AI intelligent auditing and a medium. BACKGROUND
[0002] SQL (Structured Query Language) is a standard language for managing relational databases, which can realize data query, update, definition and control operations, and is the core tool for database and application interaction.
[0003] With the accelerated promotion of digital transformation, enterprise-level database management systems are facing the challenge of explosive growth of data volume, and the performance optimization of SQL statements has become the core link to ensure the efficient operation of the database. Traditional SQL optimization mainly relies on the manual experience of database administrators, which identifies inefficient queries and formulates optimization schemes by manually reviewing SQL text, execution plans and database metadata. However, manual experience for reviewing and optimizing SQL text not only has low efficiency and is difficult to meet the real-time optimization needs of massive SQL, but also is easily affected by the personal experience and knowledge blind spots of database administrators, resulting in some performance problems being missed. SUMMARY
[0004] The embodiments of the application provide an SQL optimization method and device based on AI intelligent auditing and a medium, which are used to solve the following technical problems: manual experience for reviewing and optimizing SQL text not only has low efficiency and is difficult to meet the real-time optimization needs of massive SQL, but also is easily affected by the personal experience and knowledge blind spots of database administrators, resulting in some performance problems being missed.
[0005] The embodiments of the application adopt the following technical solutions:
[0006] The embodiments of the application provide an SQL optimization method based on AI intelligent auditing. The method comprises the following steps: obtaining SQL statements, database metadata and execution plans corresponding to the SQL statements; detecting the SQL statements and the execution plans based on a preset detection mechanism; wherein the detection at least includes one of syntax detection and performance detection; in the case that the detection result does not meet the preset condition, converting the SQL statements into semantic vectors through a preset language model; querying reference optimization suggestions in a historical case library based on the semantic vectors; optimizing the SQL statements based on the database metadata and the reference optimization suggestions; testing and verifying the optimized SQL statements, and correcting the optimization process of the SQL statements based on the test and verification result.
[0007] In an implementation manner of the present application, the SQL statement and the execution plan are detected based on a preset detection mechanism, specifically including: performing basic syntax verification and logical reasonableness detection on the SQL statement based on a preset syntax detection mechanism; wherein the basic syntax verification at least includes one of keyword error verification, syntax structure anomaly verification, data type compatibility verification and symbol matching; the logical reasonableness detection at least includes one of semantic logic detection, inefficient syntax structure detection and correlation relationship detection; performing plan detection on the execution plan based on a preset plan detection mechanism and database metadata; wherein the plan detection at least includes one of scan mode detection, connection operation detection and sorting and aggregation operation detection.
[0008] In an implementation manner of the present application, the SQL statement is converted into a semantic vector through a preset language model, specifically including: encoding the SQL statement through the preset language model to obtain a hidden layer vector sequence containing global semantic information; performing feature extraction on a key sentence in the SQL statement through a multi-head attention mechanism to obtain a feature vector corresponding to the key sentence; wherein the key sentence at least includes one of a WHERE clause and a JOIN clause; and performing weighted fusion on the hidden layer vector sequence and the feature vector to generate a semantic vector corresponding to the SQL statement, so as to determine the query intention based on the semantic vector.
[0009] In an implementation manner of the present application, the reference optimization suggestion is queried in the historical case library based on the semantic vector, and the SQL statement is optimized based on the database metadata and the reference optimization suggestion, specifically including: determining a candidate case with a similarity greater than a preset threshold to the semantic vector in the historical case library; determining optimization information corresponding to the candidate case and taking the optimization information as a reference optimization suggestion; performing feasibility detection on the reference optimization suggestion based on the database metadata corresponding to the SQL statement, and screening out the infeasible suggestions; and performing adaptability adjustment on the filtered reference optimization suggestion based on the database metadata, so as to optimize the SQL statement through the adjusted optimization suggestion.
[0010] In an implementation manner of the present application, the filtered reference optimization suggestion is adaptively adjusted based on the database metadata, specifically including: determining database table information based on the database metadata to construct a table relationship graph based on the database table information; wherein the table relationship graph takes a database table as a node and a table relationship as an edge; encoding the table relationship graph through a preset graph neural network to obtain a comprehensive feature vector corresponding to each table; wherein the comprehensive feature vector at least includes one of metadata features of the table, inter-table correlation relationship features and encoding results; adjusting a JOIN order of a multi-table based on the comprehensive feature vector through a JOIN order evaluation function to generate a table association optimization suggestion, so as to adaptively adjust the filtered reference optimization suggestion through the table association optimization suggestion.
[0011] In an implementation form of the present application, the reference optimization suggestion at least includes one of adding a BTREE index for a filter condition field, rewriting a subquery as a JOIN operation, and forcing an index usage strategy in a specified execution plan.
[0012] In an implementation form of the present application, the optimized SQL statement is tested and verified, and the optimization process of the SQL statement is corrected based on the test and verification result, specifically including: in a test environment, the optimized SQL statement is tested and verified, and performance data is recorded; wherein the performance data at least includes one of execution time and read-write amount data; a performance improvement ratio is determined based on the performance data; if the performance improvement ratio is greater than a preset ratio threshold, it is determined that the SQL statement optimization is effective, and the current optimization data is added to the model training set; if the performance improvement ratio is not greater than the preset ratio threshold, it is determined that the SQL statement optimization is ineffective, and the current optimization data is marked as a counterexample.
[0013] In an implementation form of the present application, after the SQL statement is obtained, the method further includes: converting the SQL statements of different databases into a unified intermediate representation to adapt to different database engines.
[0014] The embodiment of the present application provides an SQL optimization device based on AI intelligent auditing, including: at least one processor; and a memory in communication connection with the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions are executed by the at least one processor to enable the at least one processor to: obtain a SQL statement, database metadata and an execution plan corresponding to the SQL statement; based on a preset detection mechanism, detect the SQL statement and the execution plan; wherein the detection at least includes one of syntax detection and performance detection; in the case that the detection result does not meet a preset condition, convert the SQL statement into a semantic vector through a preset language model; based on the semantic vector, query a reference optimization suggestion from a historical case library, optimize the SQL statement based on the database metadata and the reference optimization suggestion; test and verify the optimized SQL statement, and correct the optimization process of the SQL statement based on the test and verification result.
[0015] The nonvolatile computer storage medium provided by the embodiment of the application stores computer executable instructions, and the computer executable instructions are configured to: acquire a SQL statement, database metadata, and an execution plan corresponding to the SQL statement; detect the SQL statement and the execution plan based on a preset detection mechanism; wherein the detection at least includes one of syntax detection and performance detection; in a case where a detection result does not meet a preset condition, convert the SQL statement into a semantic vector through a preset language model; query a reference optimization suggestion from a historical case library based on the semantic vector, optimize the SQL statement based on the database metadata and the reference optimization suggestion; and test and verify the optimized SQL statement, and correct an optimization process of the SQL statement based on a test and verification result.
[0016] The above at least one technical solution adopted by the embodiment of the application can achieve the following beneficial effects: the embodiment of the application can quickly locate basic syntax errors and potential performance risks through syntax and performance detection based on a preset detection mechanism, and avoid performance loss caused by low-level errors. Secondly, the embodiment of the application converts SQL semantics into a vector through a preset language model and a historical case library, and then performs matching, so that the optimization suggestion is more in line with actual business logic. In addition, the embodiment of the application can dynamically adjust the optimization strategy according to actual effects through a closed-loop process of test and verification and correction, continuously improve the accuracy and effectiveness of the optimization scheme, and ensure that the database always operates efficiently. BRIEF DESCRIPTION OF DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiment or prior art description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments described in the present application, and other drawings can be obtained by those skilled in the art without creative labor. In the drawings:
[0018] Figure 1 A SQL optimization method flowchart based on AI intelligent auditing is provided for the embodiment of the present application.
[0019] Figure 2 A structural schematic diagram of a SQL optimization device based on AI intelligent auditing is provided for the embodiment of the present application.
[0020] Reference signs:
[0021] 200: SQL optimization device based on AI intelligent auditing, 201: processor, 202: memory. DETAILED DESCRIPTION
[0022] The embodiment of the present application provides a SQL optimization method, device and medium based on AI intelligent auditing.
[0023] In order for those skilled in the art to better understand the technical solutions in the present application, the technical solutions in the embodiments of the present application will be clearly and completely described in the following with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, not all. Based on the embodiments of the present application, all other embodiments obtained by those of ordinary skill in the art without creative labor should fall within the scope of protection of the present application.
[0024] The technical solutions provided by the embodiments of the present application will be described in detail below with reference to the drawings.
[0025] Figure 1 A flow chart of an SQL optimization method based on AI intelligent auditing provided by an embodiment of the present application is shown in FIG. 1. Figure 1 The SQL optimization method based on AI intelligent auditing includes the following steps:
[0026] S101, obtaining a SQL statement, database metadata, and an execution plan corresponding to the SQL statement.
[0027] In an implementation manner of the present application, the SQL statement and the execution context are captured in real time, and the database metadata is extracted, including table structure, index information, data distribution characteristics, recording execution plan and performance indicators such as execution time, IO read / write amount, etc.
[0028] The embodiment of the present application also includes a dialect analysis module, which converts SQL statements of different databases into a unified intermediate representation to adapt to different database engines such as MySQL, Oracle, PostgreSQL, etc.
[0029] S102, detecting the SQL statement and the execution plan based on a preset detection mechanism.
[0030] In an implementation manner of the present application, the SQL statement is subjected to basic syntax verification and logical reasonableness detection based on a preset syntax detection mechanism; wherein the basic syntax verification at least includes one of keyword error verification, syntax structure anomaly verification, data type compatibility verification, and symbol matching; the logical reasonableness detection at least includes one of semantic logic detection, inefficient syntax structure detection, and correlation relationship detection. The execution plan is subjected to plan detection based on a preset plan detection mechanism and database metadata; wherein the plan detection at least includes one of scan mode detection, connection operation detection, and sorting and aggregation operation detection.
[0031] Specifically, first, preset syntax detection rules and plan detection rules are called from the rule library. The syntax detection rules include SQL syntax standards, common syntax error patterns and logic defect templates. The plan detection rules in the embodiment of the application combine database metadata characteristics and can include performance thresholds and optimization standards of various operations in the execution plan.
[0032] Further, when performing basic syntax checking of the SQL statement, the obtained SQL statement is subjected to keyword parsing to check whether there is a spelling error, an undefined keyword or keyword misuse. At the same time, the statement structure is analyzed based on the SQL syntax tree to check whether a necessary clause is missing, whether parentheses are matched, whether a function call format is correct and the like. In addition, according to the data types of fields in the database metadata, the type compatibility of data operations in the SQL statement is compared, for example, whether non-numeric type data is mixed in a numeric operation. When performing logic rationality detection, the semantic logic of the SQL statement is analyzed to check whether there is a contradiction in condition judgment and whether the logical association of a subquery and a main query is correct. An inefficient syntax structure, such as an excessively nested subquery and a large range of data filtering without using an index, is identified. At the same time, the association relationship between a table and a field is verified to ensure that a JOIN condition and a subquery association condition conform to the database table structure design and to avoid invalid association.
[0033] Further, when performing scan mode detection, a scan operation node in the execution plan is parsed to determine whether a full table scan is used. The type and efficiency of index scanning are analyzed to check whether the index coverage range is sufficient and whether there is performance loss caused by a back-table query. When performing connection operation detection, a multi-table connection part in the execution plan is detected to determine whether the connection order is reasonable and whether the selection of a connection algorithm is adapted to data characteristics according to the size of a table and the index condition of an associated field in the database metadata. When performing sorting and aggregation operation detection, sorting and aggregation operation nodes in the execution plan are focused on to evaluate the cost of the operation according to the database metadata. If the sorting data volume is too large and an index is not used for assistance, it is determined whether there is optimization space, and it is checked whether the use of an aggregation function conforms to business requirements and whether the calculation amount can be reduced to ensure efficient operation.
[0034] S103, in the case where the detection result does not conform to the preset condition, the SQL statement is converted into a semantic vector through a preset language model.
[0035] In an implementation manner of the present application, in the case that the detection result does not meet the preset condition, the SQL statement needs to be optimized, at this time, the SQL statement is encoded by using the preset language model to obtain a hidden layer vector sequence containing global semantic information. The multi-head attention mechanism is used to extract features of the key sentence in the SQL statement to obtain a feature vector corresponding to the key sentence; wherein the key sentence at least includes one of the WHERE clause and the JOIN clause. The hidden layer vector sequence and the feature vector are weighted and fused to generate a semantic vector corresponding to the SQL statement, so as to determine the query intention based on the semantic vector.
[0036] Specifically, when the detection result does not meet the preset condition, the preset language model is called to process the SQL statement. The SQL statement is first standardized and segmented, and the keywords, table names, field names and other elements are converted into basic vectors recognizable by the model, and then the multi-layer coding structure of the model is used for deep processing, the self-attention mechanism is used to capture the correlation of each part of the sentence, and a hidden layer vector sequence containing the syntax structure, logical relationship and global semantics of the entire SQL statement is generated, and the overall meaning of the sentence is completely preserved.
[0037] Further, based on the SQL syntax analysis result, the sentence part which plays a key role in query performance is located and marked, at least including the WHERE clause and the JOIN clause. The multi-head attention mechanism is used to extract features of the key sentence, wherein different attention heads are based on different dimensions such as logical combination of filtering conditions, association strength of connection fields, to extract core semantic features of the key sentence and generate a feature vector, wherein the feature vector can reflect the data filtering rule and the inter-table association logic. Finally, the hidden layer vector sequence of the global semantics and the feature vector of the key sentence are weighted and fused, and the weights of the two are dynamically adjusted according to the complexity of the SQL statement, to ensure that the fused vector can reflect both the overall query logic and the semantic influence of the key part. The query intention of the SQL statement is identified through the fused vector, and a semantic basis is provided for subsequent matching and optimization strategy.
[0038] S104, query the reference optimization suggestion in the historical case library based on the semantic vector, and optimize the SQL statement based on the database metadata and the reference optimization suggestion.
[0039] In an implementation manner of the present application, a candidate case with a similarity greater than a preset threshold to the semantic vector is determined in the historical case library. The optimization information corresponding to the candidate case is determined, and the optimization information is taken as the reference optimization suggestion. The reference optimization suggestion is detected for feasibility based on the database metadata corresponding to the SQL statement, and the unfeasible suggestions are excluded. The filtered reference optimization suggestion is adjusted for adaptability based on the database metadata, so as to optimize the SQL statement by using the adjusted optimization suggestion.
[0040] In the embodiments of the present application, the reference optimization suggestion at least includes one of adding a BTREE index to the filtering condition field, rewriting a subquery as a JOIN operation, and forcing an index usage strategy in the execution plan.
[0041] Specifically, the similarity of the semantic vector of the SQL statement to be optimized and the semantic vectors of all cases in the historical case library is calculated, and candidate cases with a similarity exceeding a preset threshold are screened out. The corresponding optimization information, including specific optimization means, applicable scenarios, and implementation effects, etc., is extracted from these candidate cases as reference optimization suggestions.
[0042] Further, in combination with the database metadata corresponding to the SQL statement to be optimized, the extracted reference optimization suggestions are verified one by one. According to the metadata characteristics such as table structure, index distribution, and data type, it is judged whether the suggestions conform to the current database environment, for example, it is checked whether the index created by the suggestion conflicts with the existing index, and whether the table association involved in the SQL rewriting conforms to the actual table relationship, and the obviously unfeasible suggestions are screened out to ensure the applicability of the remaining suggestions.
[0043] Further, based on the database metadata, the reference optimization suggestions that pass the feasibility detection are fine-tuned. Specifically, based on the database metadata, the database table information is determined, and a table relationship graph is constructed based on the database table information; wherein the table relationship graph takes the database table as the node and the inter-table relationship as the edge. The table relationship graph is encoded by a pre-set graph neural network to obtain a comprehensive feature vector corresponding to each table; wherein the comprehensive feature vector at least includes one of the metadata features of the table, the inter-table association relationship features, and the encoding result. Based on the comprehensive feature vector, the JOIN order of the multi-table is adjusted by a JOIN order evaluation function to generate a table association optimization suggestion, so as to adaptively adjust the screened reference optimization suggestions through the table association optimization suggestion.
[0044] Specifically, based on the database metadata, the database table information related to the SQL to be optimized is determined, wherein the database table information includes the basic attributes of each table and the inter-table association relationship. Each database table is taken as a node in the graph, and the actual relationship between the tables is taken as the edge connecting the nodes to construct a table relationship graph that can reflect the inter-table dependency relationship. The node attributes include the metadata features of the table such as data volume and index condition; the weight of the edge is dynamically set according to the association strength.
[0045] Further, the constructed table relationship graph is input into a preset graph neural network, and information of nodes and edges in the graph is encoded through multi-layer processing of the network. The graph neural network aggregates metadata features of each table itself and features of other associated tables through an information transmission mechanism to generate a comprehensive feature vector corresponding to each table. The vector contains not only attributes of the table itself, but also roles and influences of the table in the overall associated relationship, and comprehensively represents features and associated characteristics of the table.
[0046] Specifically, an initial feature vector is assigned to each node in the table relationship graph. The vector is composed of metadata features of the table itself, including the number of rows, field data types, index quantity and type, data update frequency, average data size per row, and other basic attributes. These attributes are quantified and combined into the initial feature vector as the starting point for processing by the graph neural network. Through the information transmission mechanism, each node can receive and integrate feature information of its adjacent nodes. For each table node, the feature vectors of adjacent tables are weighted and summed according to the weights of the edges. The higher the weight of the adjacent table feature, the greater the proportion in aggregation, so as to obtain the dependency relationship between the current table and the directly associated table, and generate an intermediate feature vector. Through multi-layer structure of the graph neural network, feature iteration processing is performed. Each layer of the network receives the feature vector output by the previous layer and again aggregates feature information of adjacent nodes processed by the previous layer. With the increase of network layers, the feature vector of each table node gradually integrates more features of indirectly associated tables, while combining iterative updates of the initial features of itself, gradually forming high-order features that can reflect the global position and role of the table in the entire relationship graph. After a preset number of iterations, the graph neural network outputs the final feature vector as the comprehensive feature vector of each table. The vector not only retains the core information of the metadata features of the table itself, but also integrates the relationship features of the directly and indirectly associated tables, and can quantify the attributes of the table itself and its influence in the overall associated network.
[0047] Based on the comprehensive feature vectors of the tables, a JOIN order evaluation function is used to calculate and evaluate possible orders of multi-table association. The evaluation function considers factors such as table size, association strength, index availability, etc., to score and rank the efficiency of different JOIN orders, and selects the optimal order to generate a table association optimization suggestion. The suggestion is combined with the filtered reference optimization suggestions to adaptively adjust the original suggestions, making the optimization scheme more suitable for the actual needs of the multi-table association scenario.
[0048] S105, test and verify the optimized SQL statement, and correct the optimization process of the SQL statement based on the test and verification results.
[0049] In an implementation form of the present application, the optimized SQL statement is tested and verified in a test environment, and performance data is recorded; wherein the performance data at least includes one of execution time and read-write amount data. The performance improvement ratio is determined based on the performance data, if the performance improvement ratio is greater than the preset ratio threshold, it is determined that the SQL statement optimization is effective, and the current optimization data is added to the model training set, if the performance improvement ratio is not greater than the preset ratio threshold, it is determined that the SQL statement optimization is invalid, and the current optimization data is marked as a counterexample.
[0050] Specifically, in the test environment, the optimized SQL statement is executed for a preset number of times, and the performance data of each execution is recorded in real time by the performance monitoring tool set in the database. The performance data at least includes execution time and IO read-write amount, and the average value of multiple executions is calculated to reduce accidental errors.
[0051] Further, the optimized performance data is compared with the benchmark data before optimization, and the performance improvement ratio is calculated. If the ratio is greater than the preset threshold, it is determined that the optimization is effective, and the SQL statement, optimization suggestion, performance data and other information involved in this optimization are sorted and added to the model training set for subsequent optimization model iteration and upgrading. If the performance improvement ratio does not reach the threshold, it is determined that the optimization is invalid, and the related data is marked as a counterexample and stored in the case library as a reference for subsequent optimization strategy adjustment to avoid repeated invalid optimization.
[0052] Figure 2 A structure schematic diagram of a SQL optimization device based on AI intelligent auditing provided by an embodiment of the present application. The SQL optimization device based on AI intelligent auditing 200 comprises at least one processor 201; and a memory 202 communicatively connected with the at least one processor 201; wherein the memory 202 stores instructions executable by the at least one processor 201, and the instructions are executed by the at least one processor 201 to enable the at least one processor 201 to: acquire a SQL statement, database metadata and an execution plan corresponding to the SQL statement; detect the SQL statement and the execution plan based on a preset detection mechanism; wherein the detection at least includes one of syntax detection and performance detection; in the case that the detection result does not meet a preset condition, convert the SQL statement into a semantic vector through a preset language model; query a reference optimization suggestion in a historical case library based on the semantic vector, optimize the SQL statement based on the database metadata and the reference optimization suggestion; test and verify the optimized SQL statement, and correct the optimization process of the SQL statement based on the test and verification result.
[0053] The embodiment of the application provides a kind of nonvolatile computer storage medium, storage has computer executable instruction, computer executable instruction is set as: obtaining SQL statement, database metadata and the execution plan corresponding to SQL statement;Based on preset detection mechanism, SQL statement and execution plan are detected;Wherein, detection at least includes one of syntax detection and performance detection;In the case where the detection result does not comply with preset condition, SQL statement is converted into semantic vector by preset language model;Reference optimization suggestion is inquired in historical case base based on semantic vector, SQL statement is optimized based on database metadata and reference optimization suggestion;The SQL statement after optimization is tested and verified, and the optimization process of SQL statement is corrected based on test verification result.
[0054] Each of the embodiments in the application is described in a progressive manner, and the same or similar parts between each of the embodiments can be referred to each other, and each of the embodiments focuses on the difference from other embodiments. Especially, for the device, equipment, nonvolatile computer storage medium embodiments, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant part can be referred to the part of the method embodiment.
[0055] The above only describes the embodiments of the application, and is not used to limit the application. For those skilled in the art, the embodiments of the application can be variously changed and changed. And these modifications or replacements do not make the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the application.
Claims
1. A method for SQL optimization based on AI intelligent auditing, characterized in that, The method comprises: acquiring a SQL statement, database metadata, and an execution plan corresponding to the SQL statement; detecting the SQL statement and the execution plan based on a preset detection mechanism, wherein the detection at least includes one of syntax detection and performance detection; in a case where a detection result does not meet a preset condition, converting the SQL statement into a semantic vector through a preset language model; querying a reference optimization suggestion from a historical case library based on the semantic vector, optimizing the SQL statement based on the database metadata and the reference optimization suggestion; testing and verifying the optimized SQL statement, and correcting the optimization process of the SQL statement based on a test and verification result.
2. The SQL optimization method based on AI intelligent auditing according to claim 1, characterized in that, The detection of the SQL statement and the execution plan based on the preset detection mechanism specifically comprises: basic syntax checking and logical reasonableness detection of the SQL statement based on a preset syntax detection mechanism, wherein the basic syntax checking at least includes one of keyword error checking, syntax structure anomaly checking, data type compatibility checking, and symbol matching; and the logical reasonableness detection at least includes one of semantic logic detection, inefficient syntax structure detection, and correlation relationship detection; plan detection of the execution plan based on a preset plan detection mechanism and the database metadata, wherein the plan detection at least includes one of scan mode detection, connection operation detection, and sorting and aggregation operation detection. 3.The SQL optimization method based on AI intelligent auditing according to claim 1, characterized in that, The conversion of the SQL statement into the semantic vector through the preset language model specifically comprises: encoding the SQL statement through the preset language model to obtain a hidden layer vector sequence containing global semantic information; feature extraction of a key sentence in the SQL statement through a multi-head attention mechanism to obtain a feature vector corresponding to the key sentence, wherein the key sentence at least includes one of a WHERE clause and a JOIN clause; weighted fusion of the hidden layer vector sequence and the feature vector to generate a semantic vector corresponding to the SQL statement, so as to determine a query intention based on the semantic vector.
4. The SQL optimization method based on AI intelligent auditing according to claim 1, characterized in that, The querying of the reference optimization suggestion from the historical case library based on the semantic vector, and the optimization of the SQL statement based on the database metadata and the reference optimization suggestion specifically comprises: determining a candidate case with a similarity greater than a preset threshold to the semantic vector in the historical case library; determining optimization information corresponding to the candidate case, and taking the optimization information as the reference optimization suggestion; feasibility detection of the reference optimization suggestion based on the database metadata corresponding to the SQL statement, and screening out infeasible suggestions; adaptability adjustment of the filtered reference optimization suggestion based on the database metadata, so as to optimize the SQL statement through the adjusted optimization suggestion.
5. The SQL optimization method based on AI intelligent auditing according to claim 4, characterized in that, The adaptability adjustment of the filtered reference optimization suggestion based on the database metadata specifically comprises: Based on the database metadata, database table information is determined to construct a table relationship graph based on the database table information; wherein the table relationship graph takes a database table as a node and a table relationship as an edge; The table relationship graph is encoded by a preset graph neural network to obtain a comprehensive feature vector corresponding to each table; wherein the comprehensive feature vector at least includes one of metadata features corresponding to the table, inter-table association relationship features, and encoding results. Based on the comprehensive feature vector, a JOIN order evaluation function is used to adjust the JOIN order of multiple tables to generate a table association optimization suggestion to adaptively adjust the filtered reference optimization suggestion based on the table association optimization suggestion.
6. The SQL optimization method based on AI intelligent auditing according to claim 1, characterized in that, The reference optimization suggestion at least includes one of adding a BTREE index to a filter condition field, rewriting a subquery as a JOIN operation, and forcibly specifying an index usage strategy in an execution plan.
7. The SQL optimization method based on AI intelligent auditing according to claim 1, characterized in that, The method further comprises: After obtaining the SQL statement, the method further comprises: Converting the SQL statements of different databases into a unified intermediate representation to adapt to different database engines. The device comprises a memory for storing computer program instructions and a processor for executing the program instructions, wherein when the computer program instructions are executed by the processor, the device is triggered to execute the method of any one of claims 1-8. The computer executable instructions can execute the method of any one of claims 1-8. 8.The SQL optimization method based on AI intelligent auditing according to claim 1, characterized in that, The computer executable instructions can execute the method of any one of claims 1-8. 9.A device for SQL optimization based on AI intelligent auditing, characterized in that, 10. A non-transitory computer storage medium storing computer-executable instructions that, when executed, cause a computer to perform: