[go: up one dir, main page]

TW201828164A - Database operation method and device capable of improving transaction execution efficiency of database transaction with higher delivery amount of transactions - Google Patents

Database operation method and device capable of improving transaction execution efficiency of database transaction with higher delivery amount of transactions Download PDF

Info

Publication number
TW201828164A
TW201828164A TW106101941A TW106101941A TW201828164A TW 201828164 A TW201828164 A TW 201828164A TW 106101941 A TW106101941 A TW 106101941A TW 106101941 A TW106101941 A TW 106101941A TW 201828164 A TW201828164 A TW 201828164A
Authority
TW
Taiwan
Prior art keywords
database
operation instruction
instruction
database operation
execution
Prior art date
Application number
TW106101941A
Other languages
Chinese (zh)
Other versions
TWI725110B (en
Inventor
王晶昱
Original Assignee
阿里巴巴集團服務有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 阿里巴巴集團服務有限公司 filed Critical 阿里巴巴集團服務有限公司
Priority to TW106101941A priority Critical patent/TWI725110B/en
Publication of TW201828164A publication Critical patent/TW201828164A/en
Application granted granted Critical
Publication of TWI725110B publication Critical patent/TWI725110B/en

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本發明提供一種資料庫操作方法及裝置。方法包括:在應用伺服器執行目標事務的過程中,依次獲取應用伺服器執行到的目標事務中的資料庫操作指令;對資料庫操作指令進行預測執行,將預測執行結果返回給應用伺服器以供應用伺服器確定下一個需要執行的資料庫操作指令,並在本地記錄資料庫操作指令以及在資料庫操作指令屬於修改資料庫類指令時記錄預測執行產生的預測執行資料;當獲取到目標事務中的事務提交指令時,根據本地記錄的資料庫操作指令以及預測執行資料,控制應用伺服器對應的資料庫實際執行目標事務。本發明可以提高事務執行效率。 The invention provides a database operation method and device. The method includes: in the process of executing the target transaction by the application server, sequentially acquiring the database operation instruction in the target transaction executed by the application server; performing prediction execution on the database operation instruction, and returning the prediction execution result to the application server. The provisioning server determines the next database operation instruction to be executed, and records the database operation instruction locally and records the predicted execution data generated by the prediction execution when the database operation instruction belongs to the modified database type instruction; when the target transaction is acquired When the transaction in the transaction commits the instruction, the database corresponding to the locally recorded database operation instruction and the predicted execution data controls the database corresponding to the application server to actually execute the target transaction. The invention can improve transaction execution efficiency.

Description

資料庫操作方法及裝置  Database operation method and device  

本發明關於資料庫技術領域,尤其關於一種資料庫操作方法及裝置。 The invention relates to the technical field of database, in particular to a database operation method and device.

資料庫事務(Database Transaction),是指作為單個邏輯工作單元執行的一系列操作,要麼完全地執行,要麼完全地不執行。一個事務由一系列資料庫操作指令構成,例如結構化查詢語言(Structured Query Language,SQL)語句,這些資料庫操作指令之間存在切分條件以及跳轉等邏輯,意味著在一次執行過程中該事務中可能有部分資料庫操作指令被跳過不執行。但在現有技術中,由於無法預先獲知事務中需要執行的資料庫操作指令,因此只能按照執行邏輯邊執行邊判斷,依次執行事務中的語句,以實現對資料庫的操作。這種事務執行方式效率較低,尤其是在事務設置讀已提交隔離級別的情況下,其執行效率會更低,事務輸送量較低。 Database Transaction refers to a series of operations performed as a single logical unit of work, either completely or completely. A transaction consists of a series of database operation instructions, such as Structured Query Language (SQL) statements. There are logics such as splitting conditions and jumps between these database operation instructions, meaning that the transaction is executed in one execution. Some database operation instructions may be skipped and not executed. However, in the prior art, since the database operation instruction that needs to be executed in the transaction cannot be known in advance, the execution judgment can only be performed according to the execution logic, and the statement in the transaction is sequentially executed to implement the operation on the database. This type of transaction execution is less efficient, especially when the transaction settings read committed isolation level is less efficient and the transaction volume is lower.

本發明的多個方面提供一種資料庫操作方法及裝置,用以提高事務執行效率並增大事務輸送量。 Aspects of the present invention provide a database operation method and apparatus for improving transaction execution efficiency and increasing transaction throughput.

本發明的一方面,提供一種資料庫操作方法,包括:在應用伺服器執行目標事務的過程中,依次獲取所述應用伺服器執行到的所述目標事務中的資料庫操作指令;對所述資料庫操作指令進行預測執行,將預測執行結果返回給所述應用伺服器以供所述應用伺服器確定下一個需要執行的資料庫操作指令,並在本地記錄所述資料庫操作指令以及在所述資料庫操作指令屬於修改資料庫類指令時記錄所述預測執行產生的預測執行資料;當獲取到所述目標事務中的事務提交指令時,根據本地記錄的所述資料庫操作指令以及所述預測執行資料,控制所述應用伺服器對應的資料庫實際執行所述目標事務。 An aspect of the present invention provides a database operation method, including: sequentially acquiring, in an execution process of an application server, a database operation instruction in the target transaction executed by the application server; The database operation instruction performs prediction execution, returns the predicted execution result to the application server for the application server to determine the next database operation instruction to be executed, and locally records the database operation instruction and the local The database operation instruction belongs to the prediction execution data generated by the prediction execution when the database instruction is modified; when the transaction commit instruction in the target transaction is acquired, according to the database operation instruction of the local record and the Predicting the execution data, and controlling the database corresponding to the application server to actually execute the target transaction.

本發明的另一方面,提供一種資料庫操作裝置,包括:獲取模組,用於在應用伺服器執行目標事務的過程中,依次獲取所述應用伺服器執行到的所述目標事務中的資料庫操作指令;預測執行模組,用於對所述資料庫操作指令進行預測執行,將預測執行結果返回給所述應用伺服器以供所述應用伺服器確定下一個需要執行的資料庫操作指令,並在本地記錄所述資料庫操作指令以及在所述資料庫操作指令屬於修改資料庫類指令時記錄所述預測執行產生的預測執行資料; 控制執行模組,用於當獲取到所述目標事務中的事務提交指令時,根據本地記錄的所述資料庫操作指令以及所述預測執行資料,控制所述應用伺服器對應的資料庫實際執行所述目標事務。 In another aspect of the present invention, a database operating device is provided, including: an obtaining module, configured to sequentially acquire data in the target transaction executed by the application server during a process of executing a target transaction by an application server a library operation instruction; a prediction execution module, configured to perform prediction execution on the database operation instruction, and return the prediction execution result to the application server for the application server to determine a next database operation instruction to be executed And recording the database operation instruction locally and recording the predicted execution data generated by the prediction execution when the database operation instruction belongs to the modification database type instruction; and controlling the execution module, when acquiring the target When the transaction in the transaction commits the instruction, the database corresponding to the application server is controlled to actually execute the target transaction according to the database operation instruction and the predicted execution data recorded locally.

在本發明中,資料庫操作裝置與應用伺服器相互配合,在應用伺服器執行目標事務的過程加入預測執行過程,預先獲得並記錄目標事務需要執行的全部資料庫操作指令,並僅針對屬於修改資料庫類指令的資料庫操作指令記錄預測執行產生的預測執行資料以適應於讀已提交隔離級別,為真實執行事務提供了條件,之後根據記錄的資料庫操作指令以及預測執行資料,控制應用伺服器對應的資料庫實際執行該目標事務,有利於提高執行效率,進而增大事務輸送量。 In the present invention, the database operating device cooperates with the application server to join the predictive execution process in the process of executing the target transaction by the application server, and obtains and records all the database operation instructions that need to be executed in the target transaction in advance, and only belongs to the modification. The database operation instruction record of the database class instruction records the prediction execution data generated by the prediction execution to adapt to the read isolation level, provides conditions for the real execution transaction, and then controls the application servo according to the recorded database operation instruction and the prediction execution data. The corresponding database of the device actually executes the target transaction, which is beneficial to improve the execution efficiency and thereby increase the transaction volume.

10‧‧‧應用伺服器 10‧‧‧Application Server

20‧‧‧資料庫 20‧‧‧Database

30‧‧‧資料庫操作裝置 30‧‧‧Database operating device

301、302、303‧‧‧方法步驟 301, 302, 303‧ ‧ method steps

41‧‧‧獲取模組 41‧‧‧Get the module

42‧‧‧預測執行模組 42‧‧‧Predictive Execution Module

43‧‧‧控制執行模組 43‧‧‧Control Execution Module

為了更清楚地說明本發明實施例中的技術方案,下面將對實施例或現有技術描述中所需要使用的附圖作一簡單地介紹,顯而易見地,下面描述中的附圖是本發明的一些實施例,對於本領域普通技術人員來講,在不付出創造性勞動性的前提下,還可以根據這些附圖獲得其他的附圖。 In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the embodiments or the prior art description will be briefly described below. Obviously, the drawings in the following description are some of the present invention. For the embodiments, other drawings may be obtained from those skilled in the art without any inventive labor.

圖1為現有技術中資料庫應用系統的部署圖;圖2為本發明一實施例提供的資料庫應用系統的部署圖;圖3為本發明一實施例提供的資料庫操作方法的流程 示意圖;圖4為本發明一實施例提供的資料庫操作裝置的結構示意圖。 1 is a deployment diagram of a database application system in the prior art; FIG. 2 is a deployment diagram of a database application system according to an embodiment of the present invention; FIG. 3 is a schematic flowchart of a database operation method according to an embodiment of the present invention; FIG. 4 is a schematic structural diagram of a database operating device according to an embodiment of the present invention.

為使本發明實施例的目的、技術方案和優點更加清楚,下面將結合本發明實施例中的附圖,對本發明實施例中的技術方案進行清楚、完整地描述,顯然,所描述的實施例是本發明一部分實施例,而不是全部的實施例。基於本發明中的實施例,本領域普通技術人員在沒有作出創造性勞動前提下所獲得的所有其他實施例,都屬於本發明保護的範圍。 The technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the drawings in the embodiments of the present invention. It is a partial embodiment of the invention, and not all of the embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative efforts are within the scope of the present invention.

圖1為現有技術中資料庫應用系統的部署圖。如圖1所示,該系統包括:應用伺服器10和資料庫20。其中,資料庫20可以為一個,也可以為多個。圖1中僅示例性的示出一個資料庫20。當需要以事務方式對資料庫20進行訪問時,應用伺服器10執行事務邏輯,依次將事務中的資料庫操作指令作用於資料庫20上。由於無法預先獲知事務中需要執行的資料庫操作指令,導致事務執行效率較低,尤其是在配置讀已提交隔離級別的情況下,其執行效率會更低,事務輸送量較低。 FIG. 1 is a deployment diagram of a database application system in the prior art. As shown in FIG. 1, the system includes an application server 10 and a database 20. The database 20 may be one or more than one. Only one database 20 is shown by way of example in FIG. When the database 20 needs to be accessed in a transactional manner, the application server 10 executes the transaction logic to sequentially apply the database operation instructions in the transaction to the database 20. Because the database operation instructions that need to be executed in the transaction cannot be known in advance, the transaction execution efficiency is low, especially when the configuration read commit isolation level is configured, the execution efficiency is lower, and the transaction volume is lower.

針對現有技術存在的缺陷,本發明提供一種新的資料庫應用系統,如圖2所示。該系統在應用伺服器10和資料庫20之間增加資料庫操作裝置30。資料庫操作裝置30 用以執行本發明提供的資料庫操作方法,在讀已提交這一隔離級別下實現一種新的事務執行邏輯,即先對事務進行預測執行,提前獲得該事務中需要執行的資料庫操作指令,實現執行路徑的預測,並且結合讀已提交這一隔離級別僅僅針對屬於修改資料庫類指令的資料庫操作指令記錄對其進行預測執行所產生的預測執行資料,進而基於預測執行得到的資料庫操作指令以及預測執行資料在資料庫20上實際執行事務,有利於提高事務執行效率,增大事務輸送量。事務輸送量是指單位時間內處理事務的數量。 In view of the deficiencies of the prior art, the present invention provides a new database application system, as shown in FIG. The system adds a database operating device 30 between the application server 10 and the database 20. The database operation device 30 is configured to execute the database operation method provided by the present invention, and implement a new transaction execution logic under the isolation level of the read commit, that is, predictive execution of the transaction and obtaining the data to be executed in the transaction in advance. The library operation instruction realizes the prediction of the execution path, and the read execution level has been submitted only for the prediction execution data generated by the prediction execution of the database operation instruction record belonging to the modified database class instruction, and then obtained based on the prediction execution. The database operation instruction and the prediction execution data actually execute the transaction on the database 20, which is beneficial to improve transaction execution efficiency and increase transaction volume. Transaction throughput refers to the number of transactions processed per unit of time.

值得說明的是,資料庫操作裝置30實際上是一種邏輯處理裝置,其可以單獨部署,位於應用伺服器10和資料庫20之間,也可以部署於應用伺服器10一端實現,或者也可以部署於資料庫20一端實現。 It should be noted that the database operating device 30 is actually a logical processing device, which can be deployed separately, between the application server 10 and the database 20, or can be deployed on one end of the application server 10, or can be deployed. Implemented at the end of the database 20.

下面實施例將具體說明本發明技術方案的方法流程。 The following embodiment will specifically describe the method flow of the technical solution of the present invention.

圖3為本發明一實施例提供的資料庫操作方法的流程示意圖。如圖3所示,該方法包括: FIG. 3 is a schematic flowchart diagram of a method for operating a database according to an embodiment of the present invention. As shown in FIG. 3, the method includes:

301、在應用伺服器執行目標事務的過程中,依次獲取應用伺服器執行到的目標事務中的資料庫操作指令。 301. In the process of executing the target transaction by the application server, sequentially acquiring the database operation instruction in the target transaction executed by the application server.

302、對資料庫操作指令進行預測執行,將預測執行結果返回給應用伺服器以供應用伺服器確定下一個需要執行的資料庫操作指令,並在本地記錄資料庫操作指令以及在資料庫操作指令屬於修改資料庫類指令時記錄預測執行產生的預測執行資料。 302. Perform predictive execution on the database operation instruction, return the predicted execution result to the application server to supply the server to determine the next database operation instruction to be executed, and locally record the database operation instruction and the database operation instruction. The forecast execution data generated by the prediction execution is recorded when the database type instruction is modified.

303、當獲取到目標事務中的事務提交指令時,根據 本地記錄的資料庫操作指令以及預測執行資料,控制應用伺服器對應的資料庫實際執行目標事務。 303. When the transaction commit instruction in the target transaction is obtained, according to the local record database operation instruction and the predicted execution data, the database corresponding to the application server is controlled to actually execute the target transaction.

首先說明,為便於描述,本實施例將應用伺服器需要執行的事務稱為目標事務。目標事務主要包括用於對資料庫進行操作的操作指令,除資料庫操作指令之外還包括一些用於控制目標事務執行狀態的控制指令,例如事務開始指令、事務提交指令、交易復原指令等。這些指令實際上是由資料庫語言編寫的語句。根據資料庫語言的不同,這些指令可以是不同語言編寫的語句。舉例說明,若採用SQL,則上述資料庫操作指令和控制指令實際上是一系列的SQL語句。 First, for convenience of description, the present embodiment refers to a transaction that the application server needs to perform as a target transaction. The target transaction mainly includes operation instructions for operating the database, and in addition to the database operation instructions, some control instructions for controlling the execution state of the target transaction, such as a transaction start instruction, a transaction commit instruction, a transaction recovery instruction, and the like. These instructions are actually statements written in the database language. Depending on the language of the database, these instructions can be statements written in different languages. For example, if SQL is used, the above database operation instructions and control instructions are actually a series of SQL statements.

本實施例提供的方法適用於對隔離級別為讀已提交的資料庫進行操作。其中,有些資料庫預設是讀已提交這一隔離級別,例如,Oracle資料庫預設是讀已提交這一隔離級別的,有些資料庫預設不是讀已提交這一隔離級別,例如MySQL資料庫預設是可重複讀這一隔離級別。基於此,在執行本實施例提供的方法之前,可以確定資料庫的隔離級別是否是讀已提交,若不是,則需要預先配置資料庫為讀已提交這一隔離級別。例如,可以在應用伺服器執行目標事務之前,配置資料庫為讀已提交這一隔離級別。 The method provided in this embodiment is applicable to operating a database whose isolation level is read and submitted. Among them, some database presets are read and submitted this isolation level. For example, the Oracle database preset is to read the isolation level that has been submitted. Some database presets are not read and submitted, such as MySQL data. The library preset is the level of isolation that can be read repeatedly. Based on this, before performing the method provided in this embodiment, it can be determined whether the isolation level of the database is a read commit, and if not, the database needs to be pre-configured to read the isolation level. For example, the repository can be configured to read this isolation level before the application server performs the target transaction.

在資料庫的隔離級別為讀已提交的前提下,可以執行本實施例提供的方法以在資料庫中執行目標事務。具體流程如下:應用伺服器控制整個目標事務的執行邏輯,可以按照 現有方式執行目標事務。資料庫操作裝置在應用伺服器執行目標事務的過程中,依次獲取應用伺服器執行到的目標事務中的資料庫操作指令。 Under the premise that the isolation level of the database is read, the method provided in this embodiment may be executed to execute the target transaction in the database. The specific process is as follows: The application server controls the execution logic of the entire target transaction, and the target transaction can be executed in the existing manner. The database operating device sequentially acquires the database operation instruction in the target transaction executed by the application server during the execution of the target transaction by the application server.

在一可選實施方式中,應用伺服器按照現有方式向資料庫發送資料庫操作指令,以實現對資料庫的訪問。資料庫操作裝置可以對應用伺服器與資料庫之間的通信進行監控,以攔截應用伺服器發往資料庫的資料庫操作指令。 In an optional implementation, the application server sends the database operation instruction to the database in an existing manner to implement access to the database. The database operating device can monitor the communication between the application server and the database to intercept the database operation instructions sent by the application server to the database.

在另一可選實施方式中,對應用伺服器的處理邏輯進行稍微修改,將原來向資料庫發送資料庫操作指令的處理邏輯改為向資料庫操作裝置發送。基於此,資料庫操作裝置可以接收應用伺服器主動下發的資料庫操作指令。 In another alternative embodiment, the processing logic of the application server is slightly modified, and the processing logic that originally sent the database operation instruction to the database is changed to be sent to the database operating device. Based on this, the database operating device can receive the database operation instruction actively issued by the application server.

在此說明,若目標事務是顯式事務,則目標事務中的首個指令是事務開始指令,如開始事務(begin transaction),基於此,資料庫操作裝置在獲取應用伺服器執行到的資料庫操作指令之前,可以攔截應用伺服器發往資料庫的目標事務中的事務開始指令,根據該事務開始指令,獲知需要執行目標事務。或者,資料庫操作裝置在獲取應用伺服器執行到的資料庫操作指令之前,可以接收應用伺服器主動下發的目標事務中的事務開始指令,根據該事務開始指令,獲知需要執行目標事務。若目標事務是隱式事務,則目標事務的首個指令就是資料庫操作指令,不包括獲取事務開始指令的步驟。 Here, if the target transaction is an explicit transaction, the first instruction in the target transaction is a transaction start instruction, such as a begin transaction, based on which the database operation device acquires the database to which the application server executes. Before the operation instruction, the transaction start instruction in the target transaction sent by the application server to the database may be intercepted, and according to the transaction start instruction, the target transaction needs to be executed. Alternatively, the database operation device may receive a transaction start instruction in the target transaction actively issued by the application server before acquiring the database operation instruction executed by the application server, and according to the transaction start instruction, learn that the target transaction needs to be executed. If the target transaction is an implicit transaction, the first instruction of the target transaction is the database operation instruction, and does not include the step of obtaining the transaction start instruction.

資料庫操作裝置在獲取應用伺服器執行到的資料庫操作指令後,對獲取到的資料庫操作指令進行預測執行,將 預測執行結果返回給應用伺服器,以供應用伺服器確定下一個需要執行的資料庫操作指令。其中,預測執行結果決定著目標事務的執行路徑,這裡的執行路徑是指資料庫操作指令之間的跳轉邏輯。透過將預測執行結果返回給應用伺服器,從而達到由應用伺服器控制整個目標事務的執行邏輯的目的。 After obtaining the database operation instruction executed by the application server, the database operation device performs predictive execution on the acquired database operation instruction, returns the predicted execution result to the application server, and uses the server to determine the next execution required. Database operation instructions. The predicted execution result determines the execution path of the target transaction, where the execution path refers to the jump logic between the database operation instructions. By returning the predicted execution result to the application server, the purpose of controlling the execution logic of the entire target transaction by the application server is achieved.

另外,資料庫操作裝置還需要在本地記錄所獲取到的資料庫操作指令,以及在該資料庫操作指令屬於修改資料庫類指令時記錄對該資料庫操作指令進行預測執行產生的預測執行資料。所述修改資料庫類指令是指對資料庫有修改的資料庫操作指令,例如以update、insert等開頭的指令;一般以select開頭的指令不屬於修改資料庫類指令。所述預測執行資料主要是指對資料庫操作指令進行預測執行過程中的一些資料。 In addition, the database operating device also needs to locally record the acquired database operation instruction, and record the predicted execution data generated by predictive execution of the database operation instruction when the database operation instruction belongs to the modified database type instruction. The modified database class instruction refers to a database operation instruction that has a modified database, for example, an instruction starting with update, insert, etc.; generally, an instruction beginning with a select does not belong to a modified database class instruction. The predicted execution data mainly refers to some materials in the process of predictive execution of the database operation instructions.

例如,資料庫操作裝置可以在本地建立記憶體庫,將所獲取到的資料庫操作指令以及預測執行資料存入記憶體庫中。進一步,若預測執行資料不包括預測執行結果,則也可以將預測執行結果存入記憶體庫中。 For example, the database operating device may locally establish a memory library, and store the acquired database operation instructions and predicted execution data in a memory library. Further, if the predicted execution data does not include the predicted execution result, the predicted execution result may also be stored in the memory bank.

從本質而言,讀已提交隔離級別只保證寫入多個資料是原子的,不在讀取的時候加鎖,這樣可以提升系統的併發度,提高事務執行效率。為了在預測執行這一核心思想的基礎上實現對讀已提交這一隔離級別的模擬,本實施例僅僅針對屬於修改資料庫類指令的資料庫操作指令,記錄其預測執行產生的預測執行資料,卻不記錄不屬於修改資 料庫類指令的資料庫操作指令對應的預測執行資料。由此可見,在實現讀已提交這一隔離級別的情況下,所記錄的資料量相對較少,這樣在後續基於本地記錄的資料庫操作指令和預測執行資料在資料庫中真實執行目標事務的過程中,所需處理的資料量相對較少,有利於進一步提高執行效率和性能,增大事務輸送量。 In essence, reading the committed isolation level only guarantees that writing multiple data is atomic, and does not lock when reading, which can improve the concurrency of the system and improve the efficiency of transaction execution. In order to implement the simulation of the isolation level submitted to the read on the basis of the core idea of predictive execution, the present embodiment records only the predicted execution data generated by the prediction execution for the database operation instruction belonging to the modified database class instruction. The predicted execution data corresponding to the database operation instruction that does not belong to the modified database class instruction is not recorded. It can be seen that in the case that the reading has been submitted to the isolation level, the amount of recorded data is relatively small, so that the subsequent target transaction based on the local record-based database operation instruction and the prediction execution data is actually executed in the database. In the process, the amount of data to be processed is relatively small, which is beneficial to further improve execution efficiency and performance, and increase transaction volume.

其中,資料庫操作指令對資料庫的操作主要是訪問資料庫中的資料,則可以類比資料庫操作指令的資料環境,基於所類比的資料環境對資料庫操作指令進行預測執行。進一步,考慮到不屬於修改資料庫類指令的資料庫操作指令不會引起資料庫的變化,因此可以直接在資料庫中對該資料庫操作指令進行預測執行,這樣可以節約類比資料環境的操作,實現相對簡單,有利於節約資源,提高執行效率。但是,對於屬於修改資料庫類指令的資料庫操作指令,由於其會引起資料庫的變化(主要是指資料庫中的資料被改變),因此需要類比資料環境,在所類比的資料環境中進行預測執行。 Among them, the operation of the database operation instruction to the database is mainly to access the data in the database, and the data environment of the database operation instruction can be analogized, and the database operation instruction is predicted and executed based on the analog data environment. Further, considering that the database operation instruction that is not the instruction to modify the database class does not cause the change of the database, the database operation instruction can be directly predicted and executed in the database, thereby saving the operation of the analog data environment. The implementation is relatively simple, which is conducive to saving resources and improving execution efficiency. However, for the database operation instructions belonging to the modified database class instruction, since it will cause changes in the database (mainly refers to the data in the database is changed), an analog data environment is required, which is performed in the analog data environment. Forecast execution.

基於上述分析,一種對資料庫操作指令進行預測執行的方式可以是:對獲取到的資料庫操作指令的類別進行識別;若資料庫操作指令屬於修改資料庫類指令,則在本地建立的記憶體庫中類比資料庫操作指令的資料環境,基於所類比的資料環境對資料庫操作指令進行預測執行;若資料庫操作指令不屬於修改資料庫類指令,在資料 庫中執行該資料庫操作指令,以對該資料庫操作指令進行預測執行。 Based on the above analysis, a method for predicting execution of the database operation instruction may be: identifying the category of the obtained database operation instruction; if the database operation instruction belongs to the modification database type instruction, the locally established memory The data environment of the analog database operation instruction in the library predicts execution of the database operation instruction based on the analogy data environment; if the database operation instruction does not belong to the modified database type instruction, the database operation instruction is executed in the database, Predictive execution of the database operation instructions.

進一步,一種在本地建立的記憶體庫中類比資料庫操作指令的資料環境,基於所類比的資料環境對資料庫操作指令進行預測執行的實施方式包括:將獲取到的資料庫操作指令拆分為一個讀指令和一個寫指令,將讀指令運行於真正的資料庫上,即在資料庫中執行該讀指令以獲取讀資料集(ReadSet),將讀資料集存入本地記憶體庫中,以類比資料庫操作指令所需的資料環境。然後,將寫指令作用於記憶體庫上,以實現對資料庫操作指令的預測執行,即在記憶體庫中執行寫指令以修改讀資料集,例如對讀資料集中的有關資料進行更新或查詢處理等。其中,執行寫指令以修改讀資料集可以產生結果資料集(affectRowInMemdb),該結果資料集包括預測執行結果。 Further, a data environment of an analog database operation instruction in a locally established memory library, and an implementation manner of predicting execution of the database operation instruction based on the analog data environment includes: splitting the obtained database operation instruction into A read instruction and a write instruction, the read instruction is run on a real database, that is, the read instruction is executed in the database to obtain a read data set (ReadSet), and the read data set is stored in the local memory library, The data environment required for the analog database operation instructions. Then, the write command is applied to the memory bank to implement predictive execution of the database operation instruction, that is, executing a write instruction in the memory bank to modify the read data set, for example, updating or querying related data in the read data set. Processing and so on. Wherein, executing a write command to modify the read data set may generate a result data set (affectRowInMemdb), the result data set including the predicted execution result.

在上述預測執行過程中,若資料庫操作指令屬於修改資料庫類指令,則資料庫操作裝置可以在本地記錄讀指令所讀取的讀資料集以及執行寫指令產生的結果資料集。由此可見,所述預測執行資料可以包括讀資料集和結果資料集,或者也可以包括讀資料集和結果資料集中的部分資料,例如能夠對在資料庫中實際執行目標事務產生有益效果的一些資料,例如一些數值的各種索引,例如一級索引、二級索引、主鍵值等。 In the above prediction execution process, if the database operation instruction belongs to the modification database class instruction, the database operation device can locally record the read data set read by the read instruction and the result data set generated by executing the write instruction. It can be seen that the predicted execution data may include a read data set and a result data set, or may also include some data in the read data set and the result data set, for example, some of the beneficial effects on the actual execution of the target transaction in the database. Data, such as various indexes of some values, such as primary index, secondary index, primary key value, and so on.

當資料庫操作裝置獲取到目標事務中的事務提交指令 (即應用伺服器執行到事務提交指令)時,則可以根據本地記錄的資料庫操作指令以及預測執行資料,控制應用伺服器對應的資料庫實際執行目標事務。 When the database operation device acquires the transaction commit instruction in the target transaction (ie, the application server executes to the transaction commit instruction), the database corresponding to the application server may be controlled according to the locally recorded database operation instruction and the predicted execution data. Actual execution of the target transaction.

上述根據本地記錄的資料庫操作指令以及預測執行資料,控制應用伺服器對應的資料庫實際執行目標事務的一種可選實施方式包括:資料庫操作裝置向資料庫下發本地記錄的所述資料庫操作指令,以指示資料庫執行資料庫操作指令,並接收資料庫返回的資料庫操作指令的實際執行結果;然後,將資料庫操作指令的實際執行結果與預測執行結果進行比較,若實際執行結果與預測執行結果相同,向資料庫下發事務提交指令,以供資料庫提交該目標事務;若實際執行結果與預測執行結果不相同,向資料庫下發交易復原指令,以供資料庫回滾該目標事務。 According to the database operation instruction and the prediction execution data recorded locally, an optional implementation manner of controlling the database corresponding to the application server to actually execute the target transaction includes: the database operation device transmitting the local record to the database An operation instruction to instruct the database to execute the database operation instruction, and receive the actual execution result of the database operation instruction returned by the database; and then compare the actual execution result of the database operation instruction with the predicted execution result, if the actual execution result Same as the predicted execution result, the transaction commit instruction is sent to the database for the database to submit the target transaction; if the actual execution result is different from the predicted execution result, the transaction recovery instruction is sent to the database for the database to be rolled back. The target transaction.

在上述實施方式中,考慮到事務的原子性,透過將實際執行結果與預測執行結果進行比較,可以避免事務執行過程出錯,有利於提高事務執行的成功機率。 In the above embodiment, considering the atomicity of the transaction, by comparing the actual execution result with the predicted execution result, the transaction execution process error can be avoided, which is advantageous for improving the success probability of the transaction execution.

進一步,在現有技術中,由於無法預先知道事務需要執行的全部資料庫操作指令,所以只能按照事務的執行邏輯依次執行資料庫操作指令,這會導致應用伺服器與資料庫之間的頻繁交互,這在遠端應用場景中將會消耗大量網路資源。但在本實施例中,透過預測執行過程已經預先獲得目標事務需要執行的全部資料庫操作指令,即本地記錄的資料庫操作指令,因此在向資料庫下發本地記錄的資料 庫操作指令,以指示資料庫執行資料庫操作指令的過程中,可以將本地記錄的資料庫操作指令同時(或者一併)下發到資料庫,有利於節約網路資源。另外,對於一些並行的資料庫操作指令,資料庫還可以平行作業,有利於進一步提高事務執行效率,增大事務輸送量。 Further, in the prior art, since all the database operation instructions that the transaction needs to execute cannot be known in advance, the database operation instruction can be executed sequentially according to the execution logic of the transaction, which causes frequent interaction between the application server and the database. This will consume a lot of network resources in the remote application scenario. However, in this embodiment, all the database operation instructions that need to be executed by the target transaction, that is, the local record database operation instruction, have been obtained in advance through the prediction execution process, so that the local record database operation instruction is sent to the database to In the process of instructing the database to execute the database operation instruction, the local record database operation instruction can be simultaneously (or collectively) sent to the database, which is conducive to saving network resources. In addition, for some parallel database operation instructions, the database can also work in parallel, which is beneficial to further improve transaction execution efficiency and increase transaction throughput.

進一步,還可以將本地記錄的所有資料庫操作指令連同本地記錄的預測執行資料一併下發給資料庫。 Further, all the database operation instructions recorded locally can be sent to the database together with the locally recorded predicted execution data.

進一步,在一種根據本地記錄的資料庫操作指令以及預測執行資料,控制應用伺服器對應的資料庫實際執行目標事務的可選實施方式中,資料庫操作裝置可以根據本地記錄的資料庫操作指令,判斷目標事務是否為單機事務;若判斷結果為是,則根據本地記錄的資料庫操作指令以及預測執行資料,以單機交易處理邏輯控制資料庫實際執行目標事務;若判斷結果為否,則根據本地記錄的資料庫操作指令以及預測執行資料,以分散式交易處理邏輯控制資料庫實際執行目標事務。 Further, in an optional implementation manner of controlling a database corresponding to the actual execution of the target transaction according to the locally recorded database operation instruction and the predicted execution data, the database operation device may operate the instruction according to the locally recorded database. Determining whether the target transaction is a stand-alone transaction; if the determination result is yes, according to the locally recorded database operation instruction and the predicted execution data, the single-machine transaction processing logic controls the database to actually execute the target transaction; if the judgment result is negative, according to the local Recorded database operation instructions and predictive execution data, and the distributed transaction processing logic controls the database to actually execute the target transaction.

其中,基於預測執行過程中獲得的資料庫操作指令可以識別出目標事務是單機事務還是分散式事務。例如,可以判斷本地記錄的資料庫操作指令的操作物件是否作用於同一物理設備上,若判斷結果為是,則可以確定該目標事務為單機事務;若判斷結果為否,則可以確定該目標事務為分散式事務。 The database operation instruction obtained during the prediction execution process can identify whether the target transaction is a stand-alone transaction or a distributed transaction. For example, it can be determined whether the operation object of the locally recorded database operation instruction acts on the same physical device. If the determination result is yes, it can be determined that the target transaction is a stand-alone transaction; if the determination result is no, the target transaction can be determined. For decentralized transactions.

由於分散式事務的處理邏輯和單機事務的處理邏輯有所不同,單機事務的處理邏輯相對簡單,例如不關於讀寫 加鎖等問題,所以所消耗的資源也相對較少。基於此,本實施例透過識別目標事務是否為單機事務,在識別為單機事務時採用單機事務的處理邏輯進行處理,而不是像現有技術那樣統一採用分散式交易處理邏輯進行處理,有利於提高處理效率,節約處理成本。 Since the processing logic of a decentralized transaction is different from the processing logic of a stand-alone transaction, the processing logic of a stand-alone transaction is relatively simple, for example, it does not involve problems such as reading and writing locks, so the resources consumed are relatively small. Based on this, the present embodiment uses the processing logic of the single-machine transaction to identify whether the target transaction is a stand-alone transaction, and does not use the distributed transaction processing logic to process the same as the prior art, which is beneficial to improve processing. Efficiency, saving processing costs.

在一可選實施方式中,若資料庫操作裝置獲取到目標事務中的交易復原指令(即應用伺服器執行到交易復原指令)時,可以刪除本地記錄的資料庫操作指令以及預測執行資料,例如可以直接清空本地記憶體庫,實現回滾操作。在該情況下,由於目標事務並未在資料庫中真正執行,所以資料庫無需執行回滾操作,可見,在交易復原這種情況下,採用本實施例方法也可以提高事務執行效率。 In an optional implementation manner, if the database operation device acquires the transaction recovery instruction in the target transaction (ie, the application server executes to the transaction recovery instruction), the local record database operation instruction and the predicted execution data may be deleted, for example, The local memory library can be directly emptied to implement the rollback operation. In this case, since the target transaction is not actually executed in the database, the database does not need to perform a rollback operation. It can be seen that in the case of transaction recovery, the transaction efficiency can be improved by using the method of the embodiment.

由上述可見,在本實施例提供的方法中,資料庫操作裝置與應用伺服器相互配合,在應用伺服器執行目標事務的過程加入預測執行過程,在預測執行過程中,可以提前獲得目標事務的執行路徑,即真正需要執行的資料庫操作指令,並僅針對屬於修改資料庫類指令的資料庫操作指令記錄預測執行產生的預測執行資料以適應於讀已提交隔離級別,為真實執行事務提供了條件,之後在根據記錄的資料庫操作指令以及預測執行資料實際執行該目標事務時,例如基於預測執行資料可以提前獲取有關資料資訊並且可以減少指令之間的跳轉等,因此可以提高執行效率,增大事務輸送量。 It can be seen from the above that in the method provided by the embodiment, the database operation device and the application server cooperate with each other, and the prediction execution process is added in the process of the application server executing the target transaction, and the target transaction can be obtained in advance during the prediction execution process. The execution path, that is, the database operation instruction that really needs to be executed, and only records the predicted execution data generated by the prediction execution for the database operation instruction belonging to the modified database class instruction to adapt to the read isolation level, and provides a real execution transaction. Condition, after actually executing the target transaction according to the recorded database operation instruction and the predicted execution data, for example, based on the predicted execution data, the related information information can be acquired in advance and the jump between the instructions can be reduced, thereby improving execution efficiency and increasing Large transaction volume.

下面以減庫存事務為例,詳細說明本發明技術方案的 工作流程。其中,資料庫的隔離級別為讀已提交這一隔離級別。 The workflow of the technical solution of the present invention will be described in detail below by taking the inventory reduction transaction as an example. The isolation level of the database is the isolation level that the read has been submitted.

減庫存事務的SQL代碼如下,括弧內的文字為注釋: The SQL code for the inventory reduction transaction is as follows, the text in parentheses is a comment:

在實際執行過程中,應用伺服器負責該減庫存事務的整個邏輯,資料庫操作裝置(或者也可稱為執行伺服器)只會獲取應用伺服器執行到的開始事務,需要執行的SQL語句,以及提交/回滾指令。 In the actual execution process, the application server is responsible for the entire logic of the inventory reduction transaction, and the database operation device (or may also be referred to as an execution server) only obtains the start transaction to which the application server executes, and the SQL statement that needs to be executed. And commit/rollback instructions.

首先,開始事務後,資料庫操作裝置在本地建立記憶體庫;當資料庫操作裝置獲取到select * from inventory where itemId=?for update這條SQL語句時,識別出這條SQL語句不會修改資料庫,因此將這條SQL語句直接作用在實際資料庫中,即在資料庫中執行該條SQL語句以獲得查詢結果,即讀資料集,將全部查詢結果返回給應 用伺服器,以供應用伺服器確定下一個需要執行的SQL語句,並在本地記憶體庫中記錄這條SQL語句。由於是讀已隔離級別,故不需要記錄任何與執行該條SQL語句有關的資料。 First, after starting the transaction, the database operating device locally creates a memory bank; when the database operating device obtains select * from inventory where itemId=? For update this SQL statement, it is recognized that this SQL statement will not modify the database, so this SQL statement directly acts on the actual database, that is, execute the SQL statement in the database to obtain the query result, ie Read the data set and return all the query results to the application server to supply the server to determine the next SQL statement to be executed, and record the SQL statement in the local memory library. Since the read level is read, there is no need to record any information related to executing the SQL statement.

應用伺服器收到資料庫操作裝置返回的查詢結果後,判斷查詢結果中目前庫存量是否大於0,若判斷結果為是,則將目前庫存量減少,並執行更新語句,即update inventory set item.inventory=$item.inventory where itemId=?;若判斷結果為否,則執行rollback語句。 After receiving the query result returned by the database operation device, the application server determines whether the current inventory quantity in the query result is greater than 0. If the judgment result is yes, the current inventory quantity is reduced, and the update statement is executed, that is, the update inventory set item. Inventory=$item.inventory where itemId=? If the result of the judgment is no, the rollback statement is executed.

第一種情況,假設應用伺服器執行了rollback語句,則資料庫操作裝置會獲取到rollback語句。一旦資料庫儲存裝置獲取到rollback語句,則清空本地記憶體庫,主要是指清空之前記錄的select * from inventory where itemId=?for update這條SQL語句。在這種情況下,因為事務並沒有在資料庫中執行,所以無需資料庫執行回滾操作。 In the first case, if the application server executes the rollback statement, the database operating device will obtain the rollback statement. Once the database storage device obtains the rollback statement, the local memory library is emptied, mainly to clear the previously selected select * from inventory where itemId=? For update this SQL statement. In this case, because the transaction is not executed in the repository, there is no need for the repository to perform a rollback operation.

第二種情況,假設應用伺服器執行了update inventory set item.inventory=$item.inventory where itemId=?這條語句,則資料庫操作裝置會獲取到update inventory set item.inventory=$item.inventory where itemId=?這條語句。則資料庫操作裝置獲取到update inventory set item.inventory=?where itemId=?這條SQL語句時,識別出該SQL語句會修改資料庫,於是將這條SQL語句拆解為一個讀指令,即select * from inventory where itemId=?和一個寫指令,即update inventory set item.inventory=?where itemId=?;接著,將select * from inventory where itemId=?這個語句下發到資料庫中,獲得讀資料集,將讀資料集中的資料寫入本地記憶體庫中;其中,讀資料集中包括主鍵列表(itemId)和該主鍵對應的版本號資訊(version)。然後,根據update inventory set item.inventory=?where itemId=?這個語句在本地記憶體庫中進行更新操作,以獲得結果資料集,並將結果資料集返回給應用伺服器。該結果資料集可以是類似修改了幾條記錄這樣的修改記錄資訊,例如,affectRow=1表示修改了一條記錄;或者,結果資料集也可以是記錄修改詳細資訊的修改詳情資訊。其中,結果資料集和讀資料集構成預測執行資料。 In the second case, suppose the application server executes update inventory set item.inventory=$item.inventory where itemId=? In this statement, the database operating device will get update inventory set item.inventory=$item.inventory where itemId=? This statement. Then the database operating device obtains update inventory set item.inventory=? Where itemId=? This SQL statement recognizes that the SQL statement will modify the database, so the SQL statement is split into a read command, ie select * from inventory where itemId=? And a write command, ie update inventory set item.inventory=? Where itemId=? Then, select * from inventory where itemId=? The statement is sent to the database, and the read data set is obtained, and the data in the read data set is written into the local memory library; wherein the read data set includes a primary key list (itemId) and a version number information corresponding to the primary key (version). . Then, according to update inventory set item.inventory=? Where itemId=? This statement performs an update operation in the local memory library to obtain the result data set and returns the result data set to the application server. The result data set may be modified record information similar to the modification of several records. For example, affectRow=1 indicates that a record is modified; or the result data set may also be modified details of the record modification detailed information. Among them, the result data set and the read data set constitute prediction execution data.

應用伺服器此時執行commit指令。 The application server executes the commit command at this time.

當資料庫操作裝置獲取到commit指令後,基於本地記憶體庫中的SQL語句以及預測執行資料,在資料庫中執行該減庫存事務,這次事務執行過程是真實執行的。例如,本地記錄的SQL語句以及預測執行資料如下所示: After the database operation device obtains the commit command, the inventory reduction transaction is executed in the database based on the SQL statement in the local memory library and the predicted execution data, and the transaction execution process is actually performed. For example, the locally recorded SQL statement and the predicted execution data are as follows:

較佳的,資料庫操作裝置可以一次性將本地記憶體庫中的SQL語句全部提交到資料庫中,資料庫基於此進行 執行,有利於節約傳輸SQL語句所消耗的網路資源。 Preferably, the database operating device can submit all the SQL statements in the local memory library to the database at one time, and the database is executed based on the data, thereby saving the network resources consumed by the transmission of the SQL statement.

這次真實執行也會返回執行結果,可以將預測執行結果與實際執行結果進行比較,例如可以先比較兩個結果中的itemId和version,然後再比較兩個結果中的affectRow;如果比較結果為相同,則可以在資料庫中提交這次事務,而如果比較結果為不相同,則認為提交是失敗的,由於在這種情況下,事務本身其實一直都沒有真正的在資料庫中執行提交,所以可以簡單地回滾整個請求,讓應用服務器重新提交即可。 This real execution will also return the execution result. You can compare the predicted execution result with the actual execution result. For example, you can compare the itemId and version of the two results first, and then compare the affectRow of the two results; if the comparison result is the same, You can submit this transaction in the database, and if the comparison result is not the same, then the submission is considered to be a failure, because in this case, the transaction itself has not actually been executed in the database, so it can be simple Roll back the entire request and let the application server resubmit.

其中,經過上述預測執行,已經獲得了所有的需要執行的SQL語句,以及相應的預測執行資料,例如全部切分條件,數值的索引等,而這些資料足以讓我們提前對事務是否是單機事務做出判斷。基於此,可以採用相應的交易處理邏輯進行處理,有利於節約資源。 Among them, after the above prediction execution, all the SQL statements that need to be executed, and the corresponding predicted execution data, such as all the segmentation conditions, the index of the values, etc., have been obtained, and the data is sufficient for us to advance whether the transaction is a stand-alone transaction. Make a judgment. Based on this, the corresponding transaction processing logic can be used for processing, which is conducive to saving resources.

需要說明的是,對於前述的各方法實施例,為了簡單描述,故將其都表述為一系列的動作組合,但是本領域技術人員應該知悉,本發明並不受所描述的動作順序的限制,因為依據本發明,某些步驟可以採用其他順序或者同時進行。其次,本領域技術人員也應該知悉,說明書中所描述的實施例均屬於較佳實施例,所關於的動作和模組並不一定是本發明所必須的。 It should be noted that, for the foregoing method embodiments, for the sake of simple description, they are all expressed as a series of action combinations, but those skilled in the art should understand that the present invention is not limited by the described action sequence. Because certain steps may be performed in other sequences or concurrently in accordance with the present invention. Secondly, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.

在上述實施例中,對各個實施例的描述都各有側重,某個實施例中沒有詳述的部分,可以參見其他實施例的相關描述。 In the above embodiments, the descriptions of the various embodiments are different, and the details that are not detailed in a certain embodiment can be referred to the related descriptions of other embodiments.

圖4為本發明一實施例提供的資料庫操作裝置的結構示意圖。如圖4所示,該裝置包括:獲取模組41、預測執行模組42和控制執行模組43。 FIG. 4 is a schematic structural diagram of a database operating device according to an embodiment of the present invention. As shown in FIG. 4, the device includes an acquisition module 41, a prediction execution module 42, and a control execution module 43.

獲取模組41,用於在應用伺服器執行目標事務的過程中,依次獲取應用伺服器執行到的目標事務中的資料庫操作指令。 The obtaining module 41 is configured to sequentially acquire the database operation instruction in the target transaction executed by the application server during the execution of the target transaction by the application server.

預測執行模組42,用於對資料庫操作指令進行預測執行,將預測執行結果返回給應用伺服器以供應用伺服器確定下一個需要執行的資料庫操作指令,並在本地記錄資料庫操作指令以及在資料庫操作指令屬於修改資料庫類指令時記錄預測執行產生的預測執行資料。 The predictive execution module 42 is configured to perform predictive execution on the database operation instruction, return the predicted execution result to the application server to supply the server to determine the next database operation instruction to be executed, and record the database operation instruction locally. And predicting the execution data generated by the prediction execution when the database operation instruction belongs to the modification database class instruction.

控制執行模組43,用於當獲取到目標事務中的事務提交指令時,根據本地記錄的資料庫操作指令以及預測執行資料,控制應用伺服器對應的資料庫實際執行目標事務。 The control execution module 43 is configured to control the database corresponding to the application server to actually execute the target transaction according to the locally recorded database operation instruction and the predicted execution data when the transaction commit instruction in the target transaction is acquired.

在一可選實施方式中,該資料庫操作裝置還包括:配置模組,用於在應用伺服器執行目標事務之前,配置資料庫為讀已提交隔離級別。 In an optional implementation, the database operating device further includes: a configuration module, configured to configure the database to read the submitted isolation level before the application server performs the target transaction.

在一可選實施方式中,獲取模組41具體可用於:攔截應用伺服器發往資料庫的資料庫操作指令;或者,接收應用伺服器主動下發的資料庫操作指令。 In an optional implementation, the obtaining module 41 is specifically configured to: intercept the database operation instruction sent by the application server to the database; or receive the database operation instruction actively sent by the application server.

在一可選實施方式中,獲取模組41還用於:在獲取應用伺服器執行到的目標事務中的資料庫操作指令之前,攔截應用伺服器發往資料庫的目標事務中的事務開始指 令;或者,接收應用伺服器主動下發的目標事務中的事務開始指令。 In an optional implementation, the obtaining module 41 is further configured to: before acquiring the database operation instruction in the target transaction executed by the application server, intercepting the transaction start instruction in the target transaction sent by the application server to the database Or, receive a transaction start instruction in the target transaction actively issued by the application server.

在一可選實施方式中,預測執行模組42具體可用於:若獲取模組41獲取到的資料庫操作指令屬於修改資料庫類指令,在本地建立的記憶體庫中類比資料庫操作指令的資料環境,基於類比的資料環境對資料庫操作指令進行預測執行;若獲取模組41獲取到的資料庫操作指令不屬於修改資料庫類指令,在資料庫中執行資料庫操作指令,以對資料庫操作指令進行預測執行。 In an optional implementation, the prediction execution module 42 is specifically configured to: if the database operation instruction acquired by the acquisition module 41 belongs to the modified database class instruction, the analog database operation instruction in the locally established memory library The data environment, based on the analogy data environment, predictive execution of the database operation instruction; if the database operation instruction acquired by the acquisition module 41 is not a modified database type instruction, the database operation instruction is executed in the data base to The library operation instruction performs prediction execution.

進一步,在獲取模組41獲取到的資料庫操作指令屬於修改資料庫類指令的情況下,預測執行模組42在執行在本地建立的記憶體庫中類比資料庫操作指令的資料環境,基於類比的資料環境對資料庫操作指令進行預測執行的操作時,具體用於:將資料庫操作指令拆分為讀指令和寫指令;在資料庫中執行讀指令以獲取讀資料集,將讀資料集存入記憶體庫中以類比資料庫操作指令的資料環境;在記憶體庫中執行寫指令以修改讀資料集。 Further, in the case that the database operation instruction acquired by the acquisition module 41 belongs to the modified database class instruction, the prediction execution module 42 executes the data environment of the analog database operation instruction in the locally established memory library, based on the analogy. When the data environment performs prediction operation on the database operation instruction, it is specifically used to: split the database operation instruction into a read instruction and a write instruction; execute a read instruction in the database to obtain a read data set, and read the data set The data environment stored in the memory bank to operate the instruction in the analog library; the write command is executed in the memory bank to modify the read data set.

在一可選實施方式中,控制執行模組43具體可用於:向資料庫下發本地記錄的資料庫操作指令,以指示資料庫執行資料庫操作指令,並接收資料庫返回的資料庫操 作指令的實際執行結果;若實際執行結果與預測執行結果相同,向資料庫下發事務提交指令,以供資料庫提交目標事務;若實際執行結果與預測執行結果不相同,向資料庫下發交易復原指令,以供資料庫回滾目標事務。考慮到事務的原子性,控制執行模組43透過將實際執行結果與預測執行結果進行比較,可以避免事務執行過程出錯,有利於提高事務執行的成功機率。 In an optional implementation, the control execution module 43 is specifically configured to: deliver a locally recorded database operation instruction to the database, instruct the database to execute the database operation instruction, and receive the database operation instruction returned by the database The actual execution result; if the actual execution result is the same as the predicted execution result, the transaction commit instruction is sent to the database for the database to submit the target transaction; if the actual execution result is different from the predicted execution result, the transaction is sent to the database for recovery. An instruction for the repository to roll back the target transaction. Considering the atomicity of the transaction, the control execution module 43 can avoid the error of the transaction execution process by comparing the actual execution result with the predicted execution result, which is beneficial to improving the success probability of the transaction execution.

進一步,控制執行模組43在向資料庫下發本地記錄的資料庫操作指令時,具體可用於:將本地記錄的資料庫操作指令同時下發給資料庫,有利於節約網路資源。 Further, when the control execution module 43 sends the locally recorded database operation instruction to the database, the control execution module 43 can be used to: simultaneously send the locally recorded database operation instruction to the data library, which is beneficial to saving network resources.

進一步,控制執行模組43可以將本地記錄的所有資料庫操作指令連同本地記錄的預測執行資料一併下發給資料庫,有利於節約網路資源。 Further, the control execution module 43 can send all the database operation instructions recorded locally together with the locally recorded predicted execution data to the database, which is beneficial to save network resources.

在一可選實施方式中,控制執行模組43具體用於:根據本地記錄的資料庫操作指令,判斷目標事務是否為單機事務;若判斷結果為是,則根據本地記錄的資料庫操作指令以及預測執行資料,以單機交易處理邏輯控制資料庫實際執行目標事務;若判斷結果為否,則根據本地記錄的資料庫操作指令以及預測執行資料,以分散式交易處理邏輯控制資料庫實際執行目標事務。由於分散式事務的處理邏輯和單機事務的處理邏輯有所不同,單機事務的處理邏輯相對簡單,例 如不關於讀寫加鎖等問題,所以所消耗的資源也相對較少。基於此,控制執行模組43透過識別目標事務是否為單機事務,在識別為單機事務時採用單機事務的處理邏輯進行處理,有利於提高處理效率,節約處理成本。 In an optional implementation, the control execution module 43 is specifically configured to: determine, according to the locally recorded database operation instruction, whether the target transaction is a stand-alone transaction; if the determination result is yes, according to the locally recorded database operation instruction and Predicting the execution data, the single-machine transaction processing logic controls the database to actually execute the target transaction; if the judgment result is no, the distributed transaction processing logic controls the database to actually execute the target transaction according to the locally recorded database operation instruction and the predicted execution data. . Since the processing logic of the decentralized transaction is different from the processing logic of the stand-alone transaction, the processing logic of the stand-alone transaction is relatively simple, for example, it does not involve problems such as reading and writing locks, so the resources consumed are relatively small. Based on this, the control execution module 43 performs processing by using the processing logic of the single-machine transaction when identifying the target transaction as a stand-alone transaction, which is advantageous for improving processing efficiency and saving processing cost.

在一可選實施方式中,預測執行模組42還用於:在獲取到目標事務中的交易復原指令時,刪除本地記錄的資料庫操作指令以及預測執行資料。 In an optional implementation, the predictive execution module 42 is further configured to delete the locally recorded database operation instruction and the predicted execution data when the transaction recovery instruction in the target transaction is acquired.

本實施例提供的資料庫操作裝置,其可以單獨部署,位於應用伺服器和資料庫之間,也可以部署於應用伺服器一端實現,或者也可以部署於資料庫一端實現。 The database operating device provided in this embodiment can be deployed separately, and is located between the application server and the database, and can also be deployed on one end of the application server, or can be deployed on one end of the database.

本實施例提供的資料庫操作裝置,與應用伺服器相互配合,在應用伺服器執行目標事務的過程加入預測執行過程,預先獲得並記錄目標事務需要執行的全部資料庫操作指令,並僅針對屬於修改資料庫類指令的資料庫操作指令記錄預測執行產生的預測執行資料以適應於讀已提交隔離級別,為真實執行事務提供了條件,之後根據記錄的資料庫操作指令以及預測執行資料,控制應用伺服器對應的資料庫實際執行該目標事務,有利於提高執行效率,增大事務輸送量。 The database operation device provided in this embodiment cooperates with the application server to join the prediction execution process in the process of executing the target transaction by the application server, and obtains and records all the database operation instructions that need to be executed in the target transaction in advance, and only belongs to The database operation instruction for modifying the database class instruction records the prediction execution data generated by the prediction execution to adapt to the read isolation level, provides conditions for the real execution transaction, and then controls the application according to the recorded database operation instruction and the prediction execution data. The database corresponding to the server actually executes the target transaction, which is beneficial to improve execution efficiency and increase transaction volume.

所屬領域的技術人員可以清楚地瞭解到,為描述的方便和簡潔,上述描述的系統,裝置和單元的具體工作過程,可以參考前述方法實施例中的對應過程,在此不再贅述。 A person skilled in the art can clearly understand that for the convenience and brevity of the description, the specific working process of the system, the device and the unit described above can refer to the corresponding process in the foregoing method embodiment, and details are not described herein again.

在本發明所提供的幾個實施例中,應該理解到,所揭 露的系統,裝置和方法,可以透過其它的方式實現。例如,以上所描述的裝置實施例僅僅是示意性的,例如,所述單元的劃分,僅僅為一種邏輯功能劃分,實際實現時可以有另外的劃分方式,例如多個單元或元件可以結合或者可以整合到另一個系統,或一些特徵可以忽略,或不執行。另一點,所顯示或討論的相互之間的耦合或直接耦合或通信連接可以是透過一些介面,裝置或單元的間接耦合或通信連接,可以是電性,機械或其它的形式。 In the several embodiments provided by the present invention, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the unit is only a logical function division. In actual implementation, there may be another division manner, for example, multiple units or components may be combined or may be Consolidate to another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or unit, and may be electrical, mechanical or otherwise.

所述作為分離部件說明的單元可以是或者也可以不是物理上分開的,作為單元顯示的部件可以是或者也可以不是物理單元,即可以位於一個地方,或者也可以分佈到多個網路單元上。可以根據實際的需要選擇其中的部分或者全部單元來實現本實施例方案的目的。 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, may be located in one place, or may be distributed to multiple network units. . Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of the embodiment.

另外,在本發明各個實施例中的各功能單元可以整合在一個處理單元中,也可以是各個單元單獨物理存在,也可以兩個或兩個以上單元整合在一個單元中。上述整合的單元既可以採用硬體的形式實現,也可以採用硬體加軟體功能單元的形式實現。 In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above integrated unit can be implemented in the form of a hardware or a hardware plus a soft functional unit.

上述以軟體功能單元的形式實現的整合的單元,可以儲存在一個電腦可讀取儲存媒體中。上述軟體功能單元儲存在一個儲存媒體中,包括若干指令用以使得一台電腦設備(可以是個人電腦,伺服器,或者網路設備等)或處理器(processor)執行本發明各個實施例所述方法的部分步驟。而前述的儲存媒體包括:U碟、移動硬碟、唯讀記憶 體(Read-Only Memory,ROM)、隨機存取記憶體(Random Access Memory,RAM)、磁碟或者光碟等各種可以儲存程式碼的媒體。 The integrated unit described above in the form of a software functional unit can be stored in a computer readable storage medium. The software functional unit is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor to perform the embodiments of the present invention. Part of the steps of the method. The foregoing storage medium includes: U disk, mobile hard disk, Read-Only Memory (ROM), Random Access Memory (RAM), disk or CD, etc. Media.

最後應說明的是:以上實施例僅用以說明本發明的技術方案,而非對其限制;儘管參照前述實施例對本發明進行了詳細的說明,本領域的普通技術人員應當理解:其依然可以對前述各實施例所記載的技術方案進行修改,或者對其中部分技術特徵進行等同替換;而這些修改或者替換,並不使相應技術方案的本質脫離本發明各實施例技術方案的精神和範圍。 It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and are not limited thereto; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that The technical solutions described in the foregoing embodiments are modified, or the equivalents of the technical features are replaced. The modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims (12)

一種資料庫操作方法,其特徵在於,包括:在應用伺服器執行目標事務的過程中,依次獲取該應用伺服器執行到的該目標事務中的資料庫操作指令;對該資料庫操作指令進行預測執行,將預測執行結果返回給該應用伺服器以供該應用伺服器確定下一個需要執行的資料庫操作指令,並在本地記錄該資料庫操作指令以及在該資料庫操作指令屬於修改資料庫類指令時記錄該預測執行產生的預測執行資料;及當獲取到該目標事務中的事務提交指令時,根據本地記錄的該資料庫操作指令以及該預測執行資料,控制該應用伺服器對應的資料庫實際執行該目標事務。  A database operation method, comprising: acquiring, in a process of executing a target transaction by an application server, a database operation instruction in the target transaction executed by the application server; and predicting the database operation instruction Executing, returning the predicted execution result to the application server for the application server to determine the next database operation instruction to be executed, and locally recording the database operation instruction and the operation instruction in the database belongs to the modification database class The instruction execution data is recorded when the instruction is executed; and when the transaction commit instruction in the target transaction is obtained, the database corresponding to the application server is controlled according to the database operation instruction and the predicted execution data recorded locally. The target transaction is actually executed.   根據申請專利範圍第1項所述的方法,其中,還包括:在該應用伺服器執行該目標事務之前,配置該資料庫為讀已提交隔離級別。  The method of claim 1, wherein the method further comprises: configuring the database to read the submitted isolation level before the application server executes the target transaction.   根據申請專利範圍第1項所述的方法,其中,該對該資料庫操作指令進行預測執行,包括:若該資料庫操作指令屬於修改資料庫類指令,在本地建立的記憶體庫中類比該資料庫操作指令的資料環境,基於該類比的資料環境對該資料庫操作指令進行預測執行;及若該資料庫操作指令不屬於修改資料庫類指令,在該資料庫中執行該資料庫操作指令,以對該資料庫操作指令 進行預測執行。  The method of claim 1, wherein the predictive execution of the database operation instruction comprises: if the database operation instruction belongs to a modified database class instruction, analogy in the locally established memory library The data environment of the database operation instruction, predictive execution of the database operation instruction based on the analog data environment; and if the database operation instruction is not a modified database type instruction, executing the database operation instruction in the database To perform predictive execution on the database operation instructions.   根據申請專利範圍第3項所述的方法,其中,該在本地建立的記憶體庫中類比該資料庫操作指令所需的資料環境,基於該類比的資料環境對該資料庫操作指令進行預測執行,包括:將該資料庫操作指令拆分為讀指令和寫指令;在該資料庫中執行該讀指令以獲取讀資料集,將該讀資料集存入該記憶體庫中以類比該資料庫操作指令的資料環境;及在該記憶體庫中執行該寫指令以修改該讀資料集。  According to the method of claim 3, wherein the locally established memory library is analogous to the data environment required by the database operation instruction, and the database operation instruction is predicted and executed based on the analog data environment. The method includes: splitting the database operation instruction into a read instruction and a write instruction; executing the read instruction in the database to obtain a read data set, and storing the read data set in the memory library to compare the database a data environment of the operation instruction; and executing the write instruction in the memory library to modify the read data set.   根據申請專利範圍第1至4項中任一項所述的方法,其中,該根據本地記錄的該資料庫操作指令以及該預測執行資料,控制該應用伺服器對應的資料庫實際執行目標事務,包括:向該資料庫下發本地記錄的該資料庫操作指令,以指示該資料庫執行該資料庫操作指令,並接收該資料庫返回的該資料庫操作指令的實際執行結果;若該實際執行結果與該預測執行結果相同,向該資料庫下發該事務提交指令,以供該資料庫提交該目標事務;及若該實際執行結果與該預測執行結果不相同,向該資料庫下發交易復原指令,以供該資料庫回滾該目標事務。  The method according to any one of claims 1 to 4, wherein, according to the database operation instruction recorded locally and the predicted execution data, controlling a database corresponding to the application server to actually execute a target transaction, The method includes: sending the local database operation instruction to the database to instruct the database to execute the database operation instruction, and receiving an actual execution result of the database operation instruction returned by the database; if the actual execution The result is the same as the prediction execution result, and the transaction commit instruction is sent to the database for the database to submit the target transaction; and if the actual execution result is different from the predicted execution result, the transaction is sent to the database. Restore the instruction for the repository to roll back the target transaction.   根據申請專利範圍第5項所述的方法,其中,該向該資料庫下發本地記錄的該資料庫操作指令,包括: 將本地記錄的該資料庫操作指令同時下發給該資料庫。  The method of claim 5, wherein the database operation instruction for issuing the local record to the database comprises: simultaneously transmitting the locally recorded database operation instruction to the database.   一種資料庫操作裝置,其特徵在於,包括:獲取模組,用於在應用伺服器執行目標事務的過程中,依次獲取該應用伺服器執行到的該目標事務中的資料庫操作指令;預測執行模組,用於對該資料庫操作指令進行預測執行,將預測執行結果返回給該應用伺服器以供該應用伺服器確定下一個需要執行的資料庫操作指令,並在本地記錄該資料庫操作指令以及在該資料庫操作指令屬於修改資料庫類指令時記錄該預測執行產生的預測執行資料;及控制執行模組,用於當獲取到該目標事務中的事務提交指令時,根據本地記錄的該資料庫操作指令以及該預測執行資料,控制該應用伺服器對應的資料庫實際執行該目標事務。  A database operating device, comprising: an obtaining module, configured to sequentially acquire a database operation instruction in the target transaction executed by the application server during a process of executing a target transaction by the application server; predictive execution a module, configured to perform predictive execution on the database operation instruction, return the predicted execution result to the application server for the application server to determine the next database operation instruction to be executed, and record the database operation locally The instruction and the predicted execution data generated by the prediction execution when the database operation instruction belongs to the modification database class instruction; and the control execution module, configured to: when acquiring the transaction commit instruction in the target transaction, according to the local record The database operation instruction and the prediction execution data control the database corresponding to the application server to actually execute the target transaction.   根據申請專利範圍第7項所述的裝置,其中,還包括:配置模組,用於在該應用伺服器執行該目標事務之前,配置該資料庫為讀已提交隔離級別。  The device of claim 7, further comprising: a configuration module, configured to configure the database to read the submitted isolation level before the application server executes the target transaction.   根據申請專利範圍第7項所述的裝置,其中,該預測執行模組具體用於:若該資料庫操作指令屬於修改資料庫類指令,在本地建立的記憶體庫中類比該資料庫操作指令的資料環境,基於該類比的資料環境對該資料庫操作指令進行預測執行; 及若該資料庫操作指令不屬於修改資料庫類指令,在該資料庫中執行該資料庫操作指令,以對該資料庫操作指令進行預測執行。  The device of claim 7, wherein the predictive execution module is specifically configured to: if the database operation instruction belongs to a modified database class instruction, compare the database operation instruction in a locally established memory library The data environment, based on the analog data environment, predictive execution of the database operation instruction; and if the database operation instruction is not a modified database type instruction, executing the database operation instruction in the database to The database operation instruction performs prediction execution.   根據申請專利範圍第9項所述的裝置,其中,該預測執行模組具體用於:將該資料庫操作指令拆分為讀指令和寫指令;在該資料庫中執行該讀指令以獲取讀資料集,將該讀資料集存入該記憶體庫中以類比該資料庫操作指令的資料環境;及在該記憶體庫中執行該寫指令以修改該讀資料集。  The apparatus of claim 9, wherein the predictive execution module is specifically configured to: split the database operation instruction into a read instruction and a write instruction; execute the read instruction in the database to obtain a read a data set, the read data set is stored in the memory library to be analogous to the data environment of the database operation instruction; and the write instruction is executed in the memory library to modify the read data set.   根據申請專利範圍第7至10項中任一項所述的裝置,其中,該控制執行模組具體用於:向該資料庫下發本地記錄的該資料庫操作指令,以指示該資料庫執行該資料庫操作指令,並接收該資料庫返回的該資料庫操作指令的實際執行結果;若該實際執行結果與該預測執行結果相同,向該資料庫下發該事務提交指令,以供該資料庫提交該目標事務;及若該實際執行結果與該預測執行結果不相同,向該資料庫下發交易復原指令,以供該資料庫回滾該目標事務。  The device according to any one of claims 7 to 10, wherein the control execution module is specifically configured to: deliver the locally recorded database operation instruction to the database to indicate that the database is executed The database operation instruction receives the actual execution result of the database operation instruction returned by the database; if the actual execution result is the same as the prediction execution result, the transaction submission instruction is issued to the database for the data The library submits the target transaction; and if the actual execution result is different from the predicted execution result, a transaction recovery instruction is issued to the database for the database to roll back the target transaction.   根據申請專利範圍第11項所述的裝置,其中,該控制執行模組具體用於:將本地記錄的該資料庫操作指令同時下發給該資料 庫。  The device of claim 11, wherein the control execution module is configured to: simultaneously send the locally recorded database operation instruction to the database.  
TW106101941A 2017-01-19 2017-01-19 Database operation method and device TWI725110B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
TW106101941A TWI725110B (en) 2017-01-19 2017-01-19 Database operation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
TW106101941A TWI725110B (en) 2017-01-19 2017-01-19 Database operation method and device

Publications (2)

Publication Number Publication Date
TW201828164A true TW201828164A (en) 2018-08-01
TWI725110B TWI725110B (en) 2021-04-21

Family

ID=63960188

Family Applications (1)

Application Number Title Priority Date Filing Date
TW106101941A TWI725110B (en) 2017-01-19 2017-01-19 Database operation method and device

Country Status (1)

Country Link
TW (1) TWI725110B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20210318935A1 (en) * 2020-04-08 2021-10-14 Salesforce.Com, Inc. Method of using statistical backup validation for predictable database restore time

Family Cites Families (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP3602840B2 (en) * 2002-10-22 2004-12-15 株式会社東芝 Speculative execution control apparatus and method for instruction
GB0318196D0 (en) * 2003-08-02 2003-09-03 Ibm A method apparatus and computer program for processing a queue of messages
US7529914B2 (en) * 2004-06-30 2009-05-05 Intel Corporation Method and apparatus for speculative execution of uncontended lock instructions
US7493419B2 (en) * 2005-12-13 2009-02-17 International Business Machines Corporation Input/output workload fingerprinting for input/output schedulers
US9424315B2 (en) * 2007-08-27 2016-08-23 Teradata Us, Inc. Methods and systems for run-time scheduling database operations that are executed in hardware
US8224845B2 (en) * 2008-01-21 2012-07-17 International Business Machines Corporation Transaction prediction modeling method
CN101587447B (en) * 2008-05-23 2013-03-27 国际商业机器公司 System supporting transaction storage and prediction-based transaction execution method
CN101625699B (en) * 2009-07-28 2013-01-09 大连新中连软件集团有限公司 Application software business control method and system based on business componentization
US20110179057A1 (en) * 2010-01-18 2011-07-21 Microsoft Corporation Database engine throttling
CN102203779B (en) * 2011-05-03 2013-04-17 华为技术有限公司 Method and control device for updating data
US9477707B2 (en) * 2013-01-29 2016-10-25 Nec Corporation System and methods for predicting query execution time for concurrent and dynamic database workloads
US9053035B1 (en) * 2013-11-25 2015-06-09 Freescale Semiconductor, Inc. Multi-threaded system for performing atomic binary translations
US10599999B2 (en) * 2014-06-02 2020-03-24 Yottamine Analytics, Inc. Digital event profile filters based on cost sensitive support vector machine for fraud detection, risk rating or electronic transaction classification
US9477481B2 (en) * 2014-06-27 2016-10-25 International Business Machines Corporation Accurate tracking of transactional read and write sets with speculation
CN105204923A (en) * 2014-06-27 2015-12-30 国际商业机器公司 Method and device for resource pre-allocation
US9684514B2 (en) * 2014-09-10 2017-06-20 International Business Machines Corporation Inference based condition code generation
US10176209B2 (en) * 2015-06-26 2019-01-08 Vmware, Inc. Abortable transactions using versioned tuple cache

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20210318935A1 (en) * 2020-04-08 2021-10-14 Salesforce.Com, Inc. Method of using statistical backup validation for predictable database restore time

Also Published As

Publication number Publication date
TWI725110B (en) 2021-04-21

Similar Documents

Publication Publication Date Title
US11182404B2 (en) Data replication technique in database management system
US10649995B2 (en) Methods and systems for optimizing queries in a multi-tenant store
JP6877435B2 (en) Database operation method and equipment
US11132350B2 (en) Replicable differential store data structure
US11500869B2 (en) Method and apparatus for optimizing database transactions
WO2019109854A1 (en) Data processing method and device for distributed database, storage medium, and electronic device
US11625389B2 (en) Snapshot isolation query transactions in distributed systems
EP3396542B1 (en) Database operating method and device
US12079205B2 (en) Snapshot isolation query transactions in distributed systems
TWI774643B (en) Database operation method and device
KR20250056814A (en) Auxiliary query optimizer providing improved query performance
WO2017041637A1 (en) Database operating method and device
CN116975053A (en) Data processing method, device, equipment, medium and program product
TW201828164A (en) Database operation method and device capable of improving transaction execution efficiency of database transaction with higher delivery amount of transactions
TWI805544B (en) Database operation method and device
TWI735512B (en) Database operation method and device
TWI790991B (en) Database operation method and device
US12423293B2 (en) Streaming change logs from streaming database tables
CN120560788A (en) Data processing method and related equipment
CN121458215A (en) Budget data management and analysis system based on multi-mode database cooperation
CN115145970A (en) A method for managing SQL marking based on database middleware

Legal Events

Date Code Title Description
MM4A Annulment or lapse of patent due to non-payment of fees