Structured query language question prediction method and device, equipment and storage medium
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA CONSTRUCTION BANK
- Filing Date
- 2023-07-11
- Publication Date
- 2026-08-07
AI Technical Summary
[0005]本申请提供一种结构化查询语言问题预测方法、装置、设备及存储介质,用以解决结构化查询语言问题预测的准确度较低的问题
[0048] Fifthly, embodiments of this application provide a computer program product, including a computer program that, when executed by a processor, implements the structured query language problem prediction method as described in the first aspect and various possible designs of the first aspect.
Smart Images

Figure CN116756176B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of big data technology, and in particular to a method, apparatus, device and storage medium for predicting structured query language problems. Background Technology
[0002] Structured Query Language (SQL), as the common language of relational databases, is a commonly used language for users to query data in databases. When using SQL statements for data querying, if the SQL statement used has problems, the query process may affect the operation of the device. Therefore, it is necessary to predict problematic SQL statements to reduce the occurrence of queries using problematic SQL statements.
[0003] In some implementations, data generated during the operation of electronic devices is used for online learning, and historical job performance is collected for model training using R-LSTM. This enables the trained model to predict whether SQL statements will cause delays in data queries and the size of the dataset retrieved by the SQL statements.
[0004] However, in the above implementation, there may be cases where problematic SQL statements are missed, resulting in low prediction accuracy. Summary of the Invention
[0005] This application provides a method, apparatus, device, and storage medium for predicting structured query language questions, in order to solve the problem of low accuracy in predicting structured query language questions.
[0006] Firstly, this application provides a method for predicting structured query language questions, the method comprising:
[0007] The structured query language to be processed is input into the rule model and the analysis model, respectively. Both the rule model and the analysis model are trained using historical data related to the structured query language of the question.
[0008] The rule model is used to perform rule analysis on the structured query language to be processed, and a first value is obtained from the rule model output. The first value represents the probability that the structured query language to be processed is a question structured query language.
[0009] The analysis model is used to analyze the structured query language to be processed, and the probability value output by the analysis model is obtained. The probability value represents the probability that the structured query language to be processed is a question structured query language.
[0010] The first value and the probability value are corrected by the correction factor output by the correction model to obtain the target probability value. The correction model is trained using historical data related to the question structured query language.
[0011] When the target probability value is greater than or equal to a preset value, the structured query language to be processed is determined to be a problem structured query language.
[0012] In one possible design, the first value and the probability value are corrected using a correction factor output by the correction model to obtain a target probability value, including:
[0013] The target probability value is obtained by correcting the first value and the probability value by y = (βa + δb) / 2;
[0014] Where a represents the first value, b represents the probability value, β represents the first correction factor, δ represents the second correction factor, and y represents the target probability value.
[0015] In one possible design, the method further includes:
[0016] At least one of the following is input into the correction model: historical feedback information, historical question structured query language information, and the syntax tree of historical question structured query language. The first correction factor and the second correction factor output by the correction model are obtained.
[0017] In one possible design, the rule model includes multiple rule expressions, which are used to detect whether the structured query language input to the rule model is a question structured query language;
[0018] The step of performing rule analysis on the structured query language to be processed through the rule model to obtain the first value output by the rule model includes:
[0019] Using each of the plurality of rule expressions, rule analysis is performed on the structured query language to be processed to determine whether the structured query language to be processed conforms to the rule expression;
[0020] When the structured query language to be processed conforms to at least one of the multiple rule expressions, the first value output by the rule model is obtained.
[0021] In one possible design, the method further includes:
[0022] When the structured query language to be processed does not conform to any of the multiple rule expressions, a second value is obtained from the output of the rule model. The second value represents the probability that the structured query language to be processed is a question structured query language.
[0023] In one possible design, the analysis model is trained based on first data input by a data processing component, which processes the acquired historical data related to the question structured query language and inputs the processed first data into the analysis model.
[0024] The first data includes at least two of the following: daily data growth, monthly data growth, quarterly data growth, annual data growth, information on periods of rapid data growth, the distinguishability information of each field in the database table, the actual operating information of electronic devices, the syntax tree of the structured query language, the number of queries in the historical structured query language, the average data volume of each field in the database table, the average data volume of a single row in the database table, page views, the number of unique visitors, and the throughput for each time period.
[0025] In one possible design, after determining that the structured query language to be processed is a question structured query language, the process includes:
[0026] The static code snippet of the structured query language to be processed is input into the strategy knowledge base, which includes multiple pre-stored static codes;
[0027] Calculate the similarity between the static code fragment and each of the plurality of pre-stored static codes;
[0028] The rectification strategy corresponding to the pre-stored static code with the highest similarity among multiple similarity values is determined and output. The rectification strategy is used to remind the user to modify the structured query language to be processed.
[0029] In one possible design, the method further includes:
[0030] The target feedback information is input into the correction model to obtain a new correction factor output by the correction model. The target feedback information is the information fed back by the user when the user does not modify the structured query language to be processed.
[0031] Secondly, this application provides a structured query language problem prediction device, comprising:
[0032] The input module is used to input the structured query language to be processed into the rule model and the analysis model respectively. Both the rule model and the analysis model are trained using historical data related to the structured query language of the question.
[0033] The processing module is used to perform rule analysis on the structured query language to be processed through the rule model to obtain a first value output by the rule model, wherein the first value represents the probability that the structured query language to be processed is a question structured query language;
[0034] The processing module is further configured to analyze the structured query language to be processed through the analysis model to obtain a probability value output by the analysis model, wherein the probability value represents the probability that the structured query language to be processed is a question structured query language;
[0035] The processing module is further configured to correct the first value and the probability value by using the correction factor output by the correction model to obtain the target probability value. The correction model is trained using historical data related to the question structured query language.
[0036] The processing module is further configured to determine that the structured query language to be processed is a question structured query language when the target probability value is greater than or equal to a preset value.
[0037] In one possible design, the processing module is specifically used to correct the first value and the probability value by y = (βa + δb) / 2 to obtain a target probability value; where a represents the first value, b represents the probability value, β represents the first correction factor, δ represents the second correction factor, and y represents the target probability value.
[0038] In one possible design, the input module is further configured to input at least one of the following into the correction model: historical feedback information, historical question structured query language information, and the syntax tree of the historical question structured query language, to obtain the first correction factor and the second correction factor output by the correction model.
[0039] In one possible design, the rule model includes multiple rule expressions, which are used to detect whether the structured query language input to the rule model is a question structured query language;
[0040] The processing module is further configured to perform rule analysis on the structured query language to be processed using each of the plurality of rule expressions, and determine whether the structured query language to be processed conforms to the rule expression; when the structured query language to be processed conforms to at least one of the plurality of rule expressions, the first value output by the rule model is obtained.
[0041] In one possible design, the processing module is further configured to obtain a second value output by the rule model when the structured query language to be processed does not conform to any of the plurality of rule expressions, wherein the second value represents the probability that the structured query language to be processed is a question structured query language.
[0042] In one possible design, the analysis model is trained based on first data input by a data processing component. The data processing component processes the acquired historical data related to the structured query language and inputs the processed first data into the analysis model. The first data includes at least two of the following: daily data growth, monthly data growth, quarterly data growth, annual data growth, information on periods of rapid data growth, the distinguishability information of each field in the database table, the actual operating information of the electronic device, the syntax tree of the structured query language, the number of queries in the historical structured query language, the average data volume of each field in the database table, the average data volume of a single row in the database table, page views, the number of unique visitors, and the throughput for each time period.
[0043] In one possible design, the input module is further configured to input the static code snippet of the structured query language to be processed into the strategy knowledge base, which includes multiple pre-stored static codes.
[0044] The processing module is further configured to calculate the similarity between the static code fragment and each of the plurality of pre-stored static codes; determine and output the rectification strategy corresponding to the pre-stored static code with the highest similarity among the plurality of similarities, the rectification strategy being used to remind the user to modify the structured query language to be processed.
[0045] In one possible design, the input module is further configured to input target feedback information into the correction model to obtain a new correction factor output by the correction model, wherein the target feedback information is the information fed back by the user when the user does not modify the structured query language to be processed.
[0046] Thirdly, embodiments of this application provide an electronic device, including: at least one processor and a memory; the memory stores computer execution instructions; the at least one processor executes the computer execution instructions stored in the memory, causing the at least one processor to perform the structured query language problem prediction method as described in the first aspect and various possible designs of the first aspect.
[0047] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer-executable instructions. When a processor executes the computer-executable instructions, it implements the structured query language problem prediction method described in the first aspect and various possible designs of the first aspect.
[0048] Fifthly, embodiments of this application provide a computer program product, including a computer program that, when executed by a processor, implements the structured query language problem prediction method as described in the first aspect and various possible designs of the first aspect.
[0049] This application provides a method, apparatus, device, and storage medium for predicting structured query language (SCL) problems. The method includes: inputting the SCL to be processed into a rule model and an analysis model, both trained using historical data related to the SCL; performing rule analysis on the SCL to be processed using the rule model to obtain a first value, representing the probability that the SCL to be processed is a problem SCL; analyzing the SCL to be processed using the analysis model to obtain a probability value, representing the probability that the SCL to be processed is a problem SCL; correcting the first value and the probability value using a correction factor output by a correction model, where the correction model is trained using historical data related to the problem SCL; and determining that the SCL to be processed is a problem SCL when the target probability value is greater than or equal to a preset value. Thus, the SCL problem prediction method provided in this application, by training the model with historical data to obtain the rule model, analysis model, and correction model, allows for direct model use, reducing the time period where problem SCLs cannot be predicted. Furthermore, the correction factor of the correction model can correct the problem probabilities obtained from the rule model and the analysis model, making the obtained target probabilities more accurate and thus improving the accuracy of the structured query language problem prediction. Attached Figure Description
[0050] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0051] Figure 1 A flowchart illustrating a structured query language problem prediction method provided in this application embodiment;
[0052] Figure 2 This application provides a schematic flowchart of a method for correcting data output from a rule model and an analysis model, as illustrated in an embodiment of the present application.
[0053] Figure 3 This application provides a schematic diagram of data flow for predicting structured query language problems.
[0054] Figure 4 This is a schematic diagram of a model training method provided in an embodiment of this application;
[0055] Figure 5 This is a schematic flowchart illustrating a method for using a model, as provided in an embodiment of this application.
[0056] Figure 6 This is a schematic diagram of the structure of a structured query language problem prediction device provided in an embodiment of this application;
[0057] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0058] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0059] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0060] In the embodiments of this application, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone, where A and B can be singular or plural. In the textual description of this application, the character " / " generally indicates that the preceding and following related objects have an "or" relationship.
[0061] To facilitate a clear description of the technical solutions in the embodiments of this application, some terms and technologies involved in the embodiments of this application will be briefly introduced below:
[0062] SQL: A purpose-specific programming language used to manage relational database management systems.
[0063] Deep learning: an artificial intelligence approach used to teach calculators to process data in a way inspired by the human brain.
[0064] During equipment operation, SQL queries may be required. However, the SQL statements used may contain problematic statements, such as overly broad query conditions, resulting in large datasets, high latency, and memory overflow issues. Therefore, it is necessary to identify problematic SQL statements to reduce their use in queries.
[0065] In some implementations, pre-defined rules can be used to perform static scanning on SQL statements to determine whether they are problematic.
[0066] However, the rules used in static scanning are not refined enough, and it is difficult to further refine the rules. Therefore, the static scanning method may identify correct SQL statements as problematic SQL statements, resulting in a high false positive rate and low accuracy in predicting problems in Structured Query Language.
[0067] In other implementations, data generated during the operation of electronic devices is used for online learning, and historical job performance is collected for model training using R-LSTM. This allows the trained model to predict whether SQL statements will cause delays in data queries and the size of the dataset retrieved by the SQL statements.
[0068] However, in the above implementation, the amount of data generated during the cold start period of electronic devices is limited, resulting in low accuracy of predictions using the model. Furthermore, the method has poor generalization ability; when using the model to predict SQL statements in other systems, false negatives or missed detections may occur. Therefore, the accuracy of SQL statement problem prediction in the above implementation is low.
[0069] To address the aforementioned technical problems, this application provides a structured query language (SCL) problem prediction method. It trains a model using historical data to obtain a rule-based model and an analysis model. The rule-based model predicts whether an input SQL statement is a problem statement, outputting a first value when the input SQL statement is likely to be a problem statement. The rule-based model also predicts the probability that the input SQL statement is a problem statement, obtaining the probability that the SQL statement is a problem statement. Furthermore, a correction factor is used to modify the output values of the two models to obtain a probability value for whether the SQL statement is a problem statement, thereby determining whether the SQL statement is a problem statement based on this probability value. This way, even during a cold start, the accuracy of the prediction results can be improved based on the training of the model during the development period. Moreover, by correcting the output values of the other two models using the correction factor, the accuracy of problem prediction can be further improved, reducing the occurrence of missed detections and false positives.
[0070] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.
[0071] Figure 1 This is a flowchart illustrating a structured query language problem prediction method provided in an embodiment of this application. The structured query language problem prediction method can be executed by software and / or hardware devices. For example, the hardware device can be a structured query language problem prediction device, which can be an electronic device at the bank or a processing chip within that device.
[0072] For example, such as Figure 1 As shown, this structured query language problem prediction method may include:
[0073] S101. Input the structured query language to be processed into the rule model and the analysis model respectively.
[0074] In the embodiments of this application, the Structured Query Language can be an SQL statement, and the SQL statements described in the following embodiments can all be understood as Structured Query Language.
[0075] In the embodiments of this application, both the rule model and the analysis model are trained using historical data related to the problematic SQL statement.
[0076] For example, during the development phase, technicians can collect information about problematic SQL statements, such as the format of the problematic SQL statement, a certain character in the problematic SQL statement, or the keywords of the problematic SQL statement. This application embodiment does not limit the information of problematic SQL statements.
[0077] Historical data may also include database table information of the system to which the rule model and analysis model can be applied, but this application does not limit this.
[0078] For example, the static code of the SQL statement to be processed can be submitted to the rule model and the analysis model, and the rule model and the analysis model can make preliminary predictions on the static code.
[0079] For example, static code can be code written by a technician during the SQL statement writing process, or it can be code written by a technician that is already running accurately; this application embodiment does not limit this. When the static code is code written by a technician during the SQL statement writing process, it is possible to predict the SQL statement during the process of the technician writing the SQL statement, so that the technician can modify the SQL statement with problems.
[0080] S102. The rule model is used to perform rule analysis on the structured query language to be processed, and the first value output by the rule model is obtained. The first value represents the probability that the structured query language to be processed is the problem structured query language.
[0081] In this embodiment of the application, the rule model may include multiple rule expressions, which can be used to detect whether the SQL statement input to the rule model is a problematic SQL statement.
[0082] For example, the rule expression may include the rules for constructing the problematic SQL statement, but this application embodiment does not limit this.
[0083] For example, when performing rule analysis on the SQL statement to be processed using a rule model to obtain the first value output by the rule model, each of the multiple rule expressions can be used to perform rule analysis on the SQL statement to be processed to determine whether the SQL statement to be processed conforms to the rule expression; when the SQL statement to be processed conforms to at least one of the multiple rule expressions, the first value output by the rule model is obtained.
[0084] For example, a rule model includes 10 rule expressions, each containing a rule chain of problematic SQL statements. When an SQL statement is input into the rule model, it breaks down the statement and compares it with each of the 10 rule expressions. If a broken SQL statement matches a rule chain in at least one of the rule expressions, it indicates that the SQL statement may be problematic, and the rule model can output the first value.
[0085] In this way, rule-based models can be used to examine the writing rules of SQL statements. When the writing rules in an SQL statement do not conform to the rule expression, it can be determined that the SQL statement may be a problematic SQL statement. This can improve the accuracy of predicting problems with SQL statements.
[0086] In another possible implementation, when the SQL statement to be processed does not conform to any of the multiple rule expressions, a second value is obtained from the output of the rule model. The second value represents the probability that the SQL statement to be processed is a problematic SQL statement.
[0087] For example, a rule model includes 10 rule expressions, each containing a rule chain for the problematic SQL statement. When an SQL statement is input into the rule model, it breaks down the statement and compares it with each of the 10 rule expressions. If the broken-down SQL statement does not conform to any rule chain in any of the rule expressions, it indicates that the probability of the SQL statement being a problematic SQL statement is low, and the rule model can output a second value.
[0088] In the embodiments of this application, the first value can be 1 and the second value can be 0. Of course, the first value and the second value can also be other values, and the embodiments of this application do not limit them.
[0089] In this way, when an SQL statement does not conform to any of the regular expressions, the likelihood of identifying the SQL statement as a problematic SQL statement is relatively low, which can reduce the number of missed SQL statements and further improve the accuracy of the structured query language's problem prediction.
[0090] S103. The structured query language to be processed is analyzed by the analysis model to obtain the probability value output by the analysis model. The probability value represents the probability that the structured query language to be processed is the problem structured query language.
[0091] In this embodiment of the application, the analysis model can be trained based on the first data input by the data processing component. The data processing component can be used to process the historical data related to the problem SQL statement and input the processed first data into the analysis model.
[0092] The first data input to the analysis model by the data processing component includes at least two of the following: daily data growth, monthly data growth, quarterly data growth, annual data growth, information on periods of rapid data growth, the distinguishability information of each field in the database table, the actual operating information of electronic devices, the syntax tree of the structured query language, the number of queries in historical SQL statements, the average data volume of each field in the database table, the average data volume of a single row in the database table, page views (PV), unique visitors (UV), and throughput (Transactions Per Second, TPS) for each time period.
[0093] It should be noted that the embodiments of this application only use the above-mentioned first data as an example for illustration. The first data may also include other data, and the embodiments of this application do not limit it.
[0094] For example, the process of training an analytical model may include: technicians collecting database information and data on the operational status of nearby locations, and inputting the collected information into a data collection component. The data collection component performs simple data processing on the input information, such as calculating daily, monthly, quarterly, and annual growth rates, as well as information on periods of rapid growth. The processed information is then formatted to a uniform format. Furthermore, the formatted data is input into the model for training, resulting in the analytical model.
[0095] In this way, the analysis model can predict the probability of an input SQL statement causing high device latency, a large amount of data in the queried dataset, etc. In other words, the analysis model can determine the probability that an SQL statement is a problematic SQL statement. Because the analysis model predicts problematic SQL statements based on database table information and the actual operating conditions of electronic devices, the accuracy of the problem prediction is high.
[0096] S104. The first value and probability value are corrected by the correction factor output by the correction model to obtain the target probability value. The correction model is trained using historical data related to the problem SQL statement.
[0097] The correction factor model can output two correction factors, corresponding to the first value and the probability value respectively, or it can output one correction factor. This application does not limit the specific correction factor output.
[0098] For example, the model can be modified by different correction factors to correct the first value and the probability value respectively, or the same correction factor can be used to correct the first value and the probability value. This application does not limit the scope of the embodiments.
[0099] S105. When the target probability value is greater than or equal to the preset value, the SQL statement to be processed is determined to be a problematic SQL statement.
[0100] For example, the preset value corresponds to the target probability value. When the first value is 1, the second value is 0, the probability value ranges from [0, 1], the first correction factor ranges from [0, 1], and the second correction factor ranges from [0, 1], the preset value can be a value within [0, 1]. For instance, if the preset value is 0.7, then when the target probability value is greater than or equal to 0.7, the SQL statement to be processed can be determined to be a problematic SQL statement.
[0101] Therefore, the Structured Query Language (SCL) problem prediction method provided in this application can perform preliminary predictions of the SQL statement to be processed through a rule model and an analysis model, obtaining a preliminary predicted value. Furthermore, the preliminary predicted value is corrected by a correction factor output by a correction model to obtain a probability value that the SQL statement to be processed is a problem SQL statement, thereby determining whether the SQL statement to be processed is a problem SQL statement. Therefore, the SCL problem prediction method provided in this application has high accuracy in predicting SQL statement problems. Moreover, since the rule model, analysis model, and correction model can be pre-trained, it still maintains high prediction accuracy during the cold start of electronic devices.
[0102] In this embodiment, after the electronic device determines that the SQL statement to be processed is a problematic SQL statement, the electronic device can input the static code fragment of the SQL statement to be processed into the policy knowledge base, which includes multiple pre-stored static codes; calculate the similarity between the static code fragment and each of the multiple pre-stored static codes; determine and output the rectification strategy corresponding to the pre-stored static code with the highest similarity among the multiple similarities, and the rectification strategy is used to remind the user to modify the SQL statement to be processed.
[0103] For example, supervised clustering training can be performed on static code snippets in advance, and clustering labels can be manually given and labeled (no restrictions, low discrimination of restricted conditions, no index for high-frequency fields, etc.). Recommended rectification methods can be entered for each label to form a strategy knowledge base.
[0104] In this way, users can promptly understand the types of problems with problematic SQL statements and the corresponding solutions, making it easier for them to rectify the problematic SQL statements.
[0105] Furthermore, for certain types of problematic SQL statements, rectification may not be necessary. When the rectification strategy output by the electronic device corresponds to the rectification strategy for that type of SQL statement, technicians may not modify the SQL statement and can fill in the reasons for not modifying it in the feedback form as feedback information.
[0106] For example, in this scenario, the electronic device can input the target feedback information into the correction model to obtain a new correction factor output by the correction model. The target feedback information is the information fed back when the user does not modify the SQL statement to be processed.
[0107] For example, if the feedback information marks a potentially problematic SQL statement as a normal SQL statement, the correction model will appropriately adjust the first and second correction factors in its output to reduce the target probability value corresponding to that SQL statement. For instance, if the SQL statement is judged as problematic primarily because the rule model identifies it as potentially problematic, the magnitude of the correction factor corresponding to the rule model's output value can be adjusted to reduce the probability of classifying the SQL statement as problematic.
[0108] In one possible implementation, if an SQL statement that does not require rectification is marked as a problematic SQL statement because the rule model determines it to be potentially problematic, the electronic device can further modify the rule expressions in the rule model based on the information of the SQL statement. Assuming the rule model determines an SQL statement to be potentially problematic using one rule expression, a new rule expression can be added to that expression. When the input SQL statement matches this expression, it is further determined whether it matches the newly added rule expression. If it does, the SQL statement can be determined to be a normal SQL statement. The newly added rule expression corresponds to the rule expression for the SQL statement that does not require rectification. This application embodiment only illustrates the updating of the rule model as an example and does not constitute any limitation on the method of this application embodiment.
[0109] In this way, during the prediction of SQL statements, the correction factors output by the correction model can be updated, making the correction factors more consistent with the actual situation of the database system. This can reduce the probability of judging normal SQL statements as problematic SQL statements and further improve the accuracy of predicting problems with SQL statements.
[0110] In this embodiment of the application, taking the output of two correction factors from the correction model as an example, the process of correcting the first value and the probability value using the correction factors output by the correction model to obtain the target probability value is described. See also... Figure 2 As shown, Figure 2This is a schematic flowchart illustrating a method for correcting data output from a rule model and an analysis model, as provided in an embodiment of this application.
[0111] like Figure 2 As shown, the method for correcting the data output by the rule model and the analysis model may include the following steps:
[0112] S201. A corrected model is obtained by training with historical data related to the problematic SQL statement.
[0113] In this embodiment, the historical data related to the question SQL statement used to train the corrected model may include, in addition to the first data described in the above steps, at least one of the following: historical feedback information, historical question SQL statement information, and historical question structured query language syntax tree. This embodiment does not limit this aspect.
[0114] For example, the process of training to obtain the corrected model may include: inputting at least one of the following into the model for training: the first data (i.e., database table information and information on the actual operation of electronic devices) and historical feedback information, historical problem SQL statement information, and the syntax tree of historical problem structured query language, to obtain the corrected model.
[0115] S202, Obtain the first and second correction factors from the modified model output.
[0116] For example, the process of the correction model outputting the first correction factor and the second correction factor may include: inputting at least one of the following into the correction model: historical feedback information, historical problem SQL statement information, and the syntax tree of the historical problem structured query language, to obtain the first correction factor and the second correction factor output by the correction model.
[0117] For example, the values of the first correction factor and the second correction factor can both be [0, 1]. Of course, they can also be other values. This application does not limit this.
[0118] It is understandable that different data input into the correction model will result in different magnitudes of the first and second correction factors.
[0119] In this way, the first and second correction factors input to the correction model are related to at least one of the following: historical feedback information, historical problem SQL statement information, and historical problem structured query language syntax tree, making the first and second correction factors output by the correction model more consistent with the actual situation.
[0120] S203. Correct the first value using the first correction factor, and correct the second value using the second correction factor to obtain the target probability value.
[0121] For example, the first value and the probability value can be corrected using the formula y = (βa + δb) / 2 to obtain the target probability value.
[0122] Where a represents the first value, b represents the probability value, β represents the first correction factor, δ represents the second correction factor, and y represents the target probability value.
[0123] Understandably, when the value output by the rule-based model is more important to the target probability value in a specific database system or time period, the value of the first correction factor output by the correction model in that scenario can be increased. Similarly, when the value output by the analytical model is more important to the target probability value in that scenario, the value of the second correction factor output by the analytical model can be increased. This further improves the accuracy of the target probability value.
[0124] In this way, the obtained target probability value takes into account both the first value output by the rule model and the probability value output by the analysis model, resulting in a high accuracy of the target probability value and improving the accuracy of structured query language problem prediction.
[0125] In this embodiment, a correction model is trained using historical data, making the correction factor output by the correction model more consistent with the current usage scenario. The accuracy of the obtained correction factor is high, which can further improve the accuracy of structured query language problem prediction.
[0126] To facilitate understanding of the structured query language problem prediction method provided in this application's embodiments, the following description uses a database corresponding to a specific system as an example to illustrate the entire process of the structured query language problem prediction method. For details, please refer to... Figure 3 As shown.
[0127] Figure 3 This is a schematic diagram of data flow for a structured query language problem prediction method provided in an embodiment of this application.
[0128] based on Figure 3 As shown, the prediction of structured query language problems can be divided into two processes: model training and model usage.
[0129] For model training methods, please refer to Figure 4 As shown, Figure 4 This is a schematic diagram of a model training method provided in an embodiment of this application.
[0130] like Figure 4 As shown, the model training method may include the following steps:
[0131] S401. The configuration information is sent to the rule model through the configuration center for training, and the trained rule model is obtained.
[0132] For example, validation rules can be written based on manual analysis of common problematic SQL statements. The rule information can be stored in the configuration center in the form of regular expressions. The configuration center can then distribute the rule configuration to the rule model to obtain the trained rule model.
[0133] The rule configuration is the rule expression described in the above embodiments. The rule configuration can be used for subsequent rule chain verification. Rule chain verification can be the process described in the above embodiments for determining whether the SQL statement input to the rule model is a rule expression, and will not be repeated here.
[0134] S402. Collect database tables and actual system operation data through the data collection system, transmit the collected data to the data processing system, process the data, and then transmit the data to the model for model training to obtain the analysis model.
[0135] It should be noted that the data collection system can be a component in an electronic device that allows users to collect data automatically. The data processing system can be the data processing component described in the above embodiments.
[0136] For example, the data collection system can collect database and table information from various systems, collect real-time data on the operation of the production system, and submit the data to the data processing system. The data processing system calculates the growth of the data, including but not limited to: daily growth, monthly growth, quarterly growth, annual growth, high-growth period analysis, discrimination analysis of each field in the table, actual operation status of each job, syntax tree of structured query language, actual number of SQL queries, average data size of a single data record in each field, average data size of a table row, PV, UV, TPS for each time period, etc. The data is then formatted and transmitted to the model for continuous training to obtain the analysis model.
[0137] S403. Train the model using accident information and feedback information to obtain a corrected model.
[0138] In this embodiment, the incident information may include the SQL statement information that actually caused the incident, incident scene information, syntax tree of the Problem Structured Query Language, keywords of the problematic SQL statement, and the cause of the incident, etc., and this embodiment does not limit these aspects. Feedback information may be historical feedback information collected up to the current moment, including user feedback information during the model correction process. For example, feedback information may include recorded feedback when the predicted result is a problematic SQL statement, or when a manual decision indicates a non-dangerous SQL statement, whether no incidents occurred within three production cycles after the feedback, and whether the feedback was adopted.
[0139] S404. Train the static code to obtain a knowledge base for rectification strategies.
[0140] For example, electronic devices can perform supervised clustering training on static code snippets, manually provide and label clustering tags (no restrictions, low discrimination due to restrictions, no index for high-frequency fields, etc.), and input rectification method recommendations for each tag to form a rectification strategy knowledge base.
[0141] The methods used in the model can be found in [reference needed]. Figure 5 As shown, Figure 5 This is a schematic diagram of a method for using a model provided in an embodiment of this application.
[0142] like Figure 5 As shown, the model training method may include the following steps:
[0143] S501. Submit static code to the rule model and analysis model.
[0144] For example, the process of submitting static code to the rule model and the analysis model can be referred to in the above embodiment of inputting the SQL statement to be processed into the rule model and the analysis model respectively, and will not be repeated here.
[0145] S502. The values output by the rule model and the analysis model are predicted by the correction factor output by the correction model, and prediction information is generated.
[0146] For example, the result output by the rule model is yes / no, and the value of the question SQL statement can be 1 or 0, denoted as 'a'. The result output by the analysis model is the question value, with a value range of [0, 1], denoted as 'b'. The correction model outputs correction factors for the rule model and the analysis model, where the correction factor for the rule model is β and the correction factor for the analysis model is δ, and the values of β and δ are both in the range of [0, 1].
[0147] Let y = (βa + δb) / 2, where y takes values in the range [0, 1]. Based on a pre-set problem threshold R, determine whether the SQL statement is a problematic SQL statement. If y > R, then the SQL statement is a problematic SQL statement.
[0148] The problem threshold R can be the preset value described in the above embodiments.
[0149] S503. If the predicted information output is a problematic SQL statement, then extract the static code fragment and input it into the knowledge base. Perform similarity calculation, obtain the label and corresponding rectification strategy based on the clustering results, and output the predicted conclusion and rectification information.
[0150] S504. Notify the development team to rectify the SQL. If the rectification is not carried out, feedback information must be filled in and added to the feedback information database for retraining.
[0151] In summary, the structured query language problem prediction method provided in this application introduces a correction model, a rule model, and an analysis model, resulting in high accuracy for the individual system and enhancing the generalization ability of the model itself. Furthermore, it can achieve high-accuracy predictions in newly created systems (without historical production data or operational data) that SQL prediction models cannot handle.
[0152] Figure 6 This is a schematic diagram of a structured query language problem prediction device provided in an embodiment of this application. Figure 6 As shown, the structured query language question prediction device includes: an input module 601 and a processing module 602;
[0153] The input module 601 is used to input the SQL statement to be processed into the rule model and the analysis model respectively. Both the rule model and the analysis model are trained using historical data related to the problem SQL statement.
[0154] Processing module 602 is used to perform rule analysis on the SQL statement to be processed through the rule model and obtain the first value output by the rule model. The first value indicates the probability that the SQL statement to be processed is a problematic SQL statement.
[0155] The processing module 602 is also used to analyze the SQL statement to be processed through the analysis model and obtain the probability value output by the analysis model. The probability value represents the probability that the SQL statement to be processed is a problematic SQL statement.
[0156] The processing module 602 is also used to correct the first value and the probability value by using the correction factor output by the correction model to obtain the target probability value. The correction model is trained using historical data related to the problem SQL statement.
[0157] The processing module 602 is also used to determine that the SQL statement to be processed is a problematic SQL statement when the target probability value is greater than or equal to a preset value.
[0158] In one possible design, the processing module 602 is specifically used to correct the first value and the probability value by y = (βa + δb) / 2 to obtain the target probability value; where a represents the first value, b represents the probability value, β represents the first correction factor, δ represents the second correction factor, and y represents the target probability value.
[0159] In one possible design, the input module 601 is further configured to input at least one of the following into the correction model: historical feedback information, historical problem SQL statement information, and historical problem structured query language syntax tree, to obtain the first correction factor and the second correction factor output by the correction model.
[0160] In one possible design, the rule model includes multiple rule expressions, which are used to detect whether the SQL statement input to the rule model is a problematic SQL statement.
[0161] The processing module 602 is also used to perform rule analysis on the SQL statement to be processed using each of the multiple rule expressions to determine whether the SQL statement to be processed conforms to the rule expression; when the SQL statement to be processed conforms to at least one of the multiple rule expressions, the first value output by the rule model is obtained.
[0162] In one possible design, the processing module 602 is further configured to obtain a second value output by the rule model when the SQL statement to be processed does not conform to any of the multiple rule expressions. The second value represents the probability that the SQL statement to be processed is a problematic SQL statement.
[0163] In one possible design, the analysis model is trained based on the first data input by the data processing component. The data processing component processes the historical data related to the problem SQL statement and inputs the processed first data into the analysis model. The first data includes at least two of the following: daily data growth, monthly data growth, quarterly data growth, annual data growth, information on periods of rapid data growth, the distinguishability information of each field in the database table, the actual operating information of the electronic device, the syntax tree of the structured query language, the number of queries in the historical SQL statements, the average data volume of each field in the database table, the average data volume of a single row in the database table, page views, the number of unique visitors, and the throughput for each time period.
[0164] In one possible design, the input module 601 is also used to input static code fragments of the SQL statement to be processed into the strategy knowledge base, which includes multiple pre-stored static codes.
[0165] The processing module 602 is also used to calculate the similarity between the static code fragment and each of the multiple pre-stored static codes; determine and output the rectification strategy corresponding to the pre-stored static code with the highest similarity among the multiple similarities, and the rectification strategy is used to remind the user to modify the SQL statement to be processed.
[0166] In one possible design, the input module 601 is also used to input the target feedback information into the correction model to obtain a new correction factor output by the correction model. The target feedback information is the information fed back by the user when the SQL statement to be processed is not modified.
[0167] The structured query language problem prediction device provided in this application embodiment can be used to execute the technical solution of the structured query language problem prediction method in the above embodiment. Its implementation principle and technical effect are similar, and will not be repeated here.
[0168] It should be noted that the division of the various modules in the above device is merely a logical functional division. In actual implementation, they can be fully or partially integrated into a single physical entity, or they can be physically separated. Furthermore, these modules can be implemented entirely in software via processing element calls; they can be fully implemented in hardware; or some modules can be implemented by processing element calls to software, while others are implemented in hardware. The implementation of other modules is similar. In addition, these modules can be fully or partially integrated together, or implemented independently. The processing element here can be an integrated circuit with signal processing capabilities. During implementation, each step of the above method or each of the above modules can be completed through the integrated logic circuits in the hardware of the processor element or through software instructions.
[0169] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 7 As shown, the electronic device may include: a transceiver 701, a processor 702, and a memory 703.
[0170] Processor 702 executes computer execution instructions stored in memory, causing processor 702 to perform the scheme in the above embodiments. Processor 702 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0171] The memory 703 is connected to the processor 702 via the system bus and completes communication between them. The memory 73 is used to store computer program instructions.
[0172] Transceiver 701 can be used to obtain the task to be run and its configuration information.
[0173] The system bus can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The system bus can be divided into address bus, data bus, control bus, etc. For ease of representation, only one thick line is used in the diagram, but this does not indicate that there is only one bus or one type of bus. Transceivers are used to enable communication between database access devices and other computers (e.g., clients, read-write libraries, and read-only libraries). Memory may include random access memory (RAM) and may also include non-volatile memory.
[0174] The electronic device provided in this application embodiment can be the terminal device described in the above embodiments.
[0175] This application also provides a chip for executing instructions, which is used to execute the technical solution of the structured query language problem prediction method in the above embodiments.
[0176] This application also provides a computer-readable storage medium storing computer instructions. When the computer instructions are executed on a computer, the computer performs the technical solution of the structured query language problem prediction method described in the above embodiments.
[0177] This application also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. At least one processor can read the computer program from the computer-readable storage medium. When the at least one processor executes the computer program, it can implement the technical solution of the structured query language problem prediction method in the above embodiments.
[0178] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or modules, and may be electrical, mechanical, or other forms.
[0179] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to implement the solution of this embodiment according to actual needs.
[0180] Furthermore, the functional modules in the various embodiments of this application can be integrated into one processing unit, or each module can exist physically separately, or two or more modules can be integrated into one unit. The unit composed of the above modules can be implemented in hardware or in the form of hardware plus software functional units.
[0181] The integrated modules described above, implemented as software functional modules, can be stored in a computer-readable storage medium. These software functional modules, stored in a storage medium, include several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute some steps of the methods of the various embodiments of this application.
[0182] It should be understood that the aforementioned processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. A general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly manifested as being executed by a hardware processor, or executed by a combination of hardware and software modules within the processor.
[0183] The memory may include high-speed RAM, and may also include non-volatile storage (NVM), such as at least one disk storage device, and may also be a USB flash drive, external hard drive, read-only memory, disk or optical disc, etc.
[0184] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.
[0185] The aforementioned storage medium can be implemented from any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The storage medium can be any available medium accessible to general-purpose or special-purpose computers.
[0186] An exemplary storage medium is coupled to a processor, enabling the processor to read information from and write information to the storage medium. Alternatively, the storage medium can be an integral part of the processor. The processor and storage medium can reside in an Application Specific Integrated Circuit (ASIC). Alternatively, the processor and storage medium can exist as discrete components in an electronic control unit or main control device.
[0187] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.
[0188] The collection, storage, use, processing, transmission, provision, and disclosure of financial data or user data involved in the technical solution of this application all comply with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0189] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. A method for predicting structured query language questions, characterized in that, include: The structured query language to be processed is input into the rule model and the analysis model, respectively. Both the rule model and the analysis model are trained using historical data related to the structured query language of the question. The rule model is used to perform rule analysis on the structured query language to be processed, and a first value is obtained from the rule model output. The first value represents the probability that the structured query language to be processed is a question structured query language. The analysis model analyzes the structured query language to be processed, and obtains the probability value output by the analysis model. The probability value represents the probability that the structured query language to be processed is a question-based structured query language. The analysis model is trained based on the first data input by the data processing component. The data processing component is used to process the historical data related to the question-based structured query language and input the processed first data into the analysis model. The first data includes: daily data growth, monthly data growth, quarterly data growth, annual data growth, information on periods of rapid data growth, the distinguishability information of each field in the database table, the actual operating information of electronic devices, the syntax tree of the structured query language, the number of queries in the historical structured query language, the average data volume of each field in the database table, the average data volume of a single row in the database table, page views, the number of unique visitors, and the throughput in each time period. The first value and the probability value are corrected by the correction factor output by the correction model to obtain the target probability value. The correction model is trained using historical data related to the Problem Structured Query Language. The correction model is trained using accident information and feedback information. The accident information includes the SQL statement information that actually caused the accident, the accident scene information, the syntax tree of the Problem Structured Query Language, the keywords of the problem SQL statement, and the cause of the accident. The feedback information includes the feedback information recorded when the prediction result is a problem SQL statement, the manual decision is a non-dangerous SQL statement, whether no accident occurred within three production cycles after the feedback, and whether the feedback was adopted. When the target probability value is greater than or equal to a preset value, the structured query language to be processed is determined to be a problem structured query language.
2. The method according to claim 1, characterized in that, The first value and the probability value are corrected using the correction factor output by the correction model to obtain the target probability value, including: via y=( a+ b) / 2 is used to correct the first value and the probability value to obtain the target probability value; Where a represents the first value, and b represents the probability value. Indicates the first correction factor. Let y represent the second correction factor, and y represent the target probability value.
3. The method according to claim 2, characterized in that, The method further includes: At least one of the following is input into the correction model: historical feedback information, historical question structured query language information, and the syntax tree of historical question structured query language. The first correction factor and the second correction factor output by the correction model are obtained.
4. The method according to any one of claims 1-3, characterized in that, The rule model includes multiple rule expressions, which are used to detect whether the structured query language input to the rule model is a question structured query language. The step of performing rule analysis on the structured query language to be processed through the rule model to obtain the first value output by the rule model includes: Using each of the plurality of rule expressions, rule analysis is performed on the structured query language to be processed to determine whether the structured query language to be processed conforms to the rule expression; When the structured query language to be processed conforms to at least one of the multiple rule expressions, the first value output by the rule model is obtained.
5. The method according to claim 4, characterized in that, The method further includes: When the structured query language to be processed does not conform to any of the multiple rule expressions, a second value is obtained from the output of the rule model. The second value represents the probability that the structured query language to be processed is a question structured query language.
6. The method according to any one of claims 1-3, characterized in that, After determining that the structured query language to be processed is a question structured query language, the process includes: The static code snippet of the structured query language to be processed is input into the strategy knowledge base, which includes multiple pre-stored static codes; Calculate the similarity between the static code fragment and each of the plurality of pre-stored static codes; The rectification strategy corresponding to the pre-stored static code with the highest similarity among multiple similarity values is determined and output. The rectification strategy is used to remind the user to modify the structured query language to be processed.
7. The method according to claim 6, characterized in that, The method further includes: The target feedback information is input into the correction model to obtain a new correction factor output by the correction model. The target feedback information is the information fed back by the user when the user does not modify the structured query language to be processed.
8. A structured query language problem prediction device, characterized in that, include: The input module is used to input the structured query language to be processed into the rule model and the analysis model respectively. Both the rule model and the analysis model are trained using historical data related to the structured query language of the question. The processing module is used to perform rule analysis on the structured query language to be processed through the rule model to obtain a first value output by the rule model, wherein the first value represents the probability that the structured query language to be processed is a question structured query language; The processing module is further configured to analyze the structured query language to be processed using the analysis model, and obtain a probability value output by the analysis model. The probability value represents the probability that the structured query language to be processed is a question-based structured query language. The analysis model is trained based on the first data input by the data processing component. The data processing component is configured to process the historical data related to the question-based structured query language and input the processed first data into the analysis model. The first data includes: daily data growth, monthly data growth, quarterly data growth, annual data growth, information on periods of rapid data growth, the distinguishability information of each field in the database table, the actual operating information of electronic devices, the syntax tree of the structured query language, the number of queries in the historical structured query language, the average data volume of each field in the database table, the average data volume of a single row in the database table, page views, the number of unique visitors, and the throughput in each time period. The processing module is further configured to correct the first value and the probability value using a correction factor output by the correction model to obtain a target probability value. The correction model is trained using historical data related to the Problem Structured Query Language (MSL). The correction model is trained using accident information and feedback information. The accident information includes the SQL statement information that actually caused the accident, the accident scene information, the syntax tree of the MSL, the keywords of the problem SQL statement, and the cause of the accident. The feedback information includes the feedback information recorded when the prediction result is a problem SQL statement, the manual decision is a non-dangerous SQL statement, whether no accident occurred within three production cycles after the feedback, and whether the feedback was adopted. The processing module is further configured to determine that the structured query language to be processed is a question structured query language when the target probability value is greater than or equal to a preset value.
9. An electronic device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the method as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1-7.
11. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method of any one of claims 1-7.
Citation Information
Patent Citations
SQL risk identification method, device and equipment
CN112784273A
SQL statement anomaly detection method and device
CN115587108A