Statement generation method, statement generation device and computing equipment

By receiving load characteristic information and database schema information, and using the Monte Carlo algorithm and finite state machine to generate diverse SQL statements, the problem of single SQL statement style in the existing technology is solved, and the portability and performance improvement of the database system are achieved.

CN120670446APending Publication Date: 2025-09-19HUAWEI TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410319849.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-03-19
Publication Date
2025-09-19

AI Technical Summary

Technical Problem

Existing technologies make it difficult to generate diverse SQL statements that meet actual needs, resulting in weak portability of database load generation and a single style of generated SQL statements, which cannot meet the diverse requirements of users.

Method used

By receiving load characteristic information and database schema information, it generates SQL statements using Monte Carlo algorithm and finite state machine. It generates diversified SQL statements, including read, write, insert, update and delete operations, simulating actual database operations and improving the portability of load generation.

Benefits of technology

It enriches the styles of SQL statements, improves the performance and responsiveness of the database system, adapts to different types of query and operation requirements, and enhances the portability of database load generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120670446A_ABST
    Figure CN120670446A_ABST
Patent Text Reader

Abstract

The invention discloses a statement generation method, which comprises the following steps of: receiving load characteristic information and database mode information, and obtaining characteristic parameters according to the load characteristic information and the database mode information; determining the statement type of the generated statement according to the feature parameters; and calculating a state transition probability according to the load feature information. In the embodiment of the invention, the load type required by the user can be determined according to the database mode information and the load feature information, and the SQL statement of the load of the determined type is generated according to the load feature information. The styles of the SQL statements of the load generated by the method are more, so that the styles of the SQL statements of the load are enriched, and the load generation mobility is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of database technology, and in particular to a statement generation method, a statement generation device and a computing device. Background Art

[0002] Structured Query Language (SQL) statements are widely used in relational database management systems to perform various database operations, such as queries, updates, and inserts. In real-world production applications, optimization tasks such as database parameter tuning, slow SQL diagnosis, generalization performance testing of database algorithms, cardinality estimation, query optimization, and learning index construction all require large numbers of SQL queries to provide comprehensive performance reports or train artificial intelligence (AI) models. However, due to data privacy concerns and real-world constraints, it is difficult for systems to obtain a large number of authentic and effective SQL queries. Summary of the Invention

[0003] To address the aforementioned issues, embodiments of the present application provide a statement generation method. This method generates a variety of SQL statement styles during load generation, thereby enriching the SQL statement styles and improving the portability of load generation. Furthermore, the present application also provides a statement generation apparatus and computing device corresponding to the statement generation method.

[0004] To this end, the following technical solutions are adopted in the embodiments of the present application:

[0005] In a first aspect, an embodiment of the present application provides a statement generation method, comprising: receiving load characteristic information and database schema information, and obtaining characteristic parameters based on the load characteristic information and the database schema information; the load characteristic information refers to key attributes that describe the operating status and performance of the database system; based on the characteristic parameters, determining the statement type for generating a structured query language SQL statement; based on the load characteristic information, calculating a state transition probability; the state transition probability refers to the transition probability between different query types, and the state transition probability is used to generate one or more characters in a SQL statement of a specified type.

[0006] In this embodiment, the method can be executed by a load generation system. The load generation system can determine the load type required by the user based on database schema information and load characteristic information, and generate SQL statements of the specified type based on the load characteristic information. The load generation system generates a variety of SQL statements, thereby enriching the SQL statement styles and improving the portability of load generation.

[0007] In one embodiment, determining the statement type for generating a structured query language SQL statement based on the characteristic parameters specifically includes: generating a random number based on the characteristic parameters; comparing the random number with the ratio of each statement type in the read-write ratio to determine the ratio of the statement type in which the random number is located, and obtaining the statement type; the characteristic parameters include the read-write ratio, and the read-write ratio includes the ratio of at least two types of statements among the ratio of read statements, the ratio of insert statements, the ratio of delete statements, and the ratio of update statements.

[0008] In this embodiment, the load generation system can determine the statement type of the generated statement based on the characteristic parameters, and route different types of statements to appropriate generation algorithms to achieve efficient processing and optimization for different operations, and better adapt to different types of query and operation requirements to improve the performance and responsiveness of the database system.

[0009] In one embodiment, calculating the state transition probability based on the load characteristic information specifically includes: determining the current state; using a Monte Carlo algorithm to calculate the state transition probability of transferring from the current state to the next state based on the load characteristic information.

[0010] In one embodiment, the method further includes: determining the next state according to the current state and the state transition probability; and generating a character according to the state types of the current state and the next state.

[0011] In one embodiment, the method further includes: recording the number of state transitions; and when the number of state transitions reaches a set number, concatenating the previously generated multiple characters into an SQL statement.

[0012] In the second aspect, an embodiment of the present application provides a statement generation device, including: a first processing unit, used to receive load characteristic information and database schema information, and obtain characteristic parameters based on the load characteristic information and the database schema information; the load characteristic information refers to the key attributes that describe the operating status and performance of the database system; a second processing unit, used to determine the statement type of the generated SQL statement based on the characteristic parameters; a third processing unit, used to calculate the state transition probability based on the load characteristic information; the state transition probability refers to the transition probability between different query types, and the state transition probability is used to generate one or more characters in the SQL statement of the specified type.

[0013] In one embodiment, the second processing unit is specifically used to generate a random number based on the characteristic parameters; the second processing unit is specifically used to compare the random number with the ratio of each statement type in the read-write ratio, determine the ratio of the statement type in which the random number is located, and obtain the statement type; the characteristic parameters include the read-write ratio, and the read-write ratio includes the ratio of at least two types of statements among the ratio of read statements, the ratio of insert statements, the ratio of delete statements, and the ratio of update statements.

[0014] In one embodiment, the third processing unit is specifically used to determine the current state; the third processing unit is specifically used to use a Monte Carlo algorithm to calculate the state transition probability from the current state to the next state according to the load characteristic information.

[0015] In one embodiment, the third processing unit is further used to determine the next state based on the current state and the state transition probability; the third processing unit is further used to generate a character based on the current state and the state type of the next state.

[0016] In one embodiment, the third processing unit is further configured to record the number of state transitions; the third processing unit is further configured to, when the number of state transitions reaches a set number, concatenate the previously generated multiple characters into an SQL statement.

[0017] In a third aspect, an embodiment of the present application provides a computing device, characterized in that it includes: at least one memory; and at least one processor, the processor being used to execute instructions stored in the memory so that the computing device executes various possible implementations of the first aspect.

[0018] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, comprising computer program instructions. When the computer program instructions are executed by a computing device, the computing device executes the various possible implementations of the first aspect.

[0019] In a fifth aspect, an embodiment of the present application provides a computer program product comprising instructions, characterized in that the computer program product stores instructions that, when executed by a computing device, enable the computing device to implement various possible implementation embodiments of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] The following is a brief introduction to the drawings required for describing the embodiments or prior art.

[0021] Figure 1 This is a schematic diagram of the architecture of a load generation system provided in an embodiment of the present application;

[0022] Figure 2 A flowchart of a sentence generation method provided in an embodiment of the present application;

[0023] Figure 3 A schematic diagram of the structure of a sentence generation device provided in an embodiment of the present application;

[0024] Figure 4 A schematic diagram of the structure of a computing device provided in an embodiment of the present application;

[0025] Figure 5 A schematic diagram of the architecture of a computing device cluster provided in an embodiment of the present application;

[0026] Figure 6 This is a schematic diagram of the architecture of another computing device cluster provided in an embodiment of the present application. DETAILED DESCRIPTION

[0027] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.

[0028] The term "and / or" as used herein describes an association between related objects, indicating that three possible relationships exist. For example, "A and / or B" can represent: A exists alone, A and B exist simultaneously, or B exists alone. The symbol " / " as used herein indicates that the related objects are in an "or" relationship, for example, A / B means either A or B.

[0029] The terms "first" and "second" in this specification and claims are used to distinguish different objects rather than to describe a specific order of objects. For example, "first response message" and "second response message" are used to distinguish different response messages rather than to describe a specific order of response messages.

[0030] In the embodiments of this application, words such as "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of this application should not be interpreted as being preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner.

[0031] In the description of the embodiments of the present application, unless otherwise specified, "multiple" means two or more, for example, multiple processing units means two or more processing units, etc.; multiple elements means two or more elements, etc.

[0032] Before introducing the technical solution protected by this application, several professional terms involved in the technical solution protected by this application are explained in advance, namely:

[0033] SQL is a standardized language for managing relational databases. SQL allows users to perform a variety of tasks, including inserting, updating, deleting, and retrieving data, as well as defining and managing database structures such as tables and indexes.

[0034] A finite state machine (FSM) is a mathematical model used to describe a system with a finite number of states and the transitions between these states. An FSM generally consists of several elements: states, transitions, an initial state, and a final state. States refer to the different states a system can be in. These states are finite; each state can only be in one at any given time. Transitions describe the transitions between states. Transitions are typically triggered by certain conditions and cause the system to move from one state to another. The initial state refers to the state the system is in at the beginning. The final state refers to the final state the system can reach, also known as the acceptance state.

[0035] Monte Carlo sampling is a numerical computational method guided by the theory of probability and statistics. It uses random or pseudorandom numbers to solve computational problems. MC sampling is applicable when the problem being solved can be transformed into characteristic numbers of a random distribution, such as the probability of a random event or the expected value of a random variable. Through random sampling, MC sampling estimates the probability of a random event based on its frequency of occurrence, or estimates the numerical characteristics of a random variable based on the sampled numerical characteristics, and uses this as the solution to the problem.

[0036] Database load generation involves evaluating the performance and stability of a database system by simulating workloads found in actual production environments. SQL statements are typically the basic unit used to simulate user requests during load generation. Database load generation is inseparable from the design, execution, and optimization of SQL statements, as they are the core of implementing user requests and operating the database.

[0037] The database in the related art obtains a large number of real and valid SQL queries, and the load generation technology can be used to generate the database load to be as close to the real scene as possible, and to effectively perform performance testing and evaluation while protecting data privacy. The load generation technology of the related art mostly generates database load by analyzing the database pattern and data distribution, such as template-based methods and random model-based methods. However, for the template-based method, the generated load has defects such as lack of flexibility and fixed database schema, and is too dependent on expert templates, which makes such methods have obvious domain color and weak portability. For the random model-based method, the generated load quality is not high, and empty statements and semantically contradictory statements may be generated. In addition, the generated load types are few and highly homogenized.

[0038] In order to solve the defects existing in the related art, an embodiment of the present application provides a statement generation method, which can determine the load type required by the user based on database schema information and load characteristic information, and generate a SQL statement of a certain type based on the load characteristic information. Compared with the related art, different SQL statements are generated by changing or filling in numerical values, resulting in a relatively single style of SQL statements, which cannot meet the diverse requirements of users. The method protected by the present application generates more styles of SQL statements, thereby enriching the styles of SQL statements and improving the portability of load generation.

[0039] Figure 1 This is a schematic diagram of the architecture of a load generation system provided in an embodiment of the present application. Figure 1 As shown, the load generation system 100 can run on one or more computing devices. A computing device can be a server, a computer, a desktop computer, a laptop computer, or the like. The load generation system 100 can be divided into a parsing module 110, a selection module 120, a sampling module 130, a generation module 140, and a processing module 150 based on the execution function of the processor 110. The parsing module 110, the selection module 120, the sampling module 130, the generation module 140, and the processing module 150 can all be implemented in software, hardware, or a combination of software and hardware.

[0040] The parsing module 110 is used to receive load signature information and database schema information, and derive characteristic parameters based on the load signature information and database schema information. Load signature information is a key attribute that describes the operating status and performance of a database system, and typically involves aspects such as the database's workload, query pattern, and concurrency. Load signature information may include query type, number of concurrent queries, query data access pattern, query timing characteristics, data distribution uniformity, error handling load, network load, memory utilization, disk input / output (I / O) load, and cache hit rate.

[0041] In the embodiment of the present application, as shown in Table 1, the load feature information includes semantic features and data access pattern features. Among them, the characteristic meanings of the semantic features include load scale, read-write ratio, the average number of tables involved in each query statement, the average number of logical predicates contained in each query constraint, the average number of aggregate functions contained in each query statement, the average number of grouping (GROUP BY) operations contained in each statement, and the average number of valid attributes of items (ITEM) returned by each query statement. The characteristic meanings of the data access pattern features include the access distribution of the tables involved in the query, the access distribution of the columns involved in the query, the access distribution of the query value range of the columns involved in the query, the access distribution of the comparison constraint type ratio involved in the WHERE clause, and the access distribution of the ascending and descending sort ratio when sorting operations are included.

[0042] Table 1 Feature types and feature meanings of load feature information

[0043]

[0044]

[0045] Database schema information refers to the organizational design of structured data within a database, including metadata such as tables, fields, indexes, and relationships. The design of the database schema directly impacts the performance, scalability, and data management efficiency of the database system. This information can include table structure, indexes, primary and foreign keys, data distribution, data types, constraints, partitioning and sharding strategies, views and stored procedures, triggers, permissions, and security settings.

[0046] The characteristic parameters may be the type of query, the number of concurrent queries, the data access mode of the query (such as sequential access, random access, etc.), the size of the data table, the uniformity of data distribution, the usage of the index, etc. The characteristic parameters include the table name and the parameters of the table. Among them, the table name is determined by the database schema information, and the parameters of the table are determined by the load characteristic information. In an embodiment of the present application, the parsing module 110 can analyze the load characteristic information, such as analyzing the query type in the load, understanding the concurrency of the load, considering the timing characteristics of the load, etc., and analyze the database schema, such as analyzing the table structure of the database, understanding the relationship between tables, considering the data distribution, etc. The parsing module 110 can identify the key information that affects the performance of the database based on the analysis results of the load characteristic information and the analysis structure of the database schema to obtain the characteristic parameters.

[0047] The selection module 120 can select the type of corresponding generation module based on the type of statement to be generated. In the embodiment of the present application, the selection module 120 presets four types of generation modules for processing different types of statements, namely read (READ) statements, insert (INSERT) statements, delete (DELETE) statements, and update (UPDATE) statements. By presetting four different selection methods, the selection module 120 can route different types of statements to the appropriate generation module to achieve efficient processing and optimization for different operations, and can better adapt to different types of query and operation requirements to improve the performance and responsiveness of the database system.

[0048] The read statement selection mode is used to process read statements, such as SELECT queries. In read statement mode, selection module 120 selects a generation module related to the read operation. This generation module is responsible for processing the query request, executing the query plan, retrieving data, and returning the results. The key goal of read statement selection is to provide fast and efficient data retrieval.

[0049] Insert statement selection mode is used to process insert statements, such as INSERT INTO. In insert statement mode, FSM selection module 120 selects the generation module associated with the insert operation. This generation module is responsible for inserting the new data into the appropriate location in the database and ensuring data integrity and consistency. A key goal of insert statement selection is to efficiently process a large number of data insertion requests.

[0050] The delete statement selection mode is used to process delete statements, such as DELETE FROM. In delete statement mode, selection module 120 selects a generation module related to the delete operation. This generation module is responsible for deleting data that meets the specified conditions from the database and updating related indexes and data structures accordingly. The key goal of delete statement selection is to efficiently delete the specified data.

[0051] Update statement selection mode is used to process update statements, such as UPDATE. In update statement mode, selection module 120 selects the generation module associated with the update operation. This generation module enters the "Update" state, where it processes the new field values ​​and locates the records to be updated. The key goal of update statement selection is to change the content of one or more records without changing the total number of records.

[0052] After receiving the characteristic parameters, the sampling module 130 can determine the type of statement to be generated based on the read-write ratio in the characteristic parameters. Since the selection module 120 presets four generation module selection methods: read statement, insert statement, delete statement and update statement, the read-write ratio feature set by the selection module 120 is Tuple<RatioRead,RatioInsert,RatioDelete,RatioUpdate> The read-write ratio feature can be viewed as a probability distribution graph, where each ratio in the distribution graph represents the probability of a corresponding statement type. After receiving the read-write ratio feature, the sampling module 130 can control the expected ratio of the number of various statements in the generated statement set based on the ratios in the read-write ratio feature.

[0053] In an embodiment of the present application, the sampling module 130 can use a random number generator to generate a random number in the range [0, 1] based on the characteristic parameters. The sampling module 130 can compare the generated random number with the ratio in the read-write ratio characteristic and, based on the comparison result, select the statement type for the generated statement based on the generated random value. For example, if the read-write ratio characteristic is Tuple<0.4, 0.3, 0.2, 0.1>, the corresponding read statements, insert statements, delete statements, and update statements in the generated statement set have a ratio of 40%, 30%, 20%, and 10%. The sampling module 130 can use a random number generator to generate a random number x. The sampling module 130 can determine which type of statement to generate based on the value of the random number x. If x < 0.4, a read statement is generated. If 0.4 <= x < 0.7, an insert statement is generated. If 0.7 <= x < 0.9, a delete statement is generated. If x >= 0.9, an update statement is generated.

[0054] Sampling module 130 is also configured to calculate state transition probabilities based on load signature information. State transition probabilities describe the transition probabilities between different query types. For example, if a user specifies an expected read / write ratio and the expected ratios of various query types, sampling module 130 can derive the transition probabilities between different query types based on the expected ratios.

[0055] In an embodiment of the present application, the sampling module 130 can use a sampling algorithm such as a Monte Carlo sampling algorithm and a Markov chain sampling algorithm for sampling. Taking the Monte Carlo sampling algorithm as an example below, the Monte Carlo sampling algorithm can construct a state space representing different query types based on the load characteristic information input by the user, and define the transition relationship between states. Among them, the state refers to the specific state of the system, for example, whether the system is in a query, insert, delete or update state. Each state may have corresponding behaviors and executable operations, as well as possible state transition rules, which determine how the system transitions between different states.

[0056] The Monte Carlo sampling algorithm constructs an initial state transition probability matrix and initializes all transition probabilities to 0. During Monte Carlo sampling, the Monte Carlo sampling algorithm randomly selects a starting state and then generates the next state with a certain probability based on the load characteristics information entered by the user. The Monte Carlo sampling algorithm updates the state transition probability matrix, recording the number of transitions from the current state to the next state. The Monte Carlo sampling algorithm can repeat the Monte Carlo sampling operation multiple times, continuously accumulating the number of state transitions. When the Monte Carlo sampling algorithm reaches a set number of accumulated state transitions, it pauses the sampling operation and stops state transitions to calculate the state transition probabilities through normalization.

[0057] Parameters in the load signature information are generally represented in the form of a probability distribution graph. If a parameter in the load signature information is not represented in the form of a probability distribution graph, the sampling module 130 can convert it using a conversion formula to represent it in the form of a probability distribution graph. For example, taking the feature "the average number of tables queried per statement (denoted as dn)" as an example, if it is assumed that there are at most two table joins, then when sampling the queried tables, it will be converted to:

[0058]

[0059] Finally, the sampling module 130 can use uniform probability distribution to generate diverse results when no load characteristic information is input.

[0060] The generation module 140 is used to enter the next state according to the state transition probability and generate a character. Characters can refer to words, numbers, symbols, etc. In an embodiment of the present application, the generation module 140 can generate characters using a generation algorithm such as FSM. Taking FSM as an example, the sampling module 130 can use a random number generator to generate a random number based on the current state and the state transition probability. FSM can determine the next state based on the random number. Among them, in FSM, the state is usually defined as the value of a set of variables that describe specific aspects of the system or object. The state can be discrete (such as on or off), continuous (such as temperature), finite (such as a state set) or infinite (such as all possible states of the system memory).

[0061] In one embodiment, an FSM has two states, state 1 and state 2. The state transition probabilities of the four statements in state 1 are SELECT:INSERT:DELETE:UPDATE = 0.5:0.2:0.2:0.1. The state transition probabilities of the four statements in state 2 are SELECT:INSERT:DELETE:UPDATE = 0.4:0.3:0.2:0.1.

[0062] Assume that the current state of the FSM is State 1. The FSM determines the next state based on the random number R generated by the sampling module 130. If R is less than or equal to 0.5 (the probability of SELECT), the FSM transitions to State 2 and generates a SELECT statement. If R is between 0.5 and 0.7 (the probability of INSERT), the FSM transitions to State 2 and generates an INSERT statement. If R is between 0.7 and 0.9 (the probability of DELETE), the FSM transitions to State 2 and generates a DELETE statement. If R is greater than 0.9 (the probability of UPDATE), the FSM transitions to State 2 and generates an UPDATE statement.

[0063] The FSM can generate a character based on the state type of the current state and the next state. For example, the FSM can determine that when transitioning from the "initial state" to the "query state", a word "StartQuery" can be generated. The FSM can determine that when transitioning from the "query state" to the "initial state", a word "QueryEnd" can be generated. The FSM can determine that when transitioning from the "initial state" to the "insert state", a word "StartInsert" can be generated. The FSM can determine that when transitioning from the "insert state" to the "initial state", a word "InsertEnd" can be generated. The FSM can determine that when transitioning from the "initial state" to the "delete state", a word "StartDelete" can be generated. The FSM can determine that when transitioning from the "delete state" to the "initial state", a word "DeleteEnd" can be generated. The FSM can determine that when transitioning from the "initial state" to the "update state", a word "StartUpdate" can be generated. The FSM can determine that when transitioning from the "update state" to the "initial state", a word "UpdateEnd" can be generated. By generating words to identify state changes during each state transition, FSM can more clearly describe system behavior and help debug and understand the system's operation. This approach also helps track state transition sequences in logs or records for troubleshooting and performance analysis.

[0064] By continuously using random numbers and state transition probabilities, FSM can simulate expected workloads and generate corresponding characters. FSM can be used to test and evaluate the performance of database systems under different load conditions and help optimize system configuration and operating parameters.

[0065] The processing module 150 is used to splice multiple characters into an SQL statement after receiving them. In an embodiment of the present application, the processing module 150 can define some rules to determine the splicing method between characters based on the grammatical rules and semantic requirements of the SQL statement. For example, when generating a SELECT statement, the processing module 150 can stipulate that the order of characters is "SELECT", "column1, column2,...", "FROM", "table". The processing module 150 splices these characters together according to this rule to form a complete SQL statement. Through the splicing function, the processing module 150 can combine multiple characters into a character string that meets the requirements of the SQL statement, which helps to generate real and valid SQL statements and simulate the actual behavior of the database system during the load generation process.

[0066] Figure 2 This is a flow chart of a sentence generation method provided in an embodiment of the present application. Figure 2 As shown, the method is executed by the load generation system 100 described above, and the specific implementation process is as follows:

[0067] Step S201: receiving load characteristic information and database mode information, and obtaining characteristic parameters according to the load characteristic information and the database mode information.

[0068] Load characteristics are key attributes that describe the operational status and performance of a database system. These characteristics include semantic characteristics and data access pattern characteristics. Semantic characteristics include load scale, read-write ratio, the average number of tables involved in each query statement, the average number of logical predicates contained in each query constraint, the average number of aggregate functions contained in each query statement, the average number of GROUP BY operations contained in each statement, and the average number of valid attributes of items returned by each query statement. Data access pattern characteristics include the access distribution of each table involved in a query, the access distribution of each column involved in a query, the access distribution of the query range of each column involved in a query, the access distribution of the proportion of comparison constraints involved in the WHERE clause, and the access distribution of ascending and descending sorting when sorting is involved.

[0069] Database schema information refers to the organization of structured data in a database, including metadata such as tables, fields, indexes, and relationships. Feature parameters include table names and table parameters. Table names are determined by database schema information, while table parameters are determined by workload feature information.

[0070] Step S201 may be performed by the analysis module 110. The analysis module 110 may analyze the load signature information and the database schema. Based on the analysis results of the load signature information and the analysis structure of the database schema, the analysis module 110 may identify key information that affects database performance to obtain characteristic parameters.

[0071] Step S202: Determine the statement type of the generated statement based on the characteristic parameters.

[0072] The above step S202 can be performed by the above sampling module 130. Since the selection module 120 presets four generation module selection modes: read statement, insert statement, delete statement and update statement, the read-write ratio feature set by the selection module 120 is Tuple<RatioRead,RatioInsert,RatioDelete,RatioUpdate> After receiving the read-write ratio feature, the sampling module 130 can control the expected ratio of the number of various statements in the generated statement set based on the ratios in the read-write ratio feature. The sampling module 130 can use a random number generator to generate a random number. The sampling module 130 can compare the generated random number with the ratio in the read-write ratio feature and, based on the comparison result, select and generate a statement of the corresponding type based on the generated random number value.

[0073] Step S203: Select the type of generation module according to the statement type.

[0074] Step S203 may be performed by the selection module 120. The selection module 120 pre-sets four types of generation modules for processing different types of statements: read statements, insert statements, delete statements, and update statements. By pre-setting four different selection methods, the selection module 120 can route statements to appropriate generation modules based on their type, achieving efficient processing and optimization for different operations. This allows for better adaptation to different query and operation requirements, thereby improving the performance and responsiveness of the database system.

[0075] Step S204: Calculate the state transition probability based on the load characteristic information.

[0076] The above-mentioned step S204 can be performed by the above-mentioned sampling module 130. The sampling module 130 can use sampling algorithms such as the Monte Carlo sampling algorithm and the Markov chain sampling algorithm for sampling. Taking the Monte Carlo sampling algorithm as an example below, the Monte Carlo sampling algorithm can construct a state space representing different query types and define the transition relationship between states based on the load characteristic information input by the user. The Monte Carlo sampling algorithm constructs an initialized state transition probability matrix and initializes all transition probabilities to 0. When the Monte Carlo sampling algorithm performs Monte Carlo sampling, it randomly selects a starting state, and then generates the next state with a certain probability based on the load characteristic information input by the user. The Monte Carlo sampling algorithm can update the state transition probability matrix and record the number of transitions from the current state to the next state.

[0077] Step S205: Determine the next state based on the current state and the state transition probability.

[0078] Step S205 may be performed by the generation module 140. The generation module 140 may utilize a generation algorithm, such as a FSM, for semantic generation. Taking the FSM as an example, the sampling module 130 may utilize a random number generator to generate a random number based on the current state and state transition probabilities. The FSM may determine the next state based on the random number.

[0079] Step S206: Generate a character according to the state types of the current state and the next state.

[0080] The above-mentioned step S206 can be performed by the above-mentioned generation module 140. The generation module 140 can use a generation algorithm such as FSM to perform semantic generation. Taking FSM as an example below, the FSM can generate a character based on the state type of the current state and the next state. For example, the FSM can determine that when transferring from the "initial state" to the "query state", a word "StartQuery" can be generated. The FSM can determine that when transferring from the "query state" to the "initial state", a word "QueryEnd" can be generated. The FSM can determine that when transferring from the "initial state" to the "insert state", a word "StartInsert" can be generated. The FSM can determine that when transferring from the "insert state" to the "initial state", a word "InsertEnd" can be generated. The FSM can determine that when transferring from the "initial state" to the "delete state", a word "StartDelete" can be generated. The FSM can determine that when transferring from the "delete state" to the "initial state", a word "DeleteEnd" can be generated. The FSM can determine that when transferring from the "initial state" to the "update state", a word "StartUpdate" can be generated. The FSM can determine that when transitioning from the "Update State" to the "Initial State," it generates a word called "UpdateEnd." By generating words to identify state changes during each state transition, the FSM can more clearly describe system behavior and aid in debugging and understanding the system's operation. This approach also helps track state transition sequences in logs or records for troubleshooting and performance analysis.

[0081] Step S207: Check whether the number of state transitions is equal to the set number. In one case, if the number of state transitions is less than the set number, execute step S204. In another case, if the number of state transitions is equal to the set number, execute step S208.

[0082] Step S207 may be performed by the sampling module 130. The Monte Carlo sampling algorithm used by the sampling module 130 may update the state transition probability matrix, recording the number of transitions from the current state to the next state. Similarly, the Monte Carlo sampling algorithm may repeatedly perform the Monte Carlo sampling operation multiple times to continuously accumulate the number of state transitions.

[0083] In one case, if the number of state transitions is less than the set number, steps S204-S206 can be executed repeatedly, and the Monte Carlo sampling algorithm can calculate the state transition probability from the next state to the next state based on the load characteristic information, and generate a character again.

[0084] In another case, after the number of accumulated state transitions of the Monte Carlo sampling algorithm reaches a set number, the sampling operation can be paused, and the state transition is stopped to calculate the state transition probability through normalization.

[0085] Step S208: concatenate multiple characters into an SQL statement.

[0086] The above step S208 can be performed by the above processing module 150. The processing module 150 can define some rules to determine the splicing method between characters according to the grammatical rules and semantic requirements of the SQL statement. For example, when generating a SELECT statement, the processing module 150 can stipulate that the order of characters is "SELECT", "column1, column2,...", "FROM", "table". The processing module 150 splices these characters together according to this rule to form a complete SQL statement. Through the splicing function, the processing module 150 can combine multiple characters into a character string that meets the requirements of the SQL statement, which helps to generate real and valid SQL statements and simulate the actual behavior of the database system during the load generation process.

[0087] In an embodiment of the present application, the load generation system 100 can determine the load type required by the user based on the database schema information and the load characteristic information, and generate a SQL statement of a certain type based on the load characteristic information. Compared with the related art, different SQL statements are generated by changing or filling in numerical values, resulting in a relatively simple style of SQL statements, which cannot meet the diverse requirements of users. The load generation system 100 protected by the present application generates a variety of SQL statements, thereby enriching the styles of SQL statements and improving the portability of load generation.

[0088] Figure 3 This is a structural diagram of a sentence generation device provided in an embodiment of the present application. Figure 3As shown, the sentence generating device 300 can be divided into a first processing unit 310, a second processing unit 320 and a third processing unit 330 according to the execution function. The specific implementation process of the sentence generating device 300 is as follows:

[0089] The first processing unit 310 is configured to receive load signature information and database schema information and, based on the load signature information and database schema information, obtain characteristic parameters. Load signature information refers to key attributes that describe the operating status and performance of a database system. The second processing unit 320 is configured to determine the statement type for generating a structured query language (SQL) statement based on the characteristic parameters. The third processing unit 330 is configured to calculate a state transition probability based on the load signature information. The state transition probability refers to the transition probability between different query types and is used to generate one or more characters in an SQL statement of a specified type.

[0090] In one embodiment, the second processing unit 320 is specifically configured to generate a random number based on characteristic parameters. The second processing unit 320 is specifically configured to compare the random number with the ratios of various statement types in the read-write ratio, determine the ratio of the statement type in which the random number resides, and obtain the statement type. The characteristic parameters include the read-write ratio, which includes the ratios of at least two statement types: the ratio of read statements, the ratio of insert statements, the ratio of delete statements, and the ratio of update statements.

[0091] In one embodiment, the third processing unit 330 is specifically configured to determine the current state and calculate the state transition probability from the current state to the next state based on the load characteristic information using a Monte Carlo algorithm.

[0092] In one embodiment, the third processing unit 330 is further configured to determine a next state based on the current state and the state transition probability. The third processing unit 330 is further configured to generate a character based on the current state and the state type of the next state.

[0093] In one embodiment, the third processing unit 330 is further configured to record the number of state transitions. The third processing unit 330 is further configured to, when the number of state transitions reaches a set number, concatenate the previously generated multiple characters into an SQL statement.

[0094] Figure 4 This is a schematic diagram of the structure of a computing device provided in an embodiment of the present application. Figure 4As shown, computing device 400 includes a bus 410, a processor 420, a memory 430, and a communication interface 440. Processor 420, memory 430, and communication interface 440 communicate with each other via bus 410. Computing device 400 may be a server, a computer, a portable notebook, a cabinet, etc. It should be understood that this application does not limit the number of processors and memories in computing device 400.

[0095] The bus 410 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 The fact that only one line is used in the figure does not mean that there is only one bus or only one type of bus. Bus 410 may include a path for transmitting information between various components of computing device 400 (eg, processor 420, memory 430, communication interface 440).

[0096] The processor 420 may be any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).

[0097] The memory 430 may include a volatile memory, such as a random access memory (RAM). The memory 430 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid state drive (SSD).

[0098] Memory 430 stores executable program code, which processor 420 executes to implement the functions of the aforementioned modules, such as parsing module 110, selection module 120, sampling module 130, generation module 140, and processing module 150, thereby implementing the data optimization method. Specifically, memory 430 stores instructions for executing the data optimization method.

[0099] Alternatively, the memory 430 stores executable codes, and the processor 420 executes the executable codes to respectively implement the functions of the aforementioned modules, thereby implementing the data optimization method. In other words, the memory 430 stores instructions for executing the data optimization method.

[0100] The communication interface 440 uses a transceiver module such as, but not limited to, a network interface card or a transceiver to implement communication between the computing device 400 and other devices or a communication network.

[0101] Embodiments of the present application also provide a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smartphone.

[0102] like Figure 5 As shown, the computing device cluster includes at least one computing device 400. The memory 430 in one or more computing devices 400 in the computing device cluster may store the same instructions for executing the data optimization method.

[0103] In some possible implementations, the memory 430 of one or more computing devices 400 in the computing device cluster may also store some instructions for executing the data optimization method. In other words, the combination of one or more computing devices 100 can jointly execute the instructions for executing the data optimization method.

[0104] It should be noted that the memory 430 in different computing devices 400 in the computing device cluster may store different instructions, each for executing part of the functions of the above-mentioned parsing module 110, selection module 120, sampling module 130, generation module 140, and processing module 150. In other words, the instructions stored in the memory 430 in different computing devices 400 may implement the functions of one or more of the above-mentioned parsing module 110, selection module 120, sampling module 130, generation module 140, and processing module 150.

[0105] In some possible implementations, one or more computing devices in a computing device cluster may be connected via a network, which may be a wide area network or a local area network. Figure 6 A possible implementation is shown. Figure 6As shown, two computing devices, computing device 400A and computing device 400B, are connected via a network. Specifically, the connection to the network is achieved through a communication interface in each computing device. In this possible implementation, the memory 430 in computing device 400A stores instructions for executing the functions of some modules among the above-mentioned parsing module 110, selection module 120, sampling module 130, generation module 140, and processing module 150. Simultaneously, the memory 430 in computing device 400B stores instructions for executing the functions of another portion of the above-mentioned parsing module 110, selection module 120, sampling module 130, generation module 140, and processing module 150.

[0106] Figure 6 The connection method between the computing device clusters shown can be based on the consideration that the data optimization method provided in this application requires a large amount of data storage, so it is considered to entrust the functions implemented by another part of the modules in the above-mentioned analysis module 110, selection module 120, sampling module 130, generation module 140 and processing module 150 to be executed by the computing device 400B.

[0107] It should be understood that Figure 6 The functionality of the computing device 400A shown in FIG. 4 may also be implemented by multiple computing devices 400. Similarly, the functionality of the computing device 400B may also be implemented by multiple computing devices 400.

[0108] The present application embodiment also provides another computing device cluster. The connection relationship between the computing devices in the computing device cluster can be similarly referred to as Figure 4 and Figure 5 The connection mode of the computing device cluster is different in that the memory 430 of one or more computing devices 400 in the computing device cluster may store the same instructions for executing the data optimization method.

[0109] In some possible implementations, the memory 430 of one or more computing devices 400 in the computing device cluster may also store partial instructions for executing the data optimization method. In other words, the combination of one or more computing devices 400 can jointly execute the instructions for executing the data optimization method.

[0110] It should be noted that the memory 430 in different computing devices 400 in the computing device cluster may store different instructions for executing partial functions of the computing device 400. That is, the instructions stored in the memory 430 in different computing devices 400 may implement the functions of one or more of the above-mentioned parsing module 110, selection module 120, sampling module 130, generation module 140, and processing module 150.

[0111] Embodiments of the present application also provide a computer program product comprising instructions. The computer program product may be software or a program product comprising instructions that can be run on a computing device or stored in any available medium. When the computer program product is run on at least one computing device, the at least one computing device executes the data optimization method.

[0112] The present application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that can be stored by a computing device or a data storage device such as a data center that contains one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a magnetic tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive). The computer-readable storage medium includes instructions that instruct the computing device to execute the data optimization method.

[0113] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the protection scope of the technical solutions of the various embodiments of the present invention.

Claims

1. A sentence generation method, characterized in that: include: receiving load characteristic information and database mode information, and obtaining characteristic parameters according to the load characteristic information and the database mode information; The load characteristic information refers to the key attributes that describe the operating status and performance of the database system; Determining, based on the characteristic parameters, a statement type for generating a structured query language SQL statement; A state transition probability is calculated based on the load characteristic information; the state transition probability refers to the transition probability between different query types, and the state transition probability is used to generate one or more characters in a SQL statement of a specified type.

2. The method according to claim 1, characterized in that Determining the statement type of generating a structured query language SQL statement based on the characteristic parameters specifically includes: Generate a random number according to the characteristic parameters; The random number is compared with the ratio of each statement type in the read-write ratio to determine the ratio of the statement type in which the random number is located, and the statement type is obtained; the characteristic parameter includes the read-write ratio, and the read-write ratio includes the ratio of at least two types of statements among the ratio of read statements, the ratio of insert statements, the ratio of delete statements, and the ratio of update statements.

3. The method according to any one of claims 1 or 2, characterized in that Calculating the state transition probability according to the load characteristic information specifically includes: Determine the current state; The state transition probability of transitioning from the current state to the next state is calculated according to the load characteristic information using a Monte Carlo algorithm.

4. The method according to any one of claims 1 to 3, characterized in that The method further comprises: Determining the next state according to the current state and the state transition probability; Generate a character according to the current state and the state type of the next state.

5. The method according to any one of claims 1 to 4, characterized in that The method further comprises: Record the number of state transitions; When the number of state transitions reaches a set number, the previously generated multiple characters are concatenated into an SQL statement.

6. A sentence generating device, characterized in that: include: a first processing unit, configured to receive load characteristic information and database mode information, and obtain characteristic parameters according to the load characteristic information and the database mode information; The load characteristic information refers to the key attributes that describe the operating status and performance of the database system; A second processing unit is used to determine the statement type of the generated SQL statement according to the characteristic parameters; The third processing unit is used to calculate the state transition probability based on the load characteristic information; the state transition probability refers to the transition probability between different query types, and the state transition probability is used to generate one or more characters in a SQL statement of a specified type.

7. The device according to claim 6, characterized in that The second processing unit is specifically configured to generate a random number according to the characteristic parameter; The second processing unit is specifically configured to compare the random number with the ratio of each statement type in the read-write ratio, determine the ratio of the statement type to which the random number belongs, and obtain the statement type; The characteristic parameter includes the read-write ratio, and the read-write ratio includes the ratio of at least two types of statements among the ratio of read statements, the ratio of insert statements, the ratio of delete statements, and the ratio of update statements.

8. The device according to any one of claims 6 or 7, characterized in that The third processing unit is specifically used to determine the current state; The third processing unit is specifically configured to calculate the state transition probability of transitioning from the current state to the next state according to the load characteristic information by using a Monte Carlo algorithm.

9. The device according to any one of claims 6 to 8, characterized in that The third processing unit is further configured to determine the next state according to the current state and the state transition probability; The third processing unit is further configured to generate a character according to the current state and the state type of the next state.

10. The device according to any one of claims 6 to 9, characterized in that: The third processing unit is further configured to record the number of state transitions; The third processing unit is further configured to, when the number of state transitions reaches a set number, combine the plurality of characters generated previously into an SQL statement.

11. A computing device, characterized in that include: at least one memory; At least one processor, wherein the processor is configured to execute instructions stored in the memory, so that the computing device executes the method according to any one of claims 1 to 5.

12. A computer-readable storage medium, characterized in that The method comprises computer program instructions, and when the computer program instructions are executed by a computing device, the computing device performs the method according to any one of claims 1 to 5.

13. A computer program product comprising instructions, characterized in that The computer program product stores instructions, which, when executed by a computing device, enable the computing device to implement the method according to any one of claims 1 to 5.