Structured query language statement display method and electronic device
By analyzing the test environment log file to generate and evaluate SQL statements, the problem of excessive human participation in SQL statement quality detection in the existing technology is solved, and automated detection and sorting display is realized, saving manpower and time.
Patent Information
- Application Number
- CN202210182391.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-25
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2042-02-25
AI Technical Summary
In the prior art, the quality detection of SQL statements requires a lot of manual participation, which is time-consuming and labor-intensive, and lacks efficient automation methods.
By obtaining the log files of the test environment, parsing the log files to generate SQL statements, and sorting and displaying them according to the quality evaluation value of the statements, reducing manual intervention.
It realizes the automated quality detection and sorting display of SQL statements, which significantly saves manpower and time and improves detection efficiency.
Smart Images

Figure CN114357038B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of database technology, and in particular to a structured query language (SQL) statement display method and electronic device. Background Art
[0002] In the process of business system development, operations such as adding and modifying database SQL statements are often involved. The impact of these operations on the business system is unknown. Therefore, it is necessary to perform quality inspection of SQL statements before the business system goes online.
[0003] The commonly used quality inspection method at present is: first manually paste a large number of SQL statements in the test environment, and then manually analyze these SQL statements using existing tools. The whole process requires a lot of manual participation and is time-consuming and labor-intensive. Summary of the invention
[0004] In order to solve the above technical problems, the present disclosure is proposed. The embodiments of the present disclosure provide a SQL statement display method and an electronic device.
[0005] According to one aspect of an embodiment of the present disclosure, a method for displaying a SQL statement is provided, including:
[0006] Get the log file corresponding to the test environment;
[0007] Generate N SQL statements according to the parsing result of the log file; where N is an integer greater than or equal to 2;
[0008] Determine N quality assessment values corresponding to the N SQL statements;
[0009] The N SQL statements are sorted and displayed according to the N quality evaluation values.
[0010] In an optional example, generating N SQL statements according to the parsing result of the log file includes:
[0011] Obtaining M original log information from the parsing result of the log file; wherein M is an integer greater than or equal to N;
[0012] Convert the M original log information into array format to generate corresponding M converted log information;
[0013] From the M conversion log information, select N conversion log information whose first designated positions are all data used to characterize that the type of the current conversion log information is an SQL log type;
[0014] Extracting SQL statements from respective second designated locations of the N conversion log information;
[0015] The N SQL statements extracted from the N conversion log information are formatted respectively to generate corresponding N SQL statements after the formatting process.
[0016] In an optional example, obtaining a log file corresponding to the test environment includes:
[0017] Establish a remote connection to the test environment;
[0018] Determine the log path corresponding to the test environment;
[0019] The log file corresponding to the test environment is read through the remote connection according to the log path.
[0020] In an optional example, before obtaining the log file corresponding to the test environment, the method further includes:
[0021] Obtain P pieces of environment information to be selected; where P is an integer greater than or equal to 2;
[0022] According to the P candidate environment information, display a candidate environment list including the corresponding P candidate environments;
[0023] Receiving a user's selection operation on a target environment to be selected; wherein the target environment to be selected is any one of the P environments to be selected;
[0024] The target candidate environment is used as the test environment.
[0025] In an optional example, determining N quality evaluation values corresponding to the N SQL statements includes:
[0026] Performing syntax analysis on a target SQL statement, and processing the target SQL statement into an abstract syntax tree; wherein the target SQL statement is any one of the N SQL statements;
[0027] According to the abstract syntax tree, K query situation data corresponding to K preset query types are determined; wherein K is an integer greater than or equal to 2, and the query situation data corresponding to any preset query type is used to characterize whether there is a query of the preset query type in the target SQL statement;
[0028] Determine K deduction points corresponding to the K preset query types according to the K query situation data;
[0029] Calculate the sum of the K deduction points;
[0030] A quality assessment value corresponding to the target SQL statement is determined according to a difference between the first preset value and the sum.
[0031] In an optional example, determining, according to the K query situation data, K deduction values corresponding to the K preset query types includes:
[0032] In the case where the query situation data corresponding to the target preset query type is used to characterize that there is no query of the target preset query type in the target SQL statement, zero is determined as the deduction value corresponding to the target preset query type; otherwise, the severity level corresponding to the target preset query type is determined; wherein the target preset query type is any preset query type among the K preset query types;
[0033] When the severity level corresponding to the target preset query type is the preset severity level, zero is determined as the deduction value corresponding to the target preset query type;
[0034] When the severity level corresponding to the target preset query type is higher than the preset severity level, the deduction value corresponding to the target preset query type is determined according to the severity level value corresponding to the target preset query type and a second preset value.
[0035] In an optional example, determining the deduction value corresponding to the target preset query type according to the level value of the severity level corresponding to the target preset query type and the second preset value includes:
[0036] The product of the severity level value corresponding to the target preset query type and the second preset value is used as the deduction value corresponding to the target preset query type.
[0037] In an optional example, the method further includes:
[0038] From the K preset query types, R preset query types that meet the preset condition are screened; wherein R is an integer greater than or equal to 1, and any preset query type that meets the preset condition means that the query situation data corresponding to the preset query type is used to characterize the query of the preset query type in the target SQL statement;
[0039] Corresponding to the N SQL statements displayed in order, N controls are displayed;
[0040] In case of receiving an input operation on a control corresponding to the target SQL statement, determining R severity levels corresponding to the R preset query types, and determining R query risk prediction information corresponding to the R preset query types;
[0041] Displaying explanatory data of the quality assessment value corresponding to the target SQL statement; wherein the explanatory data includes: the R preset query types, the R severity levels corresponding to the R preset query types, and the R query risk prediction information corresponding to the R preset query types.
[0042] According to another aspect of the embodiments of the present disclosure, a SQL statement display device is provided, including:
[0043] The first acquisition module is used to obtain the log file corresponding to the test environment;
[0044] A generation module, used to generate N SQL statements according to the parsing result of the log file; wherein N is an integer greater than or equal to 2;
[0045] A first determination module, used to determine N quality assessment values corresponding to the N SQL statements;
[0046] The first display module is used to sort and display the N SQL statements according to the N quality evaluation values.
[0047] In an optional example, the generating module includes:
[0048] The acquisition submodule is used to obtain M original log information from the parsing result of the log file; wherein M is an integer greater than or equal to N;
[0049] A conversion submodule, used for converting the M original log information into an array format to generate corresponding M conversion log information;
[0050] A screening submodule, configured to screen, from the M conversion log information, N conversion log information whose respective first designated positions are all data used to characterize that the type of the current conversion log information is an SQL log type;
[0051] An extraction submodule, used to extract SQL statements from respective second designated positions of the N conversion log information;
[0052] The first processing submodule is used to format the N SQL statements extracted from the N conversion log information respectively to generate corresponding N SQL statements after formatting.
[0053] In an optional example, the first acquisition module includes:
[0054] Create a submodule to establish a remote connection with the test environment;
[0055] A first determination submodule is used to determine the log path corresponding to the test environment;
[0056] The reading submodule is used to read the log file corresponding to the test environment through the remote connection and according to the log path.
[0057] In an optional example, the device further includes:
[0058] A second acquisition module is used to obtain P pieces of information of selected environments before obtaining the log file corresponding to the test environment; wherein P is an integer greater than or equal to 2;
[0059] A second display module is used to display a list of candidate environments including the corresponding P candidate environments according to the information of the P candidate environments;
[0060] A receiving module, configured to receive a user's selection operation on a target environment to be selected; wherein the target environment to be selected is any one of the P environments to be selected;
[0061] The second determining module is used to use the target candidate environment as the test environment.
[0062] In an optional example, the first determining module includes:
[0063] The second processing submodule is used to perform syntax analysis on the target SQL statement and process the target SQL statement into an abstract syntax tree; wherein the target SQL statement is any one of the N SQL statements;
[0064] A second determination submodule is used to determine K query situation data corresponding to K preset query types according to the abstract syntax tree; wherein K is an integer greater than or equal to 2, and the query situation data corresponding to any preset query type is used to characterize whether there is a query of the preset query type in the target SQL statement;
[0065] A third determination submodule is used to determine K deduction points corresponding to the K preset query types according to the K query situation data;
[0066] A calculation submodule, used for calculating the sum of the K deduction points;
[0067] The fourth determination submodule is used to determine the quality assessment value corresponding to the target SQL statement according to the difference between the first preset value and the sum.
[0068] In an optional example, the third determining submodule includes:
[0069] A first determining unit is configured to determine zero as the deduction value corresponding to the target preset query type when the query situation data corresponding to the target preset query type is used to characterize that there is no query of the target preset query type in the target SQL statement; otherwise, determine the severity level corresponding to the target preset query type; wherein the target preset query type is any preset query type among the K preset query types;
[0070] A second determining unit, configured to determine zero as the deduction value corresponding to the target preset query type when the severity level corresponding to the target preset query type is the preset severity level;
[0071] The third determining unit is used to determine the deduction value corresponding to the target preset query type according to the level value of the severity level corresponding to the target preset query type and a second preset value when the severity level corresponding to the target preset query type is higher than the preset severity level.
[0072] In an optional example, the third determining unit is specifically configured to:
[0073] The product of the severity level value corresponding to the target preset query type and the second preset value is used as the deduction value corresponding to the target preset query type.
[0074] In an optional example, the device further includes:
[0075] A screening module, used to screen R preset query types that meet a preset condition from the K preset query types; wherein R is an integer greater than or equal to 1, and any preset query type that meets the preset condition means that the query situation data corresponding to the preset query type is used to characterize the query of the preset query type in the target SQL statement;
[0076] A third display module, used to display N controls corresponding to the N SQL statements displayed in order;
[0077] A third determination module is used to determine R severity levels corresponding to the R preset query types and determine R query risk prediction information corresponding to the R preset query types when receiving an input operation on the control corresponding to the target SQL statement;
[0078] The fourth display module is used to display the explanatory data of the quality assessment value corresponding to the target SQL statement; wherein the explanatory data includes: the R preset query types, the R severity levels corresponding to the R preset query types, and the R query risk prediction information corresponding to the R preset query types.
[0079] According to another aspect of the embodiments of the present disclosure, there is provided an electronic device, including:
[0080] a memory for storing a computer program product;
[0081] The processor is used to execute the computer program product stored in the memory, and when the computer program product is executed, the above-mentioned SQL statement display method is implemented.
[0082] According to another aspect of the embodiments of the present disclosure, a computer-readable storage medium is provided, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the above-mentioned SQL statement display method is implemented.
[0083] According to another aspect of an embodiment of the present disclosure, a computer program product is provided, including computer program instructions, which implement the above-mentioned SQL statement display method when executed by a processor.
[0084] In the embodiment of the present disclosure, after obtaining the log file corresponding to the test environment, N SQL statements can be generated according to the parsing result of the log file, and then N quality evaluation values corresponding to the N SQL statements can be determined, and the N SQL statements can be sorted and displayed according to the N quality evaluation values. That is, in the embodiment of the present disclosure, in combination with the acquisition operation of the log file corresponding to the test environment and the parsing operation of the log file, a large number of SQL statements can be automatically generated, and in combination with the determination operation of the quality evaluation value and the sorting and display operation of the SQL statements, the quality of these SQL statements can be directly presented to the analyst, and the analyst can analyze and optimize the business system accordingly, and the analyst does not need to manually paste and analyze a large number of SQL statements. Therefore, compared with the related art, under the premise of ensuring the quality detection of a large number of SQL statements, the embodiment of the present disclosure can save a lot of manpower and time. BRIEF DESCRIPTION OF THE DRAWINGS
[0085] Figure 1 It is a flowchart of a SQL statement display method provided by an exemplary embodiment of the present disclosure.
[0086] Figure 2 It is a schematic diagram of the overall design of an embodiment of the present disclosure.
[0087] Figure 3 It is a flowchart of a SQL statement display method provided by another exemplary embodiment of the present disclosure.
[0088] Figure 4 It is a flowchart of a SQL statement display method provided by yet another exemplary embodiment of the present disclosure.
[0089] Figure 5It is a flowchart of a SQL statement display method provided by another exemplary embodiment of the present disclosure.
[0090] Figure 6 It is a flowchart of a SQL statement display method provided by another exemplary embodiment of the present disclosure.
[0091] Figure 7 It is a schematic diagram of a test environment list in an embodiment of the present disclosure.
[0092] Figure 8 It is a schematic diagram of the evaluation and display process of SQL statements in an embodiment of the present disclosure.
[0093] Fig. 9 It is a schematic diagram showing the sorting of SQL statements in an embodiment of the present disclosure.
[0094] Fig.10 is a schematic diagram for explaining data in an embodiment of the present disclosure.
[0095] Fig.11 It is a structural diagram of a SQL statement display device provided by an exemplary embodiment of the present disclosure.
[0096] Fig.12 is a structural diagram of an electronic device provided by an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION
[0097] Hereinafter, exemplary embodiments according to the present disclosure will be described in detail with reference to the accompanying drawings. The described embodiments are only a part of the embodiments, rather than all the embodiments, and the present disclosure is not limited to the exemplary embodiments described herein.
[0098] It should be noted that the relative arrangement of components and steps, the numerical expressions and numerical values set forth in these embodiments do not limit the scope of the present disclosure unless specifically stated otherwise.
[0099] Those skilled in the art will appreciate that the terms "first", "second" and the like in the embodiments of the present disclosure are only used to distinguish different steps, devices or modules, etc., and do not represent any specific technical meaning or necessary logical order. "Multiple" may refer to two or more than two, and "at least one" may refer to one, two or more than two.
[0100] It should also be understood that any component, data or structure mentioned in the embodiments of the present disclosure can generally be understood as one or more, unless explicitly limited or otherwise indicated in the context.
[0101] The term "and / or" in this disclosure is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " in this disclosure generally indicates that the associated objects before and after are in an "or" relationship.
[0102] It should also be understood that the description of each embodiment of the present disclosure emphasizes the differences between the embodiments, and the same or similar parts can be referenced to each other, and for the sake of brevity, they will not be described one by one. It should be understood that for the sake of ease of description, the sizes of the various parts shown in the drawings are not drawn according to the actual proportional relationship.
[0103] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the present disclosure and its application or use. Technologies, methods, and devices known to those of ordinary skill in the relevant art may not be discussed in detail, and where appropriate, such technologies, methods, and the like should be considered part of the specification.
[0104] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.
[0105] The embodiments of the present disclosure may be applied to electronic devices such as terminal devices, computer systems, servers, etc., which may operate with many other general or special computing system environments or configurations. Examples of well-known terminal devices, computing systems, environments and / or configurations suitable for use with electronic devices such as terminal devices, computer systems, servers, etc. include, but are not limited to: personal computer systems, server computer systems, thin clients, thick clients, handheld or laptop devices, microprocessor-based systems, network personal computers, small computer systems, large computer systems, and distributed cloud computing technology environments including any of the above systems, etc.
[0106] Electronic devices such as terminal devices, computer systems, servers, etc. can be described in the general context of computer system executable instructions (such as program modules) executed by computer systems. Generally, program modules can include routines, programs, object programs, components, logic, data structures, etc., which perform specific tasks or implement specific abstract data types. Computer systems / servers can be implemented in distributed cloud computing environments, where tasks are performed by remote processing devices linked through a communication network. In a distributed cloud computing environment, program modules can be located on local or remote computing system storage media including storage devices.
[0107] Exemplary Methods
[0108] Figure 1 It is a flowchart of a SQL statement display method provided by an exemplary embodiment of the present disclosure. Figure 1 The method shown may include step 101, step 102, step 103 and step 104, and each step is described below.
[0109] Step 101, obtaining the log file corresponding to the test environment.
[0110] It should be noted that before the business system goes online, you can use Figure 2 The integrated environment builder in the system constructs a test environment, and based on the test environment, performs a test on the business system. In addition, the relevant test information can be stored in the form of a log file corresponding to the test environment. Thus, in step 101, the log file corresponding to the test environment can be directly obtained from the stored information.
[0111] Step 102: Generate N SQL statements according to the parsing result of the log file; wherein N is an integer greater than or equal to 2.
[0112] In step 102, the log file may be parsed to obtain the parsing result of the log file, and then N SQL statements may be automatically generated according to the parsing result of the log file. Here, N may be 2, 10, 20, 50, 70 or other integers greater than 2, which are not listed here one by one.
[0113] Step 103: Determine N quality evaluation values corresponding to the N SQL statements.
[0114] In step 103, N quality evaluation values corresponding to the N SQL statements can be obtained by analyzing and evaluating the N SQL statements. The quality evaluation value corresponding to any SQL statement can be used to characterize the quality of the SQL statement.
[0115] Optionally, in step 103, a forward evaluation method can be used to determine N quality evaluation values corresponding to N SQL statements. In this case, the higher the quality of the SQL statement, the greater the quality evaluation value corresponding to it; or, in step 103, a reverse evaluation method can be used to determine N quality evaluation values corresponding to N SQL statements. In this case, the lower the quality of the SQL statement, the greater the quality evaluation value corresponding to it.
[0116] Step 104: sort and display the N SQL statements according to the N quality evaluation values.
[0117] In step 103, when a forward evaluation method is adopted to determine N quality evaluation values corresponding to N SQL statements, in step 104, when the N SQL statements are sorted and displayed, the SQL statement with a larger corresponding quality evaluation value can be sorted closer to the front; in step 103, when a reverse evaluation method is adopted to determine N quality evaluation values corresponding to N SQL statements, in step 104, when the N SQL statements are sorted and displayed, the SQL statement with a smaller corresponding quality evaluation value can be sorted closer to the front.
[0118] In the embodiment of the present disclosure, after obtaining the log file corresponding to the test environment, N SQL statements can be generated according to the parsing result of the log file, and then N quality evaluation values corresponding to the N SQL statements can be determined, and the N SQL statements can be sorted and displayed according to the N quality evaluation values. That is, in the embodiment of the present disclosure, in combination with the acquisition operation of the log file corresponding to the test environment and the parsing operation of the log file, a large number of SQL statements can be automatically generated, and in combination with the determination operation of the quality evaluation value and the sorting and display operation of the SQL statements, the quality of these SQL statements can be directly presented to the analyst, and the analyst can analyze and optimize the business system accordingly, and the analyst does not need to manually paste and analyze a large number of SQL statements. Therefore, compared with the related art, under the premise of ensuring the quality detection of a large number of SQL statements, the embodiment of the present disclosure can save a lot of manpower and time.
[0119] exist Figure 1 Based on the embodiment shown, Figure 3 As shown, step 103 includes:
[0120] Step 1031, parse the target SQL statement and process the target SQL statement into an abstract syntax tree (AST); wherein the target SQL statement is any one of the N SQL statements;
[0121] Step 1032: determining K query situation data corresponding to K preset query types according to the abstract syntax tree; wherein K is an integer greater than or equal to 2, and the query situation data corresponding to any preset query type is used to indicate whether there is a query of the preset query type in the target SQL statement;
[0122] Step 1033, determining K deduction points corresponding to K preset query types according to the K query situation data;
[0123] Step 1034, calculating the sum of K deduction points;
[0124] Step 1035: Determine the quality assessment value corresponding to the target SQL statement according to the difference between the first preset value and the sum.
[0125] Here, you can call a syntax parser to perform syntax parsing on the target SQL statement. The syntax parser includes but is not limited to Figure 2 Vitess, TiDB, etc.; among them, Vitess is a database solution for deploying, expanding and managing large open source database instance clusters, and TiDB is an open source distributed relational database.
[0126] Here, K can be 2, 5, 7, 10 or other integers greater than 2, which are not listed here one by one. Specifically, the K preset query types include but are not limited to the following query types: LIMIT query with OFFSET, query with NOT IN / NOT LIKE, query of OR query index column, Select* type query, LIMIT query without ORDER By.
[0127] Here, the first preset value may be 100.
[0128] In the embodiments of the present disclosure, open source parsers such as Vitess and TiDB can be used to process the target SQL statement into an abstract syntax tree. It should be noted that the abstract syntax tree is an abstract representation of the syntax structure of the source code. It expresses the syntax structure of the programming language in a tree form. Each node on the tree represents a structure in the source code. By referring to the abstract syntax tree, it is very convenient to determine which query types exist in the target SQL statement. Based on this, K query situation data corresponding to K preset query types can be determined, so as to further determine the K deduction values corresponding to the K preset query types.
[0129] In a specific implementation, determining K deduction values corresponding to K preset query types according to K query situation data includes:
[0130] In the case where the query situation data corresponding to the target preset query type is used to characterize the query of the target preset query type that does not exist in the target SQL statement, zero is determined as the deduction value corresponding to the target preset query type; otherwise, the severity level corresponding to the target preset query type is determined; wherein the target preset query type is any preset query type among the K preset query types;
[0131] When the severity level corresponding to the target preset query type is the preset severity level, zero is determined as the deduction value corresponding to the target preset query type;
[0132] When the severity level corresponding to the target preset query type is higher than the preset severity level, the deduction value corresponding to the target preset query type is determined according to the severity level value corresponding to the target preset query type and the second preset value.
[0133] Here, there are S severity levels in total. In order of severity from low to high, the S severity levels are L0, L1, L2, L3, ..., L(S-1), and the preset severity level may be L0.
[0134] Here, the second preset value may be 5, 7, 8, 10 or other values, which are not listed here one by one.
[0135] In this implementation, a correspondence between preset query types and severity levels may be preset.
[0136] When the query situation data corresponding to the target preset query type is used to characterize the case where there is no query of the target preset query type in the target SQL statement, this means that the quality of the target SQL statement will not be affected by the query of the preset query type. In this case, zero can be directly determined as the deduction value corresponding to the target preset query type.
[0137] When the query situation data corresponding to the target preset query type is used to characterize the existence of queries of the target preset query type in the target SQL statement, this indicates that the quality of the target SQL statement will be affected by the queries of the target preset query type. Then, the severity level corresponding to the target preset query type can be determined based on the correspondence between the pre-set preset query type and the severity level.
[0138] After determining the severity level corresponding to the target preset query type, the severity level corresponding to the target preset query type may be compared with a preset severity level (eg, L0).
[0139] If the comparison result is that the severity level corresponding to the target preset query type is the preset severity level, this means that although the quality of the target SQL statement will be affected by the query of the target preset query type, the degree of impact is small. In this case, zero can be determined as the deduction value corresponding to the target preset query type.
[0140] If the comparison result is that the severity level corresponding to the target preset query type is higher than the preset severity level, this means that the quality of the target SQL statement will be affected by the query of the target preset query type, and the degree of impact is not small. Then, the deduction value corresponding to the target preset query type can be determined based on the severity level value corresponding to the target preset query type and the second preset value.
[0141] Optionally, determining the deduction value corresponding to the target preset query type according to the level value of the severity level corresponding to the target preset query type and the second preset value includes:
[0142] The product of the severity level value corresponding to the target preset query type and the second preset value is used as the deduction value corresponding to the target preset query type.
[0143] Assuming that the second preset value is 5, when the severity level corresponding to the target preset query type is L2, the severity level corresponding to the target preset query type is 2, and the deduction value corresponding to the target preset query type is 2×5=10; when the severity level corresponding to the target preset query type is L3, the severity level corresponding to the target preset query type is 3, and the deduction value corresponding to the target preset query type is 3×5=15.
[0144] It is easy to see that by introducing the multiplication operation above, the deduction value corresponding to the target preset query type can be determined very conveniently. It should be pointed out that, according to the actual situation, when determining the deduction value corresponding to the target preset query type according to the level value of the severity level corresponding to the target preset query type and the second preset value, other types of operations can also be introduced, such as exponential operations, addition operations, etc. For example, using the level value as the base, the second preset value as the exponent for exponential operations, and using the operation result as the deduction value corresponding to the target preset query type, this is also feasible.
[0145] In this implementation, by referring to the query situation data corresponding to the target preset query type and the severity level corresponding to the target preset query type, the deduction value corresponding to the target preset query type can be reasonably determined.
[0146] It should be noted that, according to the method provided above, K deduction values corresponding to K preset query types can be determined based on K query situation data, and then the sum of the K deduction values can be calculated, and the difference between the first preset value (for example, 100) and the sum can be further calculated, so as to determine the quality evaluation value of the target SQL statement based on the difference. Optionally, when the difference is greater than zero, the difference can be used as the quality evaluation value of the target SQL statement, and when the difference is less than or equal to zero, zero can be used as the quality evaluation value of the target SQL statement; or, regardless of whether the difference is greater than or less than or equal to zero, the difference can be directly used as the quality evaluation value of the target SQL statement.
[0147] In the embodiments of the present disclosure, by calling a syntax parser and processing the target SQL statement into an abstract syntax tree, K query situation data corresponding to K preset query types can be conveniently and reliably determined, so as to reasonably determine K deduction values corresponding to the K preset query types, and then combined with addition and subtraction operations, the quality assessment value corresponding to the target SQL statement can be conveniently determined, and the quality assessment value can accurately and reliably characterize the quality of the target SQL statement.
[0148] exist Figure 2 Based on the embodiment shown, Figure 4 As shown, the method also includes:
[0149] Step 105, selecting R preset query types that meet the preset condition from the K preset query types; wherein R is an integer greater than or equal to 1, and any preset query type that meets the preset condition means that the query situation data corresponding to the preset query type is used to characterize the query of the preset query type in the target SQL statement;
[0150] Step 106, displaying N controls corresponding to the N SQL statements displayed in order;
[0151] Step 107, in the case of receiving an input operation to a control corresponding to a target SQL statement, determining R severity levels corresponding to the R preset query types, and determining R query risk prediction information corresponding to the R preset query types;
[0152] Step 108, displaying the explanatory data of the quality assessment value corresponding to the target SQL statement; wherein the explanatory data includes: R preset query types, R severity levels corresponding to the R preset query types, and R query risk prediction information corresponding to the R preset query types.
[0153] Here, the input operation on any control includes but is not limited to a click operation, a touch operation, a drag operation, etc. on the control.
[0154] Here, in addition to pre-setting the correspondence between the preset query type and the severity level, the correspondence between the preset query type and the query risk prediction information can also be pre-set; wherein the query risk prediction information corresponding to any preset query type is used to indicate the risk that may be caused by the query of the preset query type. For example, the query risk prediction information corresponding to the Select* type query can be: When the table structure changes, using the * wildcard to select all columns will cause the meaning and behavior of the query to change, which may cause the query to return more data. The query risk prediction information corresponding to the LIMIT query without using ORDER By can be: LIMIT without ORDER By will lead to non-deterministic results, which depends on the query execution plan.
[0155] In the embodiments of the present disclosure, by referring to the abstract syntax tree, it is possible to very conveniently determine which query types of queries exist in the target SQL statement, and based on this, it is possible to determine which preset query types among the K preset query types meet the preset conditions, and all preset query types that meet the preset conditions can be used as the R preset query conditions screened out in step 105.
[0156] While N SQL statements are sorted and displayed according to N quality evaluation values, N controls can also be displayed corresponding to the sorted and displayed N SQL statements, and the N controls can correspond to the N SQL statements one by one.
[0157] When receiving an input operation to a control corresponding to a target SQL statement, R severity levels corresponding to the R preset query types can be determined based on the correspondence between the preset query types and severity levels, and R query risk prediction information corresponding to the R preset query types can be determined based on the correspondence between the preset query types and the query risk prediction information. Afterwards, the explanatory data of the quality assessment value corresponding to the target SQL statement can be displayed, and the parsed data includes R preset query types, R severity levels corresponding to the R preset query types, and R query risk prediction information corresponding to the R preset query types. In this way, by referring to the explanatory data, the analyst can know which preset query types of queries are specifically responsible for the deduction of points for the target SQL statement, the severity of these queries, and the possible consequences.
[0158] exist Figure 1 Based on the embodiment shown, Figure 5 As shown, step 102 includes:
[0159] Step 1021, obtaining M original log information from the parsing result of the log file; wherein M is an integer greater than or equal to N;
[0160] Step 1022, converting the M original log information into an array format to generate corresponding M converted log information;
[0161] Step 1023, from the M conversion log information, select N conversion log information whose first designated positions are all data used to characterize that the type of the current conversion log information is an SQL log type;
[0162] Step 1024, extracting SQL statements from the second designated positions of the N conversion log information respectively;
[0163] Step 1025: formatting the N SQL statements extracted from the N conversion log information respectively to generate corresponding N SQL statements after formatting.
[0164] In an embodiment of the present disclosure, the parsing result of the log file may include a large amount of log information, and these log information in the parsing result may be directly used as the M original log information in step 1021, or part of the log information may be filtered out from these log information in the parsing result, and the filtered log information may be used as the M original log information in step 1021.
[0165] Next, the M original log information can be converted into an array format to generate M conversion log information corresponding one to one to the M original log information; wherein the first designated position of any conversion log information can be data used to characterize the type of the conversion log information, and the second designated position of any conversion log information can be business data of that type.
[0166] Afterwards, for the M conversion log information, it can be determined which conversion log information has the first designated position as data for characterizing that the type of the current conversion log information is the SQL log type, and the determined conversion log information can be used as the N conversion log information screened in step 1023.
[0167] Since the types of the N conversion log information are all SQL log types, the business data at the second designated positions of the N conversion log information can specifically be SQL statements. Therefore, SQL statements can be extracted from the second designated positions of the N conversion log information, respectively. In this way, a total of N SQL statements can be extracted from the N conversion log information. Afterwards, the N SQL statements extracted from the N conversion log information can be formatted, respectively. The formatting includes but is not limited to removing blank characters, removing meaningless fields, etc., so that N SQL statements after formatting can be generated, and the generated N SQL statements can be used as the N SQL statements that need to be sorted and displayed later.
[0168] In a specific example, some original log information obtained from the parsing results of the log file is as follows: 2021-10-2923:41:27|db-listen|{"sql":"select*from`bank_signs`where(`business_code`='JY0371012110070069'and`is_valid`='1')limit1","bind_sql":"select*from`bank_signs`where(`business_code`=?and`is_valid`=?)limit 1","consume":0.6,"db_name":"test-user"}|{"memory_usage":"4MB","process_id":213114,"consume":0.03940296173095703,"server":"10.xx.21.xx"}. It is easy to see that the original log information includes time, database name, used memory, process identifier (Identify Document, ID), machine (Internet Protocol, IP) and other information.
[0169] In specific implementation, the original log information in the above paragraph can be split according to the separator "|" to convert the original log information into an array format, thereby generating corresponding conversion log information. Consistent with the original log information, the data at the second item of the conversion log information (which can be used as the first designated position) is "db-listen", which means that the type of the conversion log information is SQL type, not other business types. Then, the data at the third item of the conversion log information (which can be used as the second designated position) can be extracted. The extracted data is specifically a SQL statement in JSON format. By formatting the SQL statement in JSON format, a subsequent SQL statement for sorting and display can be generated. The generated SQL statement is specifically: select * from `bank_signs` where (`business_code` = 'JY0371012110070069' and `is_valid` = '1') limit 1; wherein, the full name of JSON is JavaScript Object Notation, JSON is a JS object, and is a lightweight data exchange format.
[0170] In the embodiment of the present disclosure, after obtaining the parsing result of the log file, by converting the original log information in the parsing result into an array format and filtering the converted log information whose type meets the requirements, N converted log information that can be used to extract SQL statements can be obtained. After that, through SQL statement extraction processing and formatting processing, N SQL statements for sorting and display can be generated conveniently and reliably. It can be seen that the embodiment of the present disclosure has an SQL screening function for the log of the test environment, and based on this screening function, SQL statements can be automatically generated.
[0171] exist Figure 1 Based on the embodiment shown, Figure 6 As shown, step 101 includes:
[0172] Step 1011, establishing a remote connection with the test environment;
[0173] Step 1012, determining the log path corresponding to the test environment;
[0174] Step 1013, read the log file corresponding to the test environment through the remote connection according to the log path.
[0175] In the embodiment of the present disclosure, a remote connection can be established with the test environment through Linux (which is a computer operating system) system command. In addition, the corresponding relationship between the test environment and the log path can also be pre-set, so that, according to the corresponding relationship, the log path corresponding to the test environment can be determined. Afterwards, the search for log files can be performed according to the log path through a remote connection, and the log files found can be used as the log files corresponding to the test environment. The log files corresponding to the test environment can be read later, and for the log files read, the above-mentioned steps 102 to 104 can be performed.
[0176] It can be seen that in the embodiments of the present disclosure, by establishing a remote connection and reading files according to the log path, the log files corresponding to the test environment can be obtained very conveniently and reliably.
[0177] In an optional example, before obtaining the log file corresponding to the test environment, the method further includes:
[0178] Obtain P pieces of environment information to be selected; where P is an integer greater than or equal to 2;
[0179] According to the information of the P candidate environments, a candidate environment list including the corresponding P candidate environments is displayed;
[0180] Receive a user's selection operation on a target candidate environment; wherein the target candidate environment is any candidate environment among P candidate environments;
[0181] Use the target candidate environment as the test environment.
[0182] Here, P can be 2, 3, 4, 5 or an integer greater than 5, which will not be listed here one by one.
[0183] Here, the environment information to be selected includes but is not limited to the master database domain, slave database domain, port, user name, password, etc.
[0184] It should be noted that P pieces of information on selected environments can be added to the database, so that the information in the database can be read later to obtain the P pieces of information on selected environments, so as to display a list of selected environments including the corresponding P selected environments; wherein the P selected environments and the P pieces of information on selected environments can have a one-to-one correspondence.
[0185] Next, a selection operation of a user (e.g., an analyst) on a target environment in the list of environments to be selected may be received, the selection operation including but not limited to a touch input operation (e.g., a click operation, a press operation, etc.), a voice input operation, a keyboard input operation, etc. In response to the user's selection operation, the target environment may be directly used as a test environment, and a quality check of SQL statements may be further performed on the test environment.
[0186] It can be seen that in the embodiments of the present disclosure, by obtaining the candidate environment information and displaying the candidate environment list, the user can conveniently and reliably select the test environment that needs to perform the SQL statement quality inspection according to the actual situation.
[0187] In an optional example, before the business system goes online, multiple candidate environments can be constructed first, and various information of the candidate environments (equivalent to the candidate environment information mentioned above) can be added to the database in batches by adding an environment interface.
[0188] When a user (e.g., analyst) enters the SQL evaluation system, the candidate environment information can be automatically read from the database, and a list of multiple candidate environments (equivalent to the candidate environment list mentioned above) can be displayed to the analyst. For details, see Figure 7 , Figure 7 "test4-nts.lianjia.com(nts)" to "test11-nts.lianjia.com(nts)" can be used as 7 candidate environments.
[0189] According to actual needs, analysts Figure 7After selecting a candidate environment from the 7 candidate environments, the candidate environment can be used as the test environment. Next, SQL statements can be automatically read from the test environment. Specifically, you can first use the Linux system command to remotely connect to the test environment, then read the log file according to the log path, and then parse the log file and filter out all SQL statements according to the SQL matching rules (for specific filtering methods, refer to Figure 5 The method of generating N formatted SQL statements in the embodiment shown).
[0190] Next, you can call Figure 8 The evaluation interface of Security Orchestration Automation and Response (SOAR) in the REST API evaluates all the filtered SQL statements to obtain the quality evaluation values corresponding to each of the filtered SQL statements (for specific evaluation methods, refer to Figure 3 (See the relevant description in the illustrated embodiment). Optionally, when evaluating any SQL statement, points may be deducted from the full score of 100 until the score reaches 0, wherein no points are deducted for severity level L0, 5 points are deducted for severity level L1, 10 points are deducted for severity level L2, and so on.
[0191] Afterwards, you can Figure 8 The vue-markdown component located at the front end is used for processing, so as to subsequently generate and output a page in the Hypertext Markup Language (html) format. The page can sort and display all the filtered SQL statements in descending order of the corresponding quality assessment values; vue is a progressive framework for building user interfaces, and markdown is a markup language that can be written using an ordinary text editor.
[0192] Optionally, the sorting effect of the html format page can be as follows Fig. 9 It should be noted that Fig. 9 As shown, a "View SQL Details" can be displayed on the right side of each SQL statement. Each "View SQL Details" can be used as a control corresponding to the current SQL statement. If the analyst clicks on a control, the explanation data of the SQL statement corresponding to the control can be displayed.
[0193] Assume that the SQL statement corresponding to the control clicked by the analyst is select roles.*from apps leftjoin roles on roles.app_id=apps.app_id, then the explanation data can be found in Fig.10 , Fig.10 The "Select* type query" at the bottom is a preset query type. Fig.10 The "L1" at the bottom is the severity level corresponding to the preset query type. Fig.10 The following information at the bottom, "When the table structure changes, using the * wildcard to select all columns will cause the meaning and behavior of the query to change, and may cause the query to return more data" is the query risk prediction information corresponding to this preset query type.
[0194] In summary, the embodiments of the present disclosure can automatically generate SQL statements from a large-scale test environment, automatically evaluate the quality of SQL statements, and sort and display SQL statements based on the evaluation results. Analysts can perform special analysis and optimization based on this, which is conducive to reducing the number of slow SQL statements online and making the quality of query SQL quantifiable.
[0195] Any SQL statement display method provided in the embodiments of the present disclosure may be executed by any appropriate device with data processing capabilities, including but not limited to: a terminal device and a server, etc. Alternatively, any SQL statement display method provided in the embodiments of the present disclosure may be executed by a processor, such as the processor executing any SQL statement display method mentioned in the embodiments of the present disclosure by calling corresponding instructions stored in a memory. This will not be described in detail below.
[0196] Exemplary Devices
[0197] Fig.11 is a structural diagram of a SQL statement display device provided by an exemplary embodiment of the present disclosure, Fig.11 The device shown includes a first acquisition module 1101 , a generation module 1102 , a first determination module 1103 and a first display module 1104 .
[0198] The first acquisition module 1101 is used to acquire the log file corresponding to the test environment;
[0199] A generating module 1102 is used to generate N SQL statements according to the parsing result of the log file; wherein N is an integer greater than or equal to 2;
[0200] A first determination module 1103 is used to determine N quality evaluation values corresponding to N SQL statements;
[0201] The first display module 1104 is used to sort and display N SQL statements according to N quality evaluation values.
[0202] In an optional example, the generating module 1102 includes:
[0203] The acquisition submodule is used to obtain M original log information from the parsing result of the log file; where M is an integer greater than or equal to N;
[0204] The conversion submodule is used to convert the M original log information into an array format to generate corresponding M conversion log information;
[0205] A screening submodule, used for screening, from the M conversion log information, N conversion log information whose respective first designated positions are all data used to characterize that the type of the current conversion log information is an SQL log type;
[0206] An extraction submodule, used for extracting SQL statements from respective second designated positions of the N conversion log information;
[0207] The first processing submodule is used to format the N SQL statements extracted from the N conversion log information respectively to generate corresponding N SQL statements after the formatting process.
[0208] In an optional example, the first acquisition module 1101 includes:
[0209] Create a submodule to establish a remote connection with the test environment;
[0210] The first determination submodule is used to determine the log path corresponding to the test environment;
[0211] The reading submodule is used to read the log file corresponding to the test environment through a remote connection and according to the log path.
[0212] In an optional example, the device further includes:
[0213] The second acquisition module is used to obtain P pieces of information of candidate environments before obtaining the log file corresponding to the test environment; wherein P is an integer greater than or equal to 2;
[0214] A second display module is used to display a list of candidate environments including the corresponding P candidate environments according to the information of the P candidate environments;
[0215] A receiving module, used to receive a user's selection operation on a target environment to be selected; wherein the target environment to be selected is any one of the P environments to be selected;
[0216] The second determination module is used to use the target candidate environment as the test environment.
[0217] In an optional example, the first determining module 1103 includes:
[0218] The second processing submodule is used to perform syntax analysis on the target SQL statement and process the target SQL statement into an abstract syntax tree; wherein the target SQL statement is any SQL statement among the N SQL statements;
[0219] The second determination submodule is used to determine K query situation data corresponding to K preset query types according to the abstract syntax tree; wherein K is an integer greater than or equal to 2, and the query situation data corresponding to any preset query type is used to characterize whether there is a query of the preset query type in the target SQL statement;
[0220] A third determination submodule is used to determine K deduction points corresponding to K preset query types according to K query situation data;
[0221] A calculation submodule, used to calculate the sum of K deduction points;
[0222] The fourth determination submodule is used to determine the quality assessment value corresponding to the target SQL statement according to the difference between the first preset value and the sum.
[0223] In an optional example, the third determining submodule includes:
[0224] A first determination unit is configured to determine zero as a deduction value corresponding to the target preset query type when the query situation data corresponding to the target preset query type is used to characterize that there is no query of the target preset query type in the target SQL statement; otherwise, determine a severity level corresponding to the target preset query type; wherein the target preset query type is any preset query type among the K preset query types;
[0225] A second determining unit, configured to determine zero as the deduction value corresponding to the target preset query type when the severity level corresponding to the target preset query type is the preset severity level;
[0226] The third determining unit is used to determine the deduction value corresponding to the target preset query type according to the level value of the severity level corresponding to the target preset query type and the second preset value when the severity level corresponding to the target preset query type is higher than the preset severity level.
[0227] In an optional example, the third determining unit is specifically configured to:
[0228] The product of the severity level value corresponding to the target preset query type and the second preset value is used as the deduction value corresponding to the target preset query type.
[0229] In an optional example, the device further includes:
[0230] A screening module is used to screen R preset query types that meet preset conditions from K preset query types; wherein R is an integer greater than or equal to 1, and any preset query type meets the preset condition means that the query situation data corresponding to the preset query type is used to characterize the query of the preset query type in the target SQL statement;
[0231] The third display module is used to display N controls corresponding to the N SQL statements displayed in order;
[0232] A third determination module is used to determine R severity levels corresponding to the R preset query types and determine R query risk prediction information corresponding to the R preset query types when receiving an input operation on the control corresponding to the target SQL statement;
[0233] The fourth display module is used to display the explanatory data of the quality assessment value corresponding to the target SQL statement; wherein the explanatory data includes: R preset query types, R severity levels corresponding to the R preset query types, and R query risk prediction information corresponding to the R preset query types.
[0234] Exemplary Electronic Devices
[0235] Below, reference Fig.12 The electronic device according to the embodiment of the present disclosure is described. The electronic device may be any one or both of the first device and the second device, or a stand-alone device independent of them, and the stand-alone device may communicate with the first device and the second device to receive the collected input signals from them.
[0236] Fig.12 A block diagram of an electronic device 1200 according to an embodiment of the present disclosure is illustrated.
[0237] like Fig.12 As shown, the electronic device 1200 includes one or more processors 1201 and a memory 1202 .
[0238] The processor 1201 may be a central processing unit (CPU) or other forms of processing units having data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device 1200 to perform desired functions.
[0239] The memory 1202 may store one or more computer program products, and the memory 1202 may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, a random access memory (RAM) and / or a cache memory (cache), etc. The non-volatile memory may include, for example, a read-only memory (ROM), a hard disk, a flash memory, etc. One or more computer program products may be stored on the computer-readable storage medium, and the processor 1201 may run the computer program products to implement the SQL statement display method of each embodiment of the present disclosure described above and / or other desired functions.
[0240] In one example, the electronic device 1200 may further include: an input device 1203 and an output device 1204 , and these components are interconnected via a bus system and / or other forms of connection mechanisms (not shown).
[0241] For example, when the electronic device 1200 is the first device or the second device, the input device 1203 may be a microphone or a microphone array. When the electronic device 1200 is a stand-alone device, the input device 1203 may be a communication network connector for receiving collected input signals from the first device and the second device.
[0242] In addition, the input device 1203 may also include, for example, a keyboard, a mouse, and the like.
[0243] The output device 1204 can output various information to the outside, and can include, for example, a display, a speaker, a printer, a communication network and a remote output device connected thereto.
[0244] Of course, to simplify, Fig.12 Only some of the components related to the present disclosure in the electronic device 1200 are shown, and components such as a bus, an input / output interface, etc. are omitted. In addition, according to specific application situations, the electronic device 1200 may also include any other appropriate components.
[0245] Exemplary computer program products and computer-readable storage media
[0246] In addition to the above-mentioned methods and devices, an embodiment of the present disclosure may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps of the SQL statement display method according to various embodiments of the present disclosure described in the above-mentioned "Exemplary Method" section of this specification.
[0247] The computer program product may be written in any combination of one or more programming languages to write program code for performing the operations of the disclosed embodiments, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0248] The embodiments of the present disclosure may also be a computer-readable storage medium having computer program instructions stored thereon, which, when executed by a processor, enable the processor to execute the steps of the SQL statement display method according to various embodiments of the present disclosure described in the above “Exemplary Method” section of this specification.
[0249] The computer readable storage medium can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can include, for example, but is not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0250] The basic principles of the present disclosure are described above in conjunction with specific embodiments. It should be noted that the advantages, strengths, effects, etc. mentioned in the present disclosure are only examples and not limitations, and it cannot be considered that these advantages, strengths, effects, etc. must be possessed by each embodiment of the present disclosure. The specific details disclosed above are only for the purpose of illustration and ease of understanding, not limitation, and the above details do not limit the present disclosure to being implemented by adopting the above specific details.
[0251] Each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. Since the system embodiment basically corresponds to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the method embodiment.
[0252] The block diagrams of the devices, apparatuses, equipment, and systems involved in the present disclosure are intended only as illustrative examples and are not intended to require or imply that they must be connected, arranged, or configured in the manner shown in the block diagrams. These devices, apparatuses, equipment, and systems may be connected, arranged, or configured in any manner. Words such as "include," "comprise," "have," and the like are open words, meaning "including but not limited to," and may be used interchangeably therewith. The words "or" and "and" used herein refer to the words "and / or," and may be used interchangeably therewith, unless the context clearly indicates otherwise. The word "such as" used herein refers to the phrase "such as but not limited to," and may be used interchangeably therewith.
[0253] The method and apparatus of the present disclosure may be implemented in many ways. For example, the method and apparatus of the present disclosure may be implemented by software, hardware, firmware, or any combination of software, hardware, and firmware. The above order of steps for the method is for illustration only, and the steps of the method of the present disclosure are not limited to the order specifically described above, unless otherwise specifically stated. In addition, in some embodiments, the present disclosure may also be implemented as a program recorded in a recording medium, which includes machine-readable instructions for implementing the method according to the present disclosure. Therefore, the present disclosure also covers a recording medium storing a program for executing the method according to the present disclosure.
[0254] It should also be noted that in the apparatus, device and method of the present disclosure, each component or each step can be decomposed and / or recombined. Such decomposition and / or recombination should be regarded as equivalent solutions of the present disclosure.
[0255] The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use the present disclosure. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other aspects without departing from the scope of the present disclosure. Therefore, the present disclosure is not intended to be limited to the aspects shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
[0256] The above description has been given for the purpose of illustration and description. In addition, this description is not intended to limit the embodiments of the present disclosure to the forms disclosed herein. Although multiple example aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, changes, additions and sub-combinations thereof.
Claims
1. A structured query language SQL statement display method, characterized in that: include: Get the log file corresponding to the test environment; Generate N SQL statements according to the parsing result of the log file; where N is an integer greater than or equal to 2; Determine N quality assessment values corresponding to the N SQL statements; According to the N quality evaluation values, the N SQL statements are sorted and displayed; The determining of N quality evaluation values corresponding to the N SQL statements includes: Performing syntax analysis on a target SQL statement, and processing the target SQL statement into an abstract syntax tree; wherein the target SQL statement is any one of the N SQL statements; According to the abstract syntax tree, K query situation data corresponding to K preset query types are determined; wherein K is an integer greater than or equal to 2, and the query situation data corresponding to any preset query type is used to characterize whether there is a query of the preset query type in the target SQL statement; Determine K deduction points corresponding to the K preset query types according to the K query situation data; Calculate the sum of the K deduction points; Determine a quality assessment value corresponding to the target SQL statement according to a difference between the first preset value and the sum; The method further comprises: From the K preset query types, R preset query types that meet the preset condition are screened; wherein R is an integer greater than or equal to 1, and any preset query type that meets the preset condition means that the query situation data corresponding to the preset query type is used to characterize the query of the preset query type in the target SQL statement; Corresponding to the N SQL statements displayed in order, N controls are displayed; In case of receiving an input operation on a control corresponding to the target SQL statement, determining R severity levels corresponding to the R preset query types, and determining R query risk prediction information corresponding to the R preset query types; Displaying explanatory data of the quality assessment value corresponding to the target SQL statement; wherein the explanatory data includes: the R preset query types, the R severity levels corresponding to the R preset query types, and the R query risk prediction information corresponding to the R preset query types.
2. The method according to claim 1, characterized in that: The step of generating N SQL statements according to the parsing result of the log file includes: Obtaining M original log information from the parsing result of the log file; wherein M is an integer greater than or equal to N; Convert the M original log information into array format to generate corresponding M converted log information; From the M conversion log information, select N conversion log information whose first designated positions are all data used to characterize that the type of the current conversion log information is an SQL log type; Extracting SQL statements from respective second designated locations of the N conversion log information; The N SQL statements extracted from the N conversion log information are formatted respectively to generate corresponding N SQL statements after the formatting process.
3. The method according to claim 1, characterized in that The obtaining of the log file corresponding to the test environment includes: Establish a remote connection to the test environment; Determine the log path corresponding to the test environment; The log file corresponding to the test environment is read through the remote connection according to the log path.
4. The method according to claim 1, characterized in that: Before obtaining the log file corresponding to the test environment, the method further includes: Obtain P pieces of environment information to be selected; where P is an integer greater than or equal to 2; According to the P candidate environment information, display a candidate environment list including the corresponding P candidate environments; Receiving a user's selection operation on a target environment to be selected; wherein the target environment to be selected is any one of the P environments to be selected; The target candidate environment is used as the test environment.
5. The method according to claim 1, characterized in that Determining, according to the K query situation data, K deduction values corresponding to the K preset query types includes: In the case where the query situation data corresponding to the target preset query type is used to characterize that there is no query of the target preset query type in the target SQL statement, zero is determined as the deduction value corresponding to the target preset query type; otherwise, the severity level corresponding to the target preset query type is determined; wherein the target preset query type is any preset query type among the K preset query types; When the severity level corresponding to the target preset query type is the preset severity level, zero is determined as the deduction value corresponding to the target preset query type; When the severity level corresponding to the target preset query type is higher than the preset severity level, the deduction value corresponding to the target preset query type is determined according to the severity level value corresponding to the target preset query type and a second preset value.
6. The method according to claim 5, characterized in that The step of determining the deduction value corresponding to the target preset query type according to the severity level value corresponding to the target preset query type and a second preset value includes: The product of the severity level value corresponding to the target preset query type and the second preset value is used as the deduction value corresponding to the target preset query type.
7. An electronic device, characterized in that: include: a memory for storing computer program instructions; A processor, configured to execute computer program instructions stored in the memory, and when the computer program instructions are executed, implement the method according to any one of claims 1 to 6.
8. A computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the computer program instructions are executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
SQL analysis method and SQL analyzer
CN110019291A
Data query performance test method and device based on MySQL database
CN112765017A