Method, device and equipment for analyzing slow query statement and storage medium

By obtaining and encoding slow query and database indicators, extracting and fusing features, and analyzing slow query statements, the problems of low and incomplete analysis in the existing technology are solved, and more accurate and efficient slow query analysis is achieved.

CN120123358APending Publication Date: 2025-06-10WEBANK (CHINA)
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510186875.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-20
Publication Date
2025-06-10

AI Technical Summary

Technical Problem

When facing slow queries, the analysis is inefficient and incomplete, and the reasons for slow queries cannot be quickly discovered and located, and the reliance on indicators in the slow queries log results in incomplete analysis.

Method used

By obtaining the slow query indicators and database indicators of the slow query statement, encoding is obtained, low-order and high-order features are extracted, and they are fused into fusion features. The slow query statement is analyzed by fusion features.

Benefits of technology

It improves the efficiency and comprehensiveness of slow query analysis, can more accurately determine the high risk level of slow query, and provides more reasonable optimization solutions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120123358A_ABST
    Figure CN120123358A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a method, device and equipment for analyzing a slow query statement and a storage medium, and relates to the technical field of artificial intelligence. The method comprises the steps that a slow query index of the slow query statement and a database index corresponding to the slow query statement are obtained; respectively encoding the slow query index and the database index to obtain encoding features; extracting a low-order feature and a high-order feature from the coding feature, and splicing the low-order feature and the high-order feature into a fusion feature; and analyzing the slow query statement through the fusion feature. When the slow query statement is analyzed, not only is the slow query index of the slow query statement obtained, but also the database index of the slow query statement is correspondingly obtained, so that the accuracy and comprehensiveness of slow query high-risk degree analysis are improved; the high-risk degree of the slow query statement is determined by fusing the features, and then the slow query statement is analyzed, so that determination and analysis of the high-risk degree of slow query are more rigorous.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a method, device, equipment and storage medium for analyzing slow query statements. Background Art

[0002] Slow queries refer to database statement queries that exceed the specified time, which have a significant impact on system response and database resources. Under the distributed loosely coupled financial IT architecture, the system response timeliness requirements are getting higher and higher, and the business processing logic complexity is also getting higher and higher, involving multiple database queries and insert and update operations. Therefore, the execution efficiency requirements for database statements are also getting higher and higher. When a slow query occurs in a database statement, analyzing the cause of the slow query as soon as possible and proposing an optimization plan become the key to improving the execution efficiency of database statements.

[0003] Currently, when analyzing slow queries, we collect slow query logs based on monitoring plug-ins, and then analyze them manually and use expert experience to make optimization suggestions for slow queries. However, the quality and standards of manual analysis vary, and when faced with massive database statement slow queries, it cannot meet the requirements of rapid discovery and location. At the same time, when analyzing slow queries, we only rely on slow query indicators in slow query logs, which leads to incomplete slow query analysis. Summary of the invention

[0004] Embodiments of the present invention provide a method, apparatus, device and storage medium for analyzing slow query statements, which are used to improve the efficiency and comprehensiveness of slow query analysis.

[0005] In a first aspect, an embodiment of the present application provides a method for analyzing a slow query statement, including:

[0006] Obtaining a slow query index of a slow query statement and a database index corresponding to the slow query statement;

[0007] Encoding the slow query index and the database index respectively to obtain encoding features;

[0008] Extracting low-order features and high-order features from the coding features respectively, and concatenating the low-order features and the high-order features into fused features;

[0009] The slow query statement is analyzed by using the fusion feature.

[0010] In an embodiment of the present application, when analyzing a slow query statement, not only the slow query index of the slow query statement is obtained, but also the database index of the slow query statement is correspondingly obtained, thereby improving the accuracy and comprehensiveness of the high-risk analysis of the slow query; the slow query index and the database index are encoded to obtain encoding features, and high-order features and low-order features are respectively extracted from the encoding features, and then the high-order features and the low-order features are fused to obtain fused features. The high-risk degree of the slow query statement is determined by the fused features and then the slow query statement is analyzed, so that the determination and analysis of the high-risk degree of the slow query are more rigorous, and the efficiency of the slow query statement analysis is improved.

[0011] Optionally, the coding feature includes an original coding feature and an embedded layer coding feature, and the embedded layer coding feature is obtained by using an embedded layer weight matrix and the original coding feature;

[0012] Extracting low-order features and high-order features from the coding features respectively includes:

[0013] Extracting first-order features from the original coding features and extracting second-order features from the embedded layer coding features through a low-order feature extraction model; the second-order features represent the relationship between any two first-order features;

[0014] High-order features are extracted from the embedding layer encoding features through a high-order feature extraction model.

[0015] In an embodiment of the present application, the coding features are divided into high-order features and low-order features, and feature extraction is performed separately to make the feature extraction more accurate. Since the dimensions of high-order features and low-order features are different, the problem of inaccurate feature extraction caused by using the same model to extract high-order features and low-order features can be avoided.

[0016] Optionally, the original coding feature is obtained by:

[0017] According to the variable type of each indicator in the slow query indicator and the database indicator, the slow query indicator and the database indicator are respectively encoded to obtain original encoding features; wherein, one-hot encoding is performed on discrete variables, continuous variables are encoded according to their own value method, and time series variables are encoded according to the time series flattening method.

[0018] In the embodiment of the present application, the variable types in the slow query index and the database index are classified, and then different encoding methods are performed for different variable types, so that different variable types are encoded according to different indicator domains, which reduces the difficulty of encoding and improves the efficiency of encoding. At the same time, the present application learns the characteristic expression of discrete variables, continuous variables and time series variables, and enhances the generalization ability of the subsequent high-risk prediction model.

[0019] Optionally, the embedding layer coding feature is obtained by:

[0020] According to the encoded slow query index and database index, construct an eigenvalue matrix and a feature index matrix; the feature index matrix is ​​used to indicate feature dimensions with eigenvalues; the eigenvalue matrix is ​​used to indicate eigenvalues ​​corresponding to the feature index matrix;

[0021] Obtaining a latent vector from an embedding layer weight matrix according to the feature index matrix;

[0022] According to the latent vector and the eigenvalue matrix, an embedding layer encoding feature is obtained.

[0023] In an embodiment of the present application, the encoded slow query index and database index are combined to construct an eigenvalue matrix and a feature index matrix, and then the eigenvalue matrix is ​​reduced in dimension according to the feature index matrix to convert the high-dimensional sparse matrix into a low-dimensional dense matrix, thereby facilitating the subsequent analysis of the high-risk level of the slow query statement and improving the analysis efficiency of the slow query statement.

[0024] Optionally, the low-order feature extraction model is obtained by the following method, including:

[0025] Constructing a first-order equation for each feature dimension, and obtaining a weight value of each feature dimension in the first-order equation through each sample, thereby obtaining a first-order feature sub-extraction model;

[0026] A second-order equation for any two feature dimensions is constructed, and the weight value between any two feature dimensions in the second-order equation is obtained through each sample, thereby obtaining a second-order feature sub-extraction model; wherein the weight value between any two feature dimensions is represented by a latent vector in the embedding layer weight matrix.

[0027] In the embodiment of the present application, the weight value between two feature dimensions is represented by the latent vector in the embedding layer weight matrix, thereby avoiding the problem of difficulty in obtaining the weight value between two feature dimensions.

[0028] Optionally, analyzing the slow query statement by using the fusion feature includes:

[0029] Passing the fused features through at least one layer of gated recurrent units to determine the high-risk level of the slow query statement;

[0030] For slow query statements whose high risk meets the set conditions, the optimization plan is determined through the large language model.

[0031] In the embodiment of the present application, the long short-term memory neural network results are optimized by a gated recurrent unit, avoiding the problem of gradient vanishing that easily occurs when the feature vector is very small or very large. The gated recurrent unit is used to control whether the input feature affects the state at each moment, complete the transmission, reset and update of information, and effectively avoid the problems of gradient explosion and gradient vanishing.

[0032] Optionally, determining an optimization solution for a slow query statement whose high risk meets a set condition through a large language model includes:

[0033] Acquire auxiliary data of a slow query statement whose high risk meets a set condition, wherein the auxiliary data includes one or more of the slow query index, the database index, the execution plan index of the slow query statement, and data table information involved in the slow query statement;

[0034] Determine a prompt word corresponding to an analysis direction, where the analysis direction includes one or more of syntax analysis, execution plan analysis, and database performance analysis;

[0035] The auxiliary data and the prompt words corresponding to the analysis direction are input into the large language model to obtain an optimization solution.

[0036] In the embodiment of the present application, the slow query statements are analyzed through auxiliary data and multiple dimensions, so that the large language model can better learn how to analyze the slow query statements and propose a more reasonable optimization solution.

[0037] Optionally, the prompt words corresponding to the grammatical analysis include one or more of connection operation problems, nested query and subquery problems, and paging offset problems;

[0038] The prompt words corresponding to the execution plan analysis include one or more of the following: index validity problem, excessive amount of scanned data problem, excessive execution statement lock problem, sorting and grouping problem;

[0039] The prompt words corresponding to the database performance analysis include one or more of database performance bottleneck problems and problems passively generated by slow queries.

[0040] In the embodiment of the present application, by analyzing multiple dimensions corresponding to the slow query statement, different prompt words can be designed for different dimensions, so that the analysis of the slow query statement is more detailed and the efficiency of the slow query statement analysis is improved.

[0041] Optionally, the prompt words corresponding to the database performance analysis include one or more of database performance bottleneck problems and slow query passively generated problems, including:

[0042] Based on the database index corresponding to the time when the slow query statement appears and the jump time of the database performance, it is determined whether the slow query statement is passively generated.

[0043] In the embodiment of the present application, through the database indicators and the jump time of the database performance, it can be determined whether the slow query statement is actively generated by itself or is passively caused by the change of database performance, thereby improving the analysis of slow query statements and accurately making optimization suggestions.

[0044] In a second aspect, an embodiment of the present application provides a device for analyzing a slow query statement, including:

[0045] An acquisition module, used to acquire a slow query index of a slow query statement and a database index corresponding to the slow query statement;

[0046] An encoding module, used to encode the slow query index and the database index respectively to obtain encoding features;

[0047] A fusion module, used to extract low-order features and high-order features from the coding features respectively, and splice the low-order features and the high-order features into fused features;

[0048] An analysis module is used to analyze the slow query statement through the fusion feature.

[0049] Optionally, the coding feature includes an original coding feature and an embedded layer coding feature, and the embedded layer coding feature is obtained by using an embedded layer weight matrix and the original coding feature;

[0050] The fusion module is specifically used for:

[0051] Extracting first-order features from the original coding features and extracting second-order features from the embedded layer coding features through a low-order feature extraction model; the second-order features represent the relationship between any two first-order features;

[0052] High-order features are extracted from the embedding layer encoding features through a high-order feature extraction model.

[0053] Optionally, the encoding module is specifically used for:

[0054] According to the variable type of each indicator in the slow query indicator and the database indicator, the slow query indicator and the database indicator are respectively encoded to obtain original encoding features; wherein, one-hot encoding is performed on discrete variables, continuous variables are encoded according to their own value method, and time series variables are encoded according to the time series flattening method.

[0055] Optionally, the encoding module is specifically used for:

[0056] According to the encoded slow query index and database index, construct an eigenvalue matrix and a feature index matrix; the feature index matrix is ​​used to indicate feature dimensions with eigenvalues; the eigenvalue matrix is ​​used to indicate eigenvalues ​​corresponding to the feature index matrix;

[0057] Obtaining a latent vector from an embedding layer weight matrix according to the feature index matrix;

[0058] According to the latent vector and the eigenvalue matrix, an embedding layer encoding feature is obtained.

[0059] Optionally, the fusion module is specifically used for:

[0060] Constructing a first-order equation for each feature dimension, and obtaining a weight value of each feature dimension in the first-order equation through each sample, thereby obtaining a first-order feature sub-extraction model;

[0061] A second-order equation for any two feature dimensions is constructed, and the weight value between any two feature dimensions in the second-order equation is obtained through each sample, thereby obtaining a second-order feature sub-extraction model; wherein the weight value between any two feature dimensions is represented by a latent vector in the embedding layer weight matrix.

[0062] Optionally, the analysis module is specifically used for:

[0063] Passing the fused features through at least one layer of gated recurrent units to determine the high-risk level of the slow query statement;

[0064] For slow query statements whose high risk meets the set conditions, the optimization plan is determined through the large language model.

[0065] Optionally, the analysis module is specifically used for:

[0066] Acquire auxiliary data of a slow query statement whose high risk meets a set condition, wherein the auxiliary data includes one or more of the slow query indicator, the database indicator, the execution plan indicator of the slow query statement, and data table information involved in the slow query statement;

[0067] Determine a prompt word corresponding to an analysis direction, where the analysis direction includes one or more of syntax analysis, execution plan analysis, and database performance analysis;

[0068] The auxiliary data and the prompt words corresponding to the analysis direction are input into the large language model to obtain an optimization solution.

[0069] Optionally, the prompt words corresponding to the grammatical analysis include one or more of connection operation problems, nested query and subquery problems, and paging offset problems;

[0070] The prompt words corresponding to the execution plan analysis include one or more of the following: index validity problem, excessive amount of scanned data problem, excessive execution statement lock problem, sorting and grouping problem;

[0071] The prompt words corresponding to the database performance analysis include one or more of database performance bottleneck problems and problems passively generated by slow queries.

[0072] In a third aspect, an embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of any of the above-mentioned methods when executing the program.

[0073] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium storing a computer program executable by a computer device, wherein when the program is run on the computer device, the computer device executes the steps of any of the above-described methods.

[0074] In a fifth aspect, the present application provides a computer program product, which, when executed on a computer, enables the computer to execute the methods of the various embodiments of the first aspect described above.

[0075] In an embodiment of the present application, when analyzing a slow query statement, not only the slow query index of the slow query statement is obtained, but also the database index of the slow query statement is correspondingly obtained, thereby improving the accuracy and comprehensiveness of the high-risk analysis of the slow query; the slow query index and the database index are encoded to obtain encoding features, and high-order features and low-order features are respectively extracted from the encoding features, and then the high-order features and the low-order features are fused to obtain fused features. The high-risk degree of the slow query statement is determined by the fused features and then the slow query statement is analyzed, so that the determination and analysis of the high-risk degree of the slow query are more rigorous, and the efficiency of the slow query statement analysis is improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0076] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0077] Figure 1 A system architecture diagram provided for an embodiment of the present application;

[0078] Figure 2 A flowchart of a method for analyzing slow query statements provided in an embodiment of the present application;

[0079] Figure 3A schematic diagram of the structure of DeepFM provided in an embodiment of the present application;

[0080] Figure 4 A schematic diagram of a feature mapping structure provided in an embodiment of the present application;

[0081] Figure 5 A schematic diagram of a flow chart of a method for encoding embedded layer features provided in an embodiment of the present application;

[0082] Figure 6 A schematic diagram of a flow chart of a matrix method for constructing an embedding layer feature encoding provided in an embodiment of the present application;

[0083] Figure 7 A flowchart of a low-order feature extraction model training method provided in an embodiment of the present application;

[0084] Figure 8 A schematic diagram of a network structure controlled by a gate function structure provided in an embodiment of the present application;

[0085] Fig. 9 A flowchart of a method for optimizing slow query statements using a large language model provided in an embodiment of the present application;

[0086] Fig.10 An auxiliary data information diagram provided in an embodiment of the present application;

[0087] Fig.11 A schematic diagram of the structure of the prompt word design dimensions provided in the embodiment of the present application;

[0088] Fig.12 A schematic diagram of the structure of a high-risk slow query statement optimization solution provided in an embodiment of the present application;

[0089] Fig.13 A schematic diagram of the structure of a device for analyzing slow query statements provided in an embodiment of the present application;

[0090] Fig.14 A computer device is provided in an embodiment of the present application. DETAILED DESCRIPTION

[0091] In order to make the purpose, technical solution and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0092] For ease of understanding, the terms involved in the embodiments of the present invention are explained below.

[0093] Slow queries refer to database statement queries that exceed the specified time and have a significant impact on application response and database resources.

[0094] DeepFM: A hybrid recommendation algorithm that combines factorization machines (FM) and deep learning models (such as Deep Neural Networks) to capture high-order and low-order feature interactions. The FM algorithm is responsible for extracting first-order features and second-order features formed by the combination of first-order features, while the DNN algorithm is responsible for extracting high-order features formed by fully connecting the input first-order features. The DeepFM algorithm can effectively extract the fusion features of slow query log indicators and database indicators.

[0095] To facilitate understanding of this solution, the application scenario of this solution is introduced below.

[0096] Under the existing distributed loosely coupled financial IT architecture, the system's response timeliness affects the business process and user experience. In the common financial loan and repayment query transaction processing, the business logic complexity is high. The longer the business processing process, the more operations on database statements (such as query, update and delete) are involved. The execution efficiency of database statements affects the response time and interface throughput of the financial system, and is related to the overall stability and maintainability of the financial system. When slow queries occur in the database statements of the financial system, rapid analysis, hierarchical management and optimization recommendations for slow query statements can improve the execution efficiency of database statements. At present, on the one hand, for the analysis of slow query statements, slow query log collection is usually completed based on monitoring plug-ins, and the slow query indicators of various database statements are analyzed. The operation and maintenance personnel perform manual analysis and use expert experience to make optimization suggestions. However, when faced with massive database statements and slow query indicators, manual analysis leads to low analysis efficiency and prone to errors. At the same time, manual analysis faces inconsistent standards and cannot meet the operation and maintenance requirements of rapid discovery and positioning. On the other hand, there is no complete system for hierarchical management and optimization recommendations for slow query statements. Therefore, in the alarm storm caused by abnormal database load due to slow queries, it is impossible to quickly analyze and solve high-risk slow query statements and provide optimization suggestions for high-risk slow query statements. The specific operating steps of the embodiment of the present application are described in detail below:

[0097] First, when analyzing a slow query statement, the embodiment of the present application not only obtains the slow query index of the slow query statement, but also obtains the database index corresponding to the slow query statement. Then, the obtained slow query index and database index are encoded to obtain a coding feature, wherein, when encoding the slow query index and the database index, the variable types in the slow query index and the database index are encoded according to discrete variables, continuous variables and time series variables, respectively, and merged for index sorting. The coding features are then divided into original coding features and embedded layer coding features. The embedded layer coding features are obtained through the embedded layer weight matrix and the original coding features. The first-order features are extracted through the original coding features, and the second-order features and high-order features are extracted through the embedded layer coding features. The first-order features, the second-order features and the high-order features are fused to obtain fused features. The fused features are input into at least one layer of gated recurrent units to determine the high-risk coefficient of the slow query statement. Finally, the high-risk slow query statements that meet the set conditions are input into the trained large language model to obtain the optimization plan for the high-risk slow query statements. When the large language model is trained, it is based on the slow query indicators, database indicators, execution plan indicators, and data table information involved in the slow query statements as auxiliary data, and is trained in three analysis directions: syntax analysis, execution plan analysis, and database performance analysis. The auxiliary data and the three analysis directions are input into the large language model to obtain the optimization plan for the slow query statements. At the same time, according to the time series judgment of the database performance indicators, it can also be distinguished whether the slow query statements are actively generated or passively caused by changes in database performance.

[0098] See also Figure 1 , is a system architecture diagram provided in an embodiment of the present application, the system architecture includes a terminal device 101 and a server 102.

[0099] The terminal device 101 is pre-installed with a service application for text matching, wherein the service application is a client application, a web application, a small program application, etc. The terminal device 101 can be a smart phone, a POS machine, a desktop notebook, a computer, etc., but is not limited thereto.

[0100] Server 102 is the backend server for business applications. Server 102 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be 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, content delivery networks (CDNs), as well as big data and artificial intelligence platforms.

[0101] See also Figure 2, is a flow chart of a method for analyzing slow query statements provided in an embodiment of the present application, comprising the following steps:

[0102] Step 201: Obtain a slow query index of a slow query statement and a database index corresponding to the slow query statement.

[0103] Specifically, for different application scenarios, and different application systems or application software, the discrimination of slow query statements is also different. The database statements whose execution time exceeds the preset threshold are pre-set as slow query statements. The preset threshold of the time is set to 1s in the embodiment of the present application. The database statements whose execution time exceeds 1s are obtained from the database as slow query statements, and the slow query statements are written into the log file. The slow query statements are parsed to obtain slow query indicators. The slow query indicators can be used to describe the execution time, processing time and number of scanned rows of slow query statements. There are many slow query indicators with high dimensions and sparseness. Table 1 is an example of slow query indicators, slow query indicator meanings and slow query indicator values ​​collected by the embodiment of the present application. The preset threshold of slow query and the collection of slow query indicators can be determined according to the situation, and the embodiment of the present application does not make specific restrictions.

[0104]

[0105] Table 1

[0106] Table 1 explains the meaning of the slow query indicator name. Taking the slow query indicator name "first execution times" as an example, when the same type of slow query statements appear but query different contents, the first occurrence of the same type of query statements is 6 times. For example, "select name from table A" and "select ID from table A" are the same type of slow query statements and both appear for the first time, but they are for "name" and "ID" respectively, so the cumulative number is 2.

[0107] When analyzing slow query statements, in addition to analyzing the slow query indicators of slow query statements, it is also necessary to consider the impact of database overload on slow query statements. Therefore, the embodiment of the present application is based on the database gateway operation log and the host performance data bypass collection to obtain database indicators, which can be used to analyze the changes in database performance before and after the slow query statement is generated, so as to determine whether the slow query statement is actively generated or passively caused. The database indicators are mainly time series indicators. The embodiment of the present application records the database indicators 15 minutes before and after the slow query statement is generated through an array. The specific indicators are shown in Table 2. The collection of database indicators can be determined according to the circumstances, and the embodiment of the present application does not make specific limitations.

[0108]

[0109] Table 2

[0110] Step 202: Encode the slow query index and the database index respectively to obtain encoding features.

[0111] Specifically, since the generation of slow query statements is jointly determined by multiple slow query indicators and database indicators, the embodiment of the present application uniformly encodes the slow query indicators and database indicators to obtain encoding features. The encoding features reflect the co-occurrence relationship between various indicators, thereby improving the accuracy of slow query statement analysis.

[0112] Before encoding the slow query index and the database index, preprocess the index data for each index. The collected slow query index and database index are raw data. Since the maximum and minimum values ​​of each data in the raw data are unknown and the dimensions are different, in order to improve the subsequent feature extraction, fusion and prediction work, the embodiment of the present application uses a normalization method to preprocess the slow query index and the database index. After normalization, the raw data value is mapped between [0,1] and normalized using formula (1). There are many ways to preprocess the slow query index and the database index, and the embodiment of the present application does not make specific limitations.

[0113]

[0114] Among them, x is the original data, x min is the minimum value of the original data, x max is the maximum value of the original data, x ′ is the normalized data.

[0115] Step 203: extract low-order features and high-order features from the encoding features respectively, and concatenate the low-order features and the high-order features into fused features.

[0116] Specifically, the coding features can extract first-order features, second-order features, third-order features, etc. The embodiment of the present application uses first-order features and second-order features as low-order features, and third-order features and above as high-order features, and then concatenates the low-order features and the high-order features to obtain fused features.

[0117] Step 204: Analyze the slow query statement by integrating features.

[0118] Specifically, by analyzing the slow query statements through fusion features, not only the slow query indicators of the slow query statements are considered, but also the database indicator features are integrated, and the slow query statements are analyzed in combination with the complex situation of the interaction relationship between the slow query indicators and the database indicators, so that the analysis of the slow query statements in the embodiment of the present application is more comprehensive and more accurate.

[0119] In some embodiments, the coding features include original coding features and embedded layer coding features, and the embedded layer coding features are obtained through the embedded layer weight matrix and the original coding features.

[0120] Specifically, the coding features include original coding features and embedded layer coding features. The first-order features are extracted through the original coding features, and the second-order features and high-order features are extracted through the embedded layer coding features. The embedded layer coding features are obtained through the embedded layer weight matrix and the original coding features. The embedded layer weight matrix is ​​composed of the weight value corresponding to each feature assigned to the feature, such as Figure 6 This is shown in the leftmost matrix.

[0121] In some embodiments, extracting low-order features and high-order features from the encoding features respectively includes:

[0122] Through the low-order feature extraction model, first-order features are extracted from the original coding features, and second-order features are extracted from the embedded layer coding features; the second-order features characterize the relationship between any two first-order features; through the high-order feature extraction model, high-order features are extracted from the embedded layer coding features.

[0123] Specifically, low-order features and high-order features are extracted respectively by a low-order feature extraction model and a high-order feature extraction model, wherein the low-order feature model extracts first-order features for the original coding features and extracts second-order features for the embedded layer coding features. The second-order feature is obtained by combining any two first-order features, and the second-order feature can be obtained by multiplying, summing or other operations of any two first-order features.

[0124] The high-order feature extraction model is a deep neural network model, and the embodiment of the present application adopts a deep learning model based on Deep. DeepFM is a hybrid recommendation algorithm that combines a factorization machine (FM) and a deep learning model (such as a Deep neural network), which can be used to capture high-order feature interactions and low-order feature interactions. The FM algorithm is responsible for extracting first-order features and second-order features composed of first-order features in pairs. The DNN algorithm is responsible for extracting high-order features formed by fully connecting the input first-order features. The DeepFM algorithm can effectively extract the cross-features of slow query log observation indicators and various performance indicators of the database.

[0125] The DeepFM module architecture is as follows Figure 3 As shown in the figure, the Deep module and the FM module share the dimension reduction matrix v_i*x_i. The TensorFlow framework is used to build a multi-layer feedforward neural network, and complex fusion features are automatically learned. In the neural network parameter setting, the number of hidden layers is set to 3, and the output layer dimension is consistent with the embedding layer weight matrix. The processing logic is as follows:

[0126] Input layer setting, input = v_i*x_i

[0127] Hidden layer setting, using relu as the activation function of the hidden layer to improve the nonlinear feature extraction and expression capabilities of the model.

[0128] Hiddenlayer=tf.keras.layers.Dense(64,activation='relu',input_shape=(feat ure_size*embedding_size));

[0129] Output layer settings,

[0130] y_deep = tf.keras.layers.Dense(output_shape = embedding_size, activation = 'softmax'), using tanh as the activation function of the output layer, the output range is wider. The deep neural network model can be selected from many other types, and the embodiment of the present application does not make specific limitations.

[0131] In some embodiments, the original coding feature is obtained by:

[0132] According to the variable type of each indicator in the slow query indicator and the database indicator, the slow query indicator and the database indicator are encoded respectively to obtain the original encoding features; among them, one-hot encoding is performed on discrete variables, continuous variables are encoded according to their own value method, and time series variables are encoded according to the time series flattening method.

[0133] Specifically, slow query indicators and database indicators include multiple indicator fields. Each field represents a type of indicator. The variable types involved in the indicators include discrete variables (such as whether the cache is hit, the type of database statement operation), continuous variables (such as the number of executions, the execution time), and time series variables (such as the 30-minute database CPU / IO usage indicator).

[0134] Adapt the corresponding encoding operation according to the field type of the indicator domain. Among them, One-hot encoding is used for discrete variables to construct a binary vector. The vector length depends on the value of the discrete variable, and the feature values ​​are all 0 or 1; for continuous variables, the numerical value itself is directly used to encode the value; DeepFM mainly deals with static or window statistical features. For time series variables, this method is improved by flattening the time series to the original coding sequence, so that the time series variables can participate in joint encoding and perform time series variable feature mining through DeepFM. This method combines discrete, continuous and time series variables to realize multi-dimensional feature encoding of slow query indicators and database indicators, and constitutes a feature map featrue-map, which contains the feature index featrue_index that records the feature position and the feature value featrue_value that records the feature value. As Figure 4 Shown is the feature map featrue-map.

[0135] Figure 4 The construction process is to first classify the variable types of each indicator in the slow query indicator and database indicator into discrete variables, continuous variables and time series variables. Each variable type corresponds to an indicator domain, and then determine the indicator name under each variable type, such as Figure 4 The discrete variables include the following indicator names: whether the index is hit, database statement type, the continuous variables include the indicator name: the number of rows in the data table, and the time series variables include the indicator name: the CPU utilization of the database before and after 15 seconds. Among them, for the discrete variables "whether the index is hit" and "database statement type", the feature value is 0 or 1; for the continuous variable "number of rows in the data table", the feature value is represented by its own value; for the time series variable "CPU utilization of the database before and after 15 seconds", the feature value is improved by flattening the time series to the original coding sequence, so that the time series variables can participate in joint coding and mine time series features through DeepFM.

[0136] In some embodiments, the embedded layer encoding feature is obtained by: Figure 5 As shown, the following steps are included:

[0137] Step 501: construct an eigenvalue matrix and a feature index matrix according to the encoded slow query index and database index; the feature index matrix is ​​used to indicate feature dimensions with eigenvalues; and the eigenvalue matrix is ​​used to indicate eigenvalues ​​corresponding to the feature index matrix.

[0138] Specifically, Figure 4For example, the eigenvalue matrix is ​​constructed according to the eigenvalue, and the feature index matrix is ​​constructed according to the feature index. For example, sample 1 = hit index / update type SQL / data row number 10060 / database CPU performance index in the first 5 minutes, sample m = miss index / select type SQL / data row number 20060 / database CPU performance index in the first 5 minutes, the eigenvalue matrix and feature index matrix after processing by the original encoding module are as follows, Table 3 and Table 4 are based on Figure 4 The obtained original encoded eigenvalue matrix and feature index matrix.

[0139]

[0140] Table 3

[0141]

[0142] Table 4

[0143] Step 502: Obtain a latent vector from the embedding layer weight matrix according to the feature index matrix.

[0144] Step 503: Obtain the embedding layer coding features according to the latent vector and the eigenvalue matrix.

[0145] Specifically, after One-hot encoding, the sample feature vector is high-dimensional and sparse, and the algorithm structure characteristics of deep learning are not conducive to the processing of high-dimensional sparse feature vectors. Therefore, this method reduces the dimension of the embedding layer weight matrix (i.e., Embedding matrix) based on the Dense fully connected network, and converts the high-dimensional sparse feature vector into a dense low-dimensional feature vector. This method defines the size of the embedding layer Embedding_size, that is, the dimension of the Embedding matrix after dimensionality reduction. This method constructs the Embedding matrix with the dimension of feature_size*Embedding_size, where the size of feature_size is the number of features n after encoding, that is, the length of the feature index len(feature_index). The latent vector v_i of the feature is extracted from the Embedding matrix by table lookup through the feature index featrue_index. The specific table lookup method is to obtain the value from the Embedding matrix according to the corresponding index in the feature index matrix; similarly, the corresponding eigenvalue is obtained from the eigenvalue matrix according to the feature index, and the latent vector v_i corresponding to the feature index is multiplied by the corresponding eigenvalue featrue_value, and the embedding layer feature v_i*x_i is output, where x_i is the eigenvalue corresponding to the latent vector v_i, and the embedding layer is constructed. The processing flow example and method are as follows Figure 6 As shown, the far right is the matrix composed of the embedding layer features.

[0146] For example, Figure 6 As shown, according to the predefined embedding layer size Embedding_size is K=5, that is, the dimension of the dimensionality reduction matrix is ​​5. The Embedding matrix is ​​composed of latent vectors v_0, v_1, ..., v_n, where any latent vector v_i is Figure 4 The weights corresponding to different eigenvalues ​​in the matrix, such as the latent vector v_0 is the weight when the eigenvalue under the feature name "whether to hit the index" is "1", and the latent vector v_1 is the weight when the eigenvalue under the feature name "whether to hit the index" is "0". According to the feature index matrix, the latent vector v_i corresponding to the feature index is obtained from the Embedding matrix, and the eigenvalue corresponding to the feature index is obtained from the feature map featrue-map in Table 3. Multiply the latent vector v_i and the corresponding eigenvalue to obtain the embedding layer feature. Because the dimension of the Embedding matrix is ​​K=5, the dimension of v_i is also 5, and the dimension of the matrix composed of the embedding layer features is also 5, thereby realizing the dimensionality reduction processing of the Embedding matrix according to the preset dimension 5.

[0147] In some embodiments, the low-order feature extraction model is obtained by: Figure 7 As shown, the following steps are included:

[0148] Step 701: construct a first-order equation for each feature dimension, obtain the weight value of each feature dimension in the first-order equation through each sample, and thus obtain a first-order feature sub-extraction model.

[0149] Step 702: construct a second-order equation for any two feature dimensions, and obtain the weight value between any two feature dimensions in the second-order equation through each sample, thereby obtaining a second-order feature sub-extraction model; wherein the weight value between any two feature dimensions is represented by a latent vector in the embedding layer weight matrix.

[0150] Specifically, the factorization FM module is mainly divided into the first-order feature extraction part<w,x> And the second-order feature extraction part The low-order feature extraction objective function of FM is to solve the first-order weight parameter w and the second-order fusion weight parameter w through the historical sample set. ij . where y FM is a low-order feature. The calculation process is as follows:

[0151] a. First-order feature extraction Its weight w i The solution method is the same as that of the ordinary linear model. The first-order feature extraction is based on the weighted summation of the original coding features. The specific calculation process is as follows:

[0152] 1. Assign initial first weight: Based on the initial first weight w of each historical sample i , that is, assign corresponding weights to each original encoding feature and initialize the bias to w 0 ;

[0153] 2. Construct the first weight table: multiply the first weight by the characteristic value of the historical sample and get the sum

[0154] As shown in Table 5:

[0155]

[0156] Table 5

[0157] 3. Calculate the first weight: Since the high-risk coefficient of each sample in the historical sample is known, the first-order linear equation is used based on multiple historical samples. The first weight corresponding to each eigenvalue can be calculated.

[0158] b. Second-order feature extraction where x i and x j are the eigenvalues ​​corresponding to two different first-order features, w ij For x i and x j After the combination, the second-order feature extraction is based on the embedding layer features. The combined feature (i.e. x i x j )’s weight parameters are , n is the number of features, and all parameters are trained independently. In high-dimensional sparse data scenarios, x i and x j The number of historical samples that are all non-zero is small, resulting in the weight parameter w of the combined feature ij Therefore, FM is based on the idea of ​​matrix decomposition. According to the matrix composed of the embedding layer features, the latent vector is introduced to complete the weight parameter w of the second-order feature. ij Estimate, that is, w ij = <v i ,v j >, v i and v j are the i-th and j-th row vectors of the Embedding matrix, and the calculation logic is as follows:

[0159]

[0160] The above formula is constructed as follows:

[0161] 1. Construct an n*n cross matrix Cross Matrix is a symmetric matrix. Remove the upper triangle of the diagonal for the cross-term matrix. Therefore, according to the properties of the symmetric matrix: Cross Matrix Here is an example:

[0162] 2. Hidden vector v i and v j To obtain it according to the feature index matrix, its dimension is the preset K, so 3. Sum and calculate the dimension of the latent vector.

[0163] 4. Steps: Actually, the cross matrix is ​​summed twice, which can be simplified to

[0164] In some embodiments, slow query statements are analyzed by fusion features, including: passing the fusion features through at least one layer of gated recurrent units to determine the high-risk level of the slow query statements; for slow query statements whose high-risk levels meet set conditions, determining an optimization plan through a large language model.

[0165] Specifically, based on the low-order features extracted by the FM module and the high-order features extracted by the Deep module, the low-order features and high-order features are fused and output using feature concatenation based on the numpy library. 融合特征 =np.concatenate(y FM ,y deep ), the output dimension is 2K, which is twice the Embedding matrix vector, y deep It is a high-level feature.

[0166] After determining the fusion feature, the slow query statement is analyzed according to the fusion feature, and the high-risk degree of the fusion feature determines whether it is a slow query statement. A layer of sigmoid function or neural network is usually used to determine the high-risk degree of the fusion feature. When the fusion feature dimension is very small or very large, it is easy to cause the problem of gradient disappearance, and the high-risk degree of the slow query statement cannot be accurately predicted. Therefore, the embodiment of the present application uses a GRU model for high-risk degree prediction. GRU optimizes the LSTM (long short-term memory neural network) structure, and trains based on the high-risk degree matrix of historical samples and the fusion feature output by DeepFM to construct a high-risk degree prediction model for slow query statements. The high-risk degree can be represented by the high-risk coefficient output by the high-risk degree prediction model. The larger the high-risk coefficient, the higher the high-risk degree. The high-risk coefficient of the slow query statement is determined by GRU, thereby improving the accuracy and efficiency of the slow query high-risk coefficient analysis and prediction.

[0167] GRU uses a gate function structure to control whether the input fusion features affect the state at each moment, completes the transmission, reset and update of information, and effectively avoids the problems of gradient explosion and gradient disappearance. The embodiment of the present application builds a GRU high-risk prediction model based on the commonly used neural network module pytorch, and uses gru(input_dim, output_dim, layer_num) to build the GRU network layer. In the GRU network layer parameter setting, the input fusion feature matrix X is m*2k, 2k is the input fusion feature dimension, and m is the number of historical samples; the output data matrix Y is the predicted high-risk coefficient of m*1; the number of network layers layer_num is 2, and its network structure is as follows Figure 8 shown.

[0168] In some embodiments, for slow query statements with high risk levels that meet set conditions, an optimization solution is determined through a large language model, such as Fig. 9 As shown, the following steps are included:

[0169] Step 901: Obtain auxiliary data of slow query statements whose high risk meets set conditions, the auxiliary data including one or more of slow query indicators, database indicators, execution plan indicators of slow query statements, and data table information involved in the slow query statements.

[0170] Specifically, the high-risk degree meets the set conditions, that is, the high-risk coefficient meets the preset threshold. After determining the high-risk coefficient of the fusion feature, the slow query statement corresponding to the fusion feature whose high-risk coefficient meets the preset threshold is optimized. First, the auxiliary data of the slow query statement that meets the set conditions is obtained. The auxiliary data includes: slow query indicators, database indicators, execution plan indicators of slow query statements, and data table information designed for slow query statements. The slow query indicators and database indicators have been introduced in the above description. The execution plan indicators of slow query statements are based on whether there are index problems, scanned data volume problems, and slow query statement locks that are too long based on the actual execution of the slow query statement. The data table information involved in the slow query statement includes which tables the slow query statement queries, and which fields in the table. Auxiliary data such as Fig.10 shown.

[0171] Step 902: Determine a prompt word corresponding to an analysis direction, where the analysis direction includes one or more of syntax analysis, execution plan analysis, and database performance analysis.

[0172] Specifically, the prompt words corresponding to the analysis direction are determined based on the auxiliary data. The auxiliary data are scattered and unintegrated data, and the problems existing in the slow query statements and the recommended optimization directions cannot be intuitively seen from the auxiliary data. Therefore, multiple analysis directions are determined based on the auxiliary data, and the slow query statements are analyzed according to the analysis directions.

[0173] In some embodiments, the prompt words corresponding to the syntax analysis include one or more of connection operation problems, nested query and subquery problems, and paging offset problems; the prompt words corresponding to the execution plan analysis include one or more of index validity problems, excessive scan data volume problems, excessive execution statement lock problems, and sorting and grouping problems; the prompt words corresponding to the database performance analysis include one or more of database performance bottleneck problems and slow query passive generation problems. Based on the database indicators corresponding to the time when the slow query statement appears and the jump time of the database performance, it is determined whether the slow query statement is passively generated.

[0174] Specifically, based on syntax, execution plan, and database performance, corresponding prompt words are designed for each type of slow query statement, and auxiliary information is input into the dify large model framework, and step-by-step analysis is performed according to the prompt word dimensions. The final output is remark (including the analysis process and reasonable optimization S suggestions), summary (refining the key points and summarizing the remark to reduce redundant data) and slow_type (obtaining a list of matching slow query statement problem types from the remark data). The prompt word design dimensions are as follows: Fig.11 The specific analysis contents are as follows:

[0175] a. Syntax analysis

[0176] Based on grammar analysis, it mainly evaluates whether there are connection operation problems, nested query and subquery problems, and paging offset problems in the grammar itself, which lead to slow queries, and evaluates whether slow queries are generated actively. The main contents of the analysis prompt word Prompt are as follows:

[0177] 1. Connection operation problem Prompt: Whether there is a JOIN table. The analysis is mainly based on the number, size and order of JOIN table operations. The specific analysis dimensions are as follows.

[0178] ① Analyze whether the JOIN sequence is optimal and evaluate whether slow queries are caused by using a large table to drive a small table for JOIN queries;

[0179] ② Analyze the number of JOIN tables and evaluate whether the slow query is caused by the large number of JOIN tables;

[0180] ③ Analyze the size of the JOIN table, and combine the number of rows scanned in the execution plan results and the number of rows of data table information involved in the slow query statement to evaluate whether the slow query is caused by the JOIN operation due to a large amount of scanned data and a large number of rows of table information.

[0181] 2. Nested query and subquery problem Prompt: Mainly analyze whether the slow query is caused by the large external query result set.

[0182] 3. Paging offset problem Prompt: Mainly combine the size of LIMIT or OFFSET of the slow query statement to analyze whether the slow query is caused by deep paging, large LIMIT or large OFFSET offset.

[0183] b. Execution plan analysis

[0184] The execution plan analysis mainly evaluates whether the slow query statement is actually executed to see if there are index validity issues, too much scanned data, too long locks during the execution of the slow query statement, and abnormal sorting and grouping, which lead to the generation of slow queries. The execution plan and slow query indicators are used to evaluate whether the slow query is actively generated. The main contents of the analysis prompt are as follows:

[0185] 1. Index validity issue: This is mainly analyzed by confirming whether the query adjustment field covers the index and whether the field type is inconsistent. The specific analysis dimensions are as follows:

[0186] ①Confirm whether the query involves the WHERE condition field has a corresponding index;

[0187] ②Confirm whether the covering index and joint index are used reasonably;

[0188] ③Confirm whether the index is invalid due to operations on the field or field type mismatch.

[0189] 2. Too much scanned data: Combine the number of scanned rows in the execution plan, the number of table rows in the input parameter table_rows, the average number of returned data rows in the slow query statements in sql_info, return_rows_avg, and examined_rows_avg to assess whether the slow query is caused by a large table and a large amount of scanned data in the slow query statements.

[0190] 3. Lock issues when executing slow query statements: Mainly combine the average number of data rows returned by executing slow query statements in sql_info (return_rows_avg), the average number of data rows scanned by executing slow query statements (examined_rows_avg), the average db lock duration (in seconds) when executing slow query statements (lock_time_avg), and table information to analyze whether the slow query statement itself generates a lock, and evaluate the granularity of the locked object, such as row locks, page locks, and table locks, on execution performance.

[0191] 4. Sorting and grouping issues: Mainly by confirming whether ORDER BY and GROUP BY can use indexes to avoid file sorting.

[0192] c. Database performance impact analysis

[0193] The database performance impact analysis mainly evaluates whether there are jumps and bottlenecks in the CPU, IO and other resource indicators of the database before and after the execution of the slow query statement, which leads to the slow query. At the same time, the execution time of the slow query statement and the jump time of the database performance indicator are judged to evaluate whether the slow query is caused passively. The main contents of the analysis prompt are as follows:

[0194] 1. Database performance bottleneck problem: mainly through analyzing the time series performance indicators of the first 20 minutes and the last 10 minutes of executing slow query statements: whether there are jumps in indicators such as CPU utilization cpu_usage, IO utilization io_usage, connection utilization connect_usage, data disk utilization data_dir_usage, handle utilization process_fh_usage, and total request volume request_total, to identify performance bottlenecks.

[0195] 2. Slow query problems are caused passively: Mainly by analyzing the database performance jump time and the slow query statement execution time, confirm whether the slow query statement is caused passively due to the database performance bottleneck.

[0196] Due to the instability of the reasoning ability of the large model, the single classification and optimization recommendation analysis corresponding to a single slow query statement has inconsistent results. In order to improve the stability and accuracy of model reasoning, this method combines multiple slow query analysis results of the same slow query statement for refinement. The main content of the analysis prompt is as follows: Comprehensively analyze the multiple analysis results input, extract the conclusions that are consistent with the multiple analysis results, and eliminate redundant and unimportant conclusions.

[0197] Step 903: input the auxiliary data and the prompt words corresponding to the analysis direction into the large language model to obtain an optimization solution.

[0198] Specifically, the auxiliary data input is n_result, the multi-dimensional analysis prompt word input is prompt, and the qwen-72B LLM model is used. Based on the chat dialogue framework, the multi-dimensional analysis task of a single slow query statement and the joint analysis task of a single slow query statement are respectively performed to build a high-risk slow query statement optimization recommendation application. Its structure is as follows: Fig.12 shown.

[0199] In an embodiment of the present application, when analyzing a slow query statement, not only the slow query index of the slow query statement is obtained, but also the database index of the slow query statement is correspondingly obtained, thereby improving the accuracy and comprehensiveness of the high-risk analysis of the slow query; the slow query index and the database index are encoded to obtain encoding features, and high-order features and low-order features are respectively extracted from the encoding features, and then the high-order features and the low-order features are fused to obtain fused features. The high-risk degree of the slow query statement is determined by the fused features and then the slow query statement is analyzed, so that the determination and analysis of the high-risk degree of the slow query are more rigorous, and the efficiency of the slow query statement analysis is improved.

[0200] Based on the same technical concept, the embodiment of the present application provides a device for analyzing slow query statements, such as Fig.13 As shown, the device 1300 includes:

[0201] An acquisition module 1301 is used to acquire a slow query index of a slow query statement and a database index corresponding to the slow query statement;

[0202] The encoding module 1302 is used to encode the slow query index and the database index respectively to obtain encoding features;

[0203] A fusion module 1303 is used to extract low-order features and high-order features from the coding features respectively, and splice the low-order features and the high-order features into fused features;

[0204] The analysis module 1304 is used to analyze the slow query statement by using the fusion feature.

[0205] Optionally, the coding feature includes an original coding feature and an embedded layer coding feature, and the embedded layer coding feature is obtained by using an embedded layer weight matrix and the original coding feature;

[0206] The fusion module 1303 is specifically used for:

[0207] Extracting low-order features and high-order features from the coding features respectively includes:

[0208] Extracting first-order features from the original coding features and extracting second-order features from the embedded layer coding features through a low-order feature extraction model; the second-order features represent the relationship between any two first-order features;

[0209] High-order features are extracted from the embedding layer encoding features through a high-order feature extraction model.

[0210] Optionally, the encoding module 1302 is specifically used for:

[0211] According to the variable type of each indicator in the slow query indicator and the database indicator, the slow query indicator and the database indicator are respectively encoded to obtain original encoding features; wherein, One-hot encoding is performed on discrete variables, continuous variables are encoded according to their own value method, and time series variables are encoded according to time series flattening method.

[0212] Optionally, the encoding module 1302 is specifically used for:

[0213] According to the encoded slow query index and database index, construct an eigenvalue matrix and a feature index matrix; the feature index matrix is ​​used to indicate feature dimensions with eigenvalues; the eigenvalue matrix is ​​used to indicate eigenvalues ​​corresponding to the feature index matrix;

[0214] Obtaining a latent vector from an embedding layer weight matrix according to the feature index matrix;

[0215] According to the latent vector and the eigenvalue matrix, an embedding layer encoding feature is obtained.

[0216] Optionally, the fusion module 1303 is specifically used for:

[0217] The low-order feature extraction model is obtained by the following method, including:

[0218] Constructing a first-order equation for each feature dimension, and obtaining a weight value of each feature dimension in the first-order equation through each sample, thereby obtaining a first-order feature sub-extraction model;

[0219] A second-order equation for any two feature dimensions is constructed, and the weight value between any two feature dimensions in the second-order equation is obtained through each sample, thereby obtaining a second-order feature sub-extraction model; wherein the weight value between any two feature dimensions is represented by a latent vector in the embedding layer weight matrix.

[0220] Optionally, the analysis module 1304 is specifically used for:

[0221] Passing the fused features through at least one layer of gated recurrent units to determine the high-risk level of the slow query statement;

[0222] For slow query statements whose high risk meets the set conditions, the optimization plan is determined through the large language model.

[0223] Optionally, the analysis module 1304 is specifically used for:

[0224] Acquire auxiliary data of a slow query statement whose high risk meets a set condition, wherein the auxiliary data includes one or more of the slow query indicator, the database indicator, the execution plan indicator of the slow query statement, and data table information involved in the slow query statement;

[0225] Determine a prompt word corresponding to an analysis direction, where the analysis direction includes one or more of syntax analysis, execution plan analysis, and database performance analysis;

[0226] The auxiliary data and the prompt words corresponding to the analysis direction are input into the large language model to obtain an optimization solution.

[0227] Optionally, the prompt words corresponding to the grammatical analysis include one or more of connection operation problems, nested query and subquery problems, and paging offset problems;

[0228] The prompt words corresponding to the execution plan analysis include one or more of the following: index validity problem, excessive amount of scanned data problem, excessive execution statement lock problem, sorting and grouping problem;

[0229] The prompt words corresponding to the database performance analysis include one or more of database performance bottleneck problems and problems passively generated by slow queries.

[0230] Based on the same technical concept, the embodiment of the present application provides a computer device, which may be a terminal or a server, such as Fig.14 As shown, it includes at least one processor 1401 and a memory 1402 connected to the at least one processor. The specific connection medium between the processor 1401 and the memory 1402 is not limited in the embodiment of the present application. Fig.14 For example, the processor 1401 and the memory 1402 are connected via a bus. The bus can be divided into an address bus, a data bus, a control bus, and the like.

[0231] In the embodiment of the present application, the memory 1402 stores instructions that can be executed by at least one processor 1401. The at least one processor 1401 can execute the steps included in the above-mentioned cosmic ray removal method by executing the instructions stored in the memory 1402.

[0232] The processor 1401 is the control center of the computer device, and can use various interfaces and lines to connect various parts of the computer device, by running or executing instructions stored in the memory 1402 and calling data stored in the memory 1402. Optionally, the processor 1401 may include one or more processing units, and the processor 1401 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 1401. In some embodiments, the processor 1401 and the memory 1402 may be implemented on the same chip, and in some embodiments, they may also be implemented separately on independent chips.

[0233] Processor 1401 can be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit (ASIC), a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, and can implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor can be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application can be directly embodied as a hardware processor for execution, or can be executed by a combination of hardware and software modules in the processor.

[0234] Memory 1402, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer executable programs and modules. Memory 1402 may include at least one type of storage medium, such as flash memory, hard disk, multimedia card, card-type memory, random access memory (Random Access Memory, RAM), static random access memory (Static Random Access Memory, SRAM), programmable read-only memory (Programmable Read Only Memory, PROM), read-only memory (Read Only Memory, ROM), electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), magnetic memory, disk, optical disk, etc. Memory 1402 is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory 1402 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.

[0235] Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program executable by a computer device. When the program runs on the computer device, the computer device executes the steps of the above-mentioned cosmic ray removal method.

[0236] Based on the same inventive concept, an embodiment of the present application provides a computer program product, characterized in that the computer program product includes a computer program stored on a computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer device, the computer device executes the steps of the above-mentioned cosmic ray removal method.

[0237] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0238] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0239] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0240] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0241] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A method for analyzing slow query statements, characterized in that: include: Obtaining a slow query index of a slow query statement and a database index corresponding to the slow query statement; Encoding the slow query index and the database index respectively to obtain encoding features; Extracting low-order features and high-order features from the coding features respectively, and concatenating the low-order features and the high-order features into fused features; The slow query statement is analyzed by using the fusion feature.

2. The method according to claim 1, characterized in that The coding features include original coding features and embedded layer coding features, and the embedded layer coding features are obtained by using the embedded layer weight matrix and the original coding features; Extracting low-order features and high-order features from the coding features respectively includes: Extracting first-order features from the original coding features and extracting second-order features from the embedded layer coding features through a low-order feature extraction model; the second-order features represent the relationship between any two first-order features; High-order features are extracted from the embedding layer encoding features through a high-order feature extraction model.

3. The method according to claim 2, characterized in that The original coding feature is obtained by: According to the variable type of each indicator in the slow query indicator and the database indicator, the slow query indicator and the database indicator are respectively encoded to obtain original encoding features; wherein, One-hot encoding is performed on discrete variables, continuous variables are encoded according to their own value method, and time series variables are encoded according to time series flattening method.

4. The method according to claim 2, characterized in that The embedding layer encoding features are obtained by: According to the encoded slow query index and database index, construct an eigenvalue matrix and a feature index matrix; the feature index matrix is ​​used to indicate feature dimensions with eigenvalues; the eigenvalue matrix is ​​used to indicate eigenvalues ​​corresponding to the feature index matrix; Obtaining a latent vector from an embedding layer weight matrix according to the feature index matrix; According to the latent vector and the eigenvalue matrix, an embedding layer encoding feature is obtained.

5. The method according to claim 2, characterized in that The low-order feature extraction model is obtained by the following method, including: Constructing a first-order equation for each feature dimension, and obtaining a weight value of each feature dimension in the first-order equation through each sample, thereby obtaining a first-order feature sub-extraction model; A second-order equation for any two feature dimensions is constructed, and the weight value between any two feature dimensions in the second-order equation is obtained through each sample, thereby obtaining a second-order feature sub-extraction model; wherein the weight value between any two feature dimensions is represented by a latent vector in the embedding layer weight matrix.

6. The method according to any one of claims 1 to 5, characterized in that: The analyzing the slow query statement by using the fusion feature includes: Passing the fused features through at least one layer of gated recurrent units to determine the high-risk level of the slow query statement; For slow query statements whose high risk meets the set conditions, the optimization plan is determined through the large language model.

7. The method according to claim 6, characterized in that For the slow query statements with high risk levels that meet the set conditions, an optimization solution is determined through a large language model, including: Acquire auxiliary data of a slow query statement whose high risk meets a set condition, wherein the auxiliary data includes one or more of the slow query indicator, the database indicator, the execution plan indicator of the slow query statement, and data table information involved in the slow query statement; Determine a prompt word corresponding to an analysis direction, where the analysis direction includes one or more of syntax analysis, execution plan analysis, and database performance analysis; The auxiliary data and the prompt words corresponding to the analysis direction are input into the large language model to obtain an optimization solution.

8. The method according to claim 7, characterized in that The prompt words corresponding to the grammatical analysis include one or more of connection operation problems, nested query and subquery problems, and paging offset problems; The prompt words corresponding to the execution plan analysis include one or more of the following: index validity problem, excessive amount of scanned data problem, excessive execution statement lock problem, sorting and grouping problem; The prompt words corresponding to the database performance analysis include one or more of database performance bottleneck problems and problems passively generated by slow queries.

9. The method according to claim 8, characterized in that The prompt words corresponding to the database performance analysis include one or more of database performance bottleneck problems and slow query passive problems, including: Based on the database index corresponding to the time when the slow query statement appears and the jump time of the database performance, it is determined whether the slow query statement is passively generated.

10. A device for analyzing slow query statements, characterized in that: include: An acquisition module, used to acquire a slow query index of a slow query statement and a database index corresponding to the slow query statement; An encoding module, used to encode the slow query index and the database index respectively to obtain encoding features; A fusion module, used to extract low-order features and high-order features from the coding features respectively, and splice the low-order features and the high-order features into fused features; An analysis module is used to analyze the slow query statement through the fusion feature.

11. A computer device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the steps of the method according to any one of claims 1 to 9 are implemented when the processor executes the program.

12. A computer-readable storage medium, characterized in that: It stores a computer program executable by a computer device, and when the program is run on the computer device, the computer device executes the steps of any one of the methods of claims 1 to 9.

13. A computer program product, characterized in that The computer program product comprises a computer program stored on a computer-readable storage medium, wherein the computer program comprises program instructions, and when the program instructions are executed by a computer device, the computer device is caused to perform the steps of the method according to any one of claims 1 to 9.