Method and device for identifying execution statements

By building a neural network model, predicting the execution time of SQL statements and identifying slow SQL statements, the database failure caused by slow SQL statements is solved, and the database operation and maintenance capabilities are improved.

CN114265860BActive Publication Date: 2025-02-11CHINA TELECOM CORP LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111585126.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-22
Publication Date
2025-02-11
Estimated Expiration
2041-12-22

AI Technical Summary

Technical Problem

Slow SQL statements frequently perform I/O operations, resulting in long-term CPU usage and database failure, but the existing technology has failed to effectively solve this problem.

Method used

By building a neural network model, predict the execution time of SQL statements, compare the execution time with the preset time, and determine whether the execution statement to be predicted is a target execution statement, thereby identifying slow SQL statements.

Benefits of technology

It realizes accurate identification of slow SQL statements, improves database operation and maintenance capabilities, and reduces the chance of database failures.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114265860B_ABST
    Figure CN114265860B_ABST
Patent Text Reader

Abstract

The present application discloses a method and device for identifying an execution statement. The method comprises: obtaining the execution statement to be predicted; inputting the execution statement to be predicted into a neural network model for prediction to obtain the execution time of the execution statement to be predicted; comparing the execution time with the preset time; and determining whether the execution statement to be predicted is the target execution statement based on the comparison result. The present application solves the technical problem that slow SQL statements frequently perform I / O operations and occupy the CPU for a long time, causing database failures.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of Internet operation and maintenance, and specifically, to a method and device for identifying an execution statement. Background Art

[0002] Structured Query Language (SQL) is a database query and programming language, and is currently the most widely used relational database operation language. In database management systems, SQL is used to implement data access, query, and update functions. SQL is a non-procedural language that only requires "what to do" rather than "how to do it".

[0003] Slow SQL statements are slow SQL statements. They are logs that MySQL records for all SQL statements that are executed for longer than the time threshold set by the long_query_time parameter. This log can be a great help in optimizing SQL statements. By default, the slow query log is disabled. To use the slow query log function, you must first enable the slow query log function. The default value of long_query_time is 10, which means data that runs for more than 10 seconds.

[0004] In actual production scenarios, database SQL statements vary greatly when adapting to different businesses or users. Some of these statements may result in slow SQL statements, which may cause frequent I / O operations and occupy the CPU for a long time, thus causing database failures.

[0005] Currently, no effective solution has been proposed for the above-mentioned problem that slow SQL statements frequently perform I / O operations and thus occupy the CPU for a long time, causing database failures. Summary of the invention

[0006] The embodiments of the present application provide a method and device for identifying an execution statement, so as to at least solve the technical problem that slow SQL statements frequently perform I / O operations and thus occupy the CPU for a long time, causing database failures.

[0007] According to one aspect of an embodiment of the present application, a method for identifying an execution statement is provided, including: obtaining an execution statement to be predicted; inputting the execution statement to be predicted into a neural network model for prediction to obtain an execution time of the execution statement to be predicted; comparing the execution time with a preset time; and determining whether the execution statement to be predicted is a target execution statement based on the comparison result.

[0008] Optionally, before inputting the execution statement to be predicted into the neural network model for prediction, the method further includes: obtaining information of multiple historical execution statements, wherein the information includes: multiple historical execution statements and execution times of multiple historical execution statements; constructing multiple target matrices based on the information; inputting the multiple target matrices and the execution times of multiple historical execution statements into the neural network model for training to obtain a trained neural network model.

[0009] Optionally, multiple target matrices are constructed based on the information, including: obtaining execution plan information of historical execution statements, and constructing the execution plan information into a first matrix; converting the historical execution statements into a tree structure, and constructing a second matrix based on the tree structure; merging the first matrix and the second matrix into a target matrix.

[0010] Optionally, converting the historical execution statements into a tree structure and constructing a second matrix based on the tree structure includes: converting the historical execution statements into a tree structure; traversing the tree structure according to a pre-order traversal algorithm to generate a result set; and constructing the second matrix based on the result set.

[0011] Optionally, merging the first matrix and the second matrix into a target matrix includes: transposing the first matrix to obtain a third matrix; and concatenating the second matrix and the third matrix to obtain the target matrix.

[0012] Optionally, multiple target matrices and the execution time of multiple historical execution statements are input into the neural network model for training to obtain a trained neural network model, including: randomly combining multiple target matrices according to preset proportions to obtain a training set and a test set; inputting the training set and the test set into the neural network model for prediction to obtain a trained neural network model.

[0013] Optionally, determining whether the statement to be predicted and executed is a target execution statement based on the comparison result includes: when the execution time of the statement to be predicted and executed is greater than or equal to a preset time, determining the statement to be predicted and executed as a target execution statement; when the execution time of the statement to be predicted and executed is less than the preset time, determining that the statement to be predicted and executed is not a target execution statement.

[0014] According to another aspect of an embodiment of the present application, a device for identifying an execution statement is also provided, including: an acquisition module, used to acquire the execution statement to be predicted; a prediction module, used to input the execution statement to be predicted into a neural network model for prediction, and obtain the execution time of the execution statement to be predicted; a comparison module, used to compare the execution time with a preset time; and a determination module, used to determine whether the execution statement to be predicted is a target execution statement based on the comparison result.

[0015] According to another aspect of the embodiment of the present application, a non-volatile storage medium is provided, the non-volatile storage medium including a stored program, wherein when the program is running, a method for identifying the execution statement of the above-mentioned device where the non-volatile storage medium is located is controlled to execute.

[0016] According to yet another aspect of the embodiments of the present application, a processor is provided, which is used to run a program stored in a memory, wherein the above execution statement recognition method is executed when the program is running.

[0017] In an embodiment of the present application, a method is adopted in which a statement to be predicted is obtained; the statement to be predicted is input into a neural network model for prediction to obtain the execution time of the statement to be predicted; the execution time is compared with a preset time; and whether the statement to be predicted is a target execution statement is determined based on the comparison result. By constructing a neural network model to predict the execution time of SQL statements, the purpose of identifying slow SQL statements is achieved, thereby achieving the technical effects of defining slow SQL scenarios in different situations, accurately identifying slow SQL scenarios, and improving the operation and maintenance capabilities of the database, thereby solving the technical problem of database failure caused by slow SQL statements frequently performing I / O operations and occupying the CPU for a long time. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0019] Figure 1 It is a hardware structure block diagram of a computer terminal (or mobile device) for implementing an execution statement recognition method according to an embodiment of the present application;

[0020] Figure 2 is a flowchart of a method for identifying an execution statement according to an embodiment of the present application;

[0021] Figure 3 is a schematic diagram of an optional method for constructing a neural network model according to an embodiment of the present application;

[0022] Figure 4 A schematic diagram of an optional tree structure according to an embodiment of the present application;

[0023] Figure 5 is a schematic diagram of the structure of an optional neural network model according to an embodiment of the present application;

[0024] Figure 6 It is a structural block diagram of an execution statement recognition device according to an embodiment of the present application. DETAILED DESCRIPTION

[0025] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0026] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0027] The existing main method for dealing with slow SQL problems is to search and identify slow SQL statements running in the system or make post-run judgments. This has the following problems:

[0028] 1) Database management methods are required to retrieve the SQL statements being executed. The retrieval and judgment process takes a long time and consumes manpower and system resources.

[0029] 2) Traditional statement recognition requires a certain amount of slow SQL samples.

[0030] Although the other solution has designed a method for identifying slow SQL statements and predicting query time, it still has the following shortcomings:

[0031] 1) This solution identifies slow SQL statements by calculating the similarity between the features of the current statement and the historical statement based on the historical slow SQL statements. This requires a certain amount of historical slow SQL samples. If there are too few samples, the results will be inaccurate.

[0032] 2) It is necessary to establish a historical slow SQL database. Establishing this database means that a large number of slow SQL statements are generated, and the cost is that the probability of database failure is increased invisibly.

[0033] 3) The problem of defining the time limit of slow SQL in the historical slow SQL database. For example, the limit of slow SQL statements in the historical slow SQL database is that the execution time exceeds 10 seconds. However, if there is a certain demand in this business to adjust it to define slow SQL as more than 5 seconds, the slow SQL database will be inapplicable.

[0034] 4) There are certain cases of misjudgment when using the similarity of statement features. The prediction is not accurate enough when using the general prediction encoding method. For example, SQL statement 1 is deconstructed into "query table A with condition B". This SQL statement is known to be a slow SQL statement, and the statement to be identified is "query table A with condition B". These two statements have the same conditions, the same query methods, and slightly similar query table names. The similarity reaches the threshold, but if it is only due to a problem with the design structure of table A (for example, no index), but the structure of table B is normal, then the statement to be identified may not be a slow SQL statement, which results in a misjudgment.

[0035] In view of this, the present invention proposes a slow SQL statement prediction method based on a neural network and using a combined coding method, which innovates the coding method before prediction to directly predict whether the execution time of the SQL statement is greater than a certain limit value. If it is greater, it is a slow SQL statement, and if it is less, it is not. The present invention does not require a large number of slow SQL samples, and starts with the most intuitive time perspective to predict, which more effectively improves the accuracy of slow SQL prediction; and compared with the traditional comparison and recognition method, the present invention has certain scalability, and can adjust the limit values ​​in different scenarios to redefine the slow SQL scenarios in different situations; the focus of the present invention is that it uses a new type of combined coding method in other SQL prediction technologies.

[0036] The method embodiment provided in the first embodiment of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Figure 1 The hardware structure block diagram of a computer terminal (or mobile device) for implementing the recognition method of execution statement is shown. Figure 1 As shown, the computer terminal 10 (or mobile device 10) may include one or more (102a, 102b, ..., 102n are used to illustrate) processors 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 104 for storing data, and a transmission device 106 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the BUS bus), a network interface, a power supply and / or a camera. It can be understood by those skilled in the art that Figure 1The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.

[0037] It should be noted that the one or more processors 102 and / or other data processing circuits described above may generally be referred to herein as "data processing circuits". The data processing circuits may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuit may be a single independent processing module, or may be incorporated in whole or in part into any of the other components in the computer terminal 10 (or mobile device). As described in the embodiments of the present application, the data processing circuit acts as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).

[0038] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the recognition method of the execution statement in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, realizing the vulnerability detection method of the above-mentioned application program. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer terminal 10 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 a combination thereof.

[0039] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computer terminal 10. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0040] The display may be, for example, a touch screen liquid crystal display (LCD) that enables a user to interact with a user interface of the computer terminal 10 (or mobile device).

[0041] According to an embodiment of the present application, an embodiment of a method for identifying an execution statement is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0042] Figure 2 is a flowchart of a method for identifying an execution statement according to an embodiment of the present application, such as Figure 2 As shown, the method comprises the following steps:

[0043] Step S202, obtaining a statement to be predicted and executed;

[0044] For different statements to be predicted and executed, the encoding method can be used repeatedly to provide results for providing input to the neural network.

[0045] Step S204, inputting the statement to be predicted into the neural network model for prediction, and obtaining the execution time of the statement to be predicted;

[0046] Step S206, comparing the execution time with the preset time;

[0047] Step S208 , determining whether the statement to be predicted is a target statement according to the comparison result.

[0048] Through the above steps, a neural network model is constructed to predict the execution time of SQL statements, thereby achieving the purpose of identifying slow SQL statements, thereby achieving the technical effects of defining slow SQL scenarios in different situations, accurately identifying slow SQL scenarios, and improving the operation and maintenance capabilities of the database.

[0049] According to an optional embodiment of the present application, before executing step S204 to input the execution statement to be predicted into the neural network model for prediction, the method also includes: obtaining information of multiple historical execution statements, wherein the information includes: multiple historical execution statements and execution durations of multiple historical execution statements; constructing multiple target matrices based on the information; inputting the multiple target matrices and the execution durations of the multiple historical execution statements into the neural network model for training to obtain a trained neural network model.

[0050] First, the information of historical execution statements is obtained from the full query history of the database, including historical execution statements and their execution time. Then, multiple target matrices are constructed based on the information, and the final matrix obtained is used as input, and the time is used as a label to input the neural network model training to obtain a trained neural network model.

[0051] The matrix is ​​used as the input of the neural network, with time as the output label. The prediction effect is better than other encoding methods, and the time accuracy is higher. The neural network can fully extract the encoding features and more accurately predict the execution time of SQL.

[0052] According to another optional embodiment of the present application, multiple target matrices are constructed based on information, including: obtaining execution plan information of historical execution statements, and constructing the execution plan information into a first matrix; converting the historical execution statements into a tree structure, and constructing a second matrix based on the tree structure; merging the first matrix and the second matrix into a target matrix.

[0053] Optionally, the execution plan information is the explain result, the first matrix is ​​an 8*N matrix, and the second matrix is ​​an M*8 matrix. The explain result is used to analyze the execution process and efficiency of a certain SQL statement, that is, the execution plan information. First, obtain the explain result of the statement and construct an 8*N matrix; then convert the SQL statement into a parse tree and construct an M*8 matrix, and finally merge the two matrices to obtain an (M+N)*8 matrix. The schematic diagram of this step is as follows Figure 3 shown.

[0054] Get the explain results and time of historical execution statements from the database historical query records. For example, the statement select offer_id from offer where offer_name = 'void' has a query time of 0.025s. The explain results of the statement are as shown in the following table.

[0055]

[0056] By adding the explain keyword before the database execution statement, the explain result is obtained. The result reflects the specific details of the SQL statement execution, and the result is a table with 10 columns, namely id, select_type, table, type, possible_keys, key, key_len, ref, rows, and Extra. The execution statement in the original data is constructed as an SQL parsing tree. For example, the statement: select offer_id from offer where offer_name='void', where select, from, where are all keywords in SQL, offer is the source table, offer_name, 'void' are the conditions, and offer_id is the query column, which can be constructed as a tree, such as Figure 4 shown.

[0057] The first row of the matrix is ​​the binary result of the weight value of the id. The weight value is calculated by multiplying all id values ​​by the number of id values ​​(expressed as Cnt(id)), and then the final sum, that is:

[0058]

[0059] The second line is the result of the select_type encoding, which is encoded in one-hot bit value correspondence, as shown in the following table:

[0060]

[0061] The third line is type, and the encoding method is similar to select_type, see the following table:

[0062] ALL index range ref eq_ref const system NULL 1 1 1 1 1 1 1 1

[0063] The fourth line is the binary result of the number of possible_keys types, with the same index being one type;

[0064] The fifth row is the total number of key types, the method is the same as the fourth row;

[0065] The sixth line is the binary result of the sum of the index bytes, that is, (Sum(key_len)) B ;

[0066] The seventh line is the binary result of the sum of the ref types;

[0067] The eighth row is the binary result of the sum of all rows values.

[0068] After the above steps, the final matrix is:

[0069]

[0070] According to another optional embodiment of the present application, the historical execution statements are converted into a tree structure, and a second matrix is ​​constructed based on the tree structure, including: converting the historical execution statements into a tree structure; traversing the tree structure according to a pre-order traversal algorithm to generate a result set; and constructing a second matrix based on the result set.

[0071] SQL parse tree uses syntax analysis to parse SQL statements into a syntax tree, and then converts SQL statements into executable statements on SqlServer according to the syntax conversion rules to achieve conversion between different database platforms. The pre-order traversal algorithm is a type of binary tree traversal, which first visits the root node, then traverses the left subtree, and finally traverses the right subtree.

[0072] Construct the historical execution statements into a SQL parse tree, perform a pre-order traversal on the tree, and then reconstruct it into an M*8 matrix according to the specified bit results after the traversal. Constructing SQL statements into a SQL parse tree is a step in SQL compilation in the implementation of the database system. This step converts the SQL statement into a tree with a certain structure. Performing a pre-order traversal on the tree can generate a result set, and then constructing the result set into an M*8 matrix in a certain way. The construction method is as follows:

[0073] The first column takes the operation type specification bit of the basic action, such as query, create, delete, etc. The corresponding relationship between the operation type and the bit number is as follows:

[0074] query create update delete 1 1 1 1

[0075] The second column is the binary number of all keywords. The same category cannot be combined into one;

[0076] The third column is the binary result of selList and;

[0077] The fourth column is the binary result of fromList and;

[0078] The fifth column is the column name type and the binary result summed for conditional judgment;

[0079] The sixth column is the number of conditions used for conditional judgment, such as the number of conditions greater than, less than, and equal to. The same category cannot be combined into one;

[0080] The seventh column is the number of specific judgment values ​​used for the condition, such as the judgment value for the column name after the where keyword;

[0081] The eighth column is the number of all elements in the result set.

[0082] For example, perform a pre-order traversal on the tree obtained above to form a result set: {query, select, selList: 1, attribute, offer_id, from, fromList: 1, relation, offer, where, equals, attribute, name, '=', attribute_literal, 'invalid'}, and then the matrix is ​​constructed as follows:

[0083] The first column takes the operation type specified bit of the basic action in the result set, and the binary result is the first column. In the above example, query is 1. The corresponding relationship between the operation type and the bit number is shown in the following table:

[0084] query create update delete 1 1 1 1

[0085] The second column is the binary number of all keywords in the result set. The above result is select, from, where.

[0086] The third column is the binary result of selList and in the result set, which is 1 above;

[0087] The fourth column is the binary result of fromList and in the result set, which is 1 above;

[0088] The fifth column is the binary result of the sum of the column names used for conditional judgment in the result set. There is only one offer_name, so it is 1;

[0089] The sixth column is the number of conditions used for conditional judgment in the result set, such as the number of conditions greater than, less than, and equal to. The same category cannot be combined into one. The above is '=', so it is 1;

[0090] The seventh column is the number of specific judgment values ​​used for the condition in the result set, such as the judgment value of the column name after the where keyword. There is only one "invalid" in the above, so it is 1;

[0091] The eighth column is the number of all elements in the result set, which is 16 in the above example.

[0092] After the above steps, the final matrix is:

[0093]

[0094] In some optional embodiments of the present application, the first matrix and the second matrix are combined into a target matrix, including: transposing the first matrix to obtain a third matrix; and concatenating the second matrix and the third matrix to obtain the target matrix.

[0095] The N*8 matrix and the M*8 matrix obtained above are combined, and the N*8 matrix is ​​transposed and then concatenated with the M*8 matrix to finally obtain the matrix (M+N)*8, which is the final input matrix. This matrix can be used as the input layer result, and the corresponding running time is used as the label, which can be input into the neural network model for training.

[0096] In other optional embodiments of the present application, multiple target matrices and the execution time of multiple historical execution statements are input into a neural network model for training to obtain a trained neural network model, including: randomly combining multiple target matrices according to preset proportions to obtain a training set and a test set; inputting the training set and the test set into the neural network model for prediction to obtain a trained neural network model.

[0097] By repeating the above steps, a large number of target matrix data sets can be obtained. After random shuffling, they can be used as training sets and test sets in a certain proportion, and continuously input into neural network training to obtain a trained neural network model, such as Figure 5 As shown. Then input the execution statement to be predicted, the running time can be output, and the prediction of the execution time of the SQL statement can be completed. The structure of the input layer, hidden layer, and output layer of the neural network model can be adjusted by itself, and the corresponding activation function is selected for the hidden layer and the output layer.

[0098] According to an optional embodiment of the present application, step S208 is executed to determine whether the statement to be predicted is a target execution statement based on the comparison result, including: when the execution time of the statement to be predicted is greater than or equal to a preset time, determining the statement to be predicted as a target execution statement; when the execution time of the statement to be predicted is less than the preset time, determining that the statement to be predicted is not a target execution statement.

[0099] Compare the obtained results with the defined slow SQL threshold to complete the slow SQL identification.

[0100] The execution statement recognition method used in this application can use the mean square error (MSE) of the final result as an evaluation indicator to compare the effects under 5 example sentences. The comparison with the use of ordinary single explain result encoding, single syntax tree encoding, and other solutions is as follows:

[0101]

[0102] It can be seen that compared with other single or traditional encoding methods, this application has a more accurate prediction effect and can more accurately identify slow SQL scenarios.

[0103] The present invention is a method that uses a combined coding technology to predict and then identify slow SQL statements in a database. The accuracy of identifying slow SQL can be improved by predicting the neural network input data of the SQL statement execution time. The present application is based on a neural network and uses a combined coding method to predict and identify slow SQL statements. It has made innovations in the coding method before prediction to directly predict whether the execution time of an SQL statement is greater than a certain limit value. The present application does not require a slow SQL sample, and starts the prediction from the most intuitive time perspective, which more effectively improves the accuracy of slow SQL prediction; compared with traditional comparative identification methods, it has certain scalability and can define slow SQL scenarios under different circumstances; a combined coding method is used in coding, and when used for a neural network, the results obtained are more accurate and closer to the true value; starting from the statement execution time dimension, it is more intuitive and easier to judge than other feature methods.

[0104] Figure 6is a structural block diagram of an execution statement recognition device according to the present application, such as Figure 6 As shown, the device comprises:

[0105] An acquisition module 60 is used to acquire a statement to be predicted and executed;

[0106] A prediction module 62, used for inputting the execution statement to be predicted into the neural network model for prediction, and obtaining the execution time of the execution statement to be predicted;

[0107] A comparison module 64, used for comparing the execution time with a preset time;

[0108] The determination module 66 is used to determine whether the statement to be predicted is a target statement according to the comparison result.

[0109] Compared with other single or traditional coding methods, the combined coding method of this application has a more accurate prediction effect. It starts with the most intuitive time perspective, more effectively improves the accuracy of slow SQL recognition, and can more accurately identify slow SQL scenarios to improve database operation and maintenance efficiency. This application can be added to the current management method of database system operation and maintenance to accurately identify slow SQL in advance, reduce the probability of database failure, and improve operation and maintenance capabilities; it can also be combined with an early warning system to block the execution of a large number of slow SQL statements by means of alarms before the slow SQL statements are executed.

[0110] It should be noted that Figure 6 The preferred implementation of the illustrated embodiment can be found in Figure 2 The relevant description of the illustrated embodiment will not be repeated here.

[0111] According to another aspect of the embodiment of the present application, a non-volatile storage medium is provided, the non-volatile storage medium including a stored program, wherein when the program is running, a method for identifying the execution statement of the above-mentioned device where the non-volatile storage medium is located is controlled to execute.

[0112] The above-mentioned non-volatile storage medium is used to store a program that performs the following functions: obtain a statement to be predicted and executed; input the statement to be predicted and executed into a neural network model for prediction to obtain the execution time of the statement to be predicted and executed; compare the execution time with the preset time; and determine whether the statement to be predicted and executed is a target execution statement based on the comparison result.

[0113] An embodiment of the present application further provides a processor, which is used to run a program stored in a memory, wherein the above execution statement recognition method is executed when the program is running.

[0114] The above-mentioned processor is used to run a program that performs the following functions: obtain the statement to be predicted; input the statement to be predicted into the neural network model for prediction to obtain the execution time of the statement to be predicted; compare the execution time with the preset time; and determine whether the statement to be predicted is the target execution statement based on the comparison result.

[0115] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0116] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0117] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units can be a logical function division. There may be other division methods in actual implementation. For example, 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 units or modules, which can be electrical or other forms.

[0118] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0119] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0120] 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 relevant technology 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 several instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk, etc. Various media that can store program codes.

[0121] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A method for identifying an execution statement, characterized in that: include: Get the statement to be predicted and executed; Inputting the statement to be predicted into a neural network model for prediction to obtain the execution time of the statement to be predicted; Comparing the execution time with a preset time; Determining whether the statement to be predicted and executed is a target execution statement according to the comparison result; Before inputting the execution statement to be predicted into the neural network model for prediction, the method further includes: obtaining information of multiple historical execution statements, wherein the information includes: the multiple historical execution statements and the execution durations of the multiple historical execution statements; constructing multiple target matrices according to the information; inputting the multiple target matrices and the execution durations of the multiple historical execution statements into the neural network model for training to obtain a trained neural network model; Constructing multiple target matrices according to the information, including: obtaining execution plan information of the historical execution statements, and constructing the execution plan information into a first matrix; converting the historical execution statements into a tree structure, and constructing a second matrix according to the tree structure; merging the first matrix and the second matrix into the target matrix.

2. The method according to claim 1, characterized in that: Converting the historical execution statements into a tree structure, and constructing a second matrix according to the tree structure, including: Converting the historical execution statements into the tree structure; Traverse the tree structure according to a pre-order traversal algorithm to generate a result set; The second matrix is ​​constructed according to the result set.

3. The method according to claim 1, characterized in that: Combining the first matrix and the second matrix into the target matrix includes: Transpose the first matrix to obtain a third matrix; The second matrix and the third matrix are concatenated to obtain the target matrix.

4. The method according to claim 1, characterized in that: Inputting the plurality of target matrices and the execution durations of the plurality of historical execution statements into a neural network model for training to obtain a trained neural network model, including: Randomly combining the multiple target matrices according to a preset ratio to obtain a training set and a test set; The training set and the test set are input into the neural network model for prediction to obtain a trained neural network model.

5. The method according to claim 1, characterized in that Determining whether the statement to be predicted and executed is a target statement to be executed according to the comparison result includes: When the execution time of the statement to be predicted is greater than or equal to the preset time, determining the statement to be predicted as the target execution statement; When the execution time of the statement to be predicted is less than the preset time, it is determined that the statement to be predicted is not the target execution statement.

6. A device for identifying an execution statement, characterized in that: include: An acquisition module, used for acquiring statements to be predicted and executed; A prediction module, used for inputting the statement to be predicted into a neural network model for prediction, and obtaining the execution time of the statement to be predicted; A comparison module, used for comparing the execution time with a preset time; A determination module, used to determine whether the statement to be predicted is a target statement according to the comparison result; The execution statement recognition device is also used to perform the following steps before inputting the execution statement to be predicted into the neural network model for prediction: obtaining information of multiple historical execution statements, wherein the information includes: the multiple historical execution statements and the execution durations of the multiple historical execution statements; constructing multiple target matrices according to the information; inputting the multiple target matrices and the execution durations of the multiple historical execution statements into the neural network model for training to obtain a trained neural network model; The execution statement recognition device is also used to perform the following steps: obtain the execution plan information of the historical execution statement, and construct the execution plan information into a first matrix; convert the historical execution statement into a tree structure, and construct a second matrix based on the tree structure; merge the first matrix and the second matrix into the target matrix.

7. A non-volatile storage medium, characterized in that: The non-volatile storage medium includes a stored program, wherein when the program is running, the device where the non-volatile storage medium is located is controlled to execute the method for identifying execution statements according to any one of claims 1 to 5.

8. A processor, characterized in that: The processor is used to run a program stored in a memory, wherein the program executes the method for identifying an execution statement according to any one of claims 1 to 5 when running.

Citation Information

Patent Citations

  • SQL risk identification method, device and equipment

    CN112784273A

  • Query classification and processing using neural network based machine learning

    US20210224275A1