Method, device and program product for actively avoiding abnormal occupation of database resources

Through syntax analysis and monitoring of SQL task statements, high-risk tasks are identified and avoided, which solves the problem of delayed processing of abnormal database resource usage in the existing technology, and improves database operation stability and processing efficiency.

CN118245267BActive Publication Date: 2024-09-24TIANJIN NANKAI UNIV GENERAL DATA TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410641712.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-23
Publication Date
2024-09-24
Estimated Expiration
2044-05-23

AI Technical Summary

Technical Problem

In the existing technology, when risky SQL tasks cause abnormal occupation of database resources, the processing is not timely, affecting the cluster business and database operation, and lacks an automated avoidance mechanism.

Method used

Through syntax analysis and monitoring of SQL task statements, high-risk SQL tasks can be identified and avoided, potentially risky tasks can be detected in a timely manner, and abnormal resource occupation can be avoided. The SQL task statement syntax parsing module and monitoring execution module are used to achieve automated processing.

Benefits of technology

It improves the stability of database operation and the timeliness of processing, reduces human intervention, and reduces the impact on cluster business.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118245267B
    Figure CN118245267B
Patent Text Reader

Abstract

The present invention provides a method, device and program product for actively avoiding abnormal occupation of database resources, including obtaining an SQL task statement and performing grammatical analysis, if a first risk condition is met, then the SQL task statement is subjected to an avoidance execution process, if the first risk condition is not met, then the SQL task statement is executed, and the avoidance execution process is to stop the SQL task statement execution; if a second risk condition is met during the execution of the SQL task statement, then the SQL task statement is subjected to a check and kill process, if the second risk condition is not met, then the SQL task statement is executed normally, and the check and kill process is to stop the SQL task statement execution. The present invention proposes a method, device and program product for actively avoiding abnormal occupation of database resources, which can actively avoid the execution of risky SQL tasks and greatly improve the stability of database operation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of databases, and in particular relates to a method, a device and a program product for actively avoiding abnormal occupation of database resources. Background Art

[0002] The cluster deployment architecture MPP has been widely used in the database field. When a cluster node receives a SQL task, the cluster may be stuck due to the direct execution of high-risk SQL task statements. Specific situations include abnormal occupation of database resources, abnormally slow node service response, and the cluster does not recognize it as offline.

[0003] Under existing technical conditions, when risky SQL tasks cause abnormal occupation of database resources, it is generally necessary to manually identify abnormal SQL tasks and abnormal nodes, manually check and kill SQL tasks, and temporarily move abnormal nodes out of the cluster. After the node service returns to normal, the node will be included in the cluster again. This processing method is to process after the abnormal occupation of database resources, which has the problems of untimely processing, uncontrollable impact time on cluster business, and great impact on database operation. Summary of the invention

[0004] In view of this, the present invention aims to overcome the defects in the prior art and proposes a method, device and program product for actively avoiding abnormal occupation of database resources, which can actively avoid the execution of risky SQL tasks and greatly improve the stability of database operation.

[0005] To achieve the above object, the technical solution of the present invention is achieved as follows:

[0006] In a first aspect, the present invention discloses a method for actively avoiding abnormal occupation of database resources:

[0007] Obtaining the SQL task statement and performing syntax analysis, if the first risk condition is met, performing avoidance execution processing on the SQL task statement, if the first risk condition is not met, executing the SQL task statement, and the avoidance execution processing is to stop the execution of the SQL task statement;

[0008] If the second risk condition is met during the execution of the SQL task statement, the SQL task statement is checked and killed; if the second risk condition is not met, the SQL task statement is executed normally, and the checking and killing process is to stop the execution of the SQL task statement.

[0009] Further, satisfying the first risk condition includes satisfying at least one of the following analysis conditions:

[0010] Analysis condition 1: There must be at least two tables and at least one table has no association with other tables;

[0011] Analysis condition 2: There are at least two tables and the content of the where clause is empty;

[0012] Analysis condition three: There are at least two tables and the select clause is *;

[0013] Analysis condition 4: satisfying the windowed OLAP statistics without partition fields;

[0014] Analysis condition five: The number of fields in the source data file to be loaded is inconsistent with the number of fields in the target table;

[0015] Analysis condition six: any table is associated with other tables and in the first table record number sampling data, the number of rows in the associated execution result set divided by the number of rows in the largest table in the SQL task statement is greater than or equal to the expansion coefficient;

[0016] Analysis condition seven: When the number of records in a single table exceeds 10 million, in the sampling data of the number of records in the second table, the number of rows in the result set of the group by statement divided by the number of rows in the group by source table is greater than or equal to the convergence coefficient.

[0017] Further: satisfying the second risk condition includes satisfying at least one of the following monitoring conditions:

[0018] Monitoring condition 1: During the execution of the SQL task statement, the capacity of the temporary result set of multi-table associations is greater than the first threshold;

[0019] Monitoring condition 2: During the execution of the SQL task statement, the capacity of the temporary file for group by aggregation is greater than the second threshold;

[0020] Monitoring condition three: During the execution of SQL task statements, the capacity of the temporary file for windowed OLAP statistics is greater than the third threshold;

[0021] Monitoring condition four: During the execution of the SQL task statement, the number of skipped records is greater than the fourth threshold.

[0022] Furthermore, the first table record number sampling data includes: table record number <= 10 million, sampling ratio 10%; 10 million < table record number <= 50 million, sampling ratio 5%, table record number > 50 million, sampling ratio 2%; the maximum table record number sampling number does not exceed 1 million.

[0023] Furthermore, the second table record number sampling data includes: 10 million < table record number <= 50 million, sampling ratio 10%; table record number > 50 million, sampling ratio 2%; the maximum table record number sampling number does not exceed 1 million.

[0024] Furthermore, the first threshold is 10G*N, where N is 3 to 10, and G is a unit of data capacity.

[0025] Furthermore, the second threshold is 10G*N, where N is 3 to 10, and G is a unit of data capacity.

[0026] Furthermore, the third threshold is 10G*N*M, where N is 3 to 10, M is the number of nodes in the database cluster, and the fourth threshold is 100,000 to 1,000,000.

[0027] Second aspect: The present invention discloses a device capable of actively avoiding abnormal occupation of database resources. The device capable of actively avoiding abnormal occupation of database resources includes:

[0028] The SQL task statement syntax parsing module is used to obtain the SQL task statement and perform syntax parsing. If the first risk standard is met, the SQL task statement is circumvented. If the first risk standard is not met, the SQL task statement is executed. The circumvented execution process is to stop the execution of the SQL task statement.

[0029] The SQL task statement monitoring and execution module is used to perform a check and kill process on the SQL task statement if the second risk condition is met during the execution of the SQL task statement. If the second risk condition is not met, the SQL task statement is executed normally. The check and kill process is to stop the execution of the SQL task statement.

[0030] In a third aspect, the present invention discloses a computer program product, including a computer program, which, when executed by a processor, implements the steps of the above-mentioned method for actively avoiding abnormal occupation of database resources.

[0031] Compared with the prior art, the present invention has the following advantages:

[0032] The present invention discloses a method for actively avoiding abnormal occupation of database resources. By performing grammatical analysis on SQL task statements, high-risk SQL task statements are avoided in advance before the SQL task statements are formally executed. In the process of further executing the SQL task statements, risky SQL tasks are promptly checked and killed according to the execution situation, and the situation that may cause abnormal occupation of database resources is actively avoided, which speeds up the timeliness of processing and improves the stability of database operation. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] The accompanying drawings constituting a part of the present invention are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the accompanying drawings:

[0034] Figure 1 A schematic diagram of a method for actively avoiding abnormal occupation of database resources according to an embodiment of the present invention;

[0035] Figure 2 This is a schematic diagram of a first embodiment of a method for actively avoiding abnormal occupation of database resources according to an embodiment of the present invention;

[0036] Figure 3 This is a schematic diagram of a second embodiment of a method for actively avoiding abnormal occupation of database resources according to an embodiment of the present invention;

[0037] Figure 4 This is a schematic diagram of a third embodiment of a method for actively avoiding abnormal occupation of database resources according to an embodiment of the present invention;

[0038] Figure 5 A schematic diagram of a device for actively avoiding abnormal occupation of database resources according to an embodiment of the present invention. DETAILED DESCRIPTION

[0039] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments may be combined with each other.

[0040] In the description of the present invention, it is to be understood that the terms "first", "second", etc. are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first", "second", etc. may explicitly or implicitly include one or more of the feature. In the description of the present invention, unless otherwise specified, "plurality" means two or more.

[0041] The present invention will be described in detail below with reference to the accompanying drawings and in conjunction with embodiments.

[0042] Embodiment 1, as Figure 1-2 As shown, the present invention discloses a method for actively avoiding abnormal occupation of database resources:

[0043] Step S101, obtaining an SQL task statement and performing syntax analysis, if the first risk condition is met, performing avoidance execution processing on the SQL task statement, if the first risk condition is not met, executing the SQL task statement, the avoidance execution processing is to stop the execution of the SQL task statement;

[0044] Step S102: If the second risk condition is met during the execution of the SQL task statement, the SQL task statement is checked and killed; if the second risk condition is not met, the SQL task statement is executed normally, and the checking and killing process is to stop the execution of the SQL task statement.

[0045] In this embodiment, if the killing process is performed, a warning message is fed back.

[0046] Embodiment 2, as Figure 3As shown, satisfying the first risk condition includes satisfying at least one of the following analysis conditions:

[0047] Analysis condition 1 201: The condition that there are at least two tables and at least one table has no association with other tables is satisfied;

[0048] In this embodiment, there is no association condition that there is more than one table that is not associated with any other table through inner join, left join, right join or full join operation.

[0049] Analysis condition 2 202: at least two tables exist and the content of the where clause is empty;

[0050] Analysis condition three 203: at least two tables exist and the select clause is *;

[0051] Analysis condition 4 204: Satisfy windowed OLAP statistics without partition fields;

[0052] In this embodiment, if the following keywords exist in the SQL task statement, it is determined that the windowed OLAP statistics have no partition fields:

[0053] rank() over(partition by NULL)

[0054] dense_rank() over(partition by NULL)

[0055] row_number() over(partition by NULL)

[0056] The NULL in partition by NULL means that the partition field is not specified.

[0057] Analysis condition five 205: The number of fields in the source data file to be loaded is inconsistent with the number of fields in the target table;

[0058] In this embodiment, parsing condition five may be to compare whether the number of fields in a row of the data source file for loading the SQL task statement is consistent with the number of fields in the target table. If they are consistent, parsing condition five is satisfied.

[0059] Analysis condition six 206: any table is associated with other tables and in the first table record number sampling data, the number of rows of the associated execution result set divided by the number of rows of the largest table in the SQL task statement is greater than or equal to the expansion coefficient;

[0060] In this embodiment, the expansion coefficient is 3 to 10.

[0061] Analysis condition seven 207: When the number of records in a single table exceeds 10 million, in the sampling data of the number of records in the second table, the number of rows in the result set of the group by statement divided by the number of rows in the group by source table >= the convergence coefficient.

[0062] In this embodiment, the convergence coefficient is 0.8.

[0063] Embodiment three, as Figure 4 As shown, satisfying the second risk condition includes satisfying at least one of the following monitoring conditions:

[0064] Monitoring condition 1 301: During the execution of the SQL task statement, the capacity of the temporary result set of multi-table association is greater than the first threshold;

[0065] Method for obtaining the capacity of temporary result sets for multi-table association: Use the cluster-layer SQL task ID and the processlist system view on the data node to obtain the data node task GNSID. Use the GNSID to match the following files in the data node temporary data file directory ${gnode_data} / tmpdata / cache / : *${ GNSID}.express_tmp, and calculate the capacity as the capacity of temporary result sets for multi-table association.

[0066] Monitoring condition 2 302: during the execution of the SQL task statement, the capacity of the group by grouping aggregate temporary file is greater than the second threshold;

[0067] Method for obtaining the capacity of temporary files for group by aggregation: Use the cluster-layer SQL task ID and the processlist system view on the data node to obtain the data node task GNSID. Use the GNSID to match the following files in the data node temporary data file directory ${gnode_data} / tmpdata / tmp_matiralized / : tmp_${ GNSID}*.GED, and calculate the capacity as the temporary file capacity for group by aggregation.

[0068] Monitoring condition three 303: during the execution of the SQL task statement, the capacity of the temporary file for windowed OLAP statistics is greater than the third threshold;

[0069] Method for obtaining temporary file capacity for windowed OLAP statistics: Use the cluster-layer SQL task ID and the processlist system view on the data node to obtain the data node task GNSID. Use the GNSID to match the following files in the data node temporary data file directory ${gnode_data} / tmpdata / tmp_matiralized / : tmp_${ GNSID}*.GED, and calculate the capacity as the temporary file capacity for windowed OLAP statistics.

[0070] Monitoring condition four 304: during the execution of the SQL task statement, the number of skipped records is greater than the fourth threshold.

[0071] How to obtain the number of skipped records: According to the SQL task ID, obtain it through the system view load_status.

[0072] In this embodiment, the first table record number sampling data includes: table record number <= 10 million, sampling ratio 10%; 10 million < table record number <= 50 million, sampling ratio 5%, table record number > 50 million, sampling ratio 2%; the maximum table record number sampling number does not exceed 1 million.

[0073] In this embodiment, the second table record number sampling data includes: 10 million < table record number <= 50 million, sampling ratio 10%; table record number > 50 million, sampling ratio 2%; the maximum table record number sampling number does not exceed 1 million.

[0074] In this embodiment, the first threshold is 10G*N, where N is a value from 3 to 10, and G is a unit of data capacity.

[0075] In this embodiment, the second threshold is 10G*N, where N is 3 to 10, and G is a unit of data capacity.

[0076] In this embodiment, the third threshold is 10G*N*M, where N is 3 to 10, and M is the number of nodes in the database cluster.

[0077] In this embodiment, the fourth threshold value is between 100,000 and 1,000,000.

[0078] Embodiment 4, as Figure 5 As shown, the present invention discloses a device capable of actively avoiding abnormal occupation of database resources, comprising:

[0079] The SQL task statement syntax parsing module is used to obtain the SQL task statement and perform syntax parsing. If the first risk standard is met, the SQL task statement is circumvented. If the first risk standard is not met, the SQL task statement is executed. The circumvented execution process is to stop the execution of the SQL task statement.

[0080] The SQL task statement monitoring and execution module is used to perform a check and kill process on the SQL task statement if the second risk condition is met during the execution of the SQL task statement. If the second risk condition is not met, the SQL task statement is executed normally. The check and kill process is to stop the execution of the SQL task statement.

[0081] The present invention discloses a computer program product, comprising a computer program, which implements the steps of the method for actively avoiding abnormal occupation of database resources when executed by a processor.

[0082] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. 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 actively avoiding abnormal occupation of database resources, characterized by: Obtaining an SQL task statement and performing syntax analysis, if a first risk condition is met, performing an avoidance execution process on the SQL task statement, if the first risk condition is not met, executing the SQL task statement, wherein the avoidance execution process is to stop the execution of the SQL task statement; The first risk condition is satisfied, which includes satisfying at least one of the following analysis conditions: Analysis condition 1: There must be at least two tables and at least one table has no association with other tables; Analysis condition 2: There are at least two tables and the content of the where clause is empty; Analysis condition three: There are at least two tables and the select clause is *; Analysis condition 4: satisfying the windowed OLAP statistics without partition fields; Analysis condition five: The number of fields in the source data file to be loaded is inconsistent with the number of fields in the target table; If the second risk condition is met during the execution of the SQL task statement, the SQL task statement is checked and killed; if the second risk condition is not met, the SQL task statement is executed normally, and the checking and killing process is to stop the execution of the SQL task statement; The second risk condition is satisfied including at least one of the following monitoring conditions: Monitoring condition 1: during the execution of the SQL task statement, the capacity of the multi-table association temporary result set is greater than the first threshold; The method for obtaining the capacity of the temporary result set associated with multiple tables includes: obtaining the data node task GNSID through the processlist system view at the data node through the cluster layer SQL task ID, matching the file with the following characteristics in the data node temporary data file directory ${gnode_data} / tmpdata / cache / through the GNSID: *${ GNSID}.express_tmp, and calculating the capacity as the temporary result set capacity of the multi-table association; Monitoring condition 2: during the execution of the SQL task statement, the capacity of the group by grouping aggregate temporary file is greater than the second threshold; The method for obtaining the capacity of the temporary file of group by group aggregation includes: obtaining the data node task GNSID through the processlist system view at the data node through the cluster layer SQL task ID, matching the file with the following characteristics in the temporary data file directory ${gnode_data} / tmpdata / tmp_matiralized / of the data node through the GNSID: tmp_${ GNSID}*.GED, and calculating the capacity as the temporary file capacity of group by group aggregation; Monitoring condition three: during the execution of the SQL task statement, the capacity of the temporary file for windowed OLAP statistics is greater than the third threshold; The method for obtaining the capacity of temporary files for windowed OLAP statistics includes: obtaining the data node task GNSID through the processlist system view at the data node through the cluster layer SQL task ID, matching the following files in the data node temporary data file directory ${gnode_data} / tmpdata / tmp_matiralized / through the GNSID: tmp_${ GNSID}*.GED, and calculating the capacity as the temporary file capacity for windowed OLAP statistics; Monitoring condition four: during the execution of the SQL task statement, the number of skipped records is greater than the fourth threshold.

2. The method for actively avoiding abnormal occupation of database resources according to claim 1, characterized in that: The first risk condition is satisfied, which includes satisfying at least one of the following analysis conditions: Analysis condition six: any table is associated with other tables and in the first table record number sampling data, the number of rows in the associated execution result set divided by the number of rows in the largest table in the SQL task statement is greater than or equal to the expansion coefficient; Analysis condition seven: For a single table with more than 10 million records, in the sampling data of the second table, the number of rows in the result set of the group by statement divided by the number of rows in the group by source table is greater than or equal to the convergence coefficient.

3. The method for actively avoiding abnormal occupation of database resources according to claim 2, characterized in that: The first table record number sampling data includes: table record number <= 10 million, sampling ratio 10%; 10 million < table record number <= 50 million, sampling ratio 5%, table record number > 50 million, sampling ratio 2%; the maximum table record number sampling number does not exceed 1 million.

4. The method for actively avoiding abnormal occupation of database resources according to claim 2, characterized in that: The second table record number sampling data includes: 10 million < table record number <= 50 million, sampling ratio 10%; table record number > 50 million, sampling ratio 2%; the maximum table record number sampling number does not exceed 1 million.

5. The method for actively avoiding abnormal occupation of database resources according to claim 1, characterized in that: The first threshold is 10G*N, where N is 3 to 10, and G is a unit of data capacity.

6. The method for actively avoiding abnormal occupation of database resources according to claim 1, characterized in that: The second threshold is 10G*N, where N is 3 to 10, and G is a unit of data capacity.

7. The method for actively avoiding abnormal occupation of database resources according to claim 1, characterized in that: The third threshold is 10G*N*M, where N is 3 to 10, and M is the number of nodes in the database cluster; the fourth threshold is 100,000 to 1,000,000.

8. A device for actively avoiding abnormal occupation of database resources, characterized in that: The device for actively avoiding abnormal occupation of database resources includes: An SQL task statement syntax parsing module, used for obtaining an SQL task statement and performing syntax parsing, and if a first risk condition is met, performing an avoidance execution process on the SQL task statement, and if the first risk condition is not met, executing the SQL task statement, wherein the avoidance execution process is to stop the execution of the SQL task statement; The first risk condition is satisfied, which includes satisfying at least one of the following analysis conditions: Analysis condition 1: There must be at least two tables and at least one table has no association with other tables; Analysis condition 2: There are at least two tables and the content of the where clause is empty; Analysis condition three: There are at least two tables and the select clause is *; Analysis condition 4: satisfying the windowed OLAP statistics without partition fields; Analysis condition five: The number of fields in the source data file to be loaded is inconsistent with the number of fields in the target table; An SQL task statement monitoring and execution module, configured to perform a check and kill process on the SQL task statement if a second risk condition is met during the execution of the SQL task statement, and to execute the SQL task statement normally if the second risk condition is not met, wherein the check and kill process is to stop the execution of the SQL task statement; The second risk condition is satisfied including at least one of the following monitoring conditions: Monitoring condition 1: during the execution of the SQL task statement, the capacity of the temporary result set of multi-table association is greater than the first threshold; The method for obtaining the capacity of the temporary result set associated with multiple tables includes: obtaining the data node task GNSID through the processlist system view at the data node through the cluster layer SQL task ID, matching the file with the following characteristics in the data node temporary data file directory ${gnode_data} / tmpdata / cache / through the GNSID: *${ GNSID}.express_tmp, and calculating the capacity as the temporary result set capacity of the multi-table association; Monitoring condition 2: during the execution of the SQL task statement, the capacity of the group by grouping aggregate temporary file is greater than the second threshold; The method for obtaining the capacity of the temporary file of group by group aggregation includes: obtaining the data node task GNSID through the processlist system view at the data node through the cluster layer SQL task ID, matching the file with the following characteristics in the temporary data file directory ${gnode_data} / tmpdata / tmp_matiralized / of the data node through the GNSID: tmp_${ GNSID}*.GED, and calculating the capacity as the temporary file capacity of group by group aggregation; Monitoring condition three: during the execution of the SQL task statement, the capacity of the temporary file for windowed OLAP statistics is greater than the third threshold; The method for obtaining the capacity of temporary files for windowed OLAP statistics includes: obtaining the data node task GNSID through the processlist system view at the data node through the cluster layer SQL task ID, matching the following files in the data node temporary data file directory ${gnode_data} / tmpdata / tmp_matiralized / through the GNSID: tmp_${ GNSID}*.GED, and calculating the capacity as the temporary file capacity for windowed OLAP statistics; Monitoring condition four: during the execution of the SQL task statement, the number of skipped records is greater than the fourth threshold.

9. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method for actively avoiding abnormal occupation of database resources as described in any one of claims 1 to 8 are implemented.