Method and related device for optimizing the processing flow of database sub-transactions
By analyzing and optimizing the processing flow of database sub-transactions, the execution of unnecessary preset functional statements is prohibited, and the database load problem caused by unnecessary statements in the prior art is solved, and the processing efficiency of the database system is improved.
Patent Information
- Application Number
- CN202411200805.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-29
- Publication Date
- 2024-12-13
- Estimated Expiration
- 2044-08-29
AI Technical Summary
During the sub-transaction process of existing database systems, there are unnecessary save point statements and release save point statements, resulting in additional database load and affecting system efficiency.
By analyzing the pending transaction, determining the target sub-transaction type and prohibiting the execution of the preset function statement of the target sub-transaction before starting the transaction, executing the non-target sub-transaction after opening the transaction, and executing the pre-pre-transaction before and after the non-target sub-transaction after opening the transaction, Set functional statements to reduce the number of database accesses and simplify processing flow.
It effectively reduces the number of accesses to the database by the target sub-transaction, improves the processing efficiency of the database system, and simplifies the transaction processing process.
Smart Images

Figure CN118733202B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of databases, and in particular to a method for optimizing the processing flow of database sub-transactions and related devices. Background Art
[0002] A database transaction is a sequence of database operations that access and possibly manipulate various data items. Each operation in the database transaction is either executed in full or not at all, and is an indivisible unit of work. The transaction consists of all database operations performed between the start of the transaction (which can be done with a BEGIN statement) and the end of the transaction (which can be done with a COMMIT statement).
[0003] Each SQL (Structured Query Language) is currently executed within the subtransaction. Whether the execution succeeds or fails, it will not affect the execution of other SQLs.
[0004] In the current program, savepoint statements and release savepoint statements are appended before and after specific SQL statements, so that operations that have been completed or failed in the subtransaction can be rolled back without affecting subsequent operations of the transaction, ensuring that the entire transaction can be committed or rolled back.
[0005] Some SQL statements do not cause data changes during execution, but the save point statements and release save point statements before and after them may be redundant, causing additional load on the database. Summary of the invention
[0006] The first aspect of the present application provides a method for optimizing the processing flow of a database sub-transaction, comprising:
[0007] Receive a pending transaction, the pending transaction including at least two subtransactions, each subtransaction having preset function statements before and after, the preset function statements including a savepoint statement before executing the subtransaction and a release savepoint statement after executing the subtransaction;
[0008] Analyze the pending transaction to determine at least one target subtransaction, wherein the target subtransaction belongs to the target type and is the first subtransaction in the pending transaction processing sequence, or the target subtransaction belongs to the target type and is at least two consecutive subtransactions starting from the first subtransaction in the pending transaction processing sequence, and the subtransaction of the target type does not change the data in the database when it is executed;
[0009] Before opening the pending transaction, executing the at least one target sub-transaction in sequence, and prohibiting the execution of preset function statements before and after the target sub-transaction in the pending transaction;
[0010] After the pending transaction is opened, at least one non-target sub-transaction in the pending transaction is executed, and preset function statements before and after each non-target sub-transaction in the pending transaction are executed, and the processing order of the non-target sub-transaction is after the target sub-transaction.
[0011] In a possible implementation, before starting the pending transaction, sequentially executing the at least one target sub-transaction, and prohibiting execution of preset function statements before and after the target sub-transaction in the pending transaction, includes:
[0012] It is prohibited to open the pending transaction by the target subtransaction;
[0013] Accordingly, after the pending transaction is opened, at least one non-target sub-transaction in the pending transaction is executed, and the preset function statements before and after each non-target sub-transaction in the pending transaction are executed, including:
[0014] The to-be-processed transaction is controlled to be started by a first non-target subtransaction, wherein the processing order of the first non-target subtransaction is after the target subtransaction and is adjacent to the target subtransaction at the end of the processing order.
[0015] In a possible implementation, after analyzing the transaction to be processed and determining at least one target sub-transaction, the method further includes:
[0016] Parse each target sub-transaction to obtain the information contained in each target sub-transaction;
[0017] Based on the preset lock information included in the first target subtransaction, the first target subtransaction is treated as a non-target subtransaction, and the first target subtransaction and the preset function statements before and after the first target subtransaction are executed;
[0018] Based on the fact that the first target subtransaction does not include the preset lock information, the first target subtransaction is executed, and the execution of function statements before and after the first target subtransaction is prohibited.
[0019] In a possible implementation, the sequentially executing the at least one target sub-transaction and prohibiting the execution of preset function statements before and after the target sub-transaction in the pending transaction includes:
[0020] Obtaining a target data snapshot of the database, where the target data snapshot is a version of the database in a preset time period before receiving the transaction to be processed;
[0021] If the transaction isolation level of the second target subtransaction is the first level, the second target subtransaction is executed according to the target data snapshot, and the preset function statements before and after the second target subtransaction in the pending transaction are prohibited from being executed, and the first level corresponds to the default level in the database;
[0022] If the transaction isolation level of the second target subtransaction is the second level, the second target subtransaction is treated as a non-target subtransaction, and the second target subtransaction and preset function statements before and after the second target subtransaction are executed, and the second level is different from the first level.
[0023] In a possible implementation, after receiving the transaction to be processed, the method further includes:
[0024] Parsing the pending transaction to obtain setting parameters;
[0025] Based on the setting parameters satisfying the start condition, triggering the step of analyzing the pending transaction and determining at least one target sub-transaction;
[0026] Based on the fact that the set parameters do not satisfy the start condition, each sub-transaction in the pending transaction is executed in sequence, and the preset function statements before and after each sub-transaction in the pending transaction are executed.
[0027] In a possible implementation, the method further includes:
[0028] If the third target subtransaction fails, the first subtransaction is executed, and the processing order of the first subtransaction is after the third target subtransaction and is adjacent to the third target subtransaction.
[0029] In the optimization method of the processing flow of database subtasks provided by the present application, a pending transaction is received, the pending transaction includes multiple subtransactions, each subtransaction in the pending transaction has a preset function statement before and after, the preset function statement includes a save point statement before executing the subtransaction and a release save point statement after executing the subtransaction, the pending transaction is analyzed, at least one target subtransaction contained therein is determined, the type of the target subtransaction belongs to the target type and is the first subtransaction in the processing order of the pending transaction, or the type of the target subtransaction belongs to the target type and is at least two consecutive subtransactions starting from the first subtransaction in the processing order of the pending transaction, and the subtransaction of the target type does not change the data in the database when it is executed; before opening the pending transaction , execute at least one target sub-transaction in sequence, and prohibit the execution of preset function statements before and after each target sub-transaction in the pending transaction; after starting the pending transaction, execute at least one non-target sub-transaction in the pending transaction, and execute the preset function statements before and after each non-target sub-transaction in the pending transaction. The processing order of the non-target sub-transaction is after the target sub-transaction. The target-type sub-transaction at the front of the pending transaction is used as the target sub-transaction. The processing flow of the pending transaction is optimized by executing each target sub-transaction before starting the pending transaction, so that each target sub-transaction will not start transaction processing and will not affect the transaction that has actually been started, thereby reducing the number of times the target sub-transaction visits the database and simplifying the processing flow of the pending transaction.
[0030] A second aspect of the present application provides a device for optimizing a processing flow of a database sub-transaction, comprising:
[0031] A receiving module, configured to receive a pending transaction, wherein the pending transaction includes at least two subtransactions, each subtransaction has preset function statements before and after it, and the preset function statements include a save point statement before executing the subtransaction and a release save point statement after executing the subtransaction;
[0032] an analysis module, configured to analyze the pending transaction and determine at least one target subtransaction, wherein the target subtransaction belongs to the target type and is the first subtransaction in the pending transaction processing sequence, or the target subtransaction belongs to the target type and is at least two consecutive subtransactions starting from the first subtransaction in the pending transaction processing sequence, and the subtransaction of the target type does not change the data in the database when it is executed;
[0033] A first execution module, configured to execute the at least one target sub-transaction in sequence before opening the pending transaction, and prohibit execution of preset function statements before and after the target sub-transaction in the pending transaction;
[0034] The second execution module is used to execute at least one non-target sub-transaction in the pending transaction after opening the pending transaction, and execute the preset function statements before and after each non-target sub-transaction in the pending transaction, and the processing order of the non-target sub-transaction is after the target sub-transaction.
[0035] A third aspect of the present application provides a computer program product, comprising computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements the method for optimizing the processing flow of a database sub-transaction according to the first aspect or any implementation method of the first aspect.
[0036] A fourth aspect of the present application provides an electronic device, comprising at least one processor and a memory connected to the processor, wherein:
[0037] The memory is used to store computer programs;
[0038] The processor is used to execute the computer program so that the electronic device can implement the method for optimizing the processing flow of the database sub-transaction according to the above-mentioned first aspect or any implementation manner of the first aspect.
[0039] A fifth aspect of the present application provides a computer storage medium, which carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement a method for optimizing the processing flow of database sub-transactions in the above-mentioned first aspect or any implementation method of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.
[0041] Figure 1 It is a flowchart of a method for optimizing the processing flow of a database sub-transaction provided by the present application;
[0042] Figure 2 This is a schematic diagram of the processing flow of a database sub-transaction that is not optimized provided in an embodiment of the present application. Figure 1 ;
[0043] Figure 3 The following is a schematic diagram of the processing flow of the optimization method for executing the processing flow of database sub-transactions provided in the embodiment of the present application. Figure 1 ;
[0044] Figure 4 It is a flowchart of determining whether to perform an optimization process based on a target sub-transaction provided by an embodiment of the present application;
[0045] Figure 5 It is a flowchart of sequentially executing the at least one target sub-transaction and prohibiting the execution of preset function statements before and after the target sub-transaction in the pending transaction provided by an embodiment of the present application;
[0046] Figure 6 It is a flowchart of determining whether to perform an optimization process based on the setting parameters of a transaction to be processed provided by an embodiment of the present application;
[0047] Figure 7 This is a schematic diagram of the processing flow of a database sub-transaction that is not optimized provided in an embodiment of the present application. Figure 2 ;
[0048] Figure 8 The following is a schematic diagram of the processing flow of the optimization method for executing the processing flow of database sub-transactions provided in the embodiment of the present application. Figure 2 ;
[0049] Fig. 9 It is a structural schematic diagram of a device for optimizing the processing flow of a database sub-transaction provided in an embodiment of the present application;
[0050] Fig.10 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0051] The following describes the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. The terms used in the implementation method section of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application.
[0052] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0053] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, which is only to describe the distinction mode adopted by the objects of the same attributes when describing in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0054] Figure 1 It is a flowchart of a method for optimizing the processing flow of a database sub-transaction provided in an embodiment of the present application, which may include steps 101 to 104. These steps are described in detail below.
[0055] 101. Receive a pending transaction, where the pending transaction includes at least two subtransactions, and each subtransaction has preset function statements before and after it, where the preset function statements include a savepoint statement before executing the subtransaction and a release savepoint statement after executing the subtransaction;
[0056] The pending transaction is a database transaction, and each pending transaction includes two or more sub-transactions.
[0057] The sub-transaction may be SQL (Structured Query Language).
[0058] The subtransaction may include multiple types, such as DML (Data Manipulation Language), DQL (Data Query Language), DDL (Data Definition Language), DCL (Data Control Language), etc. In the existing pending transactions, no matter what type of SQL the subtransaction is, a save point statement and a release save point statement are added before and after the SQL.
[0059] Among them, the DQL type sub-transaction can be a select (query) functional transaction; the DML type sub-transaction can include an insert (insert) functional transaction, an update (update) functional transaction, a delete (delete) functional transaction, etc.; the DDL type sub-transaction can include a create (create) functional transaction, an alter (change) functional transaction, a drop (drop) functional transaction, etc.
[0060] Among them, in the received pending transactions, preset function statements are set before and after each sub-transaction.
[0061] The preset function statement includes a save point statement and a release save point statement.
[0062] The savepoint statement is used to record the savepoint before executing the subtransaction. It is an identifier that allows partial rollback within the pending transaction, and provides a basis for subsequent rollback of subtransaction failures.
[0063] As an example, the savepoint statement may employ a SAVEPOINT statement.
[0064] The release savepoint statement is used to release the set savepoint statement after the subtransaction is executed and the subtransaction does not need to be rolled back.
[0065] As an example, the release savepoint statement may employ a RELEASE SAVEPOINT statement.
[0066] As a possible implementation, parameters can also be set for the pending transaction to determine whether to optimize the pending transaction. Figure 6 The process is described in detail.
[0067] 102. Analyze the pending transaction to determine at least one target subtransaction, the target subtransaction type being of the target type and being the first subtransaction in the pending transaction processing sequence, or the target subtransaction type being of the target type and being at least two consecutive subtransactions starting from the first subtransaction in the pending transaction processing sequence, and the subtransaction of the target type does not change data in the database when executed;
[0068] After receiving the pending transaction, the pending transaction may be parsed to obtain the type and processing order of each sub-transaction in the pending transaction.
[0069] The program of the transaction to be processed includes a start statement, various sub-transactions and an end statement, and each sub-transaction has a preset function statement before and after.
[0070] As a possible implementation, the type of each sub-transaction is determined in turn according to the processing order of each sub-transaction, so as to determine the target sub-transaction in the transaction to be processed.
[0071] Among them, the target type is DQL. This type of subtransaction only reads data and does not change the data in the database. Therefore, in theory, there is no need to execute savepoint statements and release savepoint statements. Therefore, subtransactions of this target type can be optimized. However, if the subtransaction of this target type is executed after the pending transaction is started, and the preset function statements before and after the subtransaction of this target type are prohibited from being executed, it may affect the top-level parent transaction of the pending transaction. It is necessary to determine the position of the subtransaction of this target type in the pending transaction.
[0072] Among them, when the sub-transaction of this target type is at the front of the transaction to be processed, it can be treated as a sub-transaction independent of the transaction to be processed and will not affect the transaction to be processed. Therefore, it is required that the sub-transaction of this target type is one or more sub-transactions in the processing order of the transaction to be processed starting from the first one in the processing order, and the multiple sub-transactions of this target type are continuous.
[0073] As an example, the pending transaction includes three sub-transactions, namely SQL1, SQL2 and SQL3. If SQL1 is of DQL type, SQL2 and SQL3 are DML, it is determined that SQL1 is a target sub-transaction, and it is determined that SQL2 and SQL3 are non-target sub-transactions, then subsequent step 103 is executed based on SQL1, and subsequent step 104 is executed based on SQL2 and SQL3.
[0074] As an example, the pending transaction includes five sub-transactions, namely SQL1, SQL2, SQL3, SQL4 and SQL5. If SQL1, SQL2 and SQL5 are of DQL type, and SQL3 and SQL4 are of DML type, it is determined that SQL1 and SQL2 are target sub-transactions, and it is determined that SQL3, SQL4 and SQL5 are non-target sub-transactions, then the subsequent step 103 is executed based on SQL1 and SQL2, and the subsequent step 104 is executed based on SQL3, SQL4 and SQL5.
[0075] As an example, the pending transaction includes three sub-transactions, namely SQL1, SQL2 and SQL3. If SQL1 is of DML type, and SQL2 and SQL3 are DQL, it is determined that there is no target sub-transaction in the pending transaction, and subsequent step 104 is performed according to SQL1, SQL2 and SQL3.
[0076] As a possible implementation, it is also possible to determine whether the target subtransaction contains lock information to determine whether to optimize the processing flow of the corresponding target subtransaction. Figure 4 The process is described in detail.
[0077] As a possible implementation, an isolation level can also be set for the pending transaction to determine whether to optimize the processing flow of the pending transaction according to different isolation levels. Figure 5 The process is described in detail.
[0078] 103. Before opening the pending transaction, execute the at least one target sub-transaction in sequence, and prohibit execution of preset function statements before and after the target sub-transaction in the pending transaction;
[0079] After the target sub-transaction is determined, the processing flow of the transaction to be processed is optimized.
[0080] The control executes each target sub-transaction before opening the pending transaction, and optimizes the processing flow of each target sub-transaction.
[0081] The optimization of the processing flow of each target sub-transaction includes: only executing each target sub-transaction itself, and prohibiting the execution of preset function statements before and after each target sub-transaction.
[0082] Among them, for the processing flow optimization of pending transactions, each target sub-transaction can be executed before opening the pending transaction, so that the processing process of each target sub-transaction is separated from the pending transaction, so that each target sub-transaction will not open transaction processing and will not affect the transaction that has actually been opened.
[0083] As a possible implementation, before opening the pending transaction, the at least one target sub-transaction is executed in sequence, and the preset function statements before and after the target sub-transaction in the pending transaction are prohibited from being executed, including: prohibiting the pending transaction from being opened by the target sub-transaction.
[0084] The beginning and the end of the transaction to be processed have a start statement and an end statement.
[0085] As an example, the start statement may be BEGIN and the end statement may be COMMIT.
[0086] To prohibit the first subtransaction from starting the pending transaction, the start statement may be moved from before the first subtransaction to after the first subtransaction.
[0087] 104. After the pending transaction is opened, at least one non-target sub-transaction in the pending transaction is executed, and preset function statements before and after each non-target sub-transaction in the pending transaction are executed. The processing order of the non-target sub-transaction is after the target sub-transaction.
[0088] The pending transaction is opened and executed by a subsequent non-target sub-transaction.
[0089] In a possible implementation, after the pending transaction is opened, at least one non-target sub-transaction in the pending transaction is executed, and preset functional statements before and after each non-target sub-transaction in the pending transaction are executed, including: controlling the pending transaction to be opened by the first non-target sub-transaction, the processing order of the first non-target sub-transaction is after the target sub-transaction, and is adjacent to the target sub-transaction with the last processing order.
[0090] As an example, the opening statement of the pending transaction is moved after all target subtransactions and before the first non-target subtransaction.
[0091] When processing each non-target subtransaction, the preset functional statements before and after the non-target subtransaction are executed to provide a basis for rollback when the data in the database is changed.
[0092] Figure 2 This is a schematic diagram of the processing flow of a database sub-transaction that is not optimized provided in an embodiment of the present application. Figure 1, wherein, in this processing flow, the start statement BEGIN is first executed to start the transaction; then the save point statement SAVEPOINTantdb before the DQL subtransaction is executed, the DQL subtransaction is executed, and the release save point statement RELEASESAVEPOINT after the DQL1 subtransaction is executed; then the save point statement before the DML1 subtransaction is executed, the DML1 subtransaction is executed, and the release save point statement after the DML1 subtransaction is executed; then the save point statement before the DML2 subtransaction is executed, the DML2 subtransaction is executed, and the release save point statement after the DML2 subtransaction is executed; finally, the end statement COMMIT is executed. Figure 2 The dashed box in the middle indicates the number of requests that need to be made to the database to execute the DQL subtransaction.
[0093] Figure 3 The following is a schematic diagram of the processing flow of the optimization method for executing the processing flow of database sub-transactions provided in the embodiment of the present application. Figure 1 , determine the target subtransaction of DQL1, and in the optimized processing flow, first execute the target subtransaction DQL1; then execute the start statement BEGIN to start the transaction; then execute the savepoint statement before the DML1 subtransaction, execute the DML1 subtransaction, and execute the release savepoint statement after the DML1 subtransaction; then execute the savepoint statement before the DML2 subtransaction, execute the DML2 subtransaction, and execute the release savepoint statement after the DML2 subtransaction; finally execute the end statement COMMIT. Figure 3 The dashed box in the middle indicates the number of requests that need to be made to the database to execute the DQL subtransaction.
[0094] Based on this Figure 2 and Figure 3 By comparing the processing flow in , it can be seen that for the DQL that is at the top of the processing order in the subtransaction, the number of requests to the database is reduced from 3 to 1, which improves the processing efficiency.
[0095] In addition to the start statement and the end statement, other database-related savepoint statements and release savepoint statements are marked with the corresponding databases. Figure 2 and Figure 3 The database marked in is the antdb database.
[0096] In this embodiment, a pending transaction is received, the pending transaction includes multiple subtransactions, each subtransaction in the pending transaction has preset function statements before and after, the preset function statements include a save point statement before executing the subtransaction and a release save point statement after executing the subtransaction, the pending transaction is analyzed, at least one target subtransaction contained therein is determined, the type of the target subtransaction belongs to the target type and is the first subtransaction in the processing order of the pending transaction, or the type of the target subtransaction belongs to the target type and is at least two consecutive subtransactions starting from the first subtransaction in the processing order of the pending transaction, and the subtransaction of the target type does not change the data in the database when it is executed; before opening the pending transaction, at least one is executed in sequence For target subtransactions, it is forbidden to execute preset function statements before and after each target subtransaction in the pending transaction; after starting the pending transaction, execute at least one non-target subtransaction in the pending transaction, and execute preset function statements before and after each non-target subtransaction in the pending transaction. The processing order of the non-target subtransaction is after the target subtransaction. The target-type subtransaction at the front of the pending transaction is used as the target subtransaction. The processing flow of the pending transaction is optimized by executing each target subtransaction before starting the pending transaction, so that each target subtransaction will not start transaction processing and will not affect the transaction that has actually been started, thereby reducing the number of times the target subtransaction visits the database and simplifying the processing flow of the pending transaction.
[0097] Figure 4 It is a flowchart of determining whether to perform an optimization process based on a target sub-transaction provided by an embodiment of the present application, which may include steps 401 to 403. These steps are described in detail below.
[0098] 401. parse each target sub-transaction to obtain information contained in each target sub-transaction;
[0099] Here, the program of each target sub-transaction is parsed to obtain the information it contains.
[0100] Herein, it is determined whether the information included in each sub-transaction includes preset lock information.
[0101] The preset lock information is held throughout the entire transaction until the transaction ends. Therefore, when the target subtransaction includes the preset lock information, the processing flow of the target subtransaction cannot be optimized and remains unchanged.
[0102] The preset lock information may include: FOR UPDATA, FOR NO KEY UPDATE, FOR SHARE, FORKEY SHARE, etc.
[0103] Among them, FOR UPDATE causes the rows retrieved by the SELECT statement to be locked as if they were to be updated. This prevents them from being locked, modified, or deleted by other transactions until the current transaction ends.
[0104] Among them, FOR NO KEY UPDATE behaves similarly to FOR UPDATE, but the lock acquired is weaker: this lock will not block a SELECT FOR KEY SHARE command that attempts to acquire a lock on the same row. Any UPDATE that does not acquire a FOR UPDATE lock will also acquire this lock mode.
[0105] Among them, FOR SHARE behaves similarly to FOR NO KEY UPDATE, but it acquires a shared lock instead of an exclusive lock on each retrieved row. A shared lock blocks other transactions from executing UPDATE, DELETE, SELECT FOR UPDATE, or SELECT FOR NO KEY UPDATE on these rows, but it does not prevent them from executing SELECT FOR SHARE or SELECT FOR KEY SHARE.
[0106] Among them, FOR KEY SHARE, behaves similarly to FOR SHARE, but the lock is weaker: SELECT FOR UPDATE will be blocked, but SELECT FOR NO KEY UPDATE will not be blocked. A key-shared lock will block other transactions from executing DELETE or UPDATE that modify key values, but will not block other UPDATEs, nor will it prevent SELECT FOR NO KEYUPDATE, SELECT FOR SHARE, or SELECT FOR KEY SHARE.
[0107] If the target sub-transaction includes any one of the above preset lock information, it can be determined that it contains lock information.
[0108] 402. Based on the preset lock information included in the first target subtransaction, the first target subtransaction is treated as a non-target subtransaction, and the first target subtransaction and the preset function statements before and after the first target subtransaction are executed;
[0109] If the first target subtransaction includes preset lock information, the first target subtransaction cannot be optimized for processing flow, and the first target subtransaction is treated as a non-target subtransaction to execute its sequential preset function statements.
[0110] In a possible implementation, if the first target subtransaction including the preset lock information is the subtransaction that is at the top of the processing sequence in the pending transaction, the pending transaction is initiated by the first target subtransaction.
[0111] In a possible implementation, if the first target subtransaction containing the preset lock information is not the subtransaction that is first in the processing order of the pending transaction, but each target subtransaction before the first target subtransaction does not contain the preset lock information, the pending transaction is initiated by the first target subtransaction.
[0112] In a possible implementation, if the first target subtransaction containing the preset lock information is not the subtransaction that is first in the processing order of the pending transaction, but a target subtransaction before the first target subtransaction contains the preset lock information, then the first target subtransaction only needs to be treated as a non-target subtransaction, and when executing the first target subtransaction process, it is sufficient to execute the preset functional statements before and after it.
[0113] 403. Based on the fact that the first target subtransaction does not include preset lock information, the first target subtransaction is executed, and execution of function statements before and after the first target subtransaction is prohibited.
[0114] If the first target subtransaction does not include the preset lock information, the first target subtransaction can be optimized for processing flow, and the first target subtransaction is executed, and the execution of the preset functional statements before and after the first target subtransaction is prohibited.
[0115] In a possible implementation, if the first target subtransaction containing preset lock information is the subtransaction that is the first in the processing order of the pending transaction, it is prohibited to start the pending transaction by the first target subtransaction. The pending transaction can be started by other target subtransactions containing preset lock information after the first target subtransaction, or by non-target subtransactions after the first target subtransaction.
[0116] In a possible implementation, if the first target subtransaction containing the preset lock information is not the subtransaction that is first in the processing order of the transaction to be processed, and a target subtransaction before the first target subtransaction contains the preset lock information, then the first target subtransaction is executed, and the execution of the preset functional statements before and after it is prohibited.
[0117] In this embodiment, each target subtransaction is parsed to obtain the information contained in each target subtransaction; based on the preset lock information contained in the first target subtransaction, the first target subtransaction is treated as a non-target subtransaction, and the first target subtransaction and the preset functional statements before and after the first target subtransaction are executed; based on the fact that the first target subtransaction does not contain the preset lock information, the first target subtransaction is executed, and the functional statements before and after the first target subtransaction are prohibited from being executed. Based on whether the preset lock information is contained in the target subtransaction, it is determined whether to optimize the processing flow of the first target subtransaction to improve the accuracy of the optimization.
[0118] Figure 5 It is a flowchart of executing at least one target sub-transaction in sequence and prohibiting the execution of preset function statements before and after the target sub-transaction in the pending transaction provided by an embodiment of the present application, which may include steps 501 to 503, and these steps are described in detail below.
[0119] 501. Obtain a target data snapshot of a database, where the target data snapshot is a database version in a preset time period before receiving the transaction to be processed;
[0120] Among them, data consistency is maintained by using a multi-version model (MVCC, Multi-Version Concurrency Control). Accordingly, each SQL statement can only get a snapshot of the data from a short period of time ago, regardless of the current state of the underlying data.
[0121] Among them, the above multi-version model can protect statements from seeing inconsistent data that may be caused by other concurrent transactions that perform updates on the same data row, providing transaction isolation for each database session. MVCC avoids the locking method of traditional database systems and minimizes lock contention to allow reasonable performance in a multi-user environment.
[0122] Among them, the target data snapshot is a database version of a preset time period before receiving the transaction to be processed. The length of the preset time period can be set according to actual conditions and is not limited in this application.
[0123] A default transaction isolation level is set in each database, and correspondingly, a corresponding transaction isolation level is set in each subtransaction.
[0124] In each subtransaction, the transaction isolation level can be set to the first level or the second level, and the first level is the default level of the database.
[0125] Among them, the isolation level of the subtransaction can include: READ COMMITTED, READUNCOMMITTED, REPEATABLE READ, and SERIALIZABLE.
[0126] Among them, READ COMMITTED is the first level of transaction isolation level, and the remaining isolation levels are the second level of transaction isolation levels.
[0127] 502. If the transaction isolation level of the second target subtransaction is the first level, the second target subtransaction is executed according to the target data snapshot, and the execution of preset function statements before and after the second target subtransaction in the pending transaction is prohibited, and the first level corresponds to the default level in the database;
[0128] If the transaction isolation level of the second target subtransaction is the first level, which corresponds to the default level in the database, the second target subtransaction can read the data in the database without affecting the data in the database.
[0129] If the transaction isolation level of the second target sub-transaction is the first level, the processing flow of the second target sub-transaction is optimized.
[0130] The second target sub-transaction is executed according to the data snapshot, and the second target sub-transaction reads the data in the data snapshot.
[0131] When executing the second target sub-transaction, only the second target sub-transaction is executed, and the execution of preset function statements before and after the second target sub-transaction in the pending transaction is prohibited.
[0132] In a possible implementation, if the transaction isolation level of the second target subtransaction is the first level and it is the subtransaction that is first in the processing order of the pending transaction, then the second target subtransaction is prohibited from starting the pending transaction. The pending transaction can be started by other target subtransactions whose transaction isolation level is the second level after the second target subtransaction, or by non-target subtransactions after the second target subtransaction.
[0133] In a possible implementation, if the transaction isolation level of the second target subtransaction is the first level, and the second target subtransaction is not the first subtransaction in the processing order of the transaction to be processed, and the transaction isolation level of a target subtransaction before the first target subtransaction is the second level, then the second target subtransaction is executed, and the execution of the preset functional statements before and after it is prohibited.
[0134] 503. If the transaction isolation level of the second target subtransaction is the second level, treat the second target subtransaction as a non-target subtransaction, execute the second target subtransaction and the preset function statements before and after the second target subtransaction, and the second level is different from the first level.
[0135] Among them, if the transaction isolation level of the second target sub-transaction is the second level, when the second target sub-transaction reads the data in the database, it may affect other transactions or data in the database. The second target sub-transaction cannot be processed by flow optimization, so the second target sub-transaction is treated as a non-target sub-transaction.
[0136] Correspondingly, the second target sub-transaction is treated as a non-target sub-transaction, and its sequential preset function statements are executed.
[0137] In a possible implementation, if the transaction isolation level of the second target subtransaction is the second level, and the second target subtransaction is the first subtransaction in the processing sequence of the pending transaction, the pending transaction is initiated by the second target subtransaction.
[0138] In a possible implementation, if the transaction isolation level of the second target subtransaction is the second level, and the second target subtransaction is not the first subtransaction in the processing order of the pending transaction, but the transaction isolation levels of each target subtransaction before the second target subtransaction are all the first level, then the pending transaction is initiated by the first target subtransaction.
[0139] In a possible implementation, if the transaction isolation level of the second target subtransaction is the second level, and the second target subtransaction is not the first subtransaction in the processing order of the pending transaction, but the transaction isolation level of a target subtransaction before the first target subtransaction is the second level, then the second target subtransaction only needs to be treated as a non-target subtransaction, and when executing the second target subtransaction process, its sequential preset functional statements only need to be executed.
[0140] In this embodiment, a target data snapshot of the database is obtained, and the target data snapshot is a database version of a preset time period before receiving the pending transaction; if the transaction isolation level of the second target subtransaction is the first level, the second target subtransaction is executed according to the target data snapshot, and the execution of preset functional statements before and after the second target subtransaction in the pending transaction is prohibited, and the first level corresponds to the default level in the database; if the transaction isolation level of the second target subtransaction is the second level, the second target subtransaction is treated as a non-target subtransaction, and the second target subtransaction and the preset functional statements before and after the second target subtransaction are executed. The second level is different from the first level. Through the transaction isolation level of each target subtransaction, it is determined whether to optimize the processing flow of the corresponding target subtransaction, thereby improving the accuracy of the optimization.
[0141] Figure 6 It is a flowchart of determining whether to perform an optimization process based on the setting parameters of the transaction to be processed provided by an embodiment of the present application, which may include steps 601 to 603, and these steps are described in detail below.
[0142] 601. Analyze the pending transaction and obtain setting parameters;
[0143] After receiving the pending transaction, the pending transaction is parsed to obtain its setting parameters.
[0144] As an example, a parameter may be set in the global parameters of the pending transaction, and the parameter is used to indicate whether to start the processing flow optimization process of the pending transaction.
[0145] As an example, when the setting parameter value is 0, the start condition is met, and when the setting parameter value is 1, the start condition is not met.
[0146] 602. Based on the setting parameter satisfying the start condition, triggering the step of analyzing the pending transaction and determining at least one target sub-transaction;
[0147] If the setting parameters obtained by the analysis meet the start condition, the subsequent steps are triggered, the transaction to be processed is analyzed to determine the target sub-transaction therein, and steps 102-104 are executed.
[0148] 603. Based on the fact that the set parameters do not satisfy the start condition, each sub-transaction in the pending transaction is executed in sequence, and the preset function statements before and after each sub-transaction in the pending transaction are executed.
[0149] If the set parameters obtained through analysis do not meet the start conditions, the processing flow optimization process of the pending transaction will not be started.
[0150] Among them, each sub-transaction in the pending transaction is executed in sequence, and the preset function statements before and after the execution of each sub-transaction are implemented, so that the processing flow of the pending transaction is not optimized.
[0151] In this embodiment, after receiving a pending transaction, the pending transaction is parsed to obtain set parameters; if the set parameters meet the start conditions, the optimization process of the processing flow of the pending transaction is triggered; if the set parameters do not meet the start conditions, the processing flow of the pending transaction is not optimized, and each sub-transaction in the pending transaction is executed in sequence, and the preset functional statements before and after each sub-transaction in the pending transaction are executed, thereby realizing flexible control of the optimization process.
[0152] The embodiment of the present application also provides an optimization process embodiment for the target sub-transaction rollback process.
[0153] In a possible implementation, while executing the at least one target sub-transaction in sequence and prohibiting the execution of preset functional statements before and after the target sub-transaction in the pending transaction, if the third target sub-transaction fails, the first sub-transaction is executed, and the processing order of the first sub-transaction is after the third target sub-transaction and is adjacent to the third target sub-transaction.
[0154] The third target transaction is any target sub-transaction.
[0155] If a failure occurs during the execution of the third target subtransaction, the third target subtransaction needs to be rolled back to ensure that the database on which subsequent subtransactions are executed is rolled back to the database before the execution of the third target subtransaction.
[0156] Since the data in the database is not changed when the third target subtransaction is executed, the execution of the third target subtransaction can be ignored, and there is no need to roll back the operation. The first subtransaction after the third target subtransaction can be directly executed.
[0157] The first subtransaction may be a target subtransaction after the third target subtransaction or a non-target subtransaction.
[0158] If the first subtransaction is a target subtransaction, the execution of preset function statements before and after the first subtransaction may be prohibited based on directly executing the first subtransaction.
[0159] If the first subtransaction is a non-target subtransaction and the pending transaction has not been opened, the pending transaction can be opened based on the first subtransaction, and the first subtransaction and the preset function statements before and after the first subtransaction are executed.
[0160] If the first subtransaction is a non-target subtransaction and the pending transaction is currently opened, the first subtransaction can be executed, and the preset function statements before and after the first subtransaction can be executed.
[0161] Figure 7 This is a schematic diagram of the processing flow of a database sub-transaction that is not optimized provided in an embodiment of the present application. Figure 2, wherein, in the processing flow, the start statement BEGIN is first executed to start the transaction; then the save point statement SAVEPOINT before the DQL subtransaction is executed, the DQL subtransaction is executed, the DQL1 subtransaction fails, the rollback statement ROLLBACK TOSAVEPOINT is executed, and the release save point statement after the DQL subtransaction is executed; then the save point statement before the DML1 subtransaction is executed, the DML1 subtransaction is executed, and the release save point statement after the DML1 subtransaction is executed; then the save point statement before the DML2 subtransaction is executed, the DML2 subtransaction is executed, and the release save point statement after the DML2 subtransaction is executed; finally, the end statement COMMIT is executed. Figure 7 The dashed box in the middle indicates the number of requests that need to be made to the database to execute the DQL subtransaction.
[0162] Figure 8 The following is a schematic diagram of the processing flow of the optimization method for executing the processing flow of database sub-transactions provided in the embodiment of the present application. Figure 2 , determine the target subtransaction of DQL1, and in the optimized processing flow, first execute the target subtransaction DQL1; then execute the start statement BEGIN to start the transaction; then execute the savepoint statement before the DML1 subtransaction, execute the DML1 subtransaction, and execute the release savepoint statement after the DML1 subtransaction; then execute the savepoint statement before the DML2 subtransaction, execute the DML2 subtransaction, and execute the release savepoint statement after the DML2 subtransaction; finally execute the end statement COMMIT. Figure 8 The dashed box in the middle indicates the number of requests that need to be made to the database to execute the DQL subtransaction.
[0163] Based on this Figure 7 and Figure 8 By comparing the processing flow in , it can be seen that for the DQL that is at the top of the processing order in the subtransaction, the number of requests to the database is reduced from 4 to 1, which improves the processing efficiency.
[0164] In addition to the start statement and the end statement, other database-related savepoint statements, release savepoint statements, and rollback statements are marked with the corresponding databases. Figure 7 and Figure 8 The database marked in is the antdb database.
[0165] In this embodiment, if the third target subtransaction fails, the first subtransaction after the third target subtransaction is executed. The processing order of the first subtransaction is after the third target subtransaction and is adjacent to the third target subtransaction, thereby optimizing the processing flow of the target subtransaction that needs to be rolled back due to a failure, reducing the number of times the target subtransaction accesses the database, and simplifying the processing flow of the pending transactions.
[0166] A method for optimizing the processing flow of a database sub-transaction provided in an embodiment of the present application is introduced above. A device for executing the method for optimizing the processing flow of a database sub-transaction will be introduced below.
[0167] Fig. 9 1 is a schematic diagram of a structure of an optimization device for a database sub-transaction processing flow provided by an embodiment of the present application. Fig. 9 As shown, the device 900 for optimizing the processing flow of the database sub-transaction includes: a receiving module 901, an analyzing module 902, a first executing module 903 and a second executing module 904;
[0168] The receiving module 901 is used to receive a pending transaction, which includes at least two subtransactions. Each subtransaction has a preset function statement before and after the subtransaction. The preset function statement includes a save point statement before executing the subtransaction and a release save point statement after executing the subtransaction.
[0169] The analysis module 902 is used to analyze the pending transaction and determine at least one target subtransaction, the target subtransaction type is the target type and the processing order is the first subtransaction in the pending transaction, or the target subtransaction type is the target type and at least two consecutive subtransactions starting from the first subtransaction in the processing order in the pending transaction, and the subtransaction of the target type does not change the data in the database when it is executed;
[0170] The first execution module 903 is used to execute the at least one target sub-transaction in sequence before opening the pending transaction, and prohibit the execution of preset function statements before and after the target sub-transaction in the pending transaction;
[0171] Among them, the second execution module 904 is used to execute at least one non-target sub-transaction in the pending transaction after opening the pending transaction, and execute the preset function statements before and after each non-target sub-transaction in the pending transaction. The processing order of the non-target sub-transaction is after the target sub-transaction.
[0172] In a possible implementation, the first execution module is specifically configured to:
[0173] It is forbidden to start the pending transaction by the target subtransaction;
[0174] Accordingly, after the pending transaction is opened, at least one non-target sub-transaction in the pending transaction is executed, and the preset function statements before and after each non-target sub-transaction in the pending transaction are executed, including:
[0175] The transaction to be processed is controlled to be started by a first non-target subtransaction, the processing order of the first non-target subtransaction is after the target subtransaction, and is adjacent to the target subtransaction at the end of the processing order.
[0176] In a possible implementation, the method further includes:
[0177] A first parsing module is used to analyze the transaction to be processed, determine at least one target sub-transaction, and then parse each target sub-transaction to obtain information contained in each target sub-transaction;
[0178] The second execution module is further configured to, based on the preset lock information included in the first target subtransaction, use the first target subtransaction as a non-target subtransaction, and execute the first target subtransaction and preset function statements before and after the first target subtransaction;
[0179] The first execution module is further configured to execute the first target subtransaction based on the fact that the first target subtransaction does not contain preset lock information, and prohibit execution of function statements before and after the first target subtransaction.
[0180] In a possible implementation, the first execution module is specifically configured to:
[0181] Obtaining a target data snapshot of the database, where the target data snapshot is a version of the database in a preset time period before receiving the transaction to be processed;
[0182] If the transaction isolation level of the second target subtransaction is the first level, the second target subtransaction is executed according to the target data snapshot, and the execution of preset function statements before and after the second target subtransaction in the pending transaction is prohibited, and the first level corresponds to the default level in the database;
[0183] If the transaction isolation level of the second target subtransaction is the second level, the second target subtransaction is treated as a non-target subtransaction, and the second target subtransaction and the preset function statements before and after the second target subtransaction are executed. The second level is different from the first level.
[0184] In a possible implementation, the method further includes:
[0185] A second parsing module is used to parse the pending transaction after receiving the pending transaction to obtain the setting parameters;
[0186] A trigger module, configured to trigger the analysis module based on the setting parameter satisfying the start condition; and trigger the third execution module based on the setting parameter not satisfying the start condition;
[0187] The third execution module is used to execute each sub-transaction in the pending transaction in sequence, and execute the preset function statements before and after each sub-transaction in the pending transaction.
[0188] In a possible implementation, the method further includes:
[0189] The fourth execution module is configured to execute the first subtransaction if the third target subtransaction fails, wherein the processing order of the first subtransaction is after the third target subtransaction and is adjacent to the third target subtransaction.
[0190] It should be noted that, for the functional explanation of each component structure of the optimization device for the processing flow of a database sub-transaction provided in this embodiment, please refer to the explanation in the aforementioned method embodiment, which will not be repeated in this embodiment.
[0191] In this embodiment, a pending transaction is received, the pending transaction includes multiple subtransactions, each subtransaction in the pending transaction has preset function statements before and after, the preset function statements include a save point statement before executing the subtransaction and a release save point statement after executing the subtransaction, the pending transaction is analyzed, at least one target subtransaction contained therein is determined, the type of the target subtransaction belongs to the target type and is the first subtransaction in the processing order of the pending transaction, or the type of the target subtransaction belongs to the target type and is at least two consecutive subtransactions starting from the first subtransaction in the processing order of the pending transaction, and the subtransaction of the target type does not change the data in the database when it is executed; before opening the pending transaction, at least one is executed in sequence For target subtransactions, it is forbidden to execute preset function statements before and after each target subtransaction in the pending transaction; after starting the pending transaction, execute at least one non-target subtransaction in the pending transaction, and execute preset function statements before and after each non-target subtransaction in the pending transaction. The processing order of the non-target subtransaction is after the target subtransaction. The target-type subtransaction at the front of the pending transaction is used as the target subtransaction. The processing flow of the pending transaction is optimized by executing each target subtransaction before starting the pending transaction, so that each target subtransaction will not start transaction processing and will not affect the transaction that has actually been started, thereby reducing the number of times the target subtransaction visits the database and simplifying the processing flow of the pending transaction.
[0192] The present application also provides an electronic device in an embodiment. Fig.10 As shown, it shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiment of the present application. The electronic device in the embodiment of the present application may include but is not limited to fixed terminals such as mobile phones, laptops, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Fig.10 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0193] like Fig.10As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 1001, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage device 1008 to a random access memory (RAM) 1003. When the electronic device is powered on, various programs and data required for the operation of the electronic device are also stored in the RAM 1003. The processing device 1001, the ROM 1002, and the RAM 1003 are connected to each other via a bus 1004. An input / output (I / O) interface 1005 is also connected to the bus 1004.
[0194] Typically, the following devices may be connected to the I / O interface 1005: an input device 1006 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 1007 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 1008 including, for example, a memory card, a hard disk, etc.; and a communication device 1009. The communication device 1009 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although Fig.10 An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0195] An embodiment of the present application also provides a computer program product including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements a method for optimizing the processing flow of any database sub-transaction provided in the embodiment of the present application.
[0196] A computer-readable storage medium is also provided in an embodiment of the present application. The storage medium carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement an optimization method for the processing flow of any database sub-transaction provided in an embodiment of the present application.
[0197] It should also be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the drawings of the device embodiments provided by the present application, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines.
[0198] Through the description of the above implementation mode, the technicians in the field can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course, it can also be implemented by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. In general, all functions completed by computer programs can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the present application, software program implementation is a better implementation mode in more cases. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer floppy disk, a U disk, a mobile hard disk, a ROM, a RAM, a disk or an optical disk, etc., including a number of instructions to enable a computer device (which can be a personal computer, a training device, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0199] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.
[0200] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a training device, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, training device, or data center. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.
Claims
1. A method for optimizing the processing flow of database subtransactions, characterized in that: include: Receive a pending transaction, the pending transaction including at least two subtransactions, each subtransaction having preset function statements before and after, the preset function statements including a savepoint statement before executing the subtransaction and a release savepoint statement after executing the subtransaction; Analyze the pending transaction to determine at least one target subtransaction, wherein the target subtransaction belongs to the target type and is the first subtransaction in the pending transaction processing sequence, or the target subtransaction belongs to the target type and is at least two consecutive subtransactions starting from the first subtransaction in the pending transaction processing sequence, and the subtransaction of the target type does not change the data in the database when it is executed; Before opening the pending transaction, executing the at least one target sub-transaction in sequence, and prohibiting the execution of preset function statements before and after the target sub-transaction in the pending transaction; After the pending transaction is opened, at least one non-target sub-transaction in the pending transaction is executed, and preset function statements before and after each non-target sub-transaction in the pending transaction are executed, and the processing order of the non-target sub-transaction is after the target sub-transaction; The sequentially executing the at least one target sub-transaction and prohibiting the execution of preset function statements before and after the target sub-transaction in the pending transaction includes: Obtaining a target data snapshot of the database, where the target data snapshot is a version of the database in a preset time period before receiving the transaction to be processed; If the transaction isolation level of the second target subtransaction is the first level, the second target subtransaction is executed according to the target data snapshot, and the preset function statements before and after the second target subtransaction in the pending transaction are prohibited from being executed, and the first level corresponds to the default level in the database; If the transaction isolation level of the second target subtransaction is the second level, the second target subtransaction is treated as a non-target subtransaction, and the second target subtransaction and preset function statements before and after the second target subtransaction are executed, and the second level is different from the first level.
2. The method for optimizing the processing flow of database sub-transactions according to claim 1, characterized in that: The method of executing the at least one target sub-transaction in sequence before opening the pending transaction and prohibiting the execution of preset function statements before and after the target sub-transaction in the pending transaction further includes: It is prohibited to open the pending transaction by the target subtransaction; Accordingly, after the pending transaction is opened, at least one non-target sub-transaction in the pending transaction is executed, and the preset function statements before and after each non-target sub-transaction in the pending transaction are executed, including: The to-be-processed transaction is controlled to be started by a first non-target subtransaction, wherein the processing order of the first non-target subtransaction is after the target subtransaction and is adjacent to the target subtransaction at the end of the processing order.
3. The method for optimizing the processing flow of database sub-transactions according to claim 1, characterized in that: After analyzing the pending transaction and determining at least one target sub-transaction, the method further includes: Parse each target sub-transaction to obtain the information contained in each target sub-transaction; Based on the preset lock information included in the first target subtransaction, the first target subtransaction is treated as a non-target subtransaction, and the first target subtransaction and the preset function statements before and after the first target subtransaction are executed; Based on the fact that the first target subtransaction does not include the preset lock information, the first target subtransaction is executed, and the execution of function statements before and after the first target subtransaction is prohibited.
4. The method for optimizing the processing flow of database subtransactions according to claim 1, characterized in that: After receiving the pending transaction, the method further includes: Parsing the pending transaction to obtain setting parameters; Based on the setting parameters satisfying the start condition, triggering the step of analyzing the pending transaction and determining at least one target sub-transaction; Based on the fact that the set parameters do not satisfy the start condition, each sub-transaction in the pending transaction is executed in sequence, and the preset function statements before and after each sub-transaction in the pending transaction are executed.
5. The method for optimizing the processing flow of database sub-transactions according to claim 1, characterized in that: Also includes: If the third target subtransaction fails, the first subtransaction is executed, and the processing order of the first subtransaction is after the third target subtransaction and is adjacent to the third target subtransaction.
6. A device for optimizing the processing flow of database sub-transactions, characterized in that: include: A receiving module, configured to receive a pending transaction, wherein the pending transaction includes at least two subtransactions, each subtransaction has preset function statements before and after it, and the preset function statements include a save point statement before executing the subtransaction and a release save point statement after executing the subtransaction; an analysis module, configured to analyze the pending transaction and determine at least one target subtransaction, wherein the target subtransaction belongs to the target type and is the first subtransaction in the pending transaction processing sequence, or the target subtransaction belongs to the target type and is at least two consecutive subtransactions starting from the first subtransaction in the pending transaction processing sequence, and the subtransaction of the target type does not change the data in the database when it is executed; A first execution module, configured to execute the at least one target sub-transaction in sequence before opening the pending transaction, and prohibit execution of preset function statements before and after the target sub-transaction in the pending transaction; A second execution module is used to execute at least one non-target sub-transaction in the pending transaction after opening the pending transaction, and execute preset function statements before and after each non-target sub-transaction in the pending transaction, wherein the processing order of the non-target sub-transaction is after the target sub-transaction; The first execution module is specifically used for: Obtaining a target data snapshot of the database, where the target data snapshot is a version of the database in a preset time period before receiving the transaction to be processed; If the transaction isolation level of the second target subtransaction is the first level, the second target subtransaction is executed according to the target data snapshot, and the preset function statements before and after the second target subtransaction in the pending transaction are prohibited from being executed, and the first level corresponds to the default level in the database; If the transaction isolation level of the second target subtransaction is the second level, the second target subtransaction is treated as a non-target subtransaction, and the second target subtransaction and preset function statements before and after the second target subtransaction are executed, and the second level is different from the first level.
7. A computer program product, characterized in that It comprises computer-readable instructions, and when the computer-readable instructions are executed on an electronic device, the electronic device implements the method for optimizing the processing flow of a database sub-transaction as claimed in any one of claims 1 to 5.
8. An electronic device, characterized in that: The method comprises at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program so that the electronic device can implement the method for optimizing the processing flow of database sub-transactions as described in any one of claims 1 to 5.
9. A computer storage medium, characterized in that: The storage medium carries one or more computer programs, and when the one or more computer programs are executed by an electronic device, the electronic device can implement the method for optimizing the processing flow of a database sub-transaction as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Transaction savepoint management apparatus and method based on distributed database
CN107545024A
Processing method and device of database deadlock and database system
CN108205464A
Multi-version concurrency control method and device for database, server and storage medium
CN108363806A
Database-based data processing method and device, and readable storage medium
CN112084161A
Processing method and system for transaction saving points of distributed database
CN112597176A
