Query statement processing method and apparatus
By extracting and matching the execution templates of query statements, abnormal query statements are detected and interrupted in real time, solving the performance degradation problem of MYSQL database when processing high-resource SQL requests, and improving the stability and efficiency of the database.
Patent Information
- Application Number
- CN202111358070.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-16
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2041-11-16
AI Technical Summary
When the MYSQL database processes a large number of SQL requests that consume a lot of resources, it may exhaust the CPU or IO resources and be unable to serve other requests, resulting in a decrease in overall performance.
By obtaining the execution template of the query statement, using the variable specification tool to extract and match it with the reference template in the preset template library, abnormal query statements can be detected in real time, and interrupted or limited when the preset abnormal conditions are met.
It realizes real-time online detection of abnormal query statements, reduces deployment costs and maintenance risks, avoids information lag and human intervention, and improves database stability and efficiency.
Smart Images

Figure CN114265857B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present specification relate to the technical field of computer technology, and in particular, to a query statement processing method. BACKGROUND
[0002] With the continuous development of computer technology, various relational databases emerge in an endless stream, among which the MYSQL database is the most popular. When the MYSQL database is running, if a large number of structured query language (SQL) processing requests, i.e., SQL requests, with high resource occupation are received at the same time, the central processing unit (CPU) or input / output (IO) resources inside the MYSQL database server in this time period will be exhausted, and these SQL requests that occupy a large number of operating system resources for a long time are called slow SQL. When the MYSQL database processes a large number of slow SQL, it cannot serve other project requests due to resource problems, thereby causing the overall performance of the database to drop sharply and causing a huge impact on the project. Therefore, an effective solution is urgently needed to solve the above problems. SUMMARY
[0003] Therefore, the embodiments of the present specification provide a query statement processing method. One or more embodiments of the present specification also relate to a query statement processing device, a computing device, a computer-readable storage medium, and a computer program to solve the technical defects in the prior art.
[0004] According to a first aspect of the embodiments of the present specification, a query statement processing method is provided, comprising:
[0005] obtaining a query statement to be executed, extracting an execution template of the query statement by using a variable specification tool;
[0006] matching the execution template with each reference template in a preset template library, executing the query statement in the case of meeting a preset matching condition, and obtaining execution data of the query statement in the process of executing the query statement;
[0007] determining the query statement as an abnormal query statement in the case that the currently obtained execution data meets a preset abnormal condition.
[0008] Optionally, further comprising:
[0009] continuing to execute the query statement in the case that the currently obtained execution data does not meet the preset abnormal condition;
[0010] If the query statement execution ends, the total execution time of the query statement is obtained;
[0011] If the total execution time is greater than a first preset time threshold, the query statement is determined as an abnormal query statement.
[0012] Optionally, the method further comprises:
[0013] If the total execution time is less than or equal to the first preset time threshold, the query statement is determined as a normal query statement.
[0014] Optionally, after the query statement is executed, the method further comprises:
[0015] In the process of executing the query statement, if a time interval reaches a first preset interval, the execution template is matched with each reference template in a preset template library.
[0016] Optionally, after the execution template is matched with each reference template in the preset template library, the method further comprises:
[0017] If a preset matching condition is not met, the query statement is determined as an abnormal query statement, and a concurrency degree of the abnormal query statement is obtained;
[0018] If the concurrency degree is greater than or equal to a concurrency threshold, the abnormal query statement is interrupted.
[0019] Optionally, the method further comprises:
[0020] If the concurrency degree is less than the concurrency threshold, the abnormal query statement is executed, and the concurrency degree is increased by 1;
[0021] If the abnormal query statement execution ends, the concurrency degree is decreased by 1.
[0022] Optionally, after the query statement is determined as the abnormal query statement in a case where the currently obtained execution data reaches a preset abnormal condition, the method further comprises:
[0023] A concurrency degree of the abnormal query statement is obtained;
[0024] If the concurrency degree is greater than or equal to a concurrency threshold, the abnormal query statement is interrupted.
[0025] If the concurrency degree is less than the concurrency threshold, the abnormal query statement is continued to be executed, and the concurrency degree is increased by 1; if the abnormal query statement execution ends, the concurrency degree is decreased by 1.
[0026] Optionally, the execution data of the query statement is obtained in the process of executing the query statement, comprising:
[0027] In the process of executing the query statement, execution data of the query statement is periodically obtained according to a second preset interval.
[0028] Optionally, the execution data is an executed duration.
[0029] The determining the query statement as an abnormal query statement in the case that the currently obtained execution data reaches a preset abnormal condition comprises:
[0030] The determining the query statement as an abnormal query statement in the case that the currently obtained executed duration is greater than a second preset duration threshold.
[0031] Optionally, the method further comprises:
[0032] After determining the type of the query statement, updating the preset template library, the type comprising an abnormal query statement or a normal query statement.
[0033] According to a second aspect of the embodiments of the present specification, a query statement processing apparatus is provided, comprising:
[0034] An extraction module configured to obtain a query statement to be executed, and extract an execution template of the query statement.
[0035] A first execution module configured to match the execution template with each reference template in a preset template library, execute the query statement in the case that a preset matching condition is met, and obtain execution data of the query statement in the process of executing the query statement.
[0036] A first determination module configured to determine the query statement as an abnormal query statement in the case that the currently obtained execution data reaches a preset abnormal condition.
[0037] Optionally, the apparatus further comprises:
[0038] A second execution module configured to continue executing the query statement in the case that the currently obtained execution data does not reach a preset abnormal condition.
[0039] A first obtaining module configured to obtain an execution total duration of the query statement if the query statement is executed to the end.
[0040] A second determination module configured to determine the query statement as an abnormal query statement in the case that the execution total duration is greater than a first preset duration threshold.
[0041] Optionally, the apparatus further comprises:
[0042] The third determining module is configured to determine the query statement as a normal query statement when the total execution duration is less than or equal to a first preset duration threshold.
[0043] Optionally, the execution module is further configured to match the execution template with each reference template in a preset template library if a time interval reaches a first preset interval during execution of the query statement.
[0044] Optionally, the apparatus further comprises:
[0045] The fourth determining module is configured to determine the query statement as an abnormal query statement and acquire a concurrency degree of the abnormal query statement when a preset matching condition is not met.
[0046] The first interrupting module is configured to interrupt the abnormal query statement when the concurrency degree is greater than or equal to a concurrency degree threshold.
[0047] Optionally, the apparatus further comprises:
[0048] The third execution module is configured to execute the abnormal query statement when the concurrency degree is less than the concurrency degree threshold, and the concurrency degree is increased by 1; and the concurrency degree is decreased by 1 when the abnormal query statement is executed.
[0049] Optionally, the apparatus further comprises:
[0050] The second acquiring module is configured to acquire a concurrency degree of an abnormal query statement.
[0051] The second interrupting module is configured to interrupt the abnormal query statement when the concurrency degree is greater than or equal to a concurrency degree threshold.
[0052] The fourth execution module is configured to continue to execute the abnormal query statement when the concurrency degree is less than the concurrency degree threshold, and the concurrency degree is increased by 1; and the concurrency degree is decreased by 1 when the abnormal query statement is executed.
[0053] Optionally, the first execution module is further configured to periodically acquire execution data of the query statement according to a second preset interval during execution of the query statement.
[0054] Optionally, the execution data is an executed duration.
[0055] The first determining module is further configured to determine the query statement as an abnormal query statement when the currently acquired executed duration is greater than a second preset duration threshold.
[0056] Optionally, the apparatus further comprises an updating module configured to update the preset template library after determining the type of the query statement, the type comprising an abnormal query statement or a normal query statement.
[0057] According to a third aspect of the embodiments of the present specification, a computing device is provided, comprising:
[0058] a memory and a processor;
[0059] the memory is configured to store computer executable instructions, and the processor is configured to execute the computer executable instructions:
[0060] obtaining a query statement to be executed, and extracting an execution template of the query statement by using a variable specification tool;
[0061] matching the execution template with each reference template in a preset template library, executing the query statement in a case where a preset matching condition is met, and obtaining execution data of the query statement in a process of executing the query statement;
[0062] determining the query statement as an abnormal query statement in a case where the currently obtained execution data reaches a preset abnormal condition.
[0063] According to a fourth aspect of the embodiments of the present specification, a computer readable storage medium is provided, which stores computer executable instructions, and the instructions are executed by a processor to implement the steps of any one of the query statement processing methods.
[0064] According to a fifth aspect of the embodiments of the present specification, a computer program is provided, and when the computer program is executed in a computer, the computer is caused to execute the steps of the above query statement processing method.
[0065] The query statement processing method provided in the specification first acquires a query statement to be executed, extracts an execution template of the query statement by using a variable specification tool, then matches the execution template with each reference template in a preset template library, executes the query statement in the case of meeting a preset matching condition, and obtains execution data of the query statement in the process of executing the query statement, and then determines the query statement as an abnormal query statement in the case of the currently obtained execution data meeting a preset abnormal condition. By determining the query statement as an abnormal query statement in the case of the currently obtained execution data meeting a preset abnormal condition, real-time online detection of abnormal query statements is realized, the problem that offline tools cannot guarantee real-time performance is solved, and the abnormal query statement can be accurately determined through the preset template library and the abnormal condition, the information lag problem existing in external detection components is avoided, the use cost is greatly reduced, and the risk of human intervention is avoided. BRIEF DESCRIPTION OF DRAWINGS
[0066] Figure 1 is a flowchart of a query statement processing method provided by an embodiment of the specification;
[0067] Figure 2 is a processing process schematic diagram of a query statement processing method provided by an embodiment of the specification;
[0068] Figure 3 is a processing process schematic diagram of pre-positioned flow limiting provided by an embodiment of the specification;
[0069] Figure 4 is a processing process schematic diagram of background flow limiting provided by an embodiment of the specification;
[0070] Figure 5 is a processing process schematic diagram of another query statement processing method provided by an embodiment of the specification;
[0071] Figure 6 is a structural schematic diagram of a query statement processing device provided by an embodiment of the specification;
[0072] Figure 7 is a structural block diagram of a computing device provided by an embodiment of the specification. DETAILED DESCRIPTION
[0073] In the following description, many specific details are set forth in order to provide a thorough understanding of the specification. However, the specification can be practiced in many different ways beyond the specific embodiments described herein, and it is understood that one skilled in the art can make similar modifications without departing from the spirit of the specification.
[0074] The terminology used in this description of one or more embodiments is for the purpose of describing particular embodiments only and is not intended to be limiting of one or more embodiments of the description. As used in this description of one or more embodiments and the accompanying claims, the singular forms“a,”“an” and“the” are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will also be understood that the term“and / or” as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.
[0075] It will be understood that, although the terms first, second, etc. can be used herein to describe various information, these terms are not intended to denote a temporal sequence, but are used only to distinguish one piece of information from another. For example, without departing from the scope of one or more embodiments of the description, first can be termed second; likewise, second can be termed first. Depending on the context, the word“if’ as used herein can be interpreted to mean“when” or“in response to determining” or“in response to a determination.”
[0076] Firstly, the noun terms related to one or more embodiments of the description are explained.
[0077] MYSQL is a relational database management system that saves data in different tables instead of putting all data in one big warehouse, which increases speed and improves flexibility.
[0078] Structured Query Language (SQL) is a special-purpose programming language designed for managing and querying relational databases. It is used to access, query, update, and manage relational database systems, or to perform stream processing in relational stream data management systems.
[0079] Database AutonoMY Service (DAS) is a cloud service that enables database self-awareness, self-repair, self-optimization, self-operation and maintenance, and self-security based on machine learning and expert experience.
[0080] Statement Digest: A pattern of a SQL statement that can abstract and standardize the specific parameter values of the SQL.
[0081] Then, the scheme provided in the description is explained.
[0082] In order to alleviate the negative impact of slow SQL on MYSQL, and enable the database to provide stable services continuously, the industry has tried various solutions to solve this problem:
[0083] Thread pool detection scheme based on real-time internal statistical information: The thread pool stallcheck function provided by MYSQL is a thread pool slow SQL detection tool. When it detects slow SQL in the thread pool, it will try to create more threads to provide normal service. However, since slow SQL has exhausted system resources, creating more threads will occupy resources and cannot fundamentally solve the problem. That is, when it is found that there are some SQLs running for a long time in the thread pool and there are no idle threads available to serve other SQLs in the thread pool, it will try to create new threads to alleviate the current thread pool blocking pressure. However, this method will exacerbate the impact of slow SQL to some extent, because creating new threads to process other SQLs will increase the resources occupied by MYSQL, bringing greater slow SQL risk to the entire server.
[0084] Diagnosis tool based on offline slow SQL statistical information: MYSQLdumpslow tool and pt-query-digest are offline analysis tools specifically for MYSQL database slow query log, which can help database operation and maintenance personnel obtain more friendly, readable, and user-friendly SQL performance summary and analysis report. However, due to its offline nature, it cannot govern slow SQL in real time, that is, based on a specific slow SQL file, it can collect the MYSQL resources consumed by each SQL in the file to help database operation and maintenance personnel obtain more systematic slow SQL information and optimize SQL or MYSQL table structure. However, this offline tool cannot govern slow SQL in real time, and requires personnel with certain database knowledge to use, which has high use cost.
[0085] The cloud database autonomous service DAS contains a slow SQL throttling tool, which can formulate slow SQL throttling measures according to user-specified SQL keywords, but these keywords can only prevent specific SQLs that are known to be slow SQLs, and the flexibility is too poor, that is, the SQL throttling tool of the cloud database autonomous service DAS can support setting throttling measures for specific SQL keywords, and for each SQL, if it contains a pre-set keyword and meets the throttling condition, it will be throttled. The disadvantage of this tool is that the flexibility is too poor, and it can only throttle pre-set specific SQLs, and cannot handle all burst slow SQLs in the MYSQL server. In addition, there is no global consideration between various throttling measures, and it is possible that all SQL templates do not trigger throttling, but the slow SQLs accumulated by multiple templates have exhausted the MYSQL resources.
[0086] The middleware-based detection scheme is that an external middleware service periodically collects statistical information of SQL execution to the MYSQL server, and according to the information, identifies slow SQLs, and according to pre-set throttling measures or automatically extracts slow SQL feature information to throttle slow SQLs of the MYSQL server. However, since it is an external service, when obtaining information from the MYSQL server, the MYSQL server may have been exhausted by slow SQLs, resulting in obtaining lagged or even unable to obtain statistical information. Therefore, this scheme has the risk of instability and cannot provide real-time and accurate slow SQL throttling.
[0087] Therefore, the present specification provides a query statement processing method, which first obtains a query statement to be executed, extracts an execution template of the query statement; then matches the execution template with each reference template in a pre-set template library, executes the query statement under the condition that a pre-set matching condition is met, and obtains execution data of the query statement in the process of executing the query statement; and then determines the query statement as an abnormal query statement under the condition that the currently obtained execution data meets a pre-set abnormal condition. By determining the query statement as an abnormal query statement under the condition that the currently obtained execution data meets a pre-set abnormal condition, real-time online detection of abnormal query statements is realized, solving the problem that offline tools cannot guarantee real-time performance; without relying on external components, the method can be integrated into a database with lower coupling, reducing deployment costs and maintenance risks; by using a pre-set template library and abnormal conditions, abnormal query statements can be accurately determined, avoiding the information lag problem existing in external detection components; greatly reducing the use cost, and avoiding the risk of human intervention.
[0088] In the specification, a query statement processing method is provided, and the specification also relates to a query statement processing device, a computing device, and a computer readable storage medium, which are described in the following embodiments one by one.
[0089] Figure 1 A flowchart of a query statement processing method according to one embodiment of the specification is shown, and specifically includes the following steps.
[0090] Step 102: Obtain a query statement to be executed, and extract an execution template of the query statement by using a variable specification tool.
[0091] Specifically, the query statement refers to a statement generated by querying or other data processing in a database, which can be a structured query statement (SQL, Structured Query Language) or other types of query statements. Preferably, the query statement is SQL, and the database is a relational database management system, namely, a MYSQL database. The variable specification tool is a template extraction tool pre-set or specified by the database, namely, a specified template extraction tool. The variable specification tool can abstract and standardize the specific parameter values of the query statement, namely, variables. The execution template refers to a statement obtained by abstracting and standardizing the specific parameter values of the query statement, namely, variables.
[0092] In actual application, when a user queries or performs other operations in a database, or sends a query statement to the database through a client, namely, the database obtains a query statement to be executed. Then, the database standardizes the variables of the query statement by using the variable specification tool, namely, replaces the specific parameter values with preset content, so as to extract an execution template of the query statement, so as to facilitate subsequent identification of the query statement according to the execution template. The database can extract the execution template of the query statement by using a template extraction tool, or extract the execution template of the query statement by using a neural network model.
[0093] Preferably, the obtained query statement to be executed is a structured query statement, and at this time, the database is a MYSQL database. The MYSQL database can extract an execution template of the structured query statement by using a specified template extraction tool of the MYSQL database. Namely, in the case where the query statement is a structured query statement, the specific implementation process of extracting the execution template of the query statement is as follows.
[0094] According to the variable specification tool, extract the execution template of the structured query statement.
[0095] Specifically, the variable specification tool refers to a template extraction tool pre-set or specified by the database, namely, Statement Digest of the MYSQL database.
[0096] In practical application, the MYSQL database identifies the execution template of the structured query statement based on the Statement Digest, that is, the specific parameter value in the structured query statement is abstracted and normalized based on the Statement Digest: the identifier in the structured query statement is retained, and the specific parameter value is replaced with a preset content to obtain the execution template of the structured query statement, wherein the preset content can be a preset symbol such as "?" and "!" symbol, and can also be a preset number or a preset letter. Based on the statement digest, a certain general execution template can be identified from a single structured query statement.
[0097] For example, the structured query statement is "select*from t where id=1and value='hello'", which is identified by the Statement Digest to obtain the execution template "SELECT 'id' FROM 't' WHERE 'id'=?ANDValue=?".
[0098] Using the specified template extraction tool of the MYSQL database can improve the accuracy of the execution template, improve the speed of determining the execution template, and further improve the efficiency of processing the query statement.
[0099] Step 104: match the execution template with each reference template in the preset template library, execute the query statement under the condition that the preset matching condition is met, and obtain the execution data of the query statement in the process of executing the query statement.
[0100] On the basis of extracting the execution template of the query statement, the execution template is further matched with the reference template in the preset template library, and if the preset matching condition is met, the query statement is executed, and the execution data of the query statement is obtained in the execution process.
[0101] Specifically, the reference template refers to a template for measuring whether the execution template is abnormal, which can be an abnormal template or a normal template; the preset template library is used to store the reference template, which can be an abnormal template library or a normal template library, when the preset template library is an abnormal template library, each reference template in the abnormal template library is an abnormal template, and when the preset template library is a normal template library, each reference template in the normal template library is a normal template; the preset matching condition refers to a condition set in advance for the matching result of the execution template and each reference template in the preset template library; the execution data can be the current execution time of the query statement, that is, the executed time, and can also be other execution data such as background occupation.
[0102] In actual application, when the preset template library is the abnormal template library, the preset matching condition is that the execution template is different from each abnormal template in the abnormal template library; at this time, the execution template is compared and matched with each abnormal template in the abnormal template library, if the execution template fails to match with each abnormal template, that is, the execution template is different from each abnormal template in the abnormal template library, the query statement can be executed, and the query statement is detected in the background to extract the execution data of the query statement in the process of executing the query statement. When the preset template library is the normal template library, the preset matching condition is that the normal template library has a normal template same as the execution template; at this time, the execution template is compared and matched with each normal template in the normal template library, if the execution template matches with a normal template in the normal template library, that is, the normal template library has a normal template same as the execution template, the query statement can be executed, and the query statement is detected in the background to extract the execution data of the query statement in the process of executing the query statement.
[0103] For example, the preset template library is an abnormal template library, and contains three abnormal templates: template A1, template A2 and template A3, assuming that the execution template of the query statement is template A4, the query statement is executed, and the execution data of the query statement is extracted in the process of executing the query statement.
[0104] For example, the preset template library is an abnormal template library, and contains three abnormal templates: template A1, template A2 and template A3, assuming that the execution template of the query statement is template A4, the query statement is executed, and the execution data of the query statement is extracted in the process of executing the query statement.
[0105] In addition, the query statement can be periodically detected in the background in the process of executing the query statement: the execution template of the query statement being executed is periodically matched with each reference template, that is, after the query statement is executed, the method further includes:
[0106] In the process of executing the query statement, if the time interval reaches the first preset interval, the execution template is matched with each reference template in the preset template library.
[0107] Specifically, the first preset interval refers to the period of background flow control, which can be 1 minute, 5 minutes, etc.
[0108] In actual application, the preset query template can be updated during execution of the query statement, and thus periodic background throttling is needed for the statement being executed, i.e., periodically matching the execution template of the query statement being executed with each reference template in the preset template library: i.e., during execution of the query statement, when the time interval reaches the first preset interval, matching the execution template of the query statement with each reference template. In this way, the abnormal query statement can be detected in real time and accurately, and the problem of not discovering the abnormal query statement in time due to lag of the preset template library information can be avoided.
[0109] For example, the first preset interval is 3 minutes, and during execution of a query statement, if the time interval reaches 3 minutes, the execution template is matched with each reference template in the preset template library.
[0110] In one or more embodiments of the present embodiment, matching the execution template with each reference template in the preset template library can also not satisfy the preset matching condition, in which case it is indicated that the query statement is an abnormal query statement, and the concurrency degree of the abnormal query statement is further acquired, so as to determine whether to execute the abnormal query statement, i.e., after the matching of the execution template with each reference template in the preset template library, the method further includes:
[0111] In the case of not satisfying the preset matching condition, determining that the query statement is an abnormal query statement, and acquiring the concurrency degree of the abnormal query statement;
[0112] In the case of the concurrency degree being greater than or equal to the concurrency degree threshold, interrupting the abnormal query statement.
[0113] Specifically, the abnormal query statement can be a query statement with long execution time, accompanied by a large number of row scans, temporary file sorting or frequent disk read / write, such as a slow SQL; and the concurrency degree refers to the number of abnormal query statements concurrently executed at the current time, i.e., the number of abnormal query statements currently executed by the database.
[0114] In actual application, when the preset template library is the abnormal template library, the preset matching condition is that the execution template is not the same as each abnormal template in the abnormal template library, at this time, the execution template is compared and matched with each abnormal template in the abnormal template library, if the execution template is matched with a certain abnormal template in each abnormal template, that is, the abnormal template library exists the same abnormal template as the execution template, it can be determined that the query statement is an abnormal query statement; when the preset template library is the normal template library, the preset matching condition is that the normal template library exists the same normal template as the execution template, at this time, the execution template is compared and matched with each normal template in the normal template library, if the execution template is matched with each normal template, that is, the normal template library does not exist the same normal template as the execution template, it can be determined that the query statement is an abnormal query statement. After it is determined that the query statement is an abnormal query statement, the number of the abnormal query statements currently executed by the database, that is, the concurrency degree, needs to be obtained. If the concurrency degree is greater than or equal to the concurrency threshold, it indicates that the abnormal query statement being executed has reached the upper limit of the execution of the abnormal query statement of the database, in order to avoid that too many abnormal query statements are executed to reduce the processing capacity of the database, at this time, the database will interrupt the abnormal query statement. In this way, the abnormal query statement running inside the database can be collected in time and accurately, and the abnormal query statement can be stably limited.
[0115] For example, the preset template library is an abnormal template library, containing three abnormal templates: template C1, template C2 and template C3, assuming that the execution template of the query statement is template C1, the query statement is an abnormal query statement, at this time, the concurrency degree of the abnormal query statement is 20, in the case that the concurrency threshold is 20, the abnormal query statement is interrupted.
[0116] In addition, the concurrency degree of the abnormal query statement can also be less than the concurrency threshold, at this time, the abnormal query statement can be normally executed, that is:
[0117] In the case that the concurrency degree is less than the concurrency threshold, the abnormal query statement is executed, and the concurrency degree is increased by 1;
[0118] If the abnormal query statement is executed, the concurrency degree is decreased by 1.
[0119] In actual application, if the concurrency degree does not reach the concurrency degree threshold value, it indicates that the currently executed abnormal query statement does not reach the upper limit of the database for executing abnormal query statements, and the database has extra threads to execute the abnormal query statement. At this time, the abnormal query statement is normally executed. Since a currently executed abnormal query statement is added, the concurrency degree is increased by 1. When the abnormal query statement is executed, the currently executed abnormal query statement is reduced, and the concurrency degree is reduced by 1. In this way, the database can automatically limit the abnormal query statement, and the use cost is greatly reduced.
[0120] For example, the concurrency degree of the abnormal query statement is 10, and the abnormal query statement is executed when the concurrency degree threshold value is 20. At this time, the concurrency degree is 11. When the abnormal query statement is executed, the concurrency degree is 15, and when the abnormal query statement is executed, the concurrency degree is 14.
[0121] It should be noted that the background detection of the query statement during the execution of the query statement is also periodic, that is, the execution data of the query statement is periodically obtained. The specific implementation process can be as follows:
[0122] During the execution of the query statement, the execution data of the query statement is periodically obtained according to a second preset interval.
[0123] Specifically, the second preset interval refers to the period of background detection, which can be 1 minute, 5 minutes, etc. The second preset interval can be the same as or different from the first preset interval.
[0124] In actual application, the execution template is matched with each reference template in the preset template library. When the preset matching condition is met, the query statement is executed, and then the background detection of the query statement is periodically performed during the execution of the query statement, that is, the execution data of the query statement is obtained every second preset interval. In this way, the background detection efficiency is ensured, and the data processing amount of the database in the background detection is reduced, and the query statement processing efficiency is improved.
[0125] For example, the second preset interval is 5 minutes. During the execution of a query statement, if the time interval reaches 5 minutes, the execution data of the query statement is obtained.
[0126] Step 106: In a case where the currently obtained execution data reaches a preset abnormal condition, determining that the query statement is an abnormal query statement.
[0127] In the matching of the execution template with the reference template in the preset template library, if a preset matching condition is met, the query statement is executed, and after obtaining execution data of the query statement in the execution process, it is further determined that the query statement is an abnormal query statement in a case where the currently obtained execution data reaches a preset abnormal condition.
[0128] Specifically, the preset abnormal condition is a condition preset for measuring whether the currently obtained execution data is abnormal; the abnormal query statement can be a query statement with a long execution time, accompanied by a large number of row scans, temporary file sorting, or frequent disk read-write, such as a slow SQL.
[0129] In actual application, after obtaining the execution data, the currently obtained execution data is analyzed to determine whether the execution data is greater than or equal to a preset execution threshold value, and if so, the currently obtained execution data reaches the preset abnormal condition, indicating that the execution data of the query statement is abnormal, and the query statement is an abnormal query statement.
[0130] In one or more embodiments of the embodiment, the execution data can be the length of time for which the query statement has been executed, i.e., the executed duration, and the preset matching condition is that the executed duration is greater than a second preset duration threshold value, i.e., the case where the currently obtained execution data reaches the preset abnormal condition, the query statement is determined to be an abnormal query statement, and the specific implementation process can be as follows:
[0131] In a case where the currently obtained executed duration is greater than the second preset duration threshold value, the query statement is determined to be an abnormal query statement.
[0132] Specifically, the second preset duration threshold value refers to a time threshold value set in the background detection process for detecting whether the currently obtained executed duration is abnormal, and can be 10 minutes, 6 minutes, etc.
[0133] In actual application, when the currently executed duration of the query statement is greater than the second preset duration threshold value, it indicates that the length of time for executing the query statement exceeds the length of time spent by a normal query statement, and therefore the query statement is an abnormal query statement. In this way, the abnormal query statement in the query statement being executed can be identified according to the executed duration, and the abnormal query statement being executed can be terminated in a timely manner, so as to avoid that too many abnormal query statements occupy too many resources of the database, to accelerate the speed of determining the abnormal query statement, and to further improve the processing efficiency of the query statement.
[0134] For example, the currently executed duration of a certain SQL is 8 minutes, and the second preset duration threshold value is 5 minutes, and therefore the SQL is a slow SQL, i.e., an abnormal SQL.
[0135] In one or more embodiments of the present embodiment, the current obtained execution data can also not reach the preset abnormal condition, at which time the query statement can be continued to be executed. When the query statement is executed, post-detection is performed on the query statement: whether the query statement is abnormal is determined according to the total execution time of the query statement, that is:
[0136] In the case where the current obtained execution data does not reach the preset abnormal condition, the query statement is continued to be executed;
[0137] If the query statement is executed, the total execution time of the query statement is obtained;
[0138] In the case where the total execution time is greater than a first preset time threshold, the query statement is determined to be an abnormal query statement.
[0139] Specifically, the total execution time refers to the time for completely executing a query statement; and the first preset time threshold refers to a time threshold set for post-detection to determine whether a query statement is abnormal.
[0140] In actual application, when the background detection does not find an abnormality, that is, the current obtained execution data does not reach the preset abnormal condition, the query statement is continued to be executed. When the query statement is executed, the process of post-detection is performed: first, the total execution time of the query statement is obtained, that is, the total execution time, and then the total execution time is compared with the first preset time threshold in reverse. If the total execution time is greater than the first preset time threshold, it is indicated that the query statement exceeds the upper limit of the execution time of a normal query statement, that is, the query statement is an abnormal query statement.
[0141] In addition, in the case where the total execution time is less than or equal to the first preset time threshold, the query statement is determined to be a normal query statement.
[0142] For example, the current execution data of the query statement X does not reach the preset abnormal condition, and then the query statement X is continued to be executed. If the query statement X is executed, post-detection is performed on the query statement X: the total execution time of the query statement X is obtained, assuming that the total execution time of the query statement X is 30 seconds, if the first preset time threshold is 25 seconds, the query statement X is an abnormal query statement; and if the first preset time threshold is 35 seconds, the query statement X is a normal query statement.
[0143] Through post-detection, the identification of an abnormal query statement is further improved, and the efficiency of a query statement is effectively ensured.
[0144] It should be noted that, in the case that the obtained execution data reaches the preset exception condition, after determining that the query statement is an exception query statement, the background flow limiting does not end: the concurrency degree of the exception query statement needs to be further obtained, so as to determine whether to execute the exception query statement, that is, after determining that the query statement is an exception query statement in the case that the obtained execution data reaches the preset exception condition, the method further comprises:
[0145] obtaining the concurrency degree of the exception query statement;
[0146] in the case that the concurrency degree is greater than or equal to the concurrency degree threshold, interrupting the exception query statement.
[0147] Specifically, the concurrency degree refers to the number of exception query statements concurrently executed at the current time, that is, the number of exception query statements currently executed by the database.
[0148] In actual application, after determining that the query statement is an exception query statement in the case that the obtained execution data reaches the preset exception condition, the number of exception query statements currently executed by the database, that is, the concurrency degree, needs to be obtained. If the concurrency degree is greater than or equal to the concurrency degree threshold, it indicates that the number of exception query statements currently executed has reached the upper limit of the database, in order to avoid that too many exception query statements are executed to reduce the processing capacity of the database, the database will interrupt the exception query statement at this time. In this way, the exception query statements currently running in the database can be collected in time and accurately, and the exception query statements can be stably limited.
[0149] In addition, the concurrency degree of the exception query statement can also be less than the concurrency degree threshold, at this time, the exception query statement can be normally executed, that is:
[0150] in the case that the concurrency degree is less than the concurrency degree threshold, the exception query statement is continuously executed, and the concurrency degree is increased by 1; if the exception query statement is executed, the concurrency degree is decreased by 1.
[0151] In actual application, if the concurrency degree does not reach the concurrency degree threshold, it indicates that the number of exception query statements currently executed does not reach the upper limit of the database, and the database has extra threads to execute the exception query statement, at this time, the exception query statement is normally executed, and since a new exception query statement is added, the concurrency degree is increased by 1. When the exception query statement is executed, the number of exception query statements currently executed is reduced, and the concurrency degree is decreased by 1. In this way, it is ensured that the database can dynamically and automatically limit the exception query statement, and the use cost is greatly reduced.
[0152] For example, the concurrency of an abnormal query statement is 30: in the case of a concurrency threshold of 30, the abnormal query statement is interrupted; in the case of a concurrency threshold of 50, the abnormal query statement is executed, at which time the concurrency is 31, and at the moment when the abnormal query statement is executed, the concurrency is 26, and after the abnormal query statement is executed, the concurrency is 25.
[0153] It should be noted that, after determining whether the query statement is abnormal, the preset template library also needs to be updated, that is:
[0154] After determining the type of the query statement, the preset template library is updated, and the type includes an abnormal query statement or a normal query statement.
[0155] In actual application, when the preset template library is a normal template library: in the case where the total execution time is less than or equal to a first preset time threshold, after determining that the query statement is a normal query statement, the execution model of the normal query statement is added to the normal template library, that is, the preset template library is updated. When the preset template library is an abnormal template library: in the case where the current obtained execution data reaches a preset abnormal condition, after determining that the query statement is an abnormal query statement, the execution model of the abnormal query statement is added to the abnormal template library, that is, the preset template library is updated; in the case where the total execution time is greater than the first preset time threshold, after determining that the query statement is an abnormal query statement, the execution model of the abnormal query statement is added to the abnormal template library, that is, the preset template library is updated. In this way, the preset database can be updated in a timely manner, thereby effectively ensuring the effectiveness of the front-end detection and the background flow limiting.
[0156] In addition, the execution template of a normal query statement that is incorrectly identified as an abnormal query statement will be removed from the abnormal template library after certain conditions are met, preventing misjudgment and ensuring the stability of the entire query statement processing.
[0157] As Figure 2 described, Figure 2 A processing process schematic diagram of a query statement processing method provided by one embodiment of the present specification is shown, which includes three detection mechanisms, front-end detection, back-end detection, and background detection:
[0158] Step 202: obtaining a query statement.
[0159] That is, obtaining a query statement to be executed.
[0160] Step 204: extracting an execution template of the query statement.
[0161] Step 206: front-end detection: matching the execution template with each reference template in the preset template library.
[0162] Pre-checking occurs after extracting the query's execution template and before executing the query. Pre-checking searches the preset template library for reference templates that match the current execution template and performs subsequent operations based on this information. This involves matching the execution template with the reference templates in the preset template library. If the preset matching conditions are met, step 208 is executed.
[0163] Step 208: Execute the query statement.
[0164] After the query statement is executed, step 212 is executed.
[0165] Step 210: Background detection: determining whether the currently acquired execution data of the query statement meets a preset abnormality condition.
[0166] During query execution, a background check is performed to determine whether the currently acquired query execution data meets the preset exception condition. Preferably, this background check is a periodic polling check that periodically traverses the active threads in the database thread pool and determines whether the execution data of the query statement being executed by each thread meets the preset exception condition. If not, the query continues to execute.
[0167] Step 212: Post-detection: Determine whether the total execution time of the query statement is greater than a first preset time.
[0168] After the query statement is executed, the post-check is performed: determining whether the total execution time of the query statement is greater than a first preset time, that is, determining whether it is an abnormal query statement based on the total execution time of the query statement.
[0169] In addition, a query statement processing method provided by an embodiment of this specification includes two flow limiting mechanisms for abnormal query statements: pre-flow limiting and post-flow limiting.
[0170] like Figure 3 As shown, Figure 3 A schematic diagram of a process for pre-current limiting according to an embodiment of the present disclosure is shown, including the following steps:
[0171] Step 302: Extract the execution template of the query statement.
[0172] Step 304: Pre-detection: matching the execution template with reference templates in the preset template library.
[0173] After extracting the execution template and pre-detection of the query statement, that is, after matching the execution template with the reference templates in the preset template library, the pre-current limiting is entered: if the preset matching conditions are met, step 306 is executed; if the preset matching conditions are not met, step 308 is executed.
[0174] Step 306: Execute the query statement.
[0175] Step 308: Obtain the concurrency of the abnormal query statement.
[0176] Step 310: Determine whether the concurrency is less than the concurrency threshold.
[0177] If yes, go to step 306 ; if no, go to step 312 .
[0178] Step 312: Terminate the query statement.
[0179] Among them, steps 306 to 312 belong to the processing process of pre-current limiting.
[0180] like Figure 4 As shown, Figure 4 A schematic diagram of a background current limiting process provided by an embodiment of this specification is shown, including the following steps:
[0181] Step 402: Pre-detection: matching the execution template with each reference template in the preset template library.
[0182] In the process of executing the query statement when the pre-detection meets the preset matching conditions, the execution template is matched with the reference templates in the preset template library. When the preset matching conditions are met, background flow limiting is performed, that is, the preset matching conditions are met and step 404 is executed.
[0183] Step 404: Execute the query statement.
[0184] Step 406: When the time interval reaches the first preset interval, the execution template is matched with each reference template in the preset template library.
[0185] If the preset matching condition is met, step 414 is executed; if the preset matching condition is not met, step 408 is executed.
[0186] Step 408: Obtain the concurrency of the abnormal query statement.
[0187] Step 410: Determine whether the concurrency is less than the concurrency threshold.
[0188] If yes, execute step 414 ; if no, execute step 412 .
[0189] Step 412: Terminate the query statement.
[0190] Step 414: Continue executing the query statement.
[0191] Among them, steps 404 to 414 belong to the background current limiting processing process.
[0192] The following combinedFigure 5 With the query statement provided in the specification as SQL, and the preset template library as the slow SQL template library as an example, the query statement processing method is further described. Wherein, Figure 5 A processing process schematic diagram of another query statement processing method provided by an embodiment of the specification is shown, including the following steps:
[0193] Step 502: Obtain the SQL to be executed.
[0194] Step 504: Extract the execution template of the SQL through Statement Digest.
[0195] Step 506: Determine whether the execution template is different from each slow SQL template in the slow SQL template library.
[0196] If not, step 508 is executed, and if yes, step 518 is executed.
[0197] Step 508: Obtain the concurrency degree of the current slow SQL.
[0198] Step 510: Determine whether the concurrency degree is less than the concurrency degree threshold.
[0199] If not, step 512 is executed; if yes, step 514 is executed.
[0200] Step 512: Interrupt the SQL.
[0201] Step 514: Execute the SQL, and the concurrency degree is incremented by 1.
[0202] Step 516: The SQL is executed, and the concurrency degree is decremented by 1.
[0203] Step 518: Execute the SQL.
[0204] Step 520: In the process of executing the SQL, determine whether the time interval reaches the first preset interval.
[0205] If yes, step 506 is executed; if not, return to step 518.
[0206] Step 522: In the process of executing the SQL, periodically obtain the current execution duration of the SQL according to the second preset interval.
[0207] It should be noted that steps 520 and 522 are performed in the process of executing the SQL. In addition, steps 520 and 522 do not have a strict execution order, and can be executed simultaneously or alternatively.
[0208] Step 524: Determine whether the execution duration reaches the preset abnormal condition.
[0209] If yes, steps 508 and 526 are synchronously executed; if no, step 528 is executed.
[0210] Step 526: Add the execution template to the slow SQL template library.
[0211] Step 528: Determine whether the SQL is executed.
[0212] If no, step 518 is executed; if yes, step 530 is executed.
[0213] Step 530: Obtain the total execution time of the SQL.
[0214] Step 532: Determine whether the total execution time is greater than the first preset time threshold.
[0215] If yes, step 526 is executed; if no, step 534 is executed.
[0216] Step 534: End.
[0217] In this way, a slow SQL flow limiting technical framework is realized, and the easiness, real-time performance and accuracy are emphasized: the MYSQL statement digest is used to extract the SQL execution template instead of specific keyword matching, which guarantees the universality and generality of slow SQL identification; the embedded slow SQL flow limiting framework can collect the slow SQL running in the MYSQL database in real time and accurately; the automatic slow SQL identification and flow limiting greatly reduces the use cost. The embedded slow SQL real-time flow limiting technical scheme based on the MYSQL statement digest can not only detect the slow SQL running in the MYSQL server in real time, accurately limit the slow SQL and guarantee the running of other normal SQL, but also can accurately prevent a large number of slow SQL to come according to the historical information in the recent period of time.
[0218] The query statement processing method provided in the specification first acquires a query statement to be executed, extracts an execution template of the query statement by using a variable specification tool, then matches the execution template with each reference template in a preset template library, executes the query statement in the case of meeting a preset matching condition, obtains execution data of the query statement in the process of executing the query statement, and then determines the query statement as an abnormal query statement in the case of the currently obtained execution data meeting a preset abnormal condition. By determining the query statement as an abnormal query statement in the case of the currently obtained execution data meeting a preset abnormal condition, real-time online detection of abnormal query statements is realized, the problem that offline tools cannot guarantee real-time performance is solved, no external components are relied on, the method can be integrated into a database with lower coupling, deployment cost and maintenance risk are reduced, abnormal query statements can be accurately determined by using a preset template library and abnormal conditions, the information lag problem existing in external detection components is avoided, use cost is greatly reduced, and the risk of human intervention is avoided.
[0219] Corresponding to the method embodiments described above, the specification also provides query statement processing device embodiments, Figure 6 A structural schematic diagram of a query statement processing device provided by one embodiment of the specification is shown. As shown in the figure, Figure 6 The device comprises:
[0220] The extraction module 602 is configured to acquire a query statement to be executed, and extract an execution template of the query statement by using a variable specification tool.
[0221] The first execution module 604 is configured to match the execution template with each reference template in a preset template library, execute the query statement in the case of meeting a preset matching condition, and obtain execution data of the query statement in the process of executing the query statement.
[0222] The first determination module 606 is configured to determine the query statement as an abnormal query statement in the case of the currently obtained execution data meeting a preset abnormal condition.
[0223] Optionally, the device further comprises:
[0224] The second execution module is configured to continue executing the query statement in the case of the currently obtained execution data not meeting a preset abnormal condition.
[0225] The first acquisition module is configured to acquire a total execution time length of the query statement if the query statement execution ends.
[0226] The second determining module is configured to determine the query statement as an abnormal query statement if the total execution duration is greater than a first preset duration threshold.
[0227] Optionally, the apparatus further comprises:
[0228] The third determining module is configured to determine the query statement as a normal query statement if the total execution duration is less than or equal to the first preset duration threshold.
[0229] Optionally, the execution module is further configured to match the execution template with each reference template in a preset template library at a first preset interval during execution of the query statement.
[0230] Optionally, the apparatus further comprises:
[0231] The fourth determining module is configured to determine the query statement as an abnormal query statement and obtain a concurrency degree of the abnormal query statement if a preset matching condition is not met.
[0232] The first interrupting module is configured to interrupt the abnormal query statement if the concurrency degree is greater than or equal to a concurrency degree threshold.
[0233] Optionally, the apparatus further comprises:
[0234] The third execution module is configured to execute the abnormal query statement if the concurrency degree is less than the concurrency degree threshold, and the concurrency degree is increased by 1; and the concurrency degree is decreased by 1 if the abnormal query statement is executed.
[0235] Optionally, the apparatus further comprises:
[0236] The second obtaining module is configured to obtain a concurrency degree of an abnormal query statement.
[0237] The second interrupting module is configured to interrupt the abnormal query statement if the concurrency degree is greater than or equal to a concurrency degree threshold.
[0238] The fourth execution module is configured to continue to execute the abnormal query statement if the concurrency degree is less than the concurrency degree threshold, and the concurrency degree is increased by 1; and the concurrency degree is decreased by 1 if the abnormal query statement is executed.
[0239] Optionally, the first execution module 604 is further configured to periodically obtain execution data of the query statement at a second preset interval during execution of the query statement.
[0240] Optionally, the execution data is an executed duration.
[0241] The first determination module 606 is further configured to determine that the query statement is an abnormal query statement when the currently obtained executed duration is greater than a second preset duration threshold.
[0242] Optionally, the apparatus further comprises an updating module configured to update the preset template library after determining the type of the query statement, the type comprising an abnormal query statement or a normal query statement.
[0243] The query statement processing apparatus provided in the specification first acquires a query statement to be executed, extracts an execution template of the query statement by using a variable specification tool, then matches the execution template with each reference template in a preset template library, executes the query statement when a preset matching condition is met, and obtains execution data of the query statement in the process of executing the query statement, and finally determines that the query statement is an abnormal query statement when the currently obtained execution data reaches a preset abnormal condition. By determining that the query statement is an abnormal query statement when the currently obtained execution data reaches a preset abnormal condition, real-time online detection of abnormal query statements is realized, and the problem that offline tools cannot guarantee real-time performance is solved. The apparatus does not depend on external components, can be integrated into a database with lower coupling, reduces deployment cost and maintenance risk, can accurately determine abnormal query statements by using a preset template library and abnormal conditions, avoids the information lag problem existing in external detection components, greatly reduces use cost, and avoids the risk of human intervention.
[0244] The above is a schematic scheme of the query statement processing apparatus of the embodiment. It should be noted that the technical scheme of the query statement processing apparatus and the technical scheme of the query statement processing method described above belong to the same concept, and the details of the technical scheme of the query statement processing apparatus that are not described in detail can be referred to the description of the technical scheme of the query statement processing method.
[0245] Figure 7 A structural block diagram of a computing device 700 is shown according to an embodiment of the specification. The components of the computing device 700 include but are not limited to a memory 710 and a processor 720. The processor 720 is connected with the memory 710 through a bus 730, and a database 750 is used to save data.
[0246] The computing device 700 also includes an access device 740 that enables the computing device 700 to communicate via one or more networks 760. Examples of such networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or combinations of such networks, such as the Internet. The access device 740 can include one or more of any type of network interface (for example, a network interface card (NIC)) such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a Worldwide Interoperability for Microwave Access (Wi-MAX) interface, an Ethernet interface, a Universal Serial Bus (USB) interface, a cellular network interface, a Bluetooth interface, a Near Field Communication (NFC) interface, or the like.
[0247] In one embodiment of the present specification, the above-mentioned components of the computing device 700 and other components not shown in the Figure 7 may be connected to each other, for example, through a bus. It should be understood that Figure 7 The computing device structure diagram shown is merely for the purpose of example, and is not a limitation on the scope of the present specification. Those skilled in the art can add or replace other components as needed.
[0248] The computing device 700 can be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (for example, a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, and the like), a mobile phone (for example, a smartphone), a wearable computing device (for example, a smart watch, smart glasses, and the like), or other types of mobile devices, or a stationary computing device such as a desktop computer or a PC. The computing device 700 can also be a mobile or stationary server.
[0249] The processor 720 is configured to execute computer-executable instructions, which, when executed by the processor, implement the steps of the query statement processing method described above.
[0250] The above is a schematic scheme of the computing device of the embodiment. It should be noted that the technical scheme of the computing device and the technical scheme of the query statement processing method described above belong to the same concept, and the details of the technical scheme of the computing device that are not described in detail can be referred to the description of the technical scheme of the query statement processing method.
[0251] An embodiment of the present specification further provides a computer readable storage medium storing computer executable instructions, and the computer executable instructions are executed by a processor to implement the steps of the query statement processing method.
[0252] The above is a schematic scheme of the computer readable storage medium of the embodiment. It should be noted that the technical scheme of the storage medium and the technical scheme of the query statement processing method described above belong to the same concept, and the details of the technical scheme of the storage medium that are not described in detail can be referred to the description of the technical scheme of the query statement processing method.
[0253] An embodiment of the present specification further provides a computer program, and when the computer program is executed in a computer, the computer program causes the computer to execute the steps of the query statement processing method.
[0254] The above is a schematic scheme of the computer program of the embodiment. It should be noted that the technical scheme of the computer program and the technical scheme of the query statement processing method described above belong to the same concept, and the details of the technical scheme of the computer program that are not described in detail can be referred to the description of the technical scheme of the query statement processing method.
[0255] The above describes specific embodiments of the present specification. Other embodiments are within the scope of the appended claims. In some cases, the acts or steps recited in the claims can be performed in a different order than the order described in the embodiments and still achieve desirable results. In addition, the processes depicted in the figures do not necessarily require the particular order shown or sequential order in order to achieve the desired results. In some implementations, multitasking and parallel processing can be advantageous.
[0256] The computer readable medium can include any entity or apparatus capable of carrying the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal, software distribution medium, etc. It should be noted that the computer readable medium can include appropriate additions or subtractions according to the requirements of legislation and patent practice in the jurisdiction, for example, in some jurisdictions, according to legislation and patent practice, the computer readable medium does not include electrical carrier signals and telecommunication signals.
[0257] It should be noted that, for the foregoing method embodiments, in order to facilitate description, they are all described as a combination of a series of actions, but those skilled in the art should know that the embodiments of the present specification are not limited by the order of the described actions, because according to the embodiments of the present specification, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the embodiments of the present specification.
[0258] In the above embodiments, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the related description of other embodiments.
[0259] The preferred embodiments of the present specification disclosed above are only used to help explain the present specification. The alternative embodiments do not describe all the details and limit the invention to the specific embodiments described. Obviously, according to the content of the embodiments of the present specification, many modifications and changes can be made. The present specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the embodiments of the present specification, so that those skilled in the art can well understand and use the present specification. The present specification is limited by the claims and their entire scope and equivalents.
Claims
1. A query statement processing method, applied to online detection, comprising: Obtaining a query statement to be executed, and extracting an execution template of the query statement using a variable specification tool; Matching the execution template with each reference template in a preset template library, executing the query statement if a preset matching condition is met, and obtaining execution data of the query statement during the execution of the query statement, wherein the execution data of the query statement is the execution time or occupancy data of the current query statement; When the currently obtained execution data meets a preset abnormal condition, determining that the query statement is an abnormal query statement; During the execution of the query statement, if the time interval reaches a first preset interval, matching the execution template with each reference template in a preset template library; If the preset matching condition is not met, determining that the query statement is an abnormal query statement; Obtaining the concurrency of the abnormal query statement, wherein the concurrency represents the number of abnormal query statements currently being executed; When the concurrency is greater than or equal to a concurrency threshold, the abnormal query statement is interrupted. The concurrency threshold represents an upper limit of abnormal query statements being executed by the database.
2. The method according to claim 1, further comprising: If the currently acquired execution data does not meet the preset abnormal condition, continue to execute the query statement; If the query statement is executed, the total execution time of the query statement is obtained; When the total execution time is greater than a first preset time threshold, the query statement is determined to be an abnormal query statement.
3. The method according to claim 2, further comprising: When the total execution time is less than or equal to a first preset time threshold, the query statement is determined to be a normal query statement.
4. The method according to claim 1, further comprising: When the concurrency is less than the concurrency threshold, the abnormal query statement is executed, and the concurrency is incremented by 1; If the execution of the abnormal query statement ends, the concurrency is reduced by 1.
5. The method according to claim 1, wherein after determining that the query statement is an abnormal query statement when the currently obtained execution data meets a preset abnormal condition, the method further comprises: Get the concurrency of abnormal query statements; When the concurrency is greater than or equal to the concurrency threshold, interrupting the abnormal query statement; When the concurrency is less than the concurrency threshold, the abnormal query statement continues to be executed, and the concurrency is incremented by 1; if the execution of the abnormal query statement ends, the concurrency is decremented by 1.
6. The method according to claim 1, wherein obtaining execution data of the query statement during execution of the query statement comprises: During the execution of the query statement, execution data of the query statement is periodically obtained according to a second preset interval.
7. The method according to claim 1, wherein the execution data is the execution time; When the currently obtained execution data meets a preset abnormal condition, determining that the query statement is an abnormal query statement includes: When the currently obtained executed time is greater than a second preset time threshold, the query statement is determined to be an abnormal query statement.
8. The method according to any one of claims 1 to 3 or 5 to 7, further comprising: After determining the type of the query statement, the preset template library is updated, where the type includes an abnormal query statement or a normal query statement.
9. A query statement processing device, applied to online detection, comprising: an extraction module configured to obtain a query statement to be executed and extract an execution template of the query statement using a variable specification tool; a first execution module configured to match the execution template with reference templates in a preset template library, execute the query statement if a preset matching condition is met, and obtain execution data of the query statement during the execution of the query statement, wherein the execution data of the query statement is an execution time or occupancy data of the current query statement; During the execution of the query statement, if the time interval reaches a first preset interval, matching the execution template with each reference template in a preset template library; If the preset matching condition is not met, determining that the query statement is an abnormal query statement; A first determining module is configured to determine that the query statement is an abnormal query statement when the currently obtained execution data meets a preset abnormal condition; Obtain the concurrency of the abnormal query statement, wherein the concurrency represents the number of abnormal query statements currently being executed; and interrupt the abnormal query statement when the concurrency is greater than or equal to a concurrency threshold, wherein the concurrency threshold represents the upper limit of the abnormal query statements being executed by the database.
10. A computing device comprising: memory and processor; The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions. When the computer-executable instructions are executed by the processor, the steps of the query statement processing method according to any one of claims 1 to 8 are implemented.
11. A computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions, when executed by a processor, implement the steps of the query statement processing method according to any one of claims 1 to 8.
12. A computer program product comprising computer instructions, which, when executed in a computer, causes the computer to execute the steps of the query statement processing method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Slow SQL statement prediction method and system
CN112613176A
Database overload protection processing method and device and storage medium
CN112988435A
Method and device for identifying and analyzing slow query statements, and method and device for counting query statements
CN113297249A