SQL slow operation reason analysis method based on supervised machine learning
By using a method based on supervised machine learning to extract key features of SQL and train a classification model, it solves the problem of complexity and manual dependence in analyzing the causes of slow SQL execution, realizes automated analysis, and improves efficiency and accuracy.
Patent Information
- Application Number
- CN202410636940.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-22
- Publication Date
- 2024-09-06
AI Technical Summary
Existing technology makes it difficult to accurately analyze the reasons for slow SQL execution, especially in complex scenarios, and relies on manual analysis, which results in high time-consuming and labor costs.
Using a method based on supervised machine learning, by collecting and preprocessing SQL running data, extracting key features, writing automatic labeling programs, and using random forest classification algorithms to train models, we can automatically classify and label the causes of SQL slowness and reduce manual intervention.
It achieves accurate automatic analysis of the reasons for slow SQL execution, reduces the time and cost of manual analysis, and is suitable for big data environments.
Smart Images

Figure CN118606084A
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of data analysis, and in particular relates to a method for analyzing causes of slow SQL execution based on supervised machine learning. Background Art
[0002] The problem of slow SQL (Structured Query Language) execution is very common in actual use environments. Accurate analysis of the causes of slow SQL execution is crucial to improving database performance and user experience. However, with the development of cloud computing and distributed technology, database architecture is constantly changing, and the study of slow SQL execution has become more complicated.
[0003] Currently, the reasons for slow SQL execution are divided into two categories in public literature: one is caused by internal reasons (such as unreasonable and imperfect SQL writing, lack of indexes, and high SQL complexity); the other is caused by external intermittent performance problems (such as low performance or failure at the database or machine level). Among them, external intermittent slow SQL execution often occurs in cloud databases.
[0004] In the era of big data, a common method for analyzing the causes of slow SQL queries in massive amounts is to extract external related features of SQL statements (such as the execution time of SQL statements, the CPU used when SQL statements are executed, the network used when SQL statements are executed, etc.) to represent slow SQL statements, then use clustering methods or a framework based on subgroup discovery to aggregate the same type of slow SQL statements into one category, and finally analyze the specific causes of each type of slow SQL statement based on the expert experience of the DBA (Database Administrator). When this common method is applied to different database usage scenarios, the corresponding features need to vary according to the scenarios. Although this method can accurately distinguish the types of slow SQL statements, (1) the features used to characterize SQL statements are environment variables (CPU, memory, IO, execution time, etc.) of SQL statements. For more complex SQL statements, only using such environment variable features is not enough to accurately represent SQL. For example, in a database system, there may be usage scenarios where the environment variable values are similar but the SQL statements are relatively different. For such usage scenarios, simply using features such as environment variables cannot accurately distinguish the causes of slow SQL statements. (2) The specific reasons for the slowness of each type of slow SQL query still need to rely on manual analysis and annotation by the DBA, but in the face of massive SQL in a massive database, this manual analysis behavior will consume a lot of manpower and time. Summary of the invention
[0005] The technical problem to be solved by the present invention is to provide a more comprehensive feature combination scheme for representing SQL statements in response to the deficiencies of the background technology, realize the idea of automatic labeling of the reasons for slow SQL execution based on expert experience, and complete the classification of slow SQL execution based on supervised machine learning methods, thereby ultimately realizing the post-cause analysis of slow SQL execution.
[0006] The present invention adopts the following technical solutions to solve the above technical problems:
[0007] A method for analyzing the causes of slow SQL execution based on supervised machine learning, specifically comprising the following steps:
[0008] Step 1: Collect the SQL running data that was executed slowly in the past;
[0009] Step 2: Based on the collected SQL operation data, the required feature vectors are extracted to obtain the feature data set corresponding to the SQL;
[0010] Step 3: preprocess the feature data set, including data cleaning and data normalization;
[0011] Step 4: Write a cause labeling program based on the expert experience database to automatically label the cause of SQL slowness, and label the cause of the feature data set output in step 3 and add corresponding labels to obtain a labeled feature data set;
[0012] Step 5: For the labeled data outputted from step 4, a supervised machine learning algorithm is used to train and test the classification model to obtain the classification model;
[0013] Step 6: For the slow SQL statements that have been executed and are to be analyzed, the classification model obtained in step 5 is used to classify the slow SQL statements, thereby obtaining the specific reasons for the slow SQL statements.
[0014] Step 7: Since new types of slow SQL execution may appear, the expert experience library used to automatically label the causes of slow execution needs to be expanded and improved every period of time, so as to update the cause labeling program to ensure the accuracy of the SQL slow cause analysis; accordingly, the labels of the data set used to train the classification model will change accordingly, and the model needs to be retrained based on the new training set data to obtain a new classification model.
[0015] As a further preferred solution of the method for analyzing the causes of slow SQL operation based on supervised machine learning of the present invention, step 1 includes the following sub-steps:
[0016] Step 1.1, design the corresponding table structure in the database to collect the required SQL operation data;
[0017] Step 1.2, collect historical SQL operation data;
[0018] Step 1.3, filter out the slow SQL statements whose execution time exceeds the time threshold t in step 1.2 as the research object.
[0019] As a further preferred solution of the method for analyzing the causes of slow SQL operation based on supervised machine learning of the present invention, step 2 includes the following sub-steps:
[0020] Step 2.1, for the SQL operation data collected in step 1, call the Hive UDF in the massive database management system to extract traditional features such as keywords in the SQL statement and the number of time partitions corresponding to the SQL query data, the number of occurrences of regular matching keywords, whether there are non-equal value Joins and subquery complex features as text features, and collect them for step 1 at the same time.
[0021] As a further preferred solution of the method for analyzing the causes of slow SQL operation based on supervised machine learning of the present invention, step 3 includes the following sub-steps:
[0022] Step 3.1: For the data features obtained in step 2, replace the missing values and outliers in the feature data with 0;
[0023] Step 3.2: For the normal data obtained in step 3.1, continue the data normalization operation to obtain a data set that can be used to build a classification model.
[0024] As a further preferred solution of the method for analyzing the causes of slow SQL operation based on supervised machine learning of the present invention, step 4 specifically includes the following sub-steps:
[0025] Step 4.1: Collect the database operation and maintenance experience of the DBA, and determine the value of the feature corresponding to the specific reason for slow execution based on the SQL feature data extracted in step 2.1;
[0026] Step 4.2: Based on the correspondence between the slow execution reasons and the characteristic values determined in step 4.1, a cause labeling program for labeling the slow SQL reasons is written. It is necessary to find all the combinations of the 14 slow execution reasons in Table 2. The cause combination of the SQL is specifically determined based on whether the executed SQL has one or more of the 14 reasons in Table 2, thereby obtaining the corresponding label to complete the labeling of the slow SQL.
[0027] Step 4.2.1, for the 14 reasons for slow execution, find all possible combinations to obtain multiple cause combinations, where each cause combination has a corresponding label. The full combination of slow execution causes and their corresponding labels are mapped to form a cause dictionary DICT R ;
[0028] Step 4.2.2, find the specific values of the 14 slow execution reasons corresponding to each SQL in Table 2 as the basic reason value combination R0; for each SQL, if there is a slow reason, the corresponding slow reason feature value is 1, otherwise it is 0;
[0029] Step 4.2.3, the reason dictionary DICT composed of the basic reason value combination R0 of each SQL and the full combination of reasons and their corresponding labels R , get the reason number corresponding to each SQL, and complete the marking work of each SQL.
[0030] As a further preferred solution of the method for analyzing the causes of slow SQL operation based on supervised machine learning of the present invention, step 5 specifically includes the following sub-steps:
[0031] Step 5.1, for the feature samples with classification labels obtained in step 4.2.3, divide the samples into a training subset and a validation subset according to the proportion. The training subset is used to train the model, and the validation subset is used to verify the performance of the model; use the supervised random forest classification algorithm to fit the classification model based on the training subset, and verify the classification performance of the classification model based on the validation subset.
[0032] As a further preferred solution of the method for analyzing the causes of slow SQL execution based on supervised machine learning of the present invention, step 6 specifically includes the following sub-steps:
[0033] Step 6.1: For the executed slow SQL to be analyzed, call the Hive UDF function in the massive database management system to extract the traditional features of the keywords in the SQL statement and the number of time partitions corresponding to the SQL query data, the number of occurrences of regular matching keywords, whether there are non-equal joins and subqueries, and other complex features as classification features;
[0034] Step 6.2: Use the classification model trained in step 5 to classify the classification features of the slow SQL statements obtained in step 6.1 to obtain the classification probabilities of each category of each slow SQL statement.
[0035] If the classification probability of any category in each category is greater than or equal to the threshold p, you need to find the category number i with the largest probability value among all categories with classification probability greater than or equal to p, and then mark the slow SQL statement as the i-th category;
[0036] If the classification probability of any category in each category is less than the threshold p, the category number of the corresponding slow SQL is set to -1; each slow SQL is traversed and processed to finally obtain the slow SQL data with classification labels;
[0037] Step 6.3, record the slow SQL classified as -1 in step 6.2 as the incremental new SQL type into the file;
[0038] Step 6.4: Based on the corresponding relationship between the reason for the slow execution in step 4.1 and the characteristic value, statistical analysis is performed to obtain the specific reason for the slow execution corresponding to the slow SQL in step 6.2.
[0039] As a further preferred solution of the method for analyzing the causes of slow SQL execution based on supervised machine learning of the present invention, step 7 specifically includes the following sub-steps:
[0040] Step 7.1: At regular intervals, it is necessary to collect incremental slow SQL data sets running in the database, i.e., the slow SQL data marked as -1 collected in step 6.3; after manual analysis by the DBA, the newly emerged reasons for slow execution and their corresponding feature values are added to the expert experience database;
[0041] Step 7.2: Based on the expert experience library updated in step 7.1 and the incremental slow SQL data set collected, re-execute steps 2 to 4 to obtain an updated classification model.
[0042] Compared with the prior art, the present invention adopts the above technical solution and has the following technical effects:
[0043] 1. In order to accurately and comprehensively represent an SQL statement, the present invention extracts the keywords or predicates (such as group by, join, distinct, etc.) in the SQL statement and the number of time partitions corresponding to the SQL query data, the number of occurrences of regular matching keywords, whether there are non-equal value Joins and subqueries, and other complex features as the features of the SQL statement;
[0044] 2. The present invention proposes a classification and analysis method based on a supervised machine learning method in order to automatically count the reasons for slow SQL execution rather than having them manually analyzed by the DBA. In the early stage, a cause labeling program that automatically labels the reasons for slow SQL execution needs to be written based on an expert experience library. Subsequently, the present invention uses the cause labeling program to label the reasons of massive SQL data to obtain labeled data. Secondly, a supervised machine learning algorithm is used to simulate and train the data features with existing labels to obtain a classification model. Finally, according to the mapping relationship between the labels in the cause labeling program and the specific reasons for slow execution, the specific reasons for slow execution of the classified SQL are statistically obtained. Among them, the cause labeling program can automatically label the reasons for slow SQL execution, saving the time and manpower required for manual labeling of the reasons for slow execution. This technical solution is more practical in the era of big data. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.
[0046] Figure 1 It is a flow chart of a method for analyzing the causes of slow SQL operation based on supervised machine learning of the present invention;
[0047] Figure 2 This is a flow chart of the present invention using a classification model to classify the slow SQL that has been executed and is to be analyzed;
[0048] Figure 3 The present invention needs to expand and improve the schematic diagram every three months. DETAILED DESCRIPTION
[0049] The technical solution of the present invention is further described in detail below in conjunction with the accompanying drawings:
[0050] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in 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. The present invention is described in detail below based on the drawings and preferred embodiments, and the purpose and effect of the present invention will become clearer. It should be understood that the specific embodiments described here are only used to explain the present invention and are not used to limit the present invention.
[0051] The present invention will be further supplemented with the accompanying drawings and specific embodiments below. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention. Those skilled in the art should understand that without departing from the above-mentioned technical ideas of the present invention, various replacements and changes to the present invention based on the basic technical knowledge and means in the field should be included in the protection scope of the present invention.
[0052] Embodiment 1 of the present invention is as follows:
[0053] In order to accurately analyze the reasons for the slowness of the executed slow SQL statements, the present invention designs a more comprehensive feature combination scheme for representing SQL statements, realizes the idea of automatically labeling the reasons for the slow SQL statements based on expert experience, and completes the classification of the slow SQL statements based on the supervised machine learning method, thereby finally realizing the post-execution reason analysis of the slow SQL statements.
[0054] As attached Figure 1 The technical solution provided by the present invention comprises the following steps:
[0055] Step 1: Collect the SQL running data that was executed slowly in the past;
[0056] Step 1.1, design the corresponding table structure in the database to collect the required SQL operation data, which includes but is not limited to the SQL statement content, the total SQL operation time, the SQL execution status, the total number of SQL operation tasks, the total number of data scanned by the SQL operation, etc.
[0057] Step 1.2: Collect historical SQL operation data.
[0058] Step 1.3, filter out the slow SQL statements whose execution time exceeds the time threshold t (t is 10 minutes) in step 1.2 as the research objects.
[0059] Step 2: Based on the collected SQL operation data, the required feature vectors are extracted to obtain the feature data set corresponding to the SQL;
[0060] Step 2.1, for the SQL operation data collected in step 1, call the HiveUDF function in the massive database management system to extract traditional features such as keywords in SQL statements (such as groupby, join, distinct) and complex features such as the number of time partitions corresponding to the SQL query data, the number of occurrences of regular matching keywords, whether there are non-equal value Joins and subqueries as data features. The specific classification features are shown in Table 1, where the keyword feature indicates whether a keyword or predicate is contained in the SQL. If a keyword or predicate is contained, the corresponding feature value is 1, otherwise the feature value is 0.
[0061] Table 1
[0062]
[0063]
[0064]
[0065] Step 3: Preprocess the feature data set, including data cleaning and data normalization.
[0066] Step 3.1: For the data features obtained in step 2, replace the missing values and outliers in the feature data with 0.
[0067] Step 3.2, for the normal data obtained in step 3.1, continue the data normalization operation to obtain a data set that can be used to build a classification model. In order to normalize all feature data to data between [0,1], the present invention obtains the maximum value of each feature in the training set, divides the feature value whose feature value range is not between [0,1] by the historical maximum value of its corresponding feature, and normalizes the feature value to the data range of [0,1]. Specifically, the features whose feature value range is not between [0,1] are likeCnt, rlikeCnt, regexpCnt, inValueNum, regValueNum, regexpExtractCnt, regexpReplaceCnt, regexpSubstrCnt, stringKeyMatchCnt, and partitionNums in Table 1.
[0068] Step 4: Write a cause labeling program based on the expert experience database to automatically label the causes of SQL slowness, complete the cause labeling of the feature data set output in step (3) and add corresponding classification labels to obtain a labeled feature data set.
[0069] Step 4.1: Collect the database operation and maintenance experience of the DBA, and determine the value of the feature corresponding to the specific slow execution reason based on the SQL feature data extracted in step 2.1. The correspondence between the specific slow execution reason and the feature value is shown in Table 2, where the symbol "&&" represents logical AND and the symbol "||" represents logical OR.
[0070] Table 2
[0071]
[0072]
[0073] Step 4.2, based on the correspondence between the reasons for slow execution and the characteristic values determined in step 4.1, that is, Table 2, write a labeling program for labeling the reasons for slow SQL execution. Since the reason for the slow execution of a SQL statement may be one or more of the reasons in Table 2, it is necessary to find all the combinations of the 14 reasons for slow execution in Table 2; then, based on whether the executed SQL statement has one or more of the 14 reasons in Table 2, the reason combination of the SQL statement is specifically determined, thereby obtaining the corresponding label to complete the labeling of the slow SQL statement.
[0074] Step 4.2.1, for the 14 slow execution reasons in Table 2, find all possible combinations to obtain multiple cause combinations, where each cause combination has a corresponding label. The full combination of slow execution reasons and their corresponding labels are mapped to form a cause dictionary DICT R , where in the first example of the present invention the reason dictionary DICT R Some of the causes are shown in Table 3.
[0075] Table 3
[0076]
[0077] Step 4.2.2, how to determine whether an executed SQL has one or more of the 14 reasons in Table 2? First, it is necessary to find the specific values of the 14 slow execution reasons corresponding to each SQL in Table 2 as the basic reason value combination R0. For each SQL, if there is a slow reason, the corresponding slow reason feature value is 1, otherwise it is 0. For example, the basic reason value combination R0 of a certain SQL in Example 1 of the present invention = [1,1,0,0,0,0,0,0,0,0,0,0,0,0].
[0078] Step 4.2.3, then the reason dictionary DICT is composed of the basic reason value combination R0 of each SQL and the full combination of reasons and their corresponding labels R , get the cause number corresponding to each SQL, and complete the marking work of each SQL. For example, in Example 1 of the present invention, the basic cause value combination R0 of a certain SQL is [1,1,0,0,0,0,0,0,0,0,0,0,0,0], and the corresponding classification number is 2.
[0079] Step 5: For the labeled data outputted in step 4, a supervised machine learning algorithm is used to train and test the classification model to obtain the classification model.
[0080] Step 5.1 divides the feature samples with classification labels obtained in step 4.2.3 into a training subset and a validation subset in a ratio of 7:3. The training subset is used to train the model, and the validation subset is used to verify the performance of the model. Subsequently, a supervised random forest classification algorithm is used to obtain a classification model based on the training subset fitting, and the classification performance of the classification model is verified based on the validation subset. In the example of the present invention, the results obtained by the validation subset verification are shown in Table 4 below. It can be seen that 2 SQLs in the validation subset are misclassified, resulting in a misjudgment of the reason for the slow execution of SQL, but the overall classification accuracy also reaches 95.24%.
[0081] Table 4
[0082] Verify the number of SQL statements in the subset Causes of slow execution after classification and analysis The actual reason for slow execution 7 Produces a Cartesian product Produces a Cartesian product 1 Too many matching conditions Too many matching conditions 10 Too many regular matching conditions Too many regular matching conditions 10 The time span exceeds 7 days The time span exceeds 7 days 22 Articles unknown unknown 2 Only a single Task is started unknown
[0083] Step 6, as shown in the attached Figure 2 For the slow SQL to be analyzed and executed, the classification model obtained in step 5 is used to classify the slow SQL. Then, based on the mapping relationship between the slow SQL execution reason and the classification label in step 4.2.1, the specific reason for the classified slow SQL is given.
[0084] Step 6.1, for the executed slow SQL to be analyzed, call the HiveUDF function in the massive database management system to extract traditional features such as keywords in the SQL statement (such as groupby, join, distinct) and complex features such as the number of time partitions corresponding to the SQL query data, the number of occurrences of regular matching keywords, whether there are non-equal joins and subqueries as classification features.
[0085] Step 6.2, use the classification model trained in step 5 to classify the classification features of the slow SQL obtained in step 6.1, and obtain the classification probability of each category of each slow SQL. If the classification probability of any category in each category is greater than or equal to the threshold p, it is necessary to find the category number i with the largest probability value among all categories with classification probability greater than or equal to p, and then mark the slow SQL as the i-th category. If the classification probability of any category in each category is less than the threshold p, the category number of the corresponding slow SQL is set to -1. Traverse and process each slow SQL to finally obtain the slow SQL data with classification labels.
[0086] Step 6.3: Record the slow SQL classified as -1 in step 6.2 as the incremental new SQL type into the file.
[0087] Step 6.4: Based on the corresponding relationship between the slow execution reason and the characteristic value in step 4.1, statistical analysis is performed to obtain the specific slow execution reason corresponding to the slow SQL in step 6.2.
[0088] Step 7, as shown in the attached Figure 3 Since new types of slow SQL execution may appear, the expert experience library used to automatically annotate the causes of slow execution needs to be expanded and improved every three months, so as to update the cause annotation program to ensure the accuracy of the SQL slow cause analysis. Accordingly, the labels of the data set used to train the classification model will change accordingly, and the model needs to be retrained based on the new training set data to update the classification model.
[0089] Step 7.1: Every three months, you need to collect the incremental slow SQL data set running in the database, which is the slow SQL data marked as -1 collected in step 6.3. After manual analysis by the DBA, the newly emerged slow execution reasons and their corresponding feature values are added to the expert experience library.
[0090] Step 7.2: Based on the expert experience library updated in step 7.1 and the incremental slow SQL data set collected, re-execute steps 2 to 4 to obtain an updated classification model.
[0091] Those skilled in the art can understand that the above are only preferred examples of the invention and are not intended to limit the invention. Although the invention is described in detail with reference to the above examples, those skilled in the art can still modify the technical solutions recorded in the above examples or replace some of the technical features with equivalents. Any modification, equivalent replacement, etc. made within the spirit and principle of the invention should be included in the protection scope of the invention. All technical features in this embodiment can be freely combined according to actual needs.
[0092] Finally, it should be noted that the above is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, it is still possible for those skilled in the art to modify the technical solutions described in the aforementioned embodiments or to make equivalent substitutions for some of the technical features therein. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for analyzing the causes of slow SQL execution based on supervised machine learning. Features: The specific steps include: Step 1: Collect the SQL running data that was executed slowly in the past; Step 2: Based on the collected SQL operation data, the required feature vectors are extracted to obtain the feature data set corresponding to the SQL; Step 3: preprocess the feature data set, including data cleaning and data normalization; Step 4: Write a cause labeling program based on the expert experience database to automatically label the cause of SQL slowness, and label the cause of the feature data set output in step 3 and add corresponding labels to obtain a labeled feature data set; Step 5: For the labeled data outputted from step 4, a supervised machine learning algorithm is used to train and test the classification model to obtain the classification model; Step 6: For the slow SQL statements that have been executed and are to be analyzed, the classification model obtained in step 5 is used to classify the slow SQL statements, thereby obtaining the specific reasons for the slow SQL statements. Step 7: Since new types of slow SQL execution may appear, the expert experience library used to automatically label the causes of slow execution needs to be expanded and improved every period of time, so as to update the cause labeling program to ensure the accuracy of the SQL slow cause analysis; accordingly, the labels of the data set used to train the classification model will change accordingly, and the model needs to be retrained based on the new training set data to obtain a new classification model.
2. According to the method for analyzing the causes of slow SQL operation based on supervised machine learning according to claim 1, Features: The step 1 includes the following sub-steps: Step 1.1, design the corresponding table structure in the database to collect the required SQL operation data; Step 1.2, collect historical SQL operation data; Step 1.3, filter out the slow SQL statements whose execution time exceeds the time threshold t in step 1.2 as the research object.
3. According to the method for analyzing the causes of slow SQL operation based on supervised machine learning according to claim 1, Features: The step 2 includes the following sub-steps: Step 2.1, for the SQL operation data collected in step 1, call the Hive UDF in the massive database management system to extract traditional features such as keywords in the SQL statement and the number of time partitions corresponding to the SQL query data, the number of occurrences of regular matching keywords, whether there are non-equal value Joins and subquery complex features as text features, and collect them for step 1 at the same time.
4. According to the method for analyzing the causes of slow SQL operation based on supervised machine learning according to claim 1, Features: The step 3 includes the following sub-steps: Step 3.1: For the data features obtained in step 2, replace the missing values and outliers in the feature data with 0; Step 3.2: For the normal data obtained in step 3.1, continue the data normalization operation to obtain a data set that can be used to build a classification model.
5. According to the method for analyzing the causes of slow SQL operation based on supervised machine learning according to claim 1, Features: The step 4 specifically includes the following sub-steps: Step 4.1: Collect the database operation and maintenance experience of the DBA, and determine the value of the feature corresponding to the specific reason for slow execution based on the SQL feature data extracted in step 2.1; Step 4.2: Based on the correspondence between the slow execution reasons and the characteristic values determined in step 4.1, a cause labeling program for labeling the slow SQL reasons is written. It is necessary to find all the combinations of the 14 slow execution reasons in Table 2. The cause combination of the SQL is specifically determined based on whether the executed SQL has one or more of the 14 reasons in Table 2, thereby obtaining the corresponding label to complete the labeling of the slow SQL. Step 4.2.1, for the 14 reasons for slow execution, find all possible combinations to obtain multiple combinations of reasons, each of which has a corresponding label. The full combination of slow execution reasons and their corresponding labels are mapped to form a reason dictionary DICT R ; Step 4.2.2: Find the specific values of the 14 slow execution reasons corresponding to each SQL in Table 2 as the basic reason value combination R 0 ; For each SQL statement, if there is a slow reason, the corresponding slow reason feature value is 1, otherwise it is 0; Step 4.2.3, combine R according to the basic reason value of each SQL 0 The reason dictionary DICT consisting of all combinations of reasons and their corresponding labels R , get the reason number corresponding to each SQL, and complete the marking work of each SQL.
6. According to claim 1, a method for analyzing the causes of slow SQL operation based on supervised machine learning, Features: The step 5 specifically includes the following sub-steps: Step 5.1, for the feature samples with classification labels obtained in step 4.2.3, divide the samples into a training subset and a validation subset according to the proportion. The training subset is used to train the model, and the validation subset is used to verify the performance of the model; use the supervised random forest classification algorithm to fit the classification model based on the training subset, and verify the classification performance of the classification model based on the validation subset.
7. According to claim 1, a method for analyzing the causes of slow SQL operation based on supervised machine learning, Features: The step 6 specifically includes the following sub-steps: Step 6.1: For the executed slow SQL to be analyzed, call the Hive UDF function in the massive database management system to extract the traditional features of the keywords in the SQL statement and the number of time partitions corresponding to the SQL query data, the number of occurrences of regular matching keywords, whether there are non-equal joins and subqueries, and other complex features as classification features; Step 6.2: Use the classification model trained in step 5 to classify the classification features of the slow SQL statements obtained in step 6.1 to obtain the classification probabilities of each category of each slow SQL statement. If the classification probability of any category in each category is greater than or equal to the threshold p, you need to find the category number i with the largest probability value among all categories with classification probability greater than or equal to p, and then mark the slow SQL statement as the i-th category; If the classification probability of any category in each category is less than the threshold p, the category number of the corresponding slow SQL is set to -1; each slow SQL is traversed and processed to finally obtain the slow SQL data with classification labels; Step 6.3, record the slow SQL classified as -1 in step 6.2 as the incremental new SQL type into the file; Step 6.4: Based on the corresponding relationship between the reason for the slow execution in step 4.1 and the characteristic value, statistical analysis is performed to obtain the specific reason for the slow execution corresponding to the slow SQL in step 6.
2.
8. According to claim 1, a method for analyzing the causes of slow SQL operation based on supervised machine learning, Features: The step 7 specifically includes the following sub-steps: Step 7.1: At regular intervals, it is necessary to collect incremental slow SQL data sets running in the database, i.e., the slow SQL data marked as -1 collected in step 6.3; after manual analysis by the DBA, the newly emerged reasons for slow execution and their corresponding feature values are added to the expert experience database; Step 7.2: Based on the expert experience library updated in step 7.1 and the incremental slow SQL data set collected, re-execute steps 2 to 4 to obtain an updated classification model.
Citation Information
Cited By
Pareto graph data analysis method and system based on structured query language
CN120011599A
A pareto chart data analysis method and system based on structured query language
CN120011599B
