Test load generation method and device, storage medium and electronic equipment
By generating functions and finite state machines to generate test data and query statements, the problem of single query types and cardinality in the existing technology is solved, and comprehensive testing and accurate performance evaluation of the database system are achieved.
Patent Information
- Application Number
- CN202510624457.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-15
- Publication Date
- 2025-08-29
AI Technical Summary
The test query statements generated by the existing technology are too simple and have a single query type, which cannot meet the testing requirements of complex query types and arbitrary query cardinality, resulting in inaccurate database system performance testing.
The generation function is used to generate test data, and a finite state machine is built with the operator and data attributes of the query statement as the state, and the state jump path is randomly generated. The target query statement template is instantiated based on the query cardinality, and a test query statement that meets any query cardinality is generated.
It realizes comprehensive testing of the database system, can meet the customized testing requirements of any query cardinality, and improves the accuracy of cardinality estimate performance testing of the query optimizer.
Smart Images

Figure CN120560967A_ABST
Abstract
Description
Technical Field
[0001] This specification relates to the field of computer technology, and in particular to a method, device, storage medium, and electronic device for generating a test load. Background Art
[0002] Currently, database systems have been widely used in various fields. How to test the performance of database systems and their components is an important issue in the field of database technology.
[0003] Generally, when performing performance testing on a database system or its components, you need to generate a test load consisting of test data and test query statements according to the test requirements. The test data is stored in the database system, and the test query statements are used to query the test data. Testing is then performed based on the query results or intermediate results during the query process.
[0004] For example, the query optimizer is one of the core components of a database system. A key task of the query optimizer is cardinality estimation. That is, based on the stored data in the database system and the input query statement, it estimates the number of query results. Subsequently, a more optimized query plan can be generated and executed based on the estimated number of query results, so as to execute the query as efficiently and cost-effectively as possible. When testing the cardinality estimation performance of the query optimizer in a database system, it is necessary to first generate 1000 test data and test query statements and determine the number of query results (i.e., the query cardinality) that can be retrieved using the test query statement from these 1000 test data. Assuming the query cardinality is 200, after storing these test data in the database system, when using the test query statement to query, the difference between the cardinality estimated by the query optimizer for this query and the known query cardinality of 200 is determined. The smaller the difference, the better the cardinality estimation performance of the query optimizer; otherwise, the worse the performance.
[0005] However, the test query statements generated by various testing tools in the existing technology are too simple, and the query types are relatively single. They do not support more complex query types such as various forms of connections between tables, and cannot meet the requirements of arbitrary query cardinality, resulting in the inability to accurately test the database system. Summary of the Invention
[0006] The embodiments of this specification provide a method, device, storage medium, and electronic device for generating a test load to partially solve the problems existing in the above-mentioned prior art.
[0007] The embodiments of this specification adopt the following technical solutions:
[0008] This specification provides a method for generating a test load, the method comprising:
[0009] Determine a generating function for generating test data according to the characteristic configuration of the data to be tested;
[0010] Generate test data using the generating function;
[0011] generating a finite state machine with attributes of the test data and operators of the query statement as states;
[0012] Randomly generating a state jump path according to the jump relationship between different states in the finite state machine;
[0013] Generate a target query statement template according to the states included in the state jump path;
[0014] According to the required query cardinality and the generating function, the target query statement template is instantiated to obtain a test query statement corresponding to the required query cardinality.
[0015] This specification provides a device for generating a test load, the device comprising:
[0016] A function generation module, configured to determine a generation function for generating test data according to a characteristic configuration of the data to be tested;
[0017] A data generation module, configured to generate test data using the generation function;
[0018] A state machine generation module, configured to generate a finite state machine with attributes of the test data and operators of the query statement as states;
[0019] A path generation module, configured to randomly generate a state jump path according to the jump relationship between different states in the finite state machine;
[0020] A query template generation module, configured to generate a target query statement template according to the states included in the state jump path;
[0021] The instantiation module is used to instantiate the target query statement template according to the required query cardinality and the generation function to obtain a test query statement corresponding to the required query cardinality.
[0022] This specification provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the above-mentioned test load generation method.
[0023] This specification provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the above-mentioned test load generation method is implemented.
[0024] At least one of the above technical solutions adopted in the embodiments of this specification can achieve the following beneficial effects:
[0025] The embodiment of this specification discloses a method for generating a test load, which uses a generation function that conforms to the data feature configuration to generate test data, and uses the attributes of the test data and the operators of the query statement as states to generate a finite state machine, randomly generates a state jump path based on the jump relationship between different states in the finite state machine, generates a target query statement template based on the state jump path, and finally instantiates the target query statement template according to the required query cardinality and the generation function to obtain the test query statement corresponding to the required query cardinality. Since all attributes of the test data and all operators of the query statement are used as the states of the finite state machine, the query statement template corresponding to the randomly generated state jump path can theoretically traverse all query types, and the target query statement template is instantiated according to the required query cardinality and the generation function, so that the number of query results obtained by querying the generated test data by the instantiated test query statement is the required query cardinality, thereby meeting the customized test requirements of the query cardinality of any required test. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The drawings described herein are used to provide a further understanding of this specification and constitute a part of this specification. The exemplary embodiments and descriptions of this specification are used to explain this specification and do not constitute an improper limitation of this specification. In the drawings:
[0027] Figure 1 A flow chart of a method for generating a test load provided in an embodiment of this specification;
[0028] Figure 2 A partial schematic diagram of a finite state machine generated by a generation tool provided in an embodiment of this specification;
[0029] Figure 3 A schematic diagram of a test load generation device provided in an embodiment of this specification;
[0030] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this specification. DETAILED DESCRIPTION
[0031] When testing database systems, the test load primarily consists of test data and test query statements. The typical testing method involves storing the test data in the database system under test, using test query statements to query the test data in the database system under test, and then testing the database system based on the query results or intermediate results during the query process. Therefore, to meet various testing needs, the test load requirements can be summarized into the following three aspects:
[0032] 1. The characteristics of the generated test data meet the test requirements;
[0033] 2. The query type of the generated test query statement meets the test requirements;
[0034] 3. The query cardinality of the test query statement meets the test requirements.
[0035] The following describes in detail the method for generating test loads provided in the embodiments of this specification based on the test requirements in the above three aspects.
[0036] To make the objectives, technical solutions, and advantages of this specification more clear, the following will clearly and completely describe the technical solutions of this specification in conjunction with the specific embodiments of this specification and the corresponding drawings. Obviously, the embodiments described are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without making any creative efforts are within the scope of protection of this specification.
[0037] The technical solutions provided by the embodiments of this specification are described in detail below with reference to the accompanying drawings.
[0038] Figure 1 A flow chart of a method for generating a test load provided in an embodiment of this specification includes the following steps:
[0039] S100: Determine a generation function for generating test data according to the feature configuration of the data to be tested.
[0040] In the embodiments of this specification, the Figure 1 The device for generating the test load using the method shown can be any electronic device, such as a computer, a server, etc. Specifically, a test load generation tool can be installed on the device, and the test load can be generated by the generation tool.
[0041] When users generate test loads through this generation tool, they need to first generate a configuration file based on the test requirements. The configuration file includes the above three requirements for the test load to be generated. Then, the configuration file is input into the generation tool, and the generation tool can generate the corresponding test load based on the configuration file.
[0042] Specifically, regarding the first aspect above, i.e., the requirements for generated test data, the user can write the feature configuration of the test data to be generated into the configuration file. The feature configuration described in the embodiments of this specification may include: table features of the tables in the test data and data column features of each column in each table.
[0043] Since data in a database usually exists in the form of tables, the table features in the above feature configuration reflect the user's requirements for the generated tables, which may specifically include the number of tables to be generated, the primary and foreign key relationships between tables, etc.
[0044] The data column characteristics reflect the user's requirements for the column values of each column in each table, and may include the distribution of column values (such as whether they are evenly distributed) and the dependencies between columns.
[0045] Correspondingly, the generation tool can generate a table with the table characteristics according to the table characteristics in the above feature configuration, and then determine the generation function corresponding to each column in the generated table according to the data column characteristics in the feature configuration.
[0046] For example, assuming that two tables are to be generated, there is a column between the two tables as a primary-foreign key relationship, there is no dependency between the different columns of each table, and the column values are evenly distributed, then in step S100, the generation tool can first generate the following two tables, Table 1 and Table 2.
[0047] ID Name
[0048] Table 1
[0049] Name Gender Orders
[0050] Table 2
[0051] As can be seen from Table 1 and Table 2 above, the generation tool generated two tables. Table 1 uses ID as the primary key, and Table 2 uses Name as the primary key. Table 1 and Table 2 have a primary-foreign key relationship based on Name, which meets the table characteristics in the feature configuration.
[0052] Next, the generation tool can select a generating function paradigm that meets the data column characteristics from the preset generating function paradigms based on the data column characteristics in the feature configuration, and further construct parameters in the selected generating function paradigm based on the data column characteristics to obtain a generating function corresponding to each column in each generated table. In the above example, since the data column characteristics in the feature configuration are that there is no dependency between different columns and the column values are uniformly distributed, the generation tool can select a generating function paradigm corresponding to the preset uniform distribution for each column in Table 1 and Table 2, and construct parameters in the generating function paradigm to obtain a generating function corresponding to each column, and then generate column values for each column in the two tables through the subsequent step S102.
[0053] S102: Generate test data using the generation function.
[0054] Continuing with the above example, the column values generated by the generation tool for Table 1 and Table 2 using the generation function can be shown in Table 3 and Table 4.
[0055] ID Name 001 name1 002 name2 …… ……
[0056] Table 3
[0057] Name Gender Orders name1 F 2 name2 M 2 name3 F 4 name4 M 4 …… …… ……
[0058] Table 4
[0059] As can be seen from Table 3, in Table 3, each different ID corresponds to a different Name. Assuming that there are 1000 data items (i.e. 1000 rows) in Table 1, the probability of each different column value in the Name column appearing is 1 / 1000, which meets the requirement of uniform distribution.
[0060] As shown in Table 4, the Gender column has only two possible values: F and M. Therefore, the generation tool can adjust the parameters in the generating function formula corresponding to the uniform distribution to ensure that the number of data with a value of F and a value of M generated by the generating function is equal, both 500, to meet the uniform distribution requirement. The Orders column has multiple possible values. Therefore, the generation tool can adjust the parameters in the generating function formula corresponding to the uniform distribution to ensure that the probability of each different column value in the column is the same to meet the uniform distribution requirement. For example, in Table 4, the probability of a column value of 2 and a column value of 4 are the same, both 2 / 1000. The probabilities of other different column values also need to be 2 / 1000.
[0061] At this point, through the feature configuration in the configuration file, the generation tool can generate test data that meets the test requirements by generating a table that meets the table features in the feature configuration and a generation function that meets the data column features, thereby meeting the above-mentioned first aspect of the test data requirements.
[0062] S104: Generate a finite state machine with the attributes of the test data and the operators of the query statement as states.
[0063] In the embodiment of the present specification, after the generation tool generates the test data through the above step S102, all attributes of the test data and all operators of the query statement can be used as states of the finite state machine, thereby generating a finite state machine.
[0064] The test data attributes include table identifiers and column identifiers, and the query statement operators include all possible operators in the query statement, including select, *, from, where, join, on, <, >, =, between, and, or, etc. Each different state corresponds to a table identifier, a column identifier, or an operator.
[0065] There are jump relationships between different states, and the jump probability of each jump relationship can be determined by the query type distribution of the required test written in the configuration file.
[0066] Specifically, the user can write the distribution of different query types in the test query statements to be generated into the configuration file to meet the query type distribution requirement of the second aspect mentioned above. For example, the user can write in the configuration file that the filter type query is 20%, the chain connection type query is 40%, and the ring connection type query is 40%. Since the operators used in the query statements of different filter types are different, the generation tool can determine the jump probability between different states in the finite state machine based on the query type distribution of the test to be written in the configuration file, such as Figure 2 shown.
[0067] Figure 2 This is a partial schematic diagram of a finite state machine generated by a generation tool provided in an embodiment of this specification. Figure 2 The jump probability between different states can be determined according to the query type distribution required for testing written in the configuration file. Figure 2 The finite state machine shown is only a portion of a complete finite state machine.
[0068] S106: randomly generating a state jump path according to the jump relationship between different states in the finite state machine.
[0069] After determining the above finite state machine and the jump probabilities between different states therein, the generation tool can use a random walk algorithm to randomly generate state jump paths.
[0070] Specifically, the generation tool may determine the starting point of the state jump path according to preset rules. The preset rules may be, for example: the state corresponding to the select operator must be the starting point, the path length must be at most 10 hops, and so on.
[0071] In the process of random walk, we can first determine the starting state as the target state, and then determine the other states that the target state can jump to based on the jump relationship between different states, and determine the next state among all other states based on the jump probability of the target state to jump to each other state, complete one step of walk, and then redetermine the next state as the target state, and continue to walk according to the redetermined target state until the termination condition is met, and determine the path of the walk as the state jump path. Figure 2 As shown, the state jump path of the random walk is represented by a dotted line.
[0072] S108: Generate a target query statement template according to the states included in the state jump path.
[0073] After the state transition path is generated in step S108, the generation tool can generate a target query statement template based on the states included in the state transition path and the transition relationships between the states included in the state transition path. Specifically, the states included in the state transition path can be spliced forward and backward according to their transition relationships on the state transition path to obtain the target query statement template.
[0074] Still Figure 2 Take the following as an example to illustrate: Figure 2 The states and their jump relationships on the state jump path shown by the dotted line can be spliced forward and backward according to the jump relationships, and the resulting target query statement template is "select * from table2 where Orders>".
[0075] The generation tool can repeatedly execute the above step S108 to obtain multiple query statement templates by randomly walking in the finite state machine. Since the jump probability between different states in the finite state machine is determined and set according to the query type distribution to be tested in the configuration file, by repeatedly executing step S108 to obtain multiple query statement templates, multiple query statement templates that meet the query type distribution requirements can be obtained, thereby meeting the test requirements of the second aspect mentioned above.
[0076] S110: Instantiating the target query statement template according to the required query cardinality and the generation function to obtain a test query statement corresponding to the required query cardinality.
[0077] Obviously, the above "select * from table2 where Orders>" isn't an instantiated query statement; it's just a query statement template and can't be executed. Therefore, after obtaining the target query statement template, the generation tool needs to instantiate it. That is, add parameters to the target query statement template to generate the corresponding executable test query statement.
[0078] Specifically, for the test requirements of the third aspect mentioned above, the user can write the query cardinality required for the test into the configuration file, and the generation tool can determine the parameters that need to be added to the target query statement template based on the required query cardinality in the configuration file and the generation function determined in step S100, and add the parameters to the target query statement template to instantiate the target query statement template into an executable query statement, i.e., a test query statement, so that when the test query statement is used to query the test data generated in step S102, the number of query results is the required query cardinality.
[0079] Among them, since the required query cardinality is known, the generation function corresponding to the test data for each column is also known, the tables and columns required to be queried in the target query statement template can be determined by the table identifier and column identifier in the target query statement template, and the operators contained in the target query statement template are also known. Therefore, based on the required query cardinality and generation function, as well as the operators in the target query statement template and the tables and columns required to be queried, it can be inferred which parameters can make the number of query results of the instantiated query statement querying the test data equal to the query cardinality.
[0080] Specifically, the generation tool can determine each selection predicate template based on each operator in the target query statement template. For each selection predicate template, the table identifier corresponding to the selection predicate template is used as the target table identifier, and the column identifier corresponding to the selection predicate template is used as the target column identifier. According to the generation function corresponding to the target column identifier in the table corresponding to the target table identifier and the required query cardinality, the column value corresponding to the target column identifier is determined, and the column value is added as a parameter to the selection predicate template to obtain an instantiated selection predicate. Finally, based on the selection predicate obtained for each selection predicate template, the test query statement corresponding to the required query cardinality is obtained.
[0081] For example, assuming that Table 4 is the table identified by "table2" and the target query statement template is "select * from table2 where Orders>", the generation tool can determine the selection predicate template to be "where Orders>" based on the operators in the target query statement template. Since the target table identifier corresponding to the selection predicate template is "table2" and the target column identifier is "Orders", assuming the required query cardinality is 500, that is, the generated test query statement needs to retrieve 500 query results when querying the test data shown in Table 4. Since the column values of the Orders column in the test data shown in Table 4 generated by the generation tool are evenly distributed, the generation function of the column value can be determined to be two 2s, two 4s, two 6s, and so on. Therefore, the generation tool can determine that if 500 query results are to be retrieved, the column value to be added to the selection predicate template "where Orders>" is 500. That is, the selection predicate "where Orders>500" can retrieve 500 query results from Table 4. Therefore, the test query statement is "select * from table2 where Orders>500".
[0082] Specifically, when determining the parameters that need to be added to the target query statement template, the generation tool can determine the cumulative distribution function of the column value based on the generation function, and determine the required parameters based on the required query cardinality and the cumulative distribution function. Generally, the input of the cumulative distribution function of the column value is a given column value, and the output is the ratio of the number of data with column values not greater than the given column value to the total number of data in the table. Since the number of test data in each table generated in step S102 is known, the cumulative distribution function can be used to infer the required given column value if the query result of the above query cardinality is to be queried. This given column value is the parameter that needs to be added to the target query statement template.
[0083] Of course, after generating the test data in step S102, the column values of each column in the table may be grouped, such that identical column values are grouped together and different column values are grouped together. When determining the parameters to be added to the target query statement template, the groups to be included in the query result may be determined based on the required query cardinality, the operators in the target query statement template, and the cumulative distribution function of the column. The parameters to be added to the target query statement template may then be determined based on the column values in each group.
[0084] In addition, the above description only uses a simple screening query type as an example. If the query type is more complex, such as a ring join query type, the parameters that need to be added to the target query statement template using the above method may be inaccurate, resulting in the instantiated test query statement not being able to query the test data with the required query cardinality. Therefore, in the embodiment of this specification, after the target query statement template is instantiated to obtain a test query statement, the actual query cardinality of the test data generated in step S102 using the test query statement can be determined based on the test query statement and each generation function. This is because if the query type is more complex, it is relatively difficult to reversely infer the parameters that need to be added to the target query statement template from the required query cardinality. However, if the generation function of each column in each table is known and the instantiated query statement is known, it is relatively simple to determine the query cardinality of the query statement. Therefore, the generation tool can determine the actual query cardinality of the test query statement based on the test query statement and the generation function. Of course, the actual query cardinality can also be determined by directly querying the test data using a test query statement and determining the number of query results. However, this actually executes the test query statement, which wastes database system resources. To conserve database system resources, the test query statement can be omitted and the cardinality can be determined based on the generator function for each column determined in step S100 and the instantiated test query statement.
[0085] After determining the actual query cardinality of the test query statement, the generation tool can determine the difference between the actual query cardinality and the required query cardinality in the configuration file. If the difference is greater than a preset difference threshold, a preset optimization algorithm can be used to adjust the parameters in the test query statement with the optimization goal of minimizing the difference between the actual query cardinality and the required query cardinality. For example, a genetic algorithm can be used to adjust several parameters in the test query statement and determine the difference between the actual query cardinality and the required query cardinality of the adjusted test query statement. If the difference decreases, adjustments are continued based on the adjusted test query statement. Otherwise, adjustments are readjusted based on the test query statement before adjustment until the difference falls within the preset difference range, at which point the test query statement at this point is used as the final test query statement.
[0086] At this point, in response to the query cardinality requirement of the third aspect mentioned above, the method provided in this specification can also meet it by using the required query cardinality and generating function to reversely infer the parameters required for instantiation. Even if the parameters obtained by reverse inference still cannot meet the required query cardinality, the parameters in the test query statement can still be optimized through the optimization algorithm until the optimized test query statement can meet the required query cardinality.
[0087] Therefore, the test data and test query statements generated by the above method can be integrated into the test load and meet the above three test requirements at the same time.
[0088] Furthermore, due to Figure 1 During the test load generation process shown, step S108 may need to be repeatedly executed to generate multiple target query statement templates based on the query type distribution required in the configuration file. Therefore, it is necessary to prevent the generation tool from generating duplicate query statement templates. Specifically, after the generation tool generates a target query statement template and before instantiating it, the generated query statement templates other than the current target query statement template may be used as existing query statement templates, and the similarity between the current target query statement template and each existing query statement template is determined. If there is an existing query statement template whose similarity to the current target query statement template is greater than a preset similarity threshold, it indicates that the current target query statement template is a duplicate of the existing query statement template. The target query statement template can be discarded and regenerated. If there is no existing query statement template whose similarity to the current target query statement template is greater than the preset similarity threshold, it indicates that the current target query statement template is unique to all existing query statement templates and the current target query statement template can be retained.
[0089] Among them, when determining the similarity between the current target query statement template and each existing query statement template, the generation tool can use the target query statement template and each existing query statement template as a graph structure, and use a pre-trained encoder to determine the encoding vector of the target query statement template and the encoding vector of each existing query statement template, and then determine the similarity between the current target query statement template and each existing query statement template based on the encoding vector of the target query statement template and the encoding vector of each existing query statement template, such as determining the similarity between the current target query statement template and the existing query statement template based on the cosine distance or Euclidean distance between the encoding vector of the current target query statement template and the encoding vector of the existing query statement template.
[0090] In the embodiment of the present specification, after the generation tool obtains a test load that simultaneously meets the above three test requirements, the test load can be used to test the database system to be tested. For example, when testing the cardinality estimation performance of the query optimizer of the database system, the test data in the test load can be stored in the database system to be tested, and for each test query statement in the test load, the test data in the database system to be tested is queried using the test query statement to determine the difference between the cardinality estimated by the query optimizer during the query process and the query cardinality corresponding to the test query statement. The smaller the difference, the better the cardinality estimation performance of the query optimizer, and vice versa. The worse the cardinality estimation performance of the query optimizer. Of course, the above is only an example of testing the cardinality estimation performance of the query optimizer. Those skilled in the art should understand that the test load generated above can be used to perform any required test on the database system to be tested, such as testing the query efficiency of the database system under the condition of a specified query cardinality.
[0091] The above is a method for generating a test load provided in an embodiment of this specification. Based on the same idea, this specification also provides corresponding devices, storage media, and electronic devices.
[0092] Figure 3 A schematic diagram of a test load generation device provided in an embodiment of this specification, the device comprising:
[0093] Function generation module 301, used to determine a generation function for generating test data according to the feature configuration of the data to be tested;
[0094] A data generating module 302 is configured to generate test data using the generating function;
[0095] A state machine generation module 303 is used to generate a finite state machine with attributes of the test data and operators of the query statement as states;
[0096] A path generation module 304 is configured to randomly generate a state jump path according to the jump relationship between different states in the finite state machine;
[0097] A query template generating module 305 is configured to generate a target query statement template according to the states included in the state jump path;
[0098] The instantiation module 306 is configured to instantiate the target query statement template according to the required query cardinality and the generation function to obtain a test query statement corresponding to the required query cardinality.
[0099] Optionally, the function generating module 301 is specifically configured to generate a table having the table features according to the table features in the feature configuration; and determine a generating function corresponding to each column in the generated table according to the data column features in the feature configuration;
[0100] The data generation module 302 is specifically configured to generate test data for each column in the table by using a generation function corresponding to the column.
[0101] Optionally, the path generation module 304 is further configured to determine the jump probability between different states in the finite state machine according to the query type distribution required to be tested before randomly generating the state jump path.
[0102] Optionally, the path generation module 304 is specifically configured to randomly generate a state jump path using a random walk algorithm according to the jump relationship and jump probability between different states in the finite state machine.
[0103] Optionally, the instantiation module 306 is further configured to, before instantiating the query statement template, use the generated query statement templates other than the target query statement template as existing query statement templates, and determine that the similarity between the target query statement template and each existing query statement template is not greater than a preset similarity threshold.
[0104] Optionally, the attributes of the test data include table identifiers and column identifiers;
[0105] The instantiation module 306 is specifically configured to determine each selection predicate template based on each operator in the target query statement template; for each selection predicate template, use the table identifier corresponding to the selection predicate template as the target table identifier, and the column identifier corresponding to the selection predicate template as the target column identifier; determine the column value corresponding to the target column identifier based on the generating function corresponding to the target column identifier in the table corresponding to the target table identifier and the required query cardinality; add the column value as a parameter to the selection predicate template to obtain an instantiated selection predicate; and obtain a test query statement corresponding to the required query cardinality based on the selection predicate obtained for each selection predicate template.
[0106] Optionally, the instantiation module 306 is further used to determine, based on the test query statement and each generation function, an actual query cardinality for querying the test data using the test query statement; if the difference between the actual query cardinality and the required query cardinality is greater than a preset difference threshold, a preset optimization algorithm is used to adjust the parameters in the test query statement with the optimization goal of minimizing the difference between the actual query cardinality and the required query cardinality.
[0107] This specification also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it can be used to execute the test load generation method provided above.
[0108] based on Figure 1 The test load generation method shown in the embodiment of this specification also provides Figure 4 The structural diagram of the electronic device shown in FIG. Figure 4 At the hardware level, the electronic device includes a processor, an internal bus, a network interface, memory, and non-volatile storage, and may also include other hardware required for its operations. The processor reads the corresponding computer program from the non-volatile storage into the memory and then runs it to implement the above-mentioned test load generation method.
[0109] The foregoing is merely an example of the present invention and is not intended to limit the present invention. Various modifications and variations are possible for those skilled in the art. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present invention are intended to be included within the scope of the claims of the present invention.
Claims
1. A method for generating a test load, the method comprising: Determine a generating function for generating test data according to the characteristic configuration of the data to be tested; Generate test data using the generating function; generating a finite state machine with attributes of the test data and operators of the query statement as states; Randomly generating a state jump path according to the jump relationship between different states in the finite state machine; Generate a target query statement template according to the states included in the state jump path; According to the required query cardinality and the generating function, the target query statement template is instantiated to obtain a test query statement corresponding to the required query cardinality.
2. The method according to claim 1, wherein determining a generating function for generating test data based on the characteristic configuration of the data to be tested specifically comprises: generating a table having the table features according to the table features in the feature configuration; Determine, according to the data column features in the feature configuration, a generating function corresponding to each column in the generated table; Generating test data using the generating function specifically includes: For each column in the table, a generating function corresponding to the column is used to generate test data for the column.
3. The method according to claim 1, before randomly generating a state jump path, the method further comprises: The jump probability between different states in the finite state machine is determined according to the query type distribution required to be tested.
4. The method according to claim 3, wherein the state jump path is randomly generated according to the jump relationship between different states in the finite state machine, specifically comprising: According to the jump relationship and jump probability between different states in the finite state machine, a random walk algorithm is used to randomly generate a state jump path.
5. The method according to claim 1, before instantiating the query statement template, further comprising: The generated query templates other than the target query template are used as existing query templates, and it is determined that the similarity between the target query template and each existing query template is not greater than a preset similarity threshold.
6. The method according to claim 2, wherein the attributes of the test data include a table identifier and a column identifier; Instantiating the target query statement template to obtain a test query statement corresponding to the required query cardinality specifically includes: Determining each selection predicate template according to each operator in the target query statement template; For each selection predicate template, the table identifier corresponding to the selection predicate template is used as the target table identifier, the column identifier corresponding to the selection predicate template is used as the target column identifier, and according to the generating function corresponding to the target column identifier in the table corresponding to the target table identifier and the required query cardinality, the column value corresponding to the target column identifier is determined, and the column value is added as a parameter to the selection predicate template to obtain an instantiated selection predicate; According to the selection predicate obtained for each selection predicate template, a test query statement corresponding to the required query cardinality is obtained.
7. The method of claim 6, further comprising: Determining, based on the test query statement and each generating function, an actual query cardinality of querying the test data using the test query statement; If the difference between the actual query cardinality and the required query cardinality is greater than a preset difference threshold, a preset optimization algorithm is used to adjust the parameters in the test query statement with minimizing the difference between the actual query cardinality and the required query cardinality as the optimization goal.
8. A device for generating a test load, the device comprising: A function generation module, configured to determine a generation function for generating test data according to a characteristic configuration of the data to be tested; A data generation module, configured to generate test data using the generation function; A state machine generation module, configured to generate a finite state machine with attributes of the test data and operators of the query statement as states; A path generation module, configured to randomly generate a state jump path according to the jump relationship between different states in the finite state machine; A query template generation module, configured to generate a target query statement template according to the states included in the state jump path; The instantiation module is used to instantiate the target query statement template according to the required query cardinality and the generation function to obtain a test query statement corresponding to the required query cardinality.
9. A computer-readable storage medium storing a computer program, wherein the computer program implements the method according to any one of claims 1 to 7 when executed by a processor.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method according to any one of claims 1 to 7 when executing the program.
