Data processing method and device, electronic equipment, storage medium and program product
By rewriting the string SQL statements composed of multiple database operation statements of the same type, a single database operation statement containing the values of multiple database operation statements is generated, which solves the problem of poor execution performance of super large SQL statements on the database server, and achieves the effect of improving the execution performance of the database server.
Patent Information
- Application Number
- CN202510265019.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-06
- Publication Date
- 2025-06-17
AI Technical Summary
In database application scenarios, super large SQL statements spliced with multiple data operation statements of the same type have poor execution performance on the database server.
By rewriting a string statement composed of multiple database operation statements of the same type, a single database operation statement containing the values of multiple database operation statements is generated, thereby shortening the length of the string statement and reducing the time of transmission to the database server.
It improves the execution performance of the database server, reduces network transmission time, and improves the efficiency of database operations.
Smart Images

Figure CN120162347A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing, and in particular, to a data processing method, apparatus, electronic device, storage medium, and program product. Background Art
[0002] In actual database application scenarios, there is a situation where multiple data manipulation language (DML) statements of the same type are concatenated into a single large database operation statement (Structured Query Language, SQL) for execution. Currently, the database client does not process such a large SQL, but instead sends it all at once to the database server for execution. There is a problem that the execution performance of a large SQL composed of multiple DML statements of the same type is poor on the database server. Summary of the Invention
[0003] Embodiments of this application provide a data processing method, apparatus, electronic device, storage medium, and program product, so as to achieve the effect of improving the execution performance of a string statement composed of multiple database operation statements of the same type on the database server.
[0004] In a first aspect, an embodiment of this application provides a data processing method, including: parsing a first database operation statement received from an application server;
[0005] If the first database operation statement is a string statement composed of multiple database operation statements of the same type, then rewrite the first database operation statement to obtain a second database operation statement; wherein, the value of the second database operation statement includes the values of the multiple database operation statements;
[0006] Send the second database operation statement to the database server for execution.
[0007] Optionally, the rewriting the first database operation statement to obtain a second database operation statement includes:
[0008] Extracting the values of the database operation statements in the first database operation statement;
[0009] Concatenating the values of the database operation statements to obtain the value of the second database operation statement;
[0010] Generating the second database operation statement according to the value of the second database operation statement.
[0011] Optionally, the rewriting the first database operation statement to obtain a second database operation statement further includes:
[0012] Count the number of database operation statements in the first database operation statement;
[0013] If the number of the database operation statements is greater than a preset value, start multiple parallel threads to rewrite the first database operation statement.
[0014] Optionally, before starting multiple parallel threads to rewrite the first database operation statement, it further includes:
[0015] Determine the number of parallel threads according to the number of each database operation statement in the first database operation statement and the minimum number of single-thread processing, and determine the number of database operation statements that each thread needs to process;
[0016] Allocate each database operation statement in the first database operation statement to each thread according to the start order of each thread and the number of database operation statements that each thread needs to process.
[0017] Optionally, the extracting the values of each database operation statement in the first database operation statement specifically includes:
[0018] Obtain the values extracted by each thread from the database operation statements allocated to the thread.
[0019] Optionally, the parsing the first database operation statement received from the application server includes:
[0020] Detect whether the first database operation statement includes a delimiter;
[0021] If the first database operation statement includes a delimiter, determine that the first database operation statement is a string statement composed of multiple database operation statements of the same type.
[0022] In a second aspect, an embodiment of the present application provides a data processing device, including: a parsing module, configured to parse a first database operation statement received from an application server;
[0023] A processing module, configured to rewrite the first database operation statement to obtain a second database operation statement if the first database operation statement is a string statement composed of multiple database operation statements of the same type; wherein, the value of the second database operation statement includes the values of the multiple database operation statements;
[0024] A sending module, configured to send the second database operation statement to a database server for execution.
[0025] In a third aspect, an embodiment of the present application provides an electronic device, including: a processor, and a memory connected to the processor;
[0026] The memory stores computer-executable instructions;
[0027] The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of the first aspect.
[0028] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer-executable instructions are stored, and when the computer-executable instructions are executed by a processor, they are used to implement the method according to any one of the first aspect.
[0029] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, and when the computer program is executed by a processor, it implements the method according to any one of the first aspect.
[0030] The data processing method, device, electronic device, storage medium and program product provided by the embodiments of the present application rewrite a string statement composed of multiple database operation statements of the same type to generate a single database operation statement containing the values of multiple database operation statements, so as to shorten the length of the string statement, reduce the time for transmitting the string statement to the database server, and improve the execution performance of the database server. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] The drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application.
[0032] Figure 1 It is a schematic diagram of an application scenario related to an embodiment of the present application;
[0033] Figure 2 It is a schematic flowchart of a data processing method provided by an embodiment of the present application;
[0034] Figure 3 It is a schematic flowchart of another data processing method provided by an embodiment of the present application;
[0035] Figure 4 It is a schematic flowchart of a third data processing method provided by an embodiment of the present application;
[0036] Figure 5 It is a schematic flowchart of a fourth data processing method provided by an embodiment of the present application;
[0037] Figure 6 It is a schematic structural diagram of a data processing device provided by an embodiment of the present application;
[0038] Figure 7 A schematic structural diagram of an electronic device provided by an embodiment of the present application.
[0039] Through the above-mentioned drawings, specific embodiments of the present application have been shown, and more detailed descriptions will be given later. These drawings and textual descriptions are not intended to limit the scope of the concept of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. Specific Embodiments
[0040] Here, exemplary embodiments will be described in detail, and examples are shown in the drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. On the contrary, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0041] Figure 1 A schematic diagram of an application scenario related to an embodiment of the present application. As Figure 1 shown, the specific application scenario of the present application is to process SQL statements.
[0042] In today's software development and deployment, the infrastructure of modern network applications generally includes a client, an application server, and a database server.
[0043] The client can be, for example, any client that can directly interact with users. For example, it can include any one of a graphical user interface client, a command-line interface client, a browser interface client, a programmatic interface client, a mobile application client, etc.
[0044] The application server can be, for example, any computer system or software environment that can process business logic, data storage, and management.
[0045] The database server can be, for example, any computer system or software environment used to store, manage, and provide database services. Among them, the database can be used to store data.
[0046] A communication connection can be established between the client and the application server; a communication connection can be established between the application server and the database server. Among them, the application server can directly communicate and interact with the database server; or, the application server can communicate and interact with the database server through a database programming interface. The database programming interface can be, for example, any interface used to interact with a database system, and can include, for example, any one of the following: SQL interface, Open Database Connectivity (ODBC) interface, Java Database Connectivity (JDBC) interface, etc. The database programming interface allows the application to access the database server in a programming way. For example, the application server can respond to the client's request, access the database server through the database programming interface, and send SQL statements to the database server for execution to perform operations such as querying, inserting, updating, and deleting data.
[0047] For example, the client, the application server, the database programming interface, and the database server can be deployed on one electronic device or virtual machine, or deployed on different electronic devices or virtual machines.
[0048] The client can provide an interface for direct interaction with the user, receive user operations, and send them to the application server for processing. For example, the client can be implemented through a browser to receive user operations and display results. The application server can respond to the client's request, access the database server for data operations, and return the results to the client. The database server can process requests from the application server, including operations such as data query, update, insertion, and deletion.
[0049] In an actual database application scenario, there are situations where a large number of data operations need to be performed on the database. For example, during application development, a large number of data insertion operations are performed on the database. In one example, the user can read the data source from a file through the application and generate a DML statement for each piece of data read. The application sends the generated DML statements to the database server for execution one by one through the database connection. Since the execution of each DML statement involves the overhead of the database connection, in this way, there is a problem of poor execution performance of the database server.
[0050] In one example, the user can read all the data in the data source file at once through the application server, and splice multiple DML statements of the same type into a string statement for execution through the database programming interface. For example, the string statement can include: SQL part 1; SQL part 2; SQL part 3, etc. Usually, the database programming interface does not process such a string statement without bound parameters, but sends it all at once to the database server for execution. Since each DML statement that makes up the string statement is a complete SQL statement, except for the column values in the SQL statement, there is a lot of repetitive content (such as table names, column names, operation types, etc.), resulting in a very long string statement, which makes the data packet very large when the database programming interface transmits the string statement to the database server, taking a long time, and thus resulting in very poor execution performance of the database server.
[0051] In view of this, the embodiments of the present application provide a data processing method, which rewrites a string statement composed of multiple database operation statements of the same type to generate a single database operation statement containing the values of multiple database operation statements, so as to shorten the length of the string statement, reduce the time for transmitting the string statement to the database server, and improve the execution performance of the database server.
[0052] The execution subject of the embodiments of the present application can be the database programming interface, or an electronic device or a processing system installed with the database programming interface. Hereinafter, the database programming interface will be used as an example for illustration.
[0053] The following will use specific embodiments to elaborate in detail on the technical solution of the present application and how the technical solution of the present application solves the above technical problems. These specific embodiments below can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below with reference to the accompanying drawings.
[0054] Figure 2 It is a schematic flowchart of a data processing method provided by an embodiment of the present application, as Figure 2 shown, the method includes:
[0055] S201. The database programming interface parses the first database operation statement received from the application server.
[0056] For example, the application server can generate the first database operation statement based on the data input by the user or the data read from the data source file and send it to the database programming interface. Correspondingly, the database programming interface receives the first database operation statement.
[0057] The first database operation statement can be, for example, any statement that operates on the data in the database. The first database operation statement can be a single database operation statement, or a string statement composed of multiple database operation statements of the same type. When the first database operation statement is a single database operation statement, the database operation statement can be any SQL statement, for example, it can include any one of the following: DML statement, Data Definition Language (DDL) statement, Data Control Language (DCL) statement, etc. When the first database operation statement is a string statement composed of multiple database operation statements of the same type, the multiple database operation statements of the same type can be, for example, DML statements. For example, it can include any one of the following: data insertion operation statement, data update operation statement, data deletion operation statement, data query operation statement, etc.
[0058] The database programming interface parses the first database operation statement. For example, it can decompose the first database operation statement into its components to determine whether there are multiple statements in the first database operation statement.
[0059] For example, the database programming interface can use an SQL parser to decompose the first database operation statement into its components to analyze whether it contains multiple operations of the same type (such as multiple data insertion operation statements) to determine whether the first database operation statement is a string statement composed of multiple database operation statements of the same type; or, the database programming interface can write a custom string analysis algorithm to identify the pattern and structure of the first database operation statement to determine whether the first database operation statement is a string statement composed of multiple database operation statements of the same type; or, the database programming interface can detect whether the first database operation statement contains a delimiter to determine whether the first database operation statement is a string statement composed of multiple database operation statements of the same type.
[0060] S202. The database programming interface detects whether the first database operation statement is a string statement composed of multiple database operation statements of the same type.
[0061] If so, execute step S203.
[0062] S203. If the first database operation statement is a string statement composed of multiple database operation statements of the same type, the database programming interface rewrites the first database operation statement to obtain a second database operation statement; where the value of the second database operation statement contains the values of multiple database operation statements.
[0063] If the first database operation statement is a string statement composed of multiple database operation statements of the same type, it indicates that the multiple database operation statements of the same type can be DML statements of the same type. For example, the multiple database operation statements of the same type are all data insertion operation statements, or the multiple database operation statements of the same type are all data update operation statements, or the multiple database operation statements of the same type are all data deletion operation statements, or the multiple database operation statements of the same type are all data query operation statements, etc. Among them, the column values of these multiple database operation statements of the same type may be the same or different; other statement information outside the column values (such as table names, column names, operation types, etc.) are all kept consistent.
[0064] The database programming interface can retain all the column values of multiple database operation statements of the same type, remove duplicate statement information, and obtain a second database operation statement, which can shorten the length of the string statement of the first database operation statement without changing the column value information of the required operations.
[0065] Among them, the value of each database operation statement in the multiple database operation statements can be a group containing a single element or a group containing multiple elements. The embodiments of the present application do not limit this.
[0066] S204. The database programming interface sends the second database operation statement to the database server for execution.
[0067] The string length of the second database operation statement is shorter than that of the first database operation statement. When the database programming interface sends the second database operation statement to the database server, the network transmission time can be reduced, and the execution performance of the database server can be improved.
[0068] In summary, the data processing method provided by the embodiments of the present application rewrites a string statement composed of multiple database operation statements of the same type to generate a single database operation statement containing the values of multiple database operation statements, so as to shorten the length of the string statement, reduce the time for transmitting the string statement to the database server, and improve the execution performance of the database server.
[0069] Figure 3 It is a schematic flowchart of another data processing method provided by the embodiments of the present application. As Figure 3 shown, on the basis of the Figure 2 embodiment, this embodiment details the data processing method, which includes:
[0070] S301. The database programming interface parses the first database operation statement received from the application server. As an example, S301 may include the following steps:
[0071] S3011. The database programming interface detects whether the first database operation statement includes a delimiter.
[0072] For example, the database programming interface can, during the statement preparation phase (such as the prepare interface), determine whether the first database operation statement is an SQL composed of multiple DML statements based on the delimiter between statements. Such a delimiter can include, for example, any one of the following: semicolon (`;`), backslash (`\`), or double slash (` / / `), etc.
[0073] S3012. If the first database operation statement includes a delimiter, the database programming interface determines that the first database operation statement is a string statement composed of multiple database operation statements of the same type.
[0074] Correspondingly, when the database programming interface detects that the first database operation statement does not contain a delimiter, it determines that the first database operation statement is a single database operation statement.
[0075] The database programming interface determines that the first database operation statement is a string statement composed of multiple database operation statements of the same type by detecting whether the first database operation statement includes a delimiter, and the implementation is simple.
[0076] S302. The database programming interface detects that the first database operation statement is a string statement composed of multiple database operation statements of the same type.
[0077] If so, step S303 is executed. If not, the first database operation statement is sent to the database server for execution.
[0078] S303. If the first database operation statement is a string statement composed of multiple database operation statements of the same type, the database programming interface extracts the values of each database operation statement in the first database operation statement.
[0079] For example, the database programming interface can use an SQL parsing tool to parse the first database operation statement. These tools can decompose the first database operation statement into multiple independent database operation statements, and decompose each database operation statement into its components, such as data query (SELECT), data insertion (INSERT), data update (UPDATE), data deletion (DELETE), etc., as well as table names, column names, conditions, column values, etc.
[0080] The database programming interface can, for example, search for column values in the database operator statements one by one to extract the values of each database operation statement in the first database operation statement. Alternatively, when the number of database operation statements in the first database operation statement exceeds a preset value, the database programming interface can start parallel threads to extract the values of each database operation statement in the first database operation statement.
[0081] S304. The database programming interface concatenates the values of each database operation statement to obtain the value of the second database operation statement.
[0082] In one example, the database programming interface can concatenate the values of each database operation statement in the original order to obtain the value of the second database operation statement. After rewriting the first database operation statement in this way, the order of data operations on the database can be kept consistent. Alternatively, the database programming interface can rearrange the order of each database operation statement, recombine the values of these statements and then concatenate them to obtain the value of the second database operation statement. After rewriting the first database operation statement in this way, the total number of data operations on the database remains unchanged. This method can be applied to application scenarios where there is no strict requirement for the data processing order. For example, when batch inserting multiple records into the database.
[0083] S305. The database programming interface generates the second database operation statement according to the value of the second database operation statement.
[0084] For example, the database programming interface can extract other statement information (such as table name, column name or condition) of any one database operation statement in the first database operation statement.
[0085] Rearrange the other statement information extracted from the first database operation statement and the value of the second database operation statement in the original order of the database operation statements or in a specified logical order to generate the second database operation statement.
[0086] The following is an illustrative example using a string statement consisting of three DML statements as the first database operation statement. Taking the database operation statement for data insertion as an example, the first database operation statement can be, for example:
[0087] INSERT INTO table_name (column1, column2) VALUES (val1, val2);
[0088] INSERT INTO table_name (column1, column2) VALUES (val3, val4);
[0089] INSERT INTO table_name (column1, column2) VALUES (value5, value6);
[0090] Using the method of the embodiment of the present application, the rewritten second database operation statement can be:
[0091] INSERT INTO table_name (column1, column2) VALUES (val1, val2),(val3,val4),(val5, val6);
[0092] It can be seen that the length of the string of the second database operation statement is reduced compared with that of the first database operation statement.
[0093] S306. The database programming interface sends the second database operation statement to the database server for execution.
[0094] The database programming interface can directly send the second database operation statement to the database server for execution as an execution statement. Alternatively, the data programming interface can parse and optimize the second database operation statement again, and then send the optimized database operation statement to the database server for execution.
[0095] For a string statement composed of multiple database operation statements of the same type, the query plan generated by the database optimizer may not be efficient enough, or may cause too long execution time. Alternatively, multiple database operation statements of the same type will compete for the same data operation or data resource, or the statements will repeatedly execute multiple data or resource processing processes during multiple executions, resulting in redundant operations.
[0096] Rewrite the string statement composed of multiple database operation statements of the same type to generate a single database operation statement containing the values of multiple database operation statements. The query plan generated by the database optimizer for the single database operation statement is more efficient, avoiding multiple database operation statements of the same type competing for the same data operation or data resource, and can further improve the execution performance of the database server.
[0097] When multiple database operation statements are wrapped in a transaction, the start, commit, or rollback of the transaction may introduce additional overhead, especially in the case where resources need to be locked. By improving the execution performance of the database server, the execution time of the transaction can be shortened to reduce the lock holding time and reduce the impact on other transactions, thereby further improving the execution performance of the database server.
[0098] In summary, the data processing method provided by the embodiments of the present application rewrites a string statement composed of multiple database operation statements of the same type to generate a single database operation statement containing the values of multiple database operation statements, so as to shorten the length of the string statement and reduce the time for transmitting the string statement to the database server, and can improve the execution performance of the database server.
[0099] Figure 4 FIG. 4 is a schematic flowchart of a third data processing method provided by the embodiments of the present application. As Figure 4 shown, on the basis of the Figure 2 embodiment, the data processing method is described in detail. The method includes:
[0100] S401. The database programming interface parses the first database operation statement received from the application server.
[0101] S402. The database programming interface detects that the first database operation statement is a string statement composed of multiple database operation statements of the same type.
[0102] If so, step S403 is executed.
[0103] S403. If the first database operation statement is a string statement composed of multiple database operation statements of the same type, the database programming interface counts the number of database operation statements in the first database operation statement;
[0104] For example, the database programming interface can count the number of database operation statements in the first database operation statement according to the number of delimiters. For example, the number of database operation statements in the first database operation statement can be the number of delimiters plus one.
[0105] S404. The database programming interface detects whether the number of database operation statements is greater than a preset value.
[0106] For example, the database programming interface can configure the minimum number of single-threaded processes as the preset value. If the number of database operation statements exceeds this minimum number of processes, it is considered that single-threaded processing may not be efficient enough; if the number of database operation statements does not exceed the minimum number of processes, it is considered that single-threaded processing is already efficient enough at this time.
[0107] If so, step S405 is executed; if not, the database programming interface enables a single thread to rewrite the first database operation statement.
[0108] S405. If the number of sub-database operation statements is greater than a preset value, the database programming interface determines the number of parallel threads based on the number of database operation statements in the first database operation statement and the minimum number of statements processed by a single thread, and determines the number of database operation statements that each thread needs to process.
[0109] For example, the database programming interface can calculate the quotient and remainder of the number of database operation statements in the first database operation statement divided by the minimum number of statements processed by a single thread. When the remainder is zero or the remainder is less than half of the minimum number of statements processed by a single thread, the quotient value is used as the number of parallel threads, and the quotient is determined as the number of database operation statements that each thread needs to process. When the remainder is non-zero and greater than or equal to half of the minimum number of statements processed by a single thread, the quotient value plus one is used as the number of parallel threads; at this time, for the remainder of the threads, the number of database operation statements that each thread needs to process is determined as the quotient value plus one; for the remaining threads, the number of database operation statements that each thread needs to process is determined as the quotient value.
[0110] S406. The database programming interface distributes each database operation statement in the first database operation statement to each thread according to the start order of each thread and the number of database operation statements that each thread needs to process.
[0111] For example, the database programming interface can split the first database operation statement according to a delimiter to form a list of database operation statements. Each statement can be used as an element in the list. Distributing each database operation statement in the first database operation statement to each thread means determining the start and end positions of the specific statements that each thread needs to process in the list of database operation statements. For example, the database programming interface can assign a start position to each thread, indicating which database operation statement the thread starts processing from, and the start position can be one plus the end position of the previous thread; at the same time, an end position is assigned to each thread, indicating which database operation statement the thread processes up to. The end position can be the start position plus the number of database operation statements that the thread needs to process minus one.
[0112] For example, the database programming interface can, according to the start order of each thread, distribute the number of database operation statements equal to the quotient value plus one to each of the first remainder of the threads; and for the remaining threads, distribute the number of database operation statements equal to the quotient value to each thread. Or, for the first (single thread - remainder) of the threads, distribute the number of database operation statements equal to the quotient value to each thread; for the remaining threads, distribute the number of database operation statements equal to the quotient value plus one to each thread.
[0113] After distributing each database operation statement in the first database operation statement to each thread, each thread has determined the position of the database operation statements that it needs to process.
[0114] S407. The database programming interface starts multiple parallel threads to rewrite the first database operation statement.
[0115] If the number of sub-database operation statements is greater than a preset value, it is considered that single-threaded processing may not be efficient enough, and multiple parallel threads need to be started to rewrite the first database operation statement to improve the processing efficiency.
[0116] As an example, S407 may include the following steps, for example:
[0117] S4071. The database programming interface obtains the values extracted from the database operation statements allocated to each thread by that thread.
[0118] For example, each thread applies for the required memory space according to the number of database operation statements allocated to it. This memory space is used to store the values of the database operation statements. For each allocated database operation statement, the thread extracts the column value from the database operation statement allocated to it according to the position in the list of allocated database operation statements. Then, the column values are written into the newly allocated memory space in sequence. A memory containing multiple column values is obtained. After all threads have completed extraction, multiple memories containing multiple column values can be obtained.
[0119] S4072. The database programming interface splices the obtained values of each database operation statement to obtain the value of the second database operation statement.
[0120] S4073. The database programming interface generates the second database operation statement according to the value of the second database operation statement.
[0121] After generating the second database operation statement, the database programming interface releases the memory space for temporarily storing column values allocated to each thread.
[0122] S408. The database programming interface sends the second operation statement to the database server for execution.
[0123] The data processing method provided by the embodiment of the present application, by rewriting a string statement composed of multiple database operation statements of the same type, generates a single database operation statement containing the values of multiple database operation statements, so as to shorten the length of the string statement and reduce the time for transmitting the string statement to the database server, and can improve the execution performance of the database server. When the number of database operation statements in the first database operation statement is greater than a preset value, multiple parallel threads are started to rewrite the string statement composed of multiple database operation statements of the same type, which improves the processing speed of the client programming interface and further improves the execution performance of the database server.
[0124] Figure 5 This is a schematic flowchart of the fourth data processing method provided by the embodiments of this application. As Figure 5 shown, the database programming interface may include, for example, a connection management module, a meta-information module, a statement preparation module, a statement binding module, a statement execution module, and a result set acquisition module.
[0125] The connection management module is used to manage the connection between the application and the database server. For example, it includes creating, maintaining, reusing, and closing connections, etc. All other modules obtain and use the database connection through the connection management module, and a connection to the database needs to be established before performing database operations. The meta-information module is used to provide meta-information about the database structure and characteristics, such as table structure, supported SQL functions, etc. The meta-information module can help the statement preparation module and the statement binding module understand the database structure to correctly construct and execute database operation statements. The statement preparation module is used to pre-compile database operation statements to prepare for subsequent execution. The statement binding module is used to bind parameter values to the pre-compiled database operation statements. Parameter binding is performed after statement preparation and then sent to the statement execution module. The statement execution module is used to execute data operation statements, including operations such as query, update, and insert. The result set acquisition module is used to process and obtain the result set queried by the data operation statement. After the statement execution module executes the query, the result set acquisition module parses and processes the returned data for use by the application.
[0126] In an example, the application can obtain a connection to the database server through the connection management module; use the meta-information module to understand the database structure, prepare and bind database operation statements; send the constructed database operation statements to the database server through the statement execution module; and finally, process the returned data through the result set acquisition module.
[0127] For example, the application server constructs a first database operation statement through the statement preparation module. Among them, the first database operation statement is a string statement composed of multiple database operation statements. The database programming interface detects the number of database operation statements. If the number of database operation statements is greater than a preset value, multiple parallel threads are enabled to rewrite the first database operation statement. Figure 5Taking the example of enabling three parallel threads to rewrite the first database operation statement through a database programming interface for illustration. The database programming interface assigns SQL part1 to thread 1, SQL part2 to thread 2, and SQL part3 to thread 3; thread 1 extracts column values from the database operation statement of SQL part1 to obtain value1; thread 2 extracts column values from the database operation statement of SQL part2 to obtain value2; thread 3 extracts column values from the database operation statement of SQL part3 to obtain value3. The database programming interface concatenates value1, value2, and value3 in sequence to form a complete database operation statement, that is, to generate the second database operation statement. The database programming interface can send the second database operation statement to the database server.
[0128] Figure 6 The structural schematic diagram of a data processing device provided by an embodiment of the present application is as Figure 6 shown. The device includes: a parsing module 601, a processing module 602, and a sending module 603.
[0129] The parsing module 601 is used to parse the first database operation statement received from the application server;
[0130] The processing module 602 is used to rewrite the first database operation statement to obtain a second database operation statement if the first database operation statement is a string statement composed of multiple database operation statements of the same type; wherein, the value of the second database operation statement includes the values of multiple database operation statements;
[0131] The sending module 603 is used to send the second database operation statement to the database server for execution.
[0132] A possible implementation manner, the processing module 602 is used to extract the values of each database operation statement in the first database operation statement; concatenate the values of each database operation statement to obtain the value of the second database operation statement; generate the second database operation statement according to the value of the second database operation statement.
[0133] A possible implementation manner, the processing module 602 is further used to count the number of database operation statements in the first database operation statement; if the number of database operation statements is greater than a preset value, the processing module 602 is further used to start multiple parallel threads to rewrite the first database operation statement.
[0134] In a possible implementation manner, before starting multiple parallel threads to rewrite the first database operation statement, the processing module 602 is further configured to determine the number of parallel threads according to the number of database operation statements in the first database operation statement and the minimum processing number of a single thread, and determine the number of database operation statements that each thread needs to process; allocate each database operation statement in the first database operation statement to each thread according to the startup order of each thread and the number of database operation statements that each thread needs to process.
[0135] In a possible implementation manner, the processing module 602 is specifically configured to obtain the values extracted from the database operation statements allocated to the thread by each thread.
[0136] In a possible implementation manner, the parsing module 601 is configured to detect whether the first database operation statement includes a delimiter; if the first database operation statement includes a delimiter, it is determined that the first database operation statement is a string statement composed of multiple database operation statements of the same type.
[0137] The data processing device provided in this embodiment can execute the method provided in the above method embodiment, and its implementation principle and technical effect are similar, which will not be elaborated here in this embodiment.
[0138] Figure 7 This is a schematic structural diagram of an electronic device provided in an embodiment of the present application. As Figure 7 shown, the electronic device may include: at least one processor 701 and a memory 702.
[0139] The memory 702 is used to store a program. Specifically, the program may include program code, and the program code includes computer operation instructions.
[0140] The memory 702 may include a high-speed RAM memory, and may also include a non-volatile memory, such as at least one disk memory.
[0141] The processor 701 is configured to execute the computer execution instructions stored in the memory 702 to implement the actions in the foregoing method embodiment. Among them, the processor 701 may be a central processing unit (CPU), or a specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application.
[0142] Optionally, the electronic device may further include a communication interface 703 for communicating and interacting with external devices. In a specific implementation, if the communication interface 703, the memory 702, and the processor 701 are implemented independently, the communication interface 703, the memory 702, and the processor 701 may be interconnected via a bus to complete communication with each other.
[0143] Optionally, in a specific implementation, if the communication interface 703, the memory 702, and the processor 701 are integrated on a single chip, the communication interface 703, the memory 702, and the processor 701 may complete communication through an internal interface.
[0144] This application also provides a computer-readable storage medium, which may include: various media that can store program codes, such as USB flash drives, mobile hard disks, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical discs. Specifically, the computer-readable storage medium stores program instructions for implementing the actions of the above method embodiments.
[0145] This application also provides a computer program product, which includes execution instructions stored in a readable storage medium. At least one processor of the electronic device can read the execution instructions from the readable storage medium, and the execution of the execution instructions by at least one processor causes the electronic device to implement the actions of the above method embodiments.
[0146] Finally, it should be noted that those skilled in the art will readily conceive of other embodiments of the present invention after considering the specification and practicing the invention disclosed herein. The present invention is intended to cover any variations, uses, or adaptations of the present invention, which follow the general principles of the present invention and include common general knowledge or conventional technical means in the technical field not disclosed in the present invention. It is not limited to the exact structures described above and shown in the drawings, and various modifications and changes can be made without departing from its scope. The scope of the present invention is only limited by the appended claims.
Claims
1. A data processing method, characterized in that: include: Parsing a first database operation statement received from an application server; If the first database operation statement is a string statement composed of multiple database operation statements of the same type, rewrite the first database operation statement to obtain a second database operation statement; wherein the value of the second database operation statement includes the values of the multiple database operation statements; Send the second database operation statement to the database server for execution.
2. The method according to claim 1, characterized in that The step of rewriting the first database operation statement to obtain a second database operation statement includes: Extracting the value of each database operation statement in the first database operation statement; Concatenate the values of the database operation statements to obtain the value of the second database operation statement; The second database operation statement is generated according to the value of the second database operation statement.
3. The method according to claim 2, characterized in that The rewriting of the first database operation statement to obtain a second database operation statement also includes: Counting the number of database operation statements in the first database operation statement; If the number of the database operation statements is greater than a preset value, multiple parallel threads are started to rewrite the first database operation statements.
4. The method according to claim 3, characterized in that: Before starting multiple parallel threads to rewrite the first database operation statement, the method further includes: Determine the number of parallel threads according to the number of each database operation statement in the first database operation statement and the minimum processing number of a single thread, and determine the number of database operation statements that each thread needs to process; According to the startup order of each thread and the number of database operation statements that each thread needs to process, each database operation statement in the first database operation statement is allocated to each thread.
5. The method according to claim 4, characterized in that The extracting the value of each database operation statement in the first database operation statement specifically includes: Get the value that each thread extracts from the database operation statement assigned to the thread.
6. The method according to any one of claims 1 to 5, characterized in that: The parsing of the first database operation statement received from the application server includes: Detecting whether the first database operation statement includes a separator; If the first database operation statement includes a separator, it is determined that the first database operation statement is a character string statement composed of multiple database operation statements of the same type.
7. A data processing device, characterized in that: The device comprises: A parsing module, used for parsing a first database operation statement received from an application server; a processing module, configured to rewrite the first database operation statement to obtain a second database operation statement if the first database operation statement is a string statement composed of multiple database operation statements of the same type; wherein the value of the second database operation statement includes the values of the multiple database operation statements; A sending module is used to send the second database operation statement to the database server for execution.
8. An electronic device, characterized in that: include: A processor, and a memory connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 6 when executed by a processor.
10. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 6 when being executed by a processor.