SQL statement performance testing method, device, computer equipment and storage medium

By obtaining and replacing online parameters in SQL statement performance testing, the accuracy of test results is improved, the problems of high time cost and technical difficulty in the testing phase of existing tools are solved, and the significance of index selection is enhanced.

CN112597004BActive Publication Date: 2024-10-15GUANGZHOU PINWEI SOFTWARE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202011462193.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-11
Publication Date
2024-10-15
Estimated Expiration
2040-12-11

AI Technical Summary

Technical Problem

Existing SQL statement performance testing tools have high time costs and technical difficulties in the testing phase, and ignore the impact of online data distribution on index selection, resulting in reduced accuracy of performance test results.

Method used

By obtaining the parameters to be replaced in the SQL statement to be analyzed, obtaining the corresponding online parameters, replacing the parameters to be replaced in the SQL statement, and introducing the online parameters in the test to perform performance test analysis, thereby improving the accuracy of the test results. .

Benefits of technology

It improves the accuracy of SQL statement performance test results, solves the problems of high time cost and technical difficulty in the testing phase of existing tools, and enhances the significance of index selection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112597004B_ABST
    Figure CN112597004B_ABST
Patent Text Reader

Abstract

The present application relates to a SQL statement performance test method, device, computer equipment and storage medium, the method comprising: obtaining a SQL statement to be analyzed, identifying a parameter to be replaced from the SQL statement to be analyzed; obtaining an online parameter corresponding to the parameter to be replaced; replacing the parameter to be replaced in the SQL statement to be analyzed with the online parameter to obtain the replaced SQL statement; and performing performance test analysis on the replaced SQL statement. The above method can improve the accuracy of the SQL statement performance test results.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of information testing technology, and in particular to a SQL statement performance testing method, device, computer equipment and storage medium. Background Art

[0002] At present, there are major pain points such as high time cost and high technical difficulty when executing performance tests of SQL (Structured Query Language) statements during the testing phase. For example, in the performance test of SQL statements, some existing open source tools are used to perform retrieval analysis of performance tests, such as existing open source tools SOAR, SQLAdvisor, etc. These open source tools are all based on the RBO (Rule-based Heuristic Optimizer) algorithm to analyze the index scheme of SQL statements. The analysis results ignore the impact of online data distribution on the index selection of SQL statements, thereby reducing the accuracy of the performance test result data of SQL statements. Summary of the invention

[0003] Based on this, it is necessary to provide a SQL statement performance testing method, apparatus, computer equipment and storage medium that can improve the accuracy of SQL statement performance testing results in response to the above technical problems.

[0004] A SQL statement performance test method, the method comprising: obtaining a SQL statement to be analyzed, identifying a parameter to be replaced from the SQL statement to be analyzed; obtaining an online parameter corresponding to the parameter to be replaced; replacing the parameter to be replaced in the SQL statement to be analyzed with the online parameter to obtain a replaced SQL statement; and performing performance test analysis on the replaced SQL statement.

[0005] In one of the embodiments, a SQL statement performance testing method further includes: injecting interception code into the process of the tested application, and obtaining SQL statements triggered by the tested application during program execution through the interception code; obtaining SQL statements to be analyzed, including: obtaining the SQL statements to be analyzed from the triggered SQL statements.

[0006] Preferably, a SQL statement performance testing method further includes: monitoring at a preset frequency whether the process of the tested application among the multiple applications recorded in the configuration table has been injected with interception code, and if not, executing the step of injecting interception code into the process of the tested application.

[0007] In one of the embodiments, after obtaining the SQL statement triggered by the tested application during the program running process through interception code, it also includes: obtaining identification information of the triggered SQL statement, and when it is identified according to the identification information that the triggered SQL statement has not executed the performance test, executing the step of obtaining the SQL statement to be analyzed from the triggered SQL statement.

[0008] In one of the embodiments, the identification information includes a hash code of the triggered SQL statement, and obtaining the identification information of the triggered SQL statement includes: obtaining the hash code of the triggered SQL statement; identifying that the triggered SQL statement has not been subjected to performance testing based on the identification information, including: matching the hash code of the triggered SQL statement with each hash code in the storage area, and if the match fails, identifying that the triggered SQL statement has not been subjected to performance testing; wherein each hash code in the storage area is a hash code of an SQL statement that has been subjected to performance testing.

[0009] Preferably, obtaining the hash code of the triggered SQL statement includes: parsing the triggered SQL statement to obtain a first immutable character in the triggered SQL statement, where the first immutable character is a character that is not used for parameter replacement in the triggered SQL statement; calculating the hash code of the first immutable character, and using the hash code of the first immutable character as the hash code of the triggered SQL statement; wherein each hash code in the storage area is a hash code of a second immutable character in the SQL statement on which the performance test has been executed, where the second immutable character is a character that is not used for parameter replacement in the SQL statement on which the performance test has been executed.

[0010] In one of the embodiments, if the match fails, it is identified that the triggered SQL statement has not executed the performance test, including: if the match fails, obtaining the ignore rule configuration information of the SQL statement performance test, the ignore rule configuration information is used to indicate that the SQL statement that meets the preset ignore rule is not used to execute the performance test; when the triggered SQL statement does not meet the preset ignore rule in the ignore rule configuration information, it is identified that the triggered SQL statement has not executed the performance test.

[0011] In one embodiment, identifying the parameter to be replaced from the SQL statement to be analyzed includes: obtaining a preset character, and when the preset character is identified from the SQL statement to be analyzed, using the preset character in the SQL statement to be analyzed as the parameter to be replaced.

[0012] In one of the embodiments, obtaining online parameters corresponding to the parameters to be replaced includes: obtaining data table information in the SQL statement to be analyzed, the data table information is used to indicate the data table in the database used to query the SQL statement to be analyzed; collecting the field value of the SQL statement from the online database according to the data table information; obtaining the expression of the SQL statement to be analyzed, and obtaining the online parameters from the field value of the SQL statement according to the expression.

[0013] Preferably, a SQL statement performance testing method also includes: if the expression of the SQL statement to be analyzed cannot be obtained, or the online parameters cannot be obtained from the field values ​​of the SQL statement according to the expression, obtaining the test parameters in the test environment of the SQL statement to be analyzed to replace the parameters to be replaced, and using the test parameters as online parameters.

[0014] In one of the embodiments, a performance test analysis is performed on the replaced SQL statement, including: obtaining query conditions in the replaced SQL statement; creating multiple index methods according to the query conditions; performing index performance test on the replaced SQL statement under each index method to obtain the index method with the least index execution time; if there is only one index method with the least index execution time, the index method with the least index execution time is used as the index method for the replaced SQL statement; if there are multiple index methods with the least index execution time, the multiple index methods with the least index execution time are screened according to the RBO algorithm to screen out the index method for the replaced SQL statement.

[0015] A SQL statement performance testing device comprises: a first acquisition module, used for acquiring a SQL statement to be analyzed and identifying a parameter to be replaced from the SQL statement to be analyzed; a second acquisition module, used for acquiring an online parameter corresponding to the parameter to be replaced; a replacement module, used for replacing the parameter to be replaced in the SQL statement to be analyzed with the online parameter to obtain the replaced SQL statement; and a test module, used for performing performance test analysis on the replaced SQL statement.

[0016] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of any of the above-mentioned embodiments are implemented.

[0017] A computer-readable storage medium stores a computer program, which implements the steps of any of the above-mentioned method embodiments when the computer program is executed by a processor.

[0018] In the above-mentioned SQL statement performance test method, apparatus, computer equipment and storage medium, the test system obtains the SQL statement to be analyzed, identifies the parameters to be replaced from the SQL statement to be analyzed, and then obtains the online parameters corresponding to the parameters to be replaced, replaces the parameters to be replaced in the SQL statement to be analyzed with the online parameters, obtains the replaced SQL statement, and performs performance test analysis on the replaced SQL statement. Therefore, when performing the SQL statement performance test, the test system can introduce the online parameters, replace the parameters to be replaced in the SQL statement with the online parameters, and then perform the performance analysis of the SQL statement, thereby obtaining the performance analysis results based on the online data, and improving the accuracy of the performance test result data of the SQL statement. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] Figure 1 An application environment diagram of a SQL statement performance testing method in an embodiment;

[0020] Figure 2 A flowchart of a SQL statement performance testing method in one embodiment;

[0021] Figure 3 A schematic diagram of a flow chart of a deduplication operation of a triggered SQL statement executed by a test system in one embodiment;

[0022] Figure 4 A schematic diagram of a flow chart of a test system executing parameter replacement of an SQL statement to be analyzed in an embodiment;

[0023] Figure 5 A schematic diagram of a flow chart of an index performance test of a replaced SQL statement executed by a test system in an embodiment;

[0024] Figure 6 A schematic diagram of the system architecture of a test system in one embodiment;

[0025] Figure 7 A flowchart of the business timing logic of a SQL statement performance testing method in one embodiment;

[0026] Figure 8 A structural block diagram of a SQL statement performance testing device in one embodiment;

[0027] Fig. 9 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0028] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0029] This application provides a SQL statement performance testing method, which is applied to Figure 1 In the application environment shown. Figure 1 As shown, the test system 10 is used to execute a SQL statement performance test method of the present application. The SQL management platform 104 is used to collect and manage SQL statements. Among them, the server in the SQL management platform 104 is used to collect SQL statements in the tested application and store them in the database. The test platform 102 requests the SQL statement to be analyzed from the SQL management platform 104, and identifies the parameters to be replaced from the SQL statement to be analyzed. Then, parameter sampling is performed from the online data platform to obtain the online parameters corresponding to the parameters to be replaced. Finally, the test platform 102 replaces the parameters to be replaced in the SQL statement to be analyzed with the online parameters, obtains the replaced SQL statement, and performs performance test analysis on the replaced SQL statement. Therefore, when performing SQL statement performance testing, the test system 10 can introduce online parameters, replace the parameters to be replaced in the SQL statement with the online parameters, and then perform performance analysis of the SQL statement, thereby obtaining performance analysis results based on online data, and improving the accuracy of the performance test result data of the SQL statement.

[0030] In one embodiment, Figure 2 As shown, a SQL statement performance testing method is provided, which is applied to Figure 1 The test system 10 in the example is used as an example to illustrate, and includes the following steps:

[0031] S102, obtaining a SQL statement to be analyzed, and identifying parameters to be replaced from the SQL statement to be analyzed.

[0032] In this embodiment, the server of the test platform 102 obtains the SQL statement to be analyzed from the database. Specifically, it can be to set a scheduled task, and obtain one or more SQL statements to be analyzed from the database at a specified time by starting the scheduled task. Among them, the SQL statements to be analyzed stored in the database are obtained by intercepting from the process of the application under test. For example, an agent program containing an interception code is set, and the agent program is injected into the application under test. The SQL statements triggered by the running process of the application under test are intercepted by the agent program, and the intercepted SQL statements are stored in the database. The server obtains the SQL statements to be analyzed from the SQL statements stored in the database.

[0033] The SQL statement to be analyzed contains parameters to be replaced. Generally, the parameters to be replaced are characters in the SQL statement that can be changed according to the index requirements. For example, when the SQL statement is a query statement, the characters corresponding to the order number id in the SQL statement are the parameters to be replaced. For example, in id>? ? in the select statement, "??" is the parameter to be replaced. Here, id>? ? means that the order number id is "??". The queried order number can be modified according to the index requirements, and in this case, "??" can be used as a replaceable parameter to be replaced.

[0034] The server identifies the parameters to be replaced from the SQL statement to be analyzed. Specifically, the server parses the SQL statement to be analyzed according to the grammatical structure of the SQL statement to obtain multiple characters, and further performs character recognition on each character to identify the characters that can be replaced in the SQL statement to be analyzed, and uses the replaceable characters as the parameters to be replaced. The recognition method is: identify whether each character is a character that cannot be replaced in the SQL statement, such as select, from, create, databases and other characters. If so, it is determined that the character does not belong to the character to be replaced, otherwise it is determined that the character is a character to be replaced.

[0035] S104: Obtain online parameters corresponding to the parameters to be replaced.

[0036] In this embodiment, after the server determines the parameter to be replaced in the SQL statement to be analyzed, it obtains the online parameter corresponding to the parameter to be replaced. It can be that the server identifies the type of the parameter to be replaced, and calls the online parameter sampling module to collect the online parameter of the parameter to be replaced from the online data platform. It can also be that the server obtains the library name characters and table name characters in the SQL statement to be analyzed, queries the online SQL statement according to the library name characters and the table name characters, and then obtains the online parameter corresponding to the parameter to be replaced in the online SQL statement. For example, based on id>? ? in the above expression, "?" is the parameter to be replaced, and the type of the parameter to be replaced is the order number. Call the online parameter sampling module to collect the online order number from the online data platform as the online parameter as parameter replacement.

[0037] S106, replacing the parameters to be replaced in the SQL statement to be analyzed with the online parameters to obtain a replaced SQL statement.

[0038] In this embodiment, the server modifies the parameter to be replaced in the SQL statement to be analyzed into an online parameter to obtain a replaced SQL statement. For example, the parameter to be replaced, which is the order number queried in the SQL statement to be analyzed, is modified into the online parameter of the order number queried in the online SQL statement. Or, the parameter to be replaced, which is the data object to be modified in the SQL statement to be analyzed, is modified into the online parameter of the data object to be modified in the online SQL statement.

[0039] S108, performing performance test analysis on the replaced SQL statement.

[0040] In this embodiment, the server performs a performance test analysis on the replaced SQL statement. This may be: obtaining the index mode of the replaced SQL statement, and performing an index performance test analysis on the replaced SQL statement based on the index mode. For example, the performance test analysis of the replaced SQL statement is: executing the replaced SQL statement according to the index mode, calculating the time consumed when the replaced SQL statement is executed, and judging the index performance of the replaced SQL statement based on the consumed time.

[0041] In the above-mentioned SQL statement performance test method, the server of the test system obtains the SQL statement to be analyzed, identifies the parameters to be replaced from the SQL statement to be analyzed, and then obtains the online parameters corresponding to the parameters to be replaced, replaces the parameters to be replaced in the SQL statement to be analyzed with the online parameters, obtains the replaced SQL statement, and performs performance test analysis on the replaced SQL statement. Therefore, when performing the SQL statement performance test, the test system can introduce online parameters, replace the parameters to be replaced in the SQL statement with the online parameters, and then perform the performance analysis of the SQL statement, thereby obtaining the performance analysis results based on the online data, and improving the accuracy of the performance test result data of the SQL statement.

[0042] In one embodiment, before S102, it also includes: injecting interception code into the process of the application under test, and obtaining SQL statements triggered by the application under test during the program running process through the interception code. S102 includes: obtaining the SQL statement to be analyzed from the triggered SQL statement. Preferably, before injecting the interception code into the process of the application under test, it also includes: monitoring whether the process of the application under test among the multiple applications recorded in the configuration table is injected with the interception code according to a preset frequency, and if not, executing the step of injecting the interception code into the process of the application under test.

[0043] In this embodiment, a configuration table is set in the test system. One or more tested applications are recorded in the configuration table. The SQL management platform 104 is a WEB application developed based on the Spring Boot framework, and the SQL management platform 104 is used to collect SQL statements triggered by the tested application. The SQL management platform 104 includes an environment monitoring module. The environment monitoring module monitors whether the tested application in the configuration table has an agent program containing interception code injected into the SQL statement collection at a preset frequency, such as once a minute, and injects it if not. Among them, the interception code is injected into the process of the tested application, specifically: an agent program Agent for SQL statement collection is set, and the agent program Agent encapsulates the interception code of different data persistence layer frameworks. After the agent program Agent is injected into the target process of the tested application, the SQL statement triggered during the running process of the tested application is intercepted in real time, and is transmitted to the test analysis module of the test platform 102 through the API interface of the SQL management platform 104, so as to perform performance analysis of the SQL statement through the test analysis module. Therefore, real-time online collection of SQL statements to be analyzed is realized.

[0044] In one embodiment, after obtaining the SQL statement triggered by the tested application during the program running process through interception code, it also includes: obtaining identification information of the triggered SQL statement, and when it is identified according to the identification information that the triggered SQL statement has not executed the performance test, executing the step of obtaining the SQL statement to be analyzed from the triggered SQL statement.

[0045] In this embodiment, after intercepting the SQL statements triggered by the tested application during the program running process, it is necessary to perform deduplication operations on the triggered SQL statements. The SQL management platform 104 includes a SQL collection and deduplication module, which receives the triggered SQL statements transmitted by the API interface of the SQL management platform 104, and determines whether the triggered SQL statements have been used for performance testing based on the identification information of the triggered SQL statements. If so, the triggered SQL statements are discarded. If not, a performance test is performed on them. For example, after obtaining the triggered SQL statements in the tested application process by injecting interception code, if the triggered SQL statements have not been used for performance testing, the triggered SQL statements are stored in a storage area. The storage area can be a Redis database. When performing performance testing, the triggered SQL statements are obtained from the storage area to perform performance testing. Deduplication processing can eliminate SQL statements that have been analyzed historically and avoid repeated analysis of SQL statements.

[0046] In one implementation, the identification information includes a hash code of the triggered SQL statement, and obtaining the identification information of the triggered SQL statement includes: obtaining the hash code of the triggered SQL statement. According to the identification information, identifying that the triggered SQL statement has not been subjected to a performance test includes: matching the hash code of the triggered SQL statement with each hash code in the storage area, and if the match fails, identifying that the triggered SQL statement has not been subjected to a performance test; wherein each hash code in the storage area is a hash code of an SQL statement that has been subjected to a performance test.

[0047] In this embodiment, the storage area may be a Redis database. The test system 10 stores the acquired triggered SQL statements in the storage area, and acquires SQL statements that have not been subjected to performance testing from the triggered SQL statements in the storage area to perform performance testing. When the triggered SQL statements in the storage area have been subjected to performance testing, the triggered SQL statements that have been subjected to performance testing are marked. Among them, the hash code of the triggered SQL statement may be used for marking. The hash code here refers to the hash code associated with the triggered SQL statement, which may be calculated from all or part of the characters in the triggered SQL statement. When a new triggered SQL statement is collected, the hash code of the new triggered SQL statement is matched with the hash code of each triggered SQL statement in the storage area to identify the SQL statement that has not been triggered by the performance test. When the storage area is a Redis database, the hash code of the triggered SQL statement can be used as the key in the key-value pair of the Redis database to cache the triggered SQL statement. Therefore, when a new triggered SQL statement is collected, it can be identified by matching the hash code of the new triggered SQL statement with the keys in each key-value pair in the Redis database, thereby improving the matching and identification processing efficiency of the test system 10.

[0048] Preferably, obtaining the hash code of the triggered SQL statement includes: parsing the triggered SQL statement to obtain a first immutable character in the triggered SQL statement, where the first immutable character is a character that is not used for parameter replacement in the triggered SQL statement; calculating the hash code of the first immutable character, and using the hash code of the first immutable character as the hash code of the triggered SQL statement; wherein each hash code in the storage area is a hash code of a second immutable character in the SQL statement on which the performance test has been executed, where the second immutable character is a character that is not used for parameter replacement in the SQL statement on which the performance test has been executed.

[0049] In this embodiment, the hash code of the triggered SQL statement and each hash code in the storage area are determined according to the hash code of the immutable character in the corresponding SQL statement. Among them, the SQL statement contains variable characters and immutable characters. The basis for the division of variable characters and immutable characters is: immutable characters are characters that are not used for parameter replacement in the SQL statement, and variable characters are characters that can be used for parameter replacement in the SQL statement. Among them, whether the characters in the SQL statement are used for parameter replacement is determined by a pre-set rule. For example, the "?" character in the SQL statement is set to be used as parameter replacement, and other characters are not used for parameter replacement. For example, the SQL statement is a query statement: SELECT*FROM the table name of the query WHERE key name = 'key value', according to the sentence structure of the SQL statement and the index function of the SQL statement, the SELECT characters, FROM characters and WHERE characters, as well as the characters corresponding to the table name of the query and the characters corresponding to the key name are extracted as immutable characters, and the characters corresponding to the 'key value' are variable characters.

[0050] The first immutable character in the triggered SQL statement and the second immutable character in the SQL statement that has executed the performance test are extracted in the above manner. The hash code of the first immutable character is calculated, and the hash code of the first immutable character is used as the hash code of the triggered SQL statement. The hash code of the second immutable character in the SQL statement that has executed the performance test is calculated, and the SQL statement that has executed the performance test is stored for subsequent hash code matching and identification. When the test system performs a deduplication operation on the triggered SQL statement, the hash code determined by the immutable character of the SQL statement is matched and identified, which can provide the accuracy of SQL statement recognition, thereby improving the accuracy of deduplication of the triggered SQL statement.

[0051] Further, the identification information includes a hash code of the first immutable character of the triggered SQL statement and a library name and a table name in the triggered SQL statement. Identifying that the triggered SQL statement has not been subjected to a performance test based on the identification information includes: matching the hash code of the first immutable character in the identification information and the library name and the table name in the triggered SQL statement with the hash code, the library name and the table name in each identification information in the storage area, respectively; if the identification information fails to match the identification information, identifying that the triggered SQL statement has not been subjected to a performance test; wherein the hash code, the library name and the table name in the identification information are the hash code of the second immutable character of the SQL statement that has been subjected to a performance test and the library name and the table name of the SQL statement that has been subjected to a performance test.

[0052] Specifically, the library name and table name involved in the triggered SQL statement and the hash code obtained by removing the characters after the parameters to be replaced in the triggered SQL statement are concatenated to form a string, and the string is used as the identification information of the triggered SQL statement. At the same time, the method for obtaining the identification information of the SQL statement that has executed the performance test in the storage area is also obtained in this way.

[0053] For example, for the SQL statement: select*from tableA where id>?. When the SQL statement is collected, the name of the database where it is located is also collected. Assume that the database name is databaseA. After the SQL statement is parsed, the table name is tableA, and the parameter to be replaced is the "?" in id>?. The key information string composed of immutable characters is: select*fromtableA where id>. Assume that the hash code generated by the key information is 1234566789; the final identification information or recognition information is databaseAtableA1234566789.

[0054] In one embodiment, a hash code of a triggered SQL statement is matched with each hash code in a storage area, and if the match fails, it is identified that the triggered SQL statement has not been subjected to a performance test, including: if the match fails, obtaining ignore rule configuration information for the SQL statement performance test, the ignore rule configuration information being used to indicate that SQL statements that satisfy a preset ignore rule are not used to perform a performance test; when the triggered SQL statement does not satisfy a preset ignore rule in the ignore rule configuration information, it is identified that the triggered SQL statement has not been subjected to a performance test.

[0055] In this embodiment, when the hash code of the triggered SQL statement is matched with each hash code in the storage area, if the match fails, it indicates that the triggered SQL statement has not been used for performance testing. At this time, it is further detected whether the triggered SQL statement is the SQL statement to be filtered in the configuration information. Specifically, the ignore rule configuration information is pre-configured, and the ignore rule configuration information is used to indicate that the SQL statement that meets the preset ignore rule is not used for performance testing. For example, a rule configuration information table is set, and the preset ignore rule is filled in the rule configuration information table. The ignore rule configuration information includes one or more preset ignore rules in the rule configuration information table. When the triggered SQL statement does not meet the preset ignore rule in the ignore rule configuration information, it is determined that the triggered SQL statement has not been used for performance testing. On the contrary, the ignore operation is performed on the triggered SQL statement. Therefore, an operation node can be provided for manual operation, and the ignore rule configuration information is generated by manual configuration to control the performance test operation of the SQL statement, so that the test system can better meet the performance test requirements of the SQL statement.

[0056] In one embodiment, when the triggered SQL statement does not satisfy the preset ignore rule in the ignore rule configuration information, after identifying that the triggered SQL statement has not executed the performance test, it also includes: parsing the triggered SQL statement that has not executed the performance test by constructing an SQL syntax tree, extracting the third immutable character of the triggered SQL statement from the parsing result, obtaining the hash code of the third immutable character, storing the hash code of the third immutable character as the key in the key-value pair of the storage area, and when the step of matching the hash code of the triggered SQL statement with each hash code in the storage area is executed, obtaining the key in the key-value pair from the storage area to match the hash code of the triggered SQL statement.

[0057] In this embodiment, the SQL syntax tree is constructed to parse the triggered SQL statement that has not been subjected to performance testing, and obtain the third immutable character of the triggered SQL statement. The judgment rule of the third immutable character here is the same as the judgment rule of the immutable character in the above-mentioned SQL statement. When there are multiple third immutable characters, the multiple third immutable characters are used to form a string, and the hash code of the string is obtained, and the hash code of the string is stored as the key in the key-value pair of the storage area. For example, the third immutable character of the triggered SQL statement may include a select character, a form character, etc.

[0058] Specifically, after collecting the triggered SQL statements, the deduplication operation process of the triggered SQL statements is as follows: Figure 3 Reference Figure 3 The process shown is: first determine whether there is a cache in the Redis database that uses the hash code of the collected triggered SQL statement as the key in the key-value pair of the Redis database. If so, end the judgment process of the deduplication operation and discard the collected triggered SQL statement. If not, determine whether the collected triggered SQL statement meets the configured ignore rule. The ignore rule is manually configured, and the trigger SQL statement that meets the ignore rule can be controlled by the ignore rule to not perform the deduplication operation. The ignore rule uses the library name and table name as the key in the key-value pair of the Redis database for caching. Use the library name and table name in the triggered SQL statement as the key in the key-value pair of the Redis database to query the ignore rule of the triggered SQL statement.

[0059] When the triggered SQL statement meets the pre-configured ignore rule, the hash code of the triggered SQL statement is cached as the key in the key-value pair of the Redis database. If the triggered SQL statement does not meet the pre-configured ignore rule, the triggered SQL statement is parsed by building a SQL syntax tree, and the key information in the triggered SQL statement is extracted and spliced ​​into character A. Among them, the key information may include the third immutable character in the triggered SQL statement. Determine again whether there is cache information in the Redis database with the hash code of character A as the key in the key-value pair. If not, cache the hash code of character A as the key in the key-value pair of the Redis database. If so, cache the hash code of the triggered SQL statement as the key in the key-value pair of the Redis database. Among them, Figure 3 The sql in the code refers to the triggered SQL statement, hashcode refers to the hash code, key refers to the key in the key-value pair, and redis refers to the Redis database. Therefore, a technical framework is provided for the deduplication operation of the performance test of SQL statements, so that the test system can deduplicate the collected triggered SQL statements, remove the SQL statements that have been analyzed historically, avoid repeated analysis, and reduce the system operation pressure of the test system.

[0060] In one embodiment, S102 includes: obtaining a preset character, and when the preset character is identified from the SQL statement to be analyzed, using the preset character in the SQL statement to be analyzed as a parameter to be replaced.

[0061] In this embodiment, preset characters are preconfigured. For example, the preset characters may be a "?" character. The SQL statement to be analyzed is analyzed by the SQL statement analysis framework to obtain the characters of the SQL statement to be analyzed. It is determined whether the preset characters exist in the SQL statement to be analyzed. If so, the preset characters in the SQL statement to be analyzed are used as parameters to be replaced. Therefore, the parameters to be replaced in the SQL statement to be analyzed can be quickly identified.

[0062] In one embodiment, S104 includes: obtaining data table information in the SQL statement to be analyzed, the data table information is used to indicate the data table in the database used to query the SQL statement to be analyzed; collecting the field value of the SQL statement from the online database according to the data table information; obtaining the expression of the SQL statement to be analyzed, and obtaining online parameters from the field value of the SQL statement according to the expression.

[0063] Preferably, after collecting the field values ​​of the SQL statement from the online database according to the data table information, it also includes: if the expression of the SQL statement to be analyzed cannot be obtained, or the online parameters cannot be obtained from the field values ​​of the SQL statement according to the expression, obtaining the test parameters for replacing the parameters to be replaced in the test environment of the SQL statement to be analyzed, and using the test parameters as the online parameters.

[0064] In this embodiment, data is collected from an online database according to all data table names involved in the data table information in the SQL statement to be analyzed, and the collected data includes the field values ​​of the SQL statement. At the same time, the SQL statement to be analyzed is parsed using the SQL statement parsing framework to obtain the expression of the SQL statement to be analyzed. The expression of the SQL statement to be analyzed obtained by parsing includes a left expression corresponding to the parameter to be replaced. The online parameter of the parameter to be replaced is obtained from the collected data according to the left expression.

[0065] If the SQL statement to be analyzed is analyzed by using the SQL statement analysis framework, and it is determined from the analysis result that the SQL statement to be analyzed does not contain an expression, that is, the expression of the SQL statement to be analyzed cannot be obtained, the test parameter used to replace the parameter to be replaced in the test environment of the SQL statement to be analyzed is used as the online parameter. Alternatively, after the SQL statement to be analyzed is analyzed by using the SQL statement analysis framework, it is determined from the analysis result that the SQL statement to be analyzed contains an expression, but the online parameter of the parameter to be replaced cannot be obtained from the collected data according to the expression, the test parameter used to replace the parameter to be replaced in the test environment of the SQL statement to be analyzed is used as the online parameter.

[0066] For example, according to the library name and table name involved in the SQL statement to be analyzed, some online data is obtained from the online database for backup. The left expressions of all parameters that need to be replaced in the SQL statement to be analyzed are obtained, and then divided into two categories for processing: one is that the left expression belongs to a field in the online data table, then the corresponding field in the backup online data is obtained to replace the parameter; the other is that the left expression does not exist or does not correspond to any field in the online data, such as the parameter belongs to the function call parameter, sort (order by) parameter, paging (limit) parameter, etc., then the corresponding parameter value in the SQL statement with parameter replacement collected from the test environment can be directly used to replace the parameter.

[0067] For example: select*from tableA where id>? limit? This SQL statement to be analyzed. After completing parameter replacement in the test environment, the SQL statement is: select*from tableA where id>200limit 50. There are two parameters that need to be replaced. The first "?" corresponds to the id field in tableA. The value of the id field in tableA in the online data can be used as the online parameter to be replaced. Assume that the id of the collected online data is 500, and the left expression corresponding to the second "?" is limit, which is an SQL command and does not correspond to any field in the data table in the online data. At this time, the replaced parameters can be extracted from the test environment for replacement, that is, replaced with 50. The replaced SQL statement is: select*from tableA where id>500limit 50.

[0068] In one embodiment, S108 includes: obtaining query conditions in the replaced SQL statement; creating multiple index methods according to the query conditions; executing index performance tests on the replaced SQL statement under each index method to obtain the index method with the least index execution time; if there is only one index method with the least index execution time, using the index method with the least index execution time as the index method for the replaced SQL statement; if there are multiple index methods with the least index execution time, screening the multiple index methods with the least index execution time according to the RBO algorithm to screen out the index method for the replaced SQL statement.

[0069] In this embodiment, the test platform 102 of the test system 10 performs an index performance test on the replaced SQL statement. First, the query condition in the replaced SQL statement is obtained. The acquisition method may include: obtaining a query field from the replaced SQL statement, and determining one or more query conditions according to the query field. Further, multiple indexes are created according to the query condition, and the index performance test of the replaced SQL statement is performed under each index. For example, the replaced SQL statement is: select*from tableA where a=1and b=2and c>3. After parsing, it is identified that the left expression of the query condition is a, b, c. That is, the query condition includes a, b, c. The index combination obtained by permutation and combination is: 1. Only a index is built separately. 2. Only b index is built separately. 3. Only c index is built separately. 4. Build ab joint index. 5. Build ac joint index. 6. Build ba joint index. 7. Build bc joint index. 8. Build ca joint index. 9. Build cb joint index. 10. Build abc joint index. 11. Build acb joint index. 12. Build a bac joint index. 13. Build a bca joint index. 14. Build a cab joint index. 15. Build a cba joint index. Build these indexes in sequence, and then force the replaced SQL statement to execute according to these indexes to obtain the time consumption under different indexes. Furthermore, when executing each index method, obtain the index method with the least time consumption for executing the index. If there is only one index method with the least index time consumption, use the index method with the least index time consumption as the index method for the replaced SQL statement, thereby completing the performance test of the replaced SQL statement. If there are multiple index methods with the least index time consumption, screen the multiple index methods with the least index time consumption according to the RBO (Rule-Based Optimization) algorithm, and screen out the index method for the replaced SQL statement, thereby completing the performance test of the replaced SQL statement.

[0070] Specifically, Figure 5 As shown. The test system prepares the environment and online test data according to the database name to which the replaced SQL statement belongs, and then analyzes the SQL index solution based on the CBO (Cost-Based Optimization) algorithm as the main method and the RBO algorithm as the auxiliary method. Figure 5As shown in the figure, force index refers to the forceindex() method. When the test system executes the forceindex() method, it forces the use of the index in the forceindex() method. sql refers to the replaced SQL statement. cost refers to the index time consumed when the replaced SQL statement is executed according to the CBO algorithm. Therefore, the performance test of the replaced SQL statement based on the CBO algorithm as the main and the RBO algorithm as the auxiliary can improve the accuracy of the performance test of the replaced SQL statement.

[0071] With respect to the above-mentioned SQL statement performance testing method, a specific embodiment is provided below;

[0072] See also Figure 6 As shown, Figure 6 A system architecture diagram of the test system in a specific implementation process is provided. Figure 6 The system architecture shown executes a SQL statement performance testing method of this application. Figure 6 As shown, the test system can be divided into three subsystems: SQL acquisition agent offline test environment, SQL analysis management platform and SQL analysis system.

[0073] SQL Collection Agent is an offline test environment SQL statement collection agent: mainly based on the open source jvm-sandbox tool, encapsulating the interception code of different data persistence layer frameworks. After being injected into the target process of the tested application, the Agent intercepts the SQL statements triggered during the running process of the tested application in real time and transmits them through the API interface of the SQL analysis management platform.

[0074] SQL analysis and management platform, a web application developed based on the Spring Boot framework, mainly has the following sub-modules:

[0075] The environment monitoring module is mainly used to monitor once a minute whether the application under test in the configuration table has been injected with the collection agent. If not, it will be injected.

[0076] SQL collection and deduplication module, the main function of this module is to receive SQL statement information passed by the Agent, and choose to discard or store it in the database after deduplication of SQL statements according to a specific algorithm. The purpose of deduplication is to remove SQL statements that have been analyzed historically to avoid repeated analysis. The deduplication algorithm logic is as follows Figure 3 shown.

[0077] SQL analysis scheduled task module, the main purpose of the scheduled task of this module is to extract all unanalyzed SQL statements from the database, and after SQL parsing, online parameter sampling and parameter replacement, submit the replaced SQL statements to the SQL analysis system for analysis, and process the analysis results. Among them, the purpose of parameter replacement is to make full use of real online data for index analysis. The replacement logic is as follows Figure 4 shown.

[0078] The analysis result usage module mainly determines whether there is a risk based on the analysis results. For risky SQL, a risk warning email is created and sent out after being associated with the corresponding responsible person through the application name.

[0079] SQL analysis system: Its main function is to analyze the index scheme of SQL statements based on the CBO algorithm and the CRO algorithm. The calculation logic is as follows: Figure 5 shown.

[0080] against Figure 6 The system framework of the test system executes the business timing logic of a SQL statement performance testing method of this application. Figure 7 shown.

[0081] like Figure 7 As shown in the figure, the environment monitoring module in the SQL analysis management platform injects the collection agent into the application under test in the test environment. After the collection agent intercepts the SQL statement, it passes it to the SQL collection and deduplication module in the SQL analysis management platform through the interface. The scheduled task in the SQL analysis management platform extracts the unanalyzed SQL statements from the database, performs parameter sampling by calling the online parameter sampling interface of the SQL analysis system, and then performs parameter replacement after parsing the SQL statement. Finally, the replaced SQL statement is submitted to the SQL analysis system for analysis.

[0082] After receiving the SQL statement, the SQL analysis system first prepares the environment and online test data according to the name of the database to which the SQL statement belongs, and then analyzes the index scheme of the SQL statement based on the CBO algorithm as the main and the RBO algorithm as the auxiliary, and returns the analysis results to the SQL analysis management platform.

[0083] The SQL analysis management platform handles the analysis results accordingly.

[0084] In summary, a SQL statement performance testing method of the present application can support the automatic collection of SQL statements to be analyzed in an offline test environment, implement indexing and risk assessment of SQL statements in advance during the test phase, and solve the problems of high time cost and difficulty of manual testing. In addition, a SQL statement performance testing method of the present application introduces online parameters in the analysis results of the performance test, thereby improving the significance of the performance test results for the index selection of SQL statements and enhancing the reference significance of the performance test results.

[0085] It should be understood that, although the steps in the flowchart are shown in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.

[0086] This application also provides a SQL statement performance testing device, such as Figure 8 As shown, the device includes a first acquisition module 10, a second acquisition module 20, a replacement module 30 and a test module 40. The first acquisition module 10 is used to acquire the SQL statement to be analyzed and identify the parameter to be replaced from the SQL statement to be analyzed; the second acquisition module 20 is used to acquire the online parameter corresponding to the parameter to be replaced; the replacement module 30 is used to replace the parameter to be replaced in the SQL statement to be analyzed with the online parameter to obtain the replaced SQL statement; the test module 40 is used to perform performance test analysis on the replaced SQL statement.

[0087] In one of the embodiments, a SQL statement performance testing device also includes an injection module, which is used to inject interception code into the process of the tested application, and obtain SQL statements triggered by the tested application during the program running process through the interception code; obtaining the SQL statement to be analyzed includes: obtaining the SQL statement to be analyzed from the triggered SQL statement.

[0088] Preferably, a SQL statement performance testing device also includes a monitoring module for monitoring whether the process of the tested application among multiple applications recorded in the configuration table is injected with interception code at a preset frequency, and if not, executing the step of injecting interception code into the process of the tested application.

[0089] In one of the embodiments, after obtaining the SQL statement triggered by the tested application during the program running process through interception code, it also includes: obtaining identification information of the triggered SQL statement, and when it is identified according to the identification information that the triggered SQL statement has not executed the performance test, executing the step of obtaining the SQL statement to be analyzed from the triggered SQL statement.

[0090] In one of the embodiments, the identification information includes a hash code of the triggered SQL statement, and obtaining the identification information of the triggered SQL statement includes: obtaining the hash code of the triggered SQL statement; identifying that the triggered SQL statement has not been subjected to performance testing based on the identification information, including: matching the hash code of the triggered SQL statement with each hash code in the storage area, and if the match fails, identifying that the triggered SQL statement has not been subjected to performance testing; wherein each hash code in the storage area is a hash code of an SQL statement that has been subjected to performance testing.

[0091] Preferably, obtaining the hash code of the triggered SQL statement includes: parsing the triggered SQL statement to obtain a first immutable character in the triggered SQL statement, where the first immutable character is a character that is not used for parameter replacement in the triggered SQL statement; calculating the hash code of the first immutable character, and using the hash code of the first immutable character as the hash code of the triggered SQL statement; wherein each hash code in the storage area is a hash code of a second immutable character in the SQL statement on which the performance test has been executed, where the second immutable character is a character that is not used for parameter replacement in the SQL statement on which the performance test has been executed.

[0092] In one of the embodiments, if the match fails, it is identified that the triggered SQL statement has not executed the performance test, including: if the match fails, obtaining the ignore rule configuration information of the SQL statement performance test, the ignore rule configuration information is used to indicate that the SQL statement that meets the preset ignore rule is not used to execute the performance test; when the triggered SQL statement does not meet the preset ignore rule in the ignore rule configuration information, it is identified that the triggered SQL statement has not executed the performance test.

[0093] In one embodiment, the first acquisition module 10 is further used to identify the parameters to be replaced from the SQL statement to be analyzed, including: obtaining preset characters, and when the preset characters are identified from the SQL statement to be analyzed, using the preset characters in the SQL statement to be analyzed as the parameters to be replaced.

[0094] In one of the embodiments, obtaining online parameters corresponding to the parameters to be replaced includes: obtaining data table information in the SQL statement to be analyzed, the data table information is used to indicate the data table in the database used to query the SQL statement to be analyzed; collecting the field value of the SQL statement from the online database according to the data table information; obtaining the expression of the SQL statement to be analyzed, and obtaining the online parameters from the field value of the SQL statement according to the expression.

[0095] Preferably, the second acquisition module is specifically used to obtain test parameters for replacing the parameters to be replaced in the test environment of the SQL statement to be analyzed if the expression of the SQL statement to be analyzed cannot be obtained, or the online parameters cannot be obtained from the field value of the SQL statement according to the expression, and use the test parameters as online parameters.

[0096] In one of the embodiments, a performance test analysis is performed on the replaced SQL statement, including: obtaining query conditions in the replaced SQL statement; creating multiple index methods according to the query conditions; performing index performance test on the replaced SQL statement under each index method to obtain the index method with the least index execution time; if there is only one index method with the least index execution time, the index method with the least index execution time is used as the index method for the replaced SQL statement; if there are multiple index methods with the least index execution time, the multiple index methods with the least index execution time are screened according to the RBO algorithm to screen out the index method for the replaced SQL statement.

[0097] For the specific definition of the SQL statement performance testing device, please refer to the definition of the SQL statement performance testing method above, which will not be repeated here. Each module in the above-mentioned SQL statement performance testing device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.

[0098] In one embodiment, a computer device is provided. The computer device may be a server supporting the operation of the test system. The internal structure diagram thereof may be as shown in FIG. Fig. 9As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to connect to an external device to exchange information with the external device. When the computer program is executed by the processor, a SQL statement performance testing method is implemented.

[0099] Those skilled in the art will understand that Fig. 9 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0100] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the following steps are implemented: obtaining an SQL statement to be analyzed, identifying a parameter to be replaced from the SQL statement to be analyzed; obtaining an online parameter corresponding to the parameter to be replaced; replacing the parameter to be replaced in the SQL statement to be analyzed with the online parameter to obtain a replaced SQL statement; and performing performance test analysis on the replaced SQL statement.

[0101] In one of the embodiments, when the processor executes the computer program, the following steps are implemented: an interception code is injected into the process of the tested application, and the SQL statement triggered by the tested application during the program running is obtained through the interception code; when the processor executes the computer program to implement the above-mentioned step of obtaining the SQL statement to be analyzed, the following steps are specifically implemented: the SQL statement to be analyzed is obtained from the triggered SQL statement.

[0102] In one of the embodiments, when the processor executes the computer program, the following steps are implemented: monitoring at a preset frequency whether the process of the tested application among the multiple applications recorded in the configuration table is injected with interception code, and if not, executing the step of injecting interception code into the process of the tested application.

[0103] In one embodiment, when the processor executes the computer program, the following steps are implemented: obtaining identification information of the triggered SQL statement, and when it is identified based on the identification information that the triggered SQL statement has not been subjected to performance testing, executing the step of obtaining the SQL statement to be analyzed from the triggered SQL statement.

[0104] In one embodiment, the identification information includes a hash code of the triggered SQL statement. When the processor executes a computer program to implement the above-mentioned step of obtaining the identification information of the triggered SQL statement, the following steps are specifically implemented: obtaining the hash code of the triggered SQL statement. When the processor executes a computer program to implement the above-mentioned step of identifying that the triggered SQL statement has not been subjected to a performance test according to the identification information, the following steps are specifically implemented: matching the hash code of the triggered SQL statement with each hash code in the storage area, and if the match fails, identifying that the triggered SQL statement has not been subjected to a performance test; wherein each hash code in the storage area is a hash code of an SQL statement that has been subjected to a performance test.

[0105] In one of the embodiments, when the processor executes a computer program to implement the above-mentioned step of obtaining the hash code of the triggered SQL statement, the following steps are specifically implemented: parsing the triggered SQL statement to obtain the first immutable character in the triggered SQL statement, where the first immutable character is a character that is not used for parameter replacement in the triggered SQL statement; calculating the hash code of the first immutable character, and using the hash code of the first immutable character as the hash code of the triggered SQL statement; wherein each hash code in the storage area is a hash code of a second immutable character in the SQL statement on which the performance test has been executed, and the second immutable character is a character that is not used for parameter replacement in the SQL statement on which the performance test has been executed.

[0106] In one of the embodiments, the processor executes a computer program to implement the above-mentioned step of identifying that the triggered SQL statement has not executed the performance test if the match fails, and specifically implements the following steps: if the match fails, obtain the ignore rule configuration information of the SQL statement performance test, the ignore rule configuration information is used to indicate that the SQL statement that meets the preset ignore rule is not used to execute the performance test; when the triggered SQL statement does not meet the preset ignore rule in the ignore rule configuration information, identify that the triggered SQL statement has not executed the performance test.

[0107] In one of the embodiments, when the processor executes a computer program to implement the above-mentioned step of identifying the parameters to be replaced from the SQL statement to be analyzed, the following steps are specifically implemented: obtaining preset characters, and when the preset characters are identified from the SQL statement to be analyzed, using the preset characters in the SQL statement to be analyzed as the parameters to be replaced.

[0108] In one of the embodiments, when the processor executes a computer program to implement the above-mentioned step of obtaining online parameters corresponding to the parameters to be replaced, the following steps are specifically implemented: obtaining data table information in the SQL statement to be analyzed, the data table information is used to indicate the data table in the database used to query the SQL statement to be analyzed; collecting the field value of the SQL statement from the online database according to the data table information; obtaining the expression of the SQL statement to be analyzed, and obtaining the online parameters from the field value of the SQL statement according to the expression.

[0109] In one of the embodiments, the processor implements the following steps when executing the computer program: if the expression of the SQL statement to be analyzed cannot be obtained, or the online parameters cannot be obtained from the field values ​​of the SQL statement according to the expression, obtain the test parameters used to replace the parameters to be replaced in the test environment of the SQL statement to be analyzed, and use the test parameters as the online parameters.

[0110] In one of the embodiments, when the processor executes a computer program to implement the above-mentioned step of performing a performance test and analysis on the replaced SQL statement, the following steps are specifically implemented: obtaining query conditions in the replaced SQL statement; creating multiple index methods according to the query conditions; performing an index performance test on the replaced SQL statement under each index method to obtain the index method with the least index execution time; if there is only one index method with the least index execution time, the index method with the least index execution time is used as the index method for the replaced SQL statement; if there are multiple index methods with the least index execution time, the multiple index methods with the least index execution time are screened according to the RBO algorithm to screen out the index method for the replaced SQL statement.

[0111] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented: obtaining an SQL statement to be analyzed, identifying a parameter to be replaced from the SQL statement to be analyzed; obtaining an online parameter corresponding to the parameter to be replaced; replacing the parameter to be replaced in the SQL statement to be analyzed with the online parameter to obtain a replaced SQL statement; and performing performance test analysis on the replaced SQL statement.

[0112] In one of the embodiments, when the computer program is executed by the processor, the following steps are implemented: an interception code is injected into the process of the tested application, and the SQL statement triggered by the tested application during the program running is obtained through the interception code; when the computer program is executed by the processor to implement the above-mentioned step of obtaining the SQL statement to be analyzed, the following steps are specifically implemented: the SQL statement to be analyzed is obtained from the triggered SQL statement.

[0113] In one of the embodiments, when the computer program is executed by the processor, the following steps are implemented: monitoring at a preset frequency whether the process of the tested application among the multiple applications recorded in the configuration table is injected with interception code, and if not, executing the step of injecting interception code into the process of the tested application.

[0114] In one embodiment, when the computer program is executed by a processor, the following steps are implemented: obtaining identification information of a triggered SQL statement, and when it is identified based on the identification information that the triggered SQL statement has not been subjected to performance testing, executing the step of obtaining a SQL statement to be analyzed from the triggered SQL statement.

[0115] In one embodiment, the identification information includes a hash code of the triggered SQL statement. When the computer program is executed by the processor to implement the above-mentioned step of obtaining the identification information of the triggered SQL statement, the following steps are specifically implemented: obtaining the hash code of the triggered SQL statement. When the computer program is executed by the processor to implement the above-mentioned step of identifying that the triggered SQL statement has not been subjected to performance testing according to the identification information, the following steps are specifically implemented: matching the hash code of the triggered SQL statement with each hash code in the storage area, and if the match fails, identifying that the triggered SQL statement has not been subjected to performance testing; wherein each hash code in the storage area is a hash code of an SQL statement that has been subjected to performance testing.

[0116] In one of the embodiments, when the computer program is executed by the processor to implement the above-mentioned step of obtaining the hash code of the triggered SQL statement, the following steps are specifically implemented: parsing the triggered SQL statement to obtain the first immutable character in the triggered SQL statement, where the first immutable character is a character that is not used for parameter replacement in the triggered SQL statement; calculating the hash code of the first immutable character, and using the hash code of the first immutable character as the hash code of the triggered SQL statement; wherein each hash code in the storage area is a hash code of the second immutable character in the SQL statement that has executed the performance test, and the second immutable character is a character that is not used for parameter replacement in the SQL statement that has executed the performance test.

[0117] In one of the embodiments, when a computer program is executed by a processor to implement the above-mentioned step of identifying that a triggered SQL statement has not executed a performance test if a match fails, the following steps are specifically implemented: if a match fails, obtaining ignore rule configuration information for a SQL statement performance test, the ignore rule configuration information being used to indicate that SQL statements that satisfy a preset ignore rule are not used to execute a performance test; when a triggered SQL statement does not satisfy a preset ignore rule in the ignore rule configuration information, identifying that the triggered SQL statement has not executed a performance test.

[0118] In one of the embodiments, when the computer program is executed by the processor to implement the above-mentioned step of identifying the parameters to be replaced from the SQL statement to be analyzed, the following steps are specifically implemented: obtaining preset characters, and when the preset characters are identified from the SQL statement to be analyzed, using the preset characters in the SQL statement to be analyzed as the parameters to be replaced.

[0119] In one of the embodiments, when the computer program is executed by the processor to implement the above-mentioned step of obtaining online parameters corresponding to the parameters to be replaced, the following steps are specifically implemented: obtaining data table information in the SQL statement to be analyzed, the data table information is used to indicate the data table in the database used to query the SQL statement to be analyzed; collecting the field value of the SQL statement from the online database according to the data table information; obtaining the expression of the SQL statement to be analyzed, and obtaining the online parameters from the field value of the SQL statement according to the expression.

[0120] In one of the embodiments, when the computer program is executed by a processor, the following steps are implemented: if the expression of the SQL statement to be analyzed cannot be obtained, or the online parameters cannot be obtained from the field values ​​of the SQL statement according to the expression, the test parameters for replacing the parameters to be replaced in the test environment of the SQL statement to be analyzed are obtained, and the test parameters are used as online parameters.

[0121] In one of the embodiments, when the computer program is executed by the processor to implement the above-mentioned steps of performing performance test analysis on the replaced SQL statement, the following steps are specifically implemented: obtaining query conditions in the replaced SQL statement; creating multiple index methods according to the query conditions; performing index performance test of the replaced SQL statement under each index method to obtain the index method with the least index execution time; if there is only one index method with the least index execution time, the index method with the least index execution time is used as the index method of the replaced SQL statement; if there are multiple index methods with the least index execution time, the multiple index methods with the least index execution time are screened according to the RBO algorithm to screen out the index method of the replaced SQL statement.

[0122] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0123] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0124] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.

Claims

1. A SQL statement performance testing method, the method comprising: Obtaining a SQL statement to be analyzed from the triggered SQL statement, and identifying a parameter to be replaced from the SQL statement to be analyzed; Obtaining online parameters corresponding to the parameters to be replaced; Replacing the to-be-replaced parameter in the SQL statement to be analyzed with the online parameter to obtain a replaced SQL statement; Performing performance test analysis on the replaced SQL statement; The performing performance test analysis on the replaced SQL statement includes: Obtaining the query condition in the replaced SQL statement; Create multiple indexing methods according to the query conditions; Performing an index performance test of the replaced SQL statement under various index modes to obtain an index mode that consumes the least time to execute the index; If there is only one indexing method with the least indexing time consumption, the indexing method with the least indexing time consumption is used as the indexing method of the replaced SQL statement; If there are multiple indexing methods with the least indexing time consumption, the multiple indexing methods with the least indexing time consumption are screened according to the RBO algorithm to screen out the indexing method of the replaced SQL statement; Before the step of obtaining the SQL statement to be analyzed from the triggered SQL statement, the method further includes: injecting an interception code into the process of the tested application, and obtaining the SQL statement triggered by the tested application during the program running process through the interception code; obtaining identification information of the triggered SQL statement, and when it is identified according to the identification information that the triggered SQL statement has not been subjected to performance testing, executing the step of obtaining the SQL statement to be analyzed from the triggered SQL statement; The identification information includes a hash code of the triggered SQL statement, and the obtaining the identification information of the triggered SQL statement includes: obtaining the hash code of the triggered SQL statement; The step of identifying that the triggered SQL statement has not been subjected to a performance test according to the identification information includes: matching the hash code of the triggered SQL statement with each hash code in the storage area, and if the match fails, identifying that the triggered SQL statement has not been subjected to a performance test; wherein each hash code in the storage area is a hash code of an SQL statement that has been subjected to a performance test; The obtaining of the hash code of the triggered SQL statement includes: parsing the triggered SQL statement to obtain a first immutable character in the triggered SQL statement, where the first immutable character is a character that is not used for parameter replacement in the triggered SQL statement; calculating a hash code of the first immutable character, and using the hash code of the first immutable character as the hash code of the triggered SQL statement; wherein each hash code in the storage area is a hash code of a second immutable character in the SQL statement on which the performance test has been executed, where the second immutable character is a character that is not used for parameter replacement in the SQL statement on which the performance test has been executed.

2. The method according to claim 1, characterized in that The method further comprises: Monitor whether the process of the tested application among the multiple applications recorded in the configuration table is injected with the interception code according to the preset frequency, and if not, execute the step of injecting the interception code into the process of the tested application.

3. The method according to claim 1, characterized in that If the match fails, identifying that the triggered SQL statement has not been used for performance testing includes: If the match fails, obtain the ignore rule configuration information of the SQL statement performance test, wherein the ignore rule configuration information is used to indicate that the SQL statement that meets the preset ignore rule is not used to perform the performance test; When the triggered SQL statement does not satisfy the preset ignore rule in the ignore rule configuration information, it is identified that the triggered SQL statement has not been subjected to performance testing.

4. The method according to claim 1, characterized in that The step of identifying the parameters to be replaced from the SQL statement to be analyzed includes: A preset character is obtained, and when the preset character is identified from the SQL statement to be analyzed, the preset character in the SQL statement to be analyzed is used as the parameter to be replaced.

5. The method according to claim 1, characterized in that The obtaining of online parameters corresponding to the parameters to be replaced includes: Acquire data table information in the SQL statement to be analyzed, where the data table information is used to indicate a data table in a database that is used to query the SQL statement to be analyzed; Collecting field values ​​of SQL statements from the online database according to the data table information; An expression of the SQL statement to be analyzed is obtained, and the online parameter is obtained from a field value of the SQL statement according to the expression.

6. The method according to claim 5, characterized in that The method further comprises: If the expression of the SQL statement to be analyzed cannot be obtained, or the online parameter cannot be obtained from the field value of the SQL statement according to the expression, obtain the test parameter used to replace the parameter to be replaced in the test environment of the SQL statement to be analyzed, and use the test parameter as the online parameter.

7. A SQL statement performance testing device, characterized in that: The device comprises: A first acquisition module is used to acquire a SQL statement to be analyzed from a triggered SQL statement, and identify a parameter to be replaced from the SQL statement to be analyzed; A second acquisition module is used to acquire online parameters corresponding to the parameters to be replaced; A replacement module, used for replacing the to-be-replaced parameter in the SQL statement to be analyzed with the online parameter to obtain a replaced SQL statement; A testing module, used to perform performance testing and analysis on the replaced SQL statements; The performing performance test analysis on the replaced SQL statement includes: Obtaining the query condition in the replaced SQL statement; Create multiple indexing methods according to the query conditions; Performing an index performance test of the replaced SQL statement under various index modes to obtain an index mode that consumes the least time to execute the index; If there is only one indexing method with the least indexing time consumption, the indexing method with the least indexing time consumption is used as the indexing method of the replaced SQL statement; If there are multiple indexing methods with the least indexing time consumption, the multiple indexing methods with the least indexing time consumption are screened according to the RBO algorithm to screen out the indexing method of the replaced SQL statement; Before the step of obtaining the SQL statement to be analyzed from the triggered SQL statement, the method further includes: injecting an interception code into the process of the tested application, and obtaining the SQL statement triggered by the tested application during the program running process through the interception code; obtaining identification information of the triggered SQL statement, and when it is identified according to the identification information that the triggered SQL statement has not been subjected to performance testing, executing the step of obtaining the SQL statement to be analyzed from the triggered SQL statement; The identification information includes a hash code of the triggered SQL statement, and the obtaining the identification information of the triggered SQL statement includes: obtaining the hash code of the triggered SQL statement; The step of identifying that the triggered SQL statement has not been subjected to a performance test according to the identification information includes: matching the hash code of the triggered SQL statement with each hash code in the storage area, and if the match fails, identifying that the triggered SQL statement has not been subjected to a performance test; wherein each hash code in the storage area is a hash code of an SQL statement that has been subjected to a performance test; The obtaining of the hash code of the triggered SQL statement includes: parsing the triggered SQL statement to obtain a first immutable character in the triggered SQL statement, where the first immutable character is a character that is not used for parameter replacement in the triggered SQL statement; calculating a hash code of the first immutable character, and using the hash code of the first immutable character as the hash code of the triggered SQL statement; wherein each hash code in the storage area is a hash code of a second immutable character in the SQL statement on which the performance test has been executed, where the second immutable character is a character that is not used for parameter replacement in the SQL statement on which the performance test has been executed.

8. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.