Testing Method, Device, Equipment and Medium for Database Response Time
By analyzing execution plans and resource consumption of query statements, the method efficiently tests database response times under varying loads without loading extensive data, addressing inefficiencies in existing testing methods.
Patent Information
- Application Number
- CN202510051908.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-14
- Publication Date
- 2025-07-15
- Estimated Expiration
- 2045-01-14
AI Technical Summary
When testing database response time, the prior art requires loading a large amount of test data related to business logic, resulting in low testing efficiency and time-consuming and labor-consuming, and unable to effectively meet the response time requirements under large data volume and large concurrency volume.
By determining the execution plan and hardware resource consumption parameters of the structured query statement, based on table information and test conditions, a query statement is directly executed in the database to count the hardware resource consumption to determine the response time and avoid loading a large amount of test data.
It improves testing efficiency, reduces time and labor costs, can test the response time of the database at any time, and has high accuracy in determining the response time.
Smart Images

Figure CN119473827B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of databases, and more particularly to a method, apparatus, device, and medium for testing the response time of a database. Background Art
[0002] With the rapid development of cloud computing and distributed technologies, the amount of data in various business systems has also increased significantly. And with the substantial growth of the data volume, the database bottleneck has gradually emerged. Therefore, it is necessary to test whether the database can meet the response time requirements under large data volumes and high concurrency, so as to take timely countermeasures.
[0003] Normally, when testing whether the database can meet the response time requirements, it is necessary to load test data into the database and execute structured query statements corresponding to the business to simulate database operations for the business. However, when loading test data into the database, the process of loading a large amount of data related to the business logic consumes a large amount of time and labor costs, resulting in low test efficiency. Summary of the Invention
[0004] In view of the above problems, the present invention provides a method, apparatus, device, medium, and program product for testing the response time of a database.
[0005] According to a first aspect of the present invention, there is provided a method for testing the response time of a database, including: in response to receiving a test request, based on the test request, determining at least one structured query statement for testing the database, where the test request includes test conditions, and the test conditions include hardware resource configuration parameters, data volume parameters, and concurrency parameters, and the concurrency parameter characterizes the concurrency of at least one structured query statement; obtaining an execution plan and hardware resource consumption parameters when the database executes each structured query statement; based on the table information, execution plan, and hardware resource consumption parameters of the data table corresponding to each structured query statement, determining the hardware resource consumption information of the database when executing each structured query statement, where the table information includes: table structure information, table data volume information, and table index information; and based on the hardware resource consumption information, hardware resource configuration parameters, data volume parameters, and concurrency parameters, determining the response time of the database when executing each structured query statement under the test conditions.
[0006] According to an embodiment of the present invention, based on the table information, execution plan, and hardware resource consumption parameters of a data table corresponding to a structured query statement, determine the hardware resource consumption information for the database to execute each structured query statement, including: according to the execution plan, determine at least one database operator used by the database to execute the structured query statement; according to the at least one database operator, hardware resource consumption parameters, and table information of the data table corresponding to the structured query statement, determine the respective sub-hardware resource consumption parameters of each database operator; and according to each database operator and the respective sub-hardware resource consumption parameters of each database operator, determine the hardware resource consumption information.
[0007] According to an embodiment of the present invention, based on a test request, determine at least one structured query statement for testing a database, including: in response to determining that the test request includes a database script for testing the database, obtain at least one initial structured query statement in the database script; and based on the at least one initial structured query statement and the data already stored in the database, determine at least one structured query statement.
[0008] According to an embodiment of the present invention, based on at least one initial structured query statement and the data stored in the database, determine at least one structured query statement, including: in response to determining that there is a query parameter with a missing parameter value in the initial structured query statement, query the data already stored in the database according to the field name corresponding to the query parameter to obtain target data, where the query parameter is used to locate the row where the data to be queried corresponding to the initial structured query statement is located; and based on the target data, determine the parameter value of the query parameter in the initial structured query statement to obtain a structured query statement.
[0009] According to an embodiment of the present invention, the method further includes: obtaining the structured query statement for testing the database from the test request.
[0010] According to an embodiment of the present invention, based on the hardware resource consumption information, hardware resource configuration parameters, data volume parameters, and concurrency parameters, determine the response time for the database to execute each structured query statement under test conditions, including: for each structured query statement, input the hardware resource configuration parameters, data volume parameters, concurrency parameters, and hardware resource consumption information of the structured query statement into a time prediction model to obtain the response time corresponding to the structured query statement.
[0011] According to an embodiment of the present invention, the method further includes: determining, based on the response time corresponding to each structured query statement, a target structured query statement whose response time is greater than a preset threshold from at least one structured query statement; and determining target influence information from multiple pieces of influence information that affect the response time based on the target structured query statement and the data table corresponding to the target structured query statement, where the multiple pieces of influence information include: table index information of the data table, table structure information of the data table, and the target structured query statement.
[0012] A second aspect of the present invention provides a test device for database response time, including: a statement determination module, which, in response to receiving a test request, determines at least one structured query statement for testing the database based on the test request, where the test request includes test conditions, and the test conditions include hardware resource configuration parameters, data volume parameters, and concurrency parameters, and the concurrency parameter represents the concurrency of at least one structured query statement; a parameter acquisition module, configured to acquire the execution plan and hardware resource consumption parameters when the database executes each structured query statement; a consumption determination module, configured to determine the hardware resource consumption information of the database when executing each structured query statement based on the table information, execution plan, and hardware resource consumption parameters of the data table corresponding to each structured query statement, where the table information includes: table structure information, table data volume information, and table index information; and a time determination module, configured to determine the response time of the database when executing each structured query statement under the test conditions based on the hardware resource consumption information, hardware resource configuration parameters, data volume parameters, and concurrency parameters.
[0013] A third aspect of the present invention provides an electronic device, including: one or more processors; a memory for storing one or more computer programs, where the above one or more processors execute the above one or more computer programs to implement the steps of the above method.
[0014] A fourth aspect of the present invention further provides a computer-readable storage medium, on which a computer program or instruction is stored, and when the above computer program or instruction is executed by a processor, the steps of the above method are implemented.
[0015] A fifth aspect of the present invention further provides a computer program product, including a computer program or instruction, and when the above computer program or instruction is executed by a processor, the steps of the above method are implemented.
[0016] According to an embodiment of the present invention, by determining a structured query statement for testing a database based on a test request and setting test conditions such as hardware resource configuration parameters, data volume parameters, and concurrency volume parameters, it is possible to test the response time of the database for executing a specific service under specific test conditions. Moreover, by obtaining the execution plan of the database actually executing the structured query statement and the hardware resource consumption parameters as reference information for determining the hardware resource consumption parameters, and using the database hardware resource consumption parameters, table information, and execution plan to determine the hardware resource consumption information, while making the hardware resource consumption information authentic, the richness of the hardware resource consumption information is improved, and further the accuracy of the determined response time is improved. In addition, using the hardware resource consumption information of the database executing the structured query statement once to determine the response time under the test conditions, there is no need to load a large amount of test data in the database, improving the test efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Through the following description of the embodiments of the present invention with reference to the drawings, the above content and other objects, features, and advantages of the present invention will become clearer. In the drawings:
[0018] Figure 1 The application scenario diagram of the method, device, equipment, medium, and program product for testing the database response time according to an embodiment of the present invention is shown.
[0019] Figure 2 The flowchart of the method for testing the database response time according to an embodiment of the present invention is shown.
[0020] Figure 3 The data flow diagram for determining the structured query statement according to a specific embodiment of the present invention is shown.
[0021] Figure 4 The flowchart for testing the database according to a specific embodiment of the present invention is shown.
[0022] Figure 5 The structural block diagram of the device for testing the database response time according to an embodiment of the present invention is shown.
[0023] Figure 6 The block diagram of the electronic device suitable for implementing the method for testing the database response time according to an embodiment of the present invention is shown. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0024] Hereinafter, embodiments of the present invention will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are merely exemplary and are not intended to limit the scope of the present invention. In the following detailed description, for the sake of explanation, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the present invention. However, it is obvious that one or more embodiments can be implemented without these specific details. In addition, in the following description, descriptions of well-known structures and technologies are omitted to avoid unnecessarily obscuring the concepts of the present invention.
[0025] The terms used herein are merely for the purpose of describing specific embodiments and are not intended to limit the present invention. The terms "including", "comprising" and the like used herein indicate the presence of the described features, steps, operations and / or components, but do not exclude the presence or addition of one or more other features, steps, operations or components.
[0026] All terms used herein (including technical and scientific terms) have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification and should not be interpreted in an idealized or overly rigid manner.
[0027] In cases where expressions similar to "at least one of A, B, and C, etc." are used, generally, it should be interpreted according to the meaning commonly understood by those skilled in the art (for example, "a system having at least one of A, B, and C" should include, but not be limited to, a system having only A, only B, only C, having A and B, having A and C, having B and C, and / or having A, B, and C, etc.).
[0028] In the technical solution of the present invention, the user information involved (including but not limited to user personal information, user image information, user device information, such as location information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) are all information and data authorized by the user or fully authorized by all parties. Moreover, the processing of relevant data, such as collection, storage, use, processing, transmission, provision, disclosure, and application, etc., all comply with relevant laws, regulations and standards, adopt necessary confidentiality measures, do not violate public order and good customs, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0029] In the scenario of making automated decisions using personal information, the method, device, and system provided by the embodiments of the present invention all provide corresponding operation entrances for users to choose to agree or reject the results of automated decisions; if the user chooses to reject, the expert decision-making process will be entered. The expression "automated decision" here refers to the activity of automatically analyzing and evaluating an individual's behavior habits, hobbies, or economic, health, credit status, etc. through a computer program and making decisions. The expression "expert decision" here refers to the activity of making decisions by personnel who are specialized in a certain field, have specialized experience, knowledge, and skills, and have reached a certain professional level.
[0030] When testing whether a database can meet the response requirements, it is usually necessary to load data into the database and then execute the structured query statements corresponding to the business to simulate database operations for the business. Since the loaded test data must also be related to the business logic, it is necessary to analyze the business-related data when loading the data, which is time-consuming and laborious. Moreover, the large amount of loaded data will not only increase the database maintenance cost but also have certain hardware resource requirements for the server environment, such as the Central Processing Unit (CPU), memory capacity, and disk capacity. In addition, since a large amount of loaded test data cannot be stored for a long time, the response time of the database cannot be tested at any time.
[0031] The embodiments of the present invention provide a method for testing the response time of a database. In response to receiving a test request, at least one structured query statement for testing the database is determined based on the test request, where the test request includes test conditions, and the test conditions include hardware resource configuration parameters, data volume parameters, and concurrency parameters. The concurrency parameter characterizes the concurrency of at least one structured query statement; the execution plan and hardware resource consumption parameters when the database executes each structured query statement are obtained; based on the table information, execution plan, and hardware resource consumption parameters of the data table corresponding to each structured query statement, the hardware resource consumption information for the database to execute each structured query statement is determined, where the table information includes: table structure information, table data volume information, and table index information; and based on the hardware resource consumption information, the hardware resource configuration parameters, data volume parameters, and concurrency parameters in the test conditions, the response time for the database to execute each structured query statement under the test conditions is determined. To solve the above technical problems, the embodiments of the present invention only execute the structured query statement once in the database, and determine the database response time under the test conditions by counting the hardware resource consumption when the database executes the structured query statement. Therefore, it is possible to avoid loading a large amount of data related to the business logic in the database, not only without consuming time and manpower to load the data, but also without the hardware resource conditions of the server environment, and the database can be tested at any time, improving the test efficiency.
[0032] Figure 1 The application scenario diagram of the test method, device, equipment, medium and program product for the database response time according to an embodiment of the present invention is shown.
[0033] As Figure 1 shown, the application scenario 100 according to this embodiment may include a first terminal device 101, a second terminal device 102, a third terminal device 103, a network 104, and a server 105. The network 104 is used as a medium to provide a communication link between the first terminal device 101, the second terminal device 102, the third terminal device 103, and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, etc.
[0034] Users can use the first terminal device 101, the second terminal device 102, and the third terminal device 103 to interact with the server 105 through the network 104 to receive or send messages, etc. Various communication client applications may be installed on the first terminal device 101, the second terminal device 102, and the third terminal device 103, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only as examples).
[0035] The first terminal device 101, the second terminal device 102, and the third terminal device 103 may be various electronic devices with a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, and desktop computers, etc.
[0036] The server 105 may be a server that provides various services, such as a background management server that supports the websites browsed by users using the first terminal device 101, the second terminal device 102, and the third terminal device 103 (only as an example). The background management server may analyze and process data such as received user requests, and feedback the processing results (such as web pages, information, or data obtained or generated according to user requests) to the terminal device.
[0037] Specifically, the server 105 can be a server that provides database services or a server that provides database testing services. The user uses the first terminal device 101, the second terminal device 102, or the third terminal device 103 to send a test request to the server 105 through the network 104. In response to receiving the test request, the server 105 determines at least one structured query statement for testing the database based on the test request. The test request includes test conditions, and the test conditions include hardware resource configuration parameters, data volume parameters, and concurrency parameters. The concurrency parameter characterizes the concurrency of at least one structured query statement; obtains the execution plan and hardware resource consumption parameters when the database executes each structured query statement; determines the hardware resource consumption information of the database when executing each structured query statement based on the table information, execution plan, and hardware resource consumption parameters of the data table corresponding to each structured query statement, where the table information includes: table structure information, table data volume information, and table index information; and determines the response time of the database when executing each structured query statement under the test conditions based on the hardware resource consumption information, hardware resource configuration parameters, data volume parameters, and concurrency parameters.
[0038] It should be noted that the method for testing the database response time provided in the embodiments of the present invention can generally be executed by the server 105. Correspondingly, the device for testing the database response time provided in the embodiments of the present invention can generally be set in the server 105. The method for testing the database response time provided in the embodiments of the present invention can also be executed by a server or a server cluster different from the server 105 and capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103, and / or the server 105. Correspondingly, the device for testing the database response time provided in the embodiments of the present invention can also be set in a server or a server cluster different from the server 105 and capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103, and / or the server 105.
[0039] It should be understood that Figure 1 the numbers of terminal devices, networks, and servers in
[0040] are merely illustrative. According to the implementation requirements, there can be any number of terminal devices, networks, and servers. Figure 1 The following will be based on Figures 2 to 4 the described scenario and will describe in detail the method for testing the database response time of the embodiments of the present invention through
[0041] Figure 2 shows a flowchart of the method for testing the database response time according to the embodiments of the present invention.
[0042] As Figure 2As shown, the test method for the database response time of this embodiment includes operations S210 to S240.
[0043] In operation S210, in response to receiving a test request, based on the test request, at least one structured query statement for testing the database is determined.
[0044] According to an embodiment of the present invention, the user can directly input at least one structured query statement for testing the database on the test interface of the terminal, can also upload the database script for testing the database to the test interface, or can also connect the database script and the database through an interface.
[0045] According to an embodiment of the present invention, in the case where the user input includes a database script, the database script can be parsed, and at least one structured query statement for testing is obtained from the database script.
[0046] According to an embodiment of the present invention, the test request includes test conditions, and the user can also input test conditions on the test interface of the terminal. The test conditions include hardware resource configuration parameters, data volume parameters, and concurrency parameters. The concurrency parameter characterizes the concurrency of at least one structured query statement, and the data volume parameter can characterize the multiple of the data volume under the test conditions to the currently stored data volume in the database.
[0047] In operation S220, the execution plan and hardware resource consumption parameters when the database executes each structured query statement are obtained.
[0048] According to an embodiment of the present invention, the execution plan may include multiple operations when the database executes the structured query statement and the sequence of precedence between the multiple operations. The hardware resource consumption parameter can characterize the hardware resource consumption when the database executes the structured query statement. Specifically, the hardware resource consumption may include CPU consumption, memory consumption, and disk consumption, etc.
[0049] According to an embodiment of the present invention, when obtaining the execution plan, after the database executes the structured query statement, the corresponding execution plan can be queried in the database according to the execution plan query instruction corresponding to the database. When obtaining the hardware resource consumption parameter, the corresponding hardware resource consumption information can also be queried in the database according to the hardware resource consumption query instruction corresponding to the database, or the hardware resource consumption information can be obtained by directly monitoring the hardware resource consumption of the server during the execution of the structured query statement.
[0050] In operation S230, based on the table information, execution plan, and hardware resource consumption parameters of the data table corresponding to each structured query statement, the hardware resource consumption information when the database executes each structured query statement is determined.
[0051] According to an embodiment of the present invention, the table information includes: table structure information, table data volume information, and table index information. Specifically, the table structure information may include field information, table creation statements, and metadata in the data table, etc. The table data volume information may include the current stored data volume in the data table, such as the number of table rows, etc. The table index information may include information such as columns where the data table index is located, etc.
[0052] In operation S240, based on the hardware resource consumption information, hardware resource configuration parameters, data volume parameters, and concurrency parameters, determine the response time of the database for executing each structured query statement under the test conditions.
[0053] According to an embodiment of the present invention, since under the conditions of a large amount of data and a large number of concurrent requests, the hardware resources of the server cannot respond to a large number of concurrent structured query statements at one time, a queuing situation will occur. Therefore, it is necessary to determine whether there is a queuing situation and information such as the queuing time when executing a large number of concurrent structured query statements through the hardware resource consumption information of a single execution of a structured query statement and the hardware resource configuration parameters, and then determine the response time.
[0054] According to an embodiment of the present invention, it is also possible to obtain the response time of the database for executing each structured query statement, and then estimate the response time of executing each structured query statement under the test conditions.
[0055] According to an embodiment of the present invention, the hardware resource consumption information, hardware resource configuration parameters, data volume parameters, and concurrency parameters in the test conditions can be input into a machine learning model, etc., to determine the response time. It is also possible to input the hardware resource consumption information, hardware resource configuration parameters, data volume parameters, and concurrency parameters in the test conditions into a statistical model to determine the response time.
[0056] According to an embodiment of the present invention, by determining the structured query statements for testing the database based on the test requests and setting test conditions such as hardware resource configuration parameters, data volume parameters, and concurrency parameters, it is possible to test the response time of the database for executing specific services under specific test conditions. Moreover, by obtaining the execution plan and hardware resource consumption parameters of the database actually executing the structured query statements as reference information for determining the hardware resource consumption parameters, and using the database hardware resource consumption parameters, table information, and execution plan to determine the hardware resource consumption information, while making the hardware resource consumption information authentic, it improves the richness of the hardware resource consumption information, and further improves the accuracy of the determined response time. In addition, using the hardware resource consumption information of the database for a single execution of a structured query statement to determine the response time under the test conditions does not require loading a large amount of test data in the database, improving the test efficiency.
[0057] According to an embodiment of the present invention, based on the table information, execution plan, and hardware resource consumption parameters of the data table corresponding to the structured query statement, determine the hardware resource consumption information for the database to execute each structured query statement, including: determining at least one database operator used by the database to execute the structured query statement according to the execution plan; determining the sub-hardware resource consumption parameters of each database operator according to the at least one database operator, the hardware resource consumption parameters, and the table information of the data table corresponding to the structured query statement; and determining the hardware resource consumption information according to each database operator and the sub-hardware resource consumption parameters of each database operator.
[0058] According to an embodiment of the present invention, a database operator can represent the specific operation when the database executes a structured query statement. Specifically, the execution plan may include at least one database operator used by the database to execute the structured query statement and the execution order between at least one database operator. Therefore, the database operator can be obtained from the execution plan.
[0059] According to an embodiment of the present invention, since the hardware resource consumption parameters for executing the structured query statement have been obtained, the hardware resource parameters can be split into sub-resource consumption parameters for each of at least one database operator.
[0060] According to an embodiment of the present invention, when a database operator executes an operation, the consumed hardware resources are related to the table structure, table index, and table data volume, etc. Therefore, the hardware resource parameters can be split into sub-resource consumption parameters for each of at least one database operator according to the table information of the data table.
[0061] According to an embodiment of the present invention, when determining the sub-resource consumption parameters, at least one database operator, the hardware resource consumption parameters, and the table information of the data table can be input into a resource consumption determination model to determine the sub-hardware resource consumption of each database operator.
[0062] According to an embodiment of the present invention, the hardware resource consumption information may include at least one database operator and the sub-hardware resource consumption parameters of each database operator. Furthermore, the response time in the case of a large concurrency volume and a large data volume can be determined according to the sub-hardware resource consumption parameters of each database operator.
[0063] According to an embodiment of the present invention, since the database executes a structured query statement in units of database operators, by counting the sub-hardware resource consumption parameters consumed by the database operators and determining the hardware resource consumption information according to the finer-grained sub-hardware resource consumption parameters, the response time can be determined more accurately according to the hardware resource consumption information.
[0064] According to an embodiment of the present invention, based on a test request, determining at least one structured query statement for testing a database includes: in response to determining that the test request includes a database script for testing the database, obtaining at least one initial structured query statement in the database script; and determining at least one structured query statement based on the at least one initial structured query statement and the data already stored in the database.
[0065] According to an embodiment of the present invention, a user can directly upload a database script for testing the database in a test interface. Specifically, the database script can be a database script for actual business. By using the database script of actual business to test the database, the database response time when actually executing the business can be predicted, which is closer to the actual business situation.
[0066] According to an embodiment of the present invention, in at least one initial structured query statement of the database script, there may be missing information, and the missing information is usually completed during the actual execution of the business. Therefore, without actually executing the business, the initial structured query statement cannot be executed in the database due to the existing missing information.
[0067] According to an embodiment of the present invention, in the case where there is missing information in the initial structured query statement, the initial structured query statement can be completed by using the data already stored in the database to obtain a structured query statement; in the case where there is no missing information in the initial structured query statement, the initial structured query statement can be directly determined as the structured query statement.
[0068] According to an embodiment of the present invention, by using the data already stored in the database to generate a structured query statement, it is possible to avoid manually loading a large amount of test data in the database and improve the test efficiency.
[0069] According to an embodiment of the present invention, determining at least one structured query statement based on the at least one initial structured query statement and the data stored in the database includes: in response to determining that there is a query parameter with a missing parameter value in the initial structured query statement, querying the data already stored in the database according to the field name corresponding to the query parameter to obtain target data; and determining the parameter value of the query parameter in the initial structured query statement based on the target data to obtain a structured query statement.
[0070] According to an embodiment of the present invention, the initial structured query statement may include a query condition, and the query condition may include query parameters. The query parameters are used to locate the row where the data to be queried corresponding to the initial structured query statement is located. For example, when the initialization query statement is "SELECT * FROM employees WHERE age > :age", the query parameter is " :age" and the parameter value is missing, and the field name corresponding to the query parameter is "age".
[0071] According to an embodiment of the present invention, since the query parameters of the initial structured query statement lack parameter values when the business is not actually executed, that is, the query conditions in the initial structured query statement are incomplete, the initial structured query statement cannot be normally executed in the database, and the initial structured query statement needs to be completed to obtain an executable structured query statement.
[0072] According to an embodiment of the present invention, when determining the target data that can be used as the parameter value, the data stored in the database can be queried according to the field name corresponding to the query parameter. Specifically, the data stored in the database can be queried using the field name to obtain a data set corresponding to the field name, and then the target data is determined from the data set. For example, all field values corresponding to the field name "age" in the employees table can be queried, and the obtained data set includes {22, 25, 26, 28}, and "25" in the data set is determined as the target data.
[0073] According to an embodiment of the present invention, after determining the target data, the target data can be filled as the parameter value of the query parameter into the initial structured query statement to obtain a structured query statement. For example, "25" can be used as the parameter value of the query parameter "age" to obtain the structured query statement "SELECT * FROM employees WHERE age > 25".
[0074] According to an embodiment of the present invention, by using the data stored in the database to complete the missing parameter values in the initial structured query statement, a structured query statement can be automatically generated, without the need to manually load a large amount of test data in the database, nor to manually write a structured query statement according to the loaded data, improving the test efficiency.
[0075] Figure 3 A data flow diagram for determining a structured query statement according to a specific embodiment of the present invention is shown.
[0076] As Figure 3As shown, obtain the initial structured query statement 302 from the database script 301, obtain the field name 303 corresponding to the query parameter with the missing parameter value from the initial structured query statement 302, query the data stored in the database using the field name 303 to obtain the target data 304. Use the target data 304 to complete the missing parameter values in the initial structured query statement 302 to obtain the target structured query statement 305.
[0077] According to an embodiment of the present invention, based on a test request, determining at least one structured query statement for testing a database further includes: obtaining a structured query statement for testing the database from the test request.
[0078] According to an embodiment of the present invention, when a user needs to test the response of the database to complete a simple query task, the user can also directly input a structured query statement for testing the database on the test interface.
[0079] According to an embodiment of the present invention, when the user inputs a structured query statement, the data stored in the database can also be displayed on the test interface, so that the user can directly construct a structured query statement based on the stored data, improving the efficiency of the user in constructing a structured query statement.
[0080] According to an embodiment of the present invention, when it is determined that the structured query statement input by the user is complete, the structured query statement input by the user can be directly used as the structured query statement for testing the database. When it is determined that the structured query statement input by the user is an incomplete statement, it can be completed using the data stored in the database, and the completed structured query statement is used as the structured query statement for testing the database.
[0081] According to an embodiment of the present invention, by directly using the structured query statement in the test request for testing, it is possible to test the execution of the database when completing a simple query task, making the test method diverse and rich.
[0082] According to an embodiment of the present invention, based on the hardware resource consumption information, hardware resource configuration parameters, data volume parameters, and concurrency parameters, determining the response time of the database to execute each structured query statement under test conditions includes: for each structured query statement, inputting the hardware resource configuration parameters, data volume parameters, concurrency parameters, and the hardware resource consumption information of the structured query statement into a time prediction model to obtain the response time corresponding to the structured query statement.
[0083] According to an embodiment of the present invention, relevant parameters for testing, such as hardware resource configuration parameters, data volume parameters, and concurrency parameters, can be obtained from the test conditions set by the user.
[0084] According to an embodiment of the present invention, the time prediction model can be obtained by pre-training a machine learning model or by fitting data to a statistical model. Specifically, the hardware resource configuration parameters, data volume parameters, concurrency parameters, and hardware resource consumption information of other databases can be used as training samples, and the corresponding true response time can be used as labels to train the machine learning model.
[0085] According to an embodiment of the present invention, when determining the response time corresponding to each structured query statement, the hardware resource configuration parameters, data volume parameters, concurrency parameters, and hardware resource consumption information of the structured query statement can be input into the time prediction model to obtain the response time output by the time prediction model.
[0086] According to an embodiment of the present invention, the response time is predicted using the time prediction model, which improves the degree of automation of testing and further improves the testing efficiency.
[0087] According to an embodiment of the present invention, the method for testing the database response time further includes: determining a target structured query statement with a response time greater than a preset threshold from at least one structured query statement based on the response time corresponding to each structured query statement; and determining target influence information from multiple influence information affecting the response time based on the target structured query statement and the data table corresponding to the target structured query statement.
[0088] According to an embodiment of the present invention, a threshold for the response time can be preset to determine whether there is a situation of high consumption time when the database executes the structured query statement, so as to specifically improve the response speed of the database. Specifically, when the response time of the structured query statement is greater than the preset threshold, the structured query statement can be determined as a target structured query statement with high consumption time.
[0089] According to an embodiment of the present invention, the response time of the database may be affected by the data table and the structured query statement. For example, the response time is long because the data table is not indexed or the index is set unreasonably, because of certain field types in the data table, and because the structured query statement requires the database to perform a full table scan or a subquery.
[0090] According to an embodiment of the present invention, the multiple influence information includes: the table index information of the data table, the table structure information of the data table, and the target structured query statement. Specifically, the table index information of the data table can include whether the data table has an index and the columns where the index is located, and the table structure information of the data table can include the fields in the table and the field type of each field.
[0091] According to an embodiment of the present invention, the target impact information can be determined from multiple impact information by means of rule matching. For example, multiple field types that cause long response times can be preset and matched with the field types in the table structure information, and it can also be scanned whether the target structured query statement includes characters representing full-table query, etc.
[0092] According to an embodiment of the present invention, after determining the target impact factor, the target impact factor can also be displayed on the user's terminal to facilitate the user to optimize the data table or the target structured query statement according to the target impact factor.
[0093] According to an embodiment of the present invention, by means of automation, the target impact factor affecting the response time is determined from multiple impact factors, improving the efficiency of determining the target impact factor and facilitating the user to maintain the database.
[0094] According to an embodiment of the present invention, in addition to the response time, a curve showing the change of the response time with the data volume parameter and the hardware resource configuration parameter can also be drawn and displayed on the user terminal. In addition, when the user uploads a database script, the n structured query statements with the highest execution frequency or execution time-consuming can also be analyzed to intuitively display the test results to the user.
[0095] Figure 4 The flowchart of testing the database according to a specific embodiment of the present invention is shown.
[0096] As Figure 4 shown, the testing of the database includes operations S410 to S460.
[0097] In operation S410, after the user configures the test conditions and executes the service for testing the database, the execution plan, table information, and hardware resource consumption parameters when the database executes the structured query statement are obtained.
[0098] According to an embodiment of the present invention, after connecting the script of the service to the database by using a database proxy, the service can be executed. The test conditions can include hardware resource configuration parameters, data volume parameters, and concurrency parameters, etc.
[0099] According to an embodiment of the present invention, the table information can include table structure information, table index information, and table data volume information, etc. The hardware resource consumption information can represent the hardware resource consumption of the database when executing the structured query statement.
[0100] According to an embodiment of the present invention, the database can be connected through an interface (connect api) to obtain the execution plan, table information, and hardware resource consumption parameters.
[0101] In operation S420, based on the execution plan, table information, and hardware resource consumption parameters, determine the sub-hardware resource consumption parameters of each database operator during the execution of the structured query statement.
[0102] In operation S430, generate hardware resource consumption information based on each database operator and the sub-hardware resource consumption parameters of each database operator.
[0103] In operation S440, determine the response time of the database under the test conditions based on the test conditions and the hardware resource consumption information.
[0104] In operation S450, count the 20 structured query statements with the longest response times and the structured query statements with the highest execution frequencies.
[0105] In operation S460, determine the target influencing factors that affect the response time.
[0106] According to an embodiment of the present invention, the influencing factors may include the table structure information, table index information of the data table corresponding to the structured query statement, and the structured query statement itself.
[0107] Based on the above test method for database response time, the present invention also provides a test device for database response time. The following will be combined with Figure 5 Describe this device in detail.
[0108] Figure 5 The structural block diagram of the test device for database response time according to an embodiment of the present invention is shown.
[0109] As Figure 5 shown, the test device 500 for database response time of this embodiment includes a statement determination module 510, a parameter acquisition module 520, a consumption determination module 530, and a time determination module 540.
[0110] The statement determination module 510 is configured to, in response to receiving a test request, based on the test request, determine at least one structured query statement for testing the database, where the test request includes test conditions, and the test conditions include hardware resource configuration parameters, data volume parameters, and concurrency parameters, and the concurrency parameter characterizes the concurrency of at least one structured query statement. In one embodiment, the statement determination module 510 may be used to execute the operation S210 described above, which will not be elaborated here.
[0111] The parameter acquisition module 520 is configured to acquire the execution plan and hardware resource consumption parameters when the database executes each structured query statement. In one embodiment, the parameter acquisition module 520 may be used to execute the operation S220 described above, which will not be elaborated here.
[0112] The consumption determination module 530 is configured to determine the hardware resource consumption information of the database for executing each structured query statement based on the table information, execution plan, and hardware resource consumption parameters of the data table corresponding to each structured query statement, where the table information includes: table structure information, table data volume information, and table index information. In one embodiment, the consumption determination module 530 may be configured to perform the operation S230 described above, which will not be elaborated here.
[0113] The time determination module 540 is configured to determine the response time of the database for executing each structured query statement under test conditions based on the hardware resource consumption information, hardware resource configuration parameters, data volume parameters, and concurrency parameters. In one embodiment, the time determination module 540 may be configured to perform the operation S240 described above, which will not be elaborated here.
[0114] According to an embodiment of the present invention, the consumption determination module 530 includes an operator determination sub-module, a parameter determination sub-module, and an information determination sub-module.
[0115] The operator determination sub-module is configured to determine at least one database operator used by the database when executing the structured query statement according to the execution plan.
[0116] The parameter determination sub-module is configured to determine the respective sub-hardware resource consumption parameters of each database operator according to at least one database operator, the hardware resource consumption parameters, and the table information of the data table corresponding to the structured query statement.
[0117] The information determination sub-module is configured to determine the hardware resource consumption information according to each database operator and the respective sub-hardware resource consumption parameters of each database operator.
[0118] According to an embodiment of the present invention, the statement determination module 510 includes an initial determination sub-module and a query determination sub-module.
[0119] The initial determination sub-module is configured to, in response to determining that the test request includes a database script for testing the database, obtain at least one initial structured query statement in the database script.
[0120] The query determination sub-module is configured to determine at least one structured query statement based on at least one initial structured query statement and the data already stored in the database.
[0121] According to an embodiment of the present invention, the query determination sub-module includes a target determination unit and a parameter determination unit.
[0122] The target determination unit is configured to, in response to determining that there is a query parameter with a missing parameter value in the initial structured query statement, query the data stored in the database according to the field name corresponding to the query parameter to obtain target data, where the query parameter is used to locate the row where the data to be queried corresponding to the initial structured query statement is located.
[0123] The parameter determination unit is configured to determine the parameter value of the query parameter in the initial structured query statement based on the target data to obtain a structured query statement.
[0124] According to an embodiment of the present invention, the statement determination module 510 further includes a statement acquisition sub-module.
[0125] The statement acquisition sub-module is configured to acquire a structured query statement for testing the database from the test request.
[0126] According to an embodiment of the present invention, the time determination module 540 includes a model prediction sub-module.
[0127] The model prediction sub-module is configured to input, for each structured query statement, the hardware resource configuration parameter, the data volume parameter, the concurrency parameter, and the hardware resource consumption information of the structured query statement into the time prediction model to obtain the response time corresponding to the structured query statement.
[0128] According to an embodiment of the present invention, the test device 500 for the database response time further includes a target statement determination module and an influencing factor determination module.
[0129] The target statement determination module is configured to determine a target structured query statement with a response time greater than a preset threshold from at least one structured query statement based on the response time corresponding to each structured query statement.
[0130] The influencing factor determination module is configured to determine target influencing information from multiple influencing information that affects the response time based on the target structured query statement and the data table corresponding to the target structured query statement, where the multiple influencing information includes: the table index information of the data table, the table structure information of the data table, and the target structured query statement.
[0131] According to an embodiment of the present invention, any multiple of the statement determination module 510, the parameter acquisition module 520, the consumption determination module 530, and the time determination module 540 may be combined and implemented in one module, or any one of them may be split into multiple modules. Alternatively, at least part of the functions of one or more of these modules may be combined with at least part of the functions of other modules and implemented in one module. According to an embodiment of the present invention, at least one of the statement determination module 510, the parameter acquisition module 520, the consumption determination module 530, and the time determination module 540 may be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on chip, a system on substrate, a system on package, an application specific integrated circuit (ASIC), or any other reasonable way of integrating or packaging circuits, etc., implemented by hardware or firmware, or implemented in any one of the three implementation manners of software, hardware, and firmware, or in any appropriate combination of several of them. Alternatively, at least one of the statement determination module 510, the parameter acquisition module 520, the consumption determination module 530, and the time determination module 540 may be at least partially implemented as a computer program module, which can perform corresponding functions when the computer program module is run.
[0132] Figure 6 The block diagram of an electronic device suitable for implementing the test method of database response time according to an embodiment of the present invention is shown.
[0133] As Figure 6 shown, the electronic device 600 according to an embodiment of the present invention includes a processor 601, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 602 or the program loaded from the storage section 608 into the random access memory (RAM) 603. The processor 601 may include, for example, a general microprocessor (such as a CPU), an instruction set processor, and / or a related chipset, and / or a dedicated microprocessor (such as an application specific integrated circuit (ASIC)), etc. The processor 601 may also include on-board memory for caching purposes. The processor 601 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present invention.
[0134] In the RAM 603, various programs and data required for the operation of the electronic device 600 are stored. The processor 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. The processor 601 performs various operations of the method flow according to the embodiments of the present invention by executing programs in the ROM 602 and / or the RAM 603. It should be noted that the program can also be stored in one or more memories other than the ROM 602 and the RAM 603. The processor 601 can also perform various operations of the method flow according to the embodiments of the present invention by executing the program stored in the one or more memories.
[0135] According to an embodiment of the present invention, the electronic device 600 may further include an input / output (I / O) interface 605, and the input / output (I / O) interface 605 is also connected to the bus 604. The electronic device 600 may further include one or more of the following components connected to the input / output (I / O) interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including, for example, a cathode ray tube (CRT), a liquid crystal display (LCD), etc. and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the input / output (I / O) interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed so that a computer program read from it can be installed into the storage section 608 as needed.
[0136] The present invention also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or may exist alone without being assembled into the device / apparatus / system. The above computer-readable storage medium carries one or more programs, and when the one or more programs are executed, the method according to the embodiments of the present invention is implemented.
[0137] According to an embodiment of the present invention, the computer-readable storage medium may be a non-volatile computer-readable storage medium, for example, it may include but is not limited to: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above. In the present invention, the computer-readable storage medium may be any tangible medium that contains or stores a program, and this program can be used by or in conjunction with an instruction execution system, apparatus, or device. For example, according to an embodiment of the present invention, the computer-readable storage medium may include the ROM 602 and / or RAM 603 described above and / or one or more memories other than the ROM 602 and RAM 603.
[0138] An embodiment of the present invention also includes a computer program product, which includes a computer program that contains program code for executing the method shown in the flowchart. When the computer program product runs in a computer system, the program code is used to enable the computer system to implement the method for testing the database response time provided by the embodiment of the present invention.
[0139] When the computer program is executed by the processor 601, it executes the above functions defined in the system / apparatus of the embodiment of the present invention. According to an embodiment of the present invention, the above-described systems, apparatuses, modules, units, etc. can be implemented by computer program modules.
[0140] In one embodiment, the computer program may rely on tangible storage media such as optical storage devices and magnetic storage devices. In another embodiment, the computer program may also be transmitted and distributed in the form of a signal on a network medium, and be downloaded and installed through the communication part 609, and / or be installed from the removable medium 611. The program code included in the computer program can be transmitted using any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0141] In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 609, and / or be installed from the removable medium 611. When the computer program is executed by the processor 601, it executes the above functions defined in the system of the embodiment of the present invention. According to an embodiment of the present invention, the above-described systems, devices, apparatuses, modules, units, etc. can be implemented by computer program modules.
[0142] According to embodiments of the present invention, program code for executing the computer programs provided by the embodiments of the present invention can be written in any combination of one or more programming languages. Specifically, these computing programs can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, such as Java, C++, Python, the "C" language, or similar programming languages. The program code can be executed entirely on the user's computing device, partially on the user device, partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (for example, by using an Internet service provider to connect through the Internet).
[0143] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagram can represent a module, a program segment, or a part of code that contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram or flowchart, and the combination of blocks in the block diagram or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.
[0144] Those skilled in the art can understand that the features described in the various embodiments of the present invention can be combined and / or combined in various ways, even if such combinations or combinations are not explicitly described in the present invention. In particular, without departing from the spirit and teachings of the present invention, the features described in the various embodiments of the present invention can be combined and / or combined in various ways. All such combinations and / or combinations fall within the scope of the present invention.
[0145] The above describes the embodiments of the present invention. However, these embodiments are for illustrative purposes only and are not intended to limit the scope of the present invention. Although the embodiments have been described separately above, this does not mean that the measures in the respective embodiments cannot be used advantageously in combination. Without departing from the scope of the present invention, those skilled in the art can make various substitutions and modifications, and all such substitutions and modifications should fall within the scope of the present invention.
Claims
1. A method for testing the response time of a database, characterized in that, The method includes: In response to receiving a test request, based on the test request, determining at least one structured query statement for testing a database, where the test request includes test conditions, the test conditions include hardware resource configuration parameters, data volume parameters, and concurrency volume parameters, and the concurrency volume parameter characterizes the concurrency volume of at least one of the structured query statements; Obtaining an execution plan and hardware resource consumption parameters when the database executes each of the structured query statements; Determining at least one database operator used by the database when executing the structured query statement according to the execution plan; Determining respective sub-hardware resource consumption parameters for each of the database operators according to at least one of the database operators, the hardware resource consumption parameters, and table information of the data table corresponding to the structured query statement, where the table information includes: table structure information, table data volume information, and table index information; Determining hardware resource consumption information according to each of the database operators and the respective sub-hardware resource consumption parameters of each of the database operators, where the hardware resource consumption information includes at least one of the database operators and the respective sub-hardware resource consumption parameters of each of the database operators; and Based on the hardware resource consumption information, the hardware resource configuration parameters, the data volume parameters, and the concurrency volume parameters, determining the response time of the database for executing each of the structured query statements under the test conditions.
2. The method according to claim 1, characterized in that, The determining, based on the test request, at least one structured query statement for testing a database includes: In response to determining that the test request includes a database script for testing the database, obtaining at least one initial structured query statement in the database script; and Based on at least one of the initial structured query statements and the data stored in the database, determining at least one of the structured query statements.
3. The method according to claim 2, wherein The determining, based on at least one of the initial structured query statements and the data stored in the database, at least one of the structured query statements includes: In response to determining that there is a query parameter with a missing parameter value in the initial structured query statement, querying the data stored in the database according to the field name corresponding to the query parameter to obtain target data, where the query parameter is used to locate the row where the data to be queried corresponding to the initial structured query statement is located; and Based on the target data, determining the parameter value of the query parameter in the initial structured query statement to obtain the structured query statement.
4. The method according to claim 2, wherein The method further includes: Obtaining the structured query statement for testing the database from the test request.
5. The method according to claim 1, characterized in that The determining, based on the hardware resource consumption information, the hardware resource configuration parameters, the data volume parameters, and the concurrency volume parameters, the response time of the database for executing each of the structured query statements under the test conditions includes: For each of the structured query statements, input the hardware resource configuration parameters, the data volume parameters, the concurrency parameters, and the hardware resource consumption information of the structured query statement into a time prediction model to obtain the response time corresponding to the structured query statement.
6. The method according to any one of claims 1 to 5, characterized in that, The method further includes: Based on the response time corresponding to each of the structured query statements, determine, from at least one of the structured query statements, a target structured query statement whose response time is greater than a preset threshold; and Based on the target structured query statement and the data table corresponding to the target structured query statement, determine target influence information from multiple influence information, where the multiple influence information includes: the table index information of the data table, the table structure information of the data table, and the target structured query statement.
7. A test device for database response time, characterized in that The apparatus includes: A statement determination module, configured to, in response to receiving a test request, based on the test request, determine at least one structured query statement for testing a database, where the test request includes test conditions, and the test conditions include hardware resource configuration parameters, data volume parameters, and concurrency parameters, and the concurrency parameters characterize the concurrency of at least one of the structured query statements; A parameter acquisition module, configured to acquire an execution plan and hardware resource consumption parameters when the database executes each of the structured query statements; A consumption determination module, configured to, based on the table information of the data table corresponding to each of the structured query statements, the execution plan, and the hardware resource consumption parameters, determine the hardware resource consumption information when the database executes each of the structured query statements, where the table information includes: table structure information, table data volume information, and table index information; and A time determination module, configured to, based on the hardware resource consumption information, the hardware resource configuration parameters, the data volume parameters, and the concurrency parameters, determine the response time when the database executes each of the structured query statements under the test conditions; Wherein, the consumption determination module includes: An operator determination sub-module, configured to, according to the execution plan, determine at least one database operator used when the database executes the structured query statement; A parameter determination sub-module, configured to, according to at least one of the database operators, the hardware resource consumption parameters, and the table information of the data table corresponding to the structured query statement, determine the sub-hardware resource consumption parameters of each of the database operators; An information determination sub-module, configured to, according to each of the database operators and the sub-hardware resource consumption parameters of each of the database operators, determine the hardware resource consumption information, and the hardware resource consumption information includes at least one of the database operators and the sub-hardware resource consumption parameters of each of the database operators.
8. An electronic device, including: One or more processors; A memory, configured to store one or more computer programs, Characterized in that the one or more processors execute the one or more computer programs to implement the steps of the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program or instructions stored thereon, characterized in that, When the computer program or instruction is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Task queue execution time prediction method and device and implementation device
CN109901921A
Method and device for determining distributed keys in distributed database and electronic equipment
CN119149644A
Request processing method and device based on distributed database
CN119166363A