A method, apparatus, device and storage medium for multi-version concurrency control

By obtaining the current transaction and row pointer, and combining status information and flags, the visibility of data rows is determined, thus solving the locking problem caused by obtaining the active transaction list in the existing MVCC scheme and improving system performance.

CN114443672BActive Publication Date: 2026-03-24GUANGZHOU YAXIN TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-11-06
Publication Date
2026-03-24

AI Technical Summary

Technical Problem

Existing MVCC implementations suffer from performance degradation when retrieving the list of active transactions, especially under high concurrency, as this causes the start and commit of other transactions to be locked, impacting system performance.

Method used

By obtaining the current transaction pointer and row pointer, and combining the row status information, effective flag, and termination flag, the visibility of data rows is determined, avoiding the need to obtain the list of active transactions and achieving lock-free judgment.

Benefits of technology

In high-concurrency scenarios, it improves system performance, avoids locking the start and commit of other transactions, and enhances system processing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114443672B_ABST
    Figure CN114443672B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a multi-version concurrency control method and device, electronic equipment and computer readable storage medium, and relate to the technical field of database. The method comprises: obtaining a current transaction pointer and a row pointer of a current row; obtaining a current transaction start number according to the current transaction pointer; obtaining row state information of the current row, a row effective flag and a row termination flag of the current row according to the row pointer of the current row; and judging the visibility of the current row according to the row state information and at least one of the current transaction start number, the row effective flag and the row termination flag. Embodiments of the present application realize the visibility judgment of the row by only using the hidden field on the row without obtaining the current active transaction list.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of database, in particular, the present application relates to a kind of multiversion concurrency control method, device, equipment and storage medium. BACKGROUND

[0002] Multiversion concurrency control (hereinafter referred to as MVCC) refers to a kind of concurrent technology, the earliest database system, only read can be concurrent between reading, read-write, write read, write write are blocked. After introducing multiple versions, only write-write is blocked, and the other three operations can be parallel, which greatly improves the concurrency of the database. In the same transaction, users can only see the modifications committed before the snapshot created by the transaction and the modifications made by the transaction itself. MVCC works only at Read Committed and Repeatable Read isolation levels.

[0003] The implementation principle of MVCC in PostgreSQL is to copy the entire transaction table at the beginning of the reader when the transaction starts, making the transaction table a hot spot. Since the records of the suspended transactions are not physically rolled back, all transaction histories need to save bitmap until the data batch processing is completed, which often affects the performance of the system. In the MVCC implementation of another database DB management system, the system commit transaction identifier and current log record sequence number can be copied from the transaction log at the beginning of the reader without obtaining the entire transaction table. However, in some scenarios, the active transaction list still needs to be obtained.

[0004] Therefore, in order to determine the visibility of data rows, when the first select (read-only operation) statement is executed after the start of the transaction, the active transaction list is obtained, or the active transaction list is re-obtained when each select (read-only operation) statement is executed after the start of the transaction, or in some scenarios, the active transaction list is obtained. In short, these MVCC implementation schemes involve obtaining the current active transaction list, and obtaining the active transaction list usually blocks the start and commit of other transactions, which often leads to a decrease in system performance when the concurrency is large. SUMMARY

[0005] The present application provides a multiversion concurrency control method, device, electronic equipment and computer readable storage medium, which can realize row visibility judgment without obtaining the current active transaction list, thereby improving the system performance in the MVCC scenario. The technical scheme adopted by the present application is as follows:

[0006] In a first aspect, a multiversion concurrency control method is provided, the method comprising:

[0007] obtaining a current transaction pointer and a row pointer of a current row;

[0008] obtaining a current transaction start number according to the current transaction pointer;

[0009] obtaining row state information of the current row, a row validation flag and a row termination flag of the current row according to the row pointer of the current row;

[0010] judging the visibility of the current row according to the row state information and at least one of the current transaction start number, the row validation flag and the row termination flag.

[0011] In the embodiment of the present application, the judging of the visibility of the current row according to the row pointer of the current row and at least one of the current transaction start number, the row validation flag and the row termination flag comprises:

[0012] if the row validation flag corresponds to a row validation transaction pointer and the row termination flag corresponds to a row termination transaction number, judging the visibility of the current row according to the row state information and at least one of the current transaction start number, the row validation transaction pointer and the row termination transaction number;

[0013] if the row validation flag corresponds to a row validation transaction number and the row termination flag corresponds to a row termination transaction pointer, judging the visibility of the current row according to the current transaction start number, the row validation transaction number and the row termination transaction pointer;

[0014] if the row validation flag corresponds to a row validation transaction number and the row termination flag corresponds to a row termination transaction number, judging the visibility of the current row according to the current transaction start number, the row validation transaction number and the row termination transaction number.

[0015] In the embodiment of the present application, the judging of the visibility of the current row according to the row state information and at least one of the current transaction start number, the row validation transaction pointer and the row termination transaction number comprises:

[0016] when the row state information is that the current row is a deleted row, determining that the current row is invisible;

[0017] when the row state information is that the current row is a non-deleted row and the row validation transaction pointer is the current transaction pointer, determining that the current row is visible;

[0018] when the row state information is that the current row is a non-deleted row and the row validation transaction pointer is not the current transaction pointer, judging the visibility of the current row according to at least one of the current transaction start number, the row validation transaction pointer and the row termination transaction number.

[0019] In the embodiment of the present application, the judging of the visibility of the current row according to at least one of the current transaction start number, the row validation transaction pointer and the row termination transaction number comprises:

[0020] According to the row valid transaction pointer, the row valid transaction commit number of the current row is acquired;

[0021] According to at least one of the current transaction start number, the row valid transaction commit number and the row termination transaction number, the visibility of the current row is judged.

[0022] In the embodiment of the application, according to at least one of the current transaction start number, the row valid transaction commit number and the row termination transaction number, the visibility of the current row is judged, including:

[0023] If the row valid transaction commit number is equal to zero, it is determined that the current row is invisible;

[0024] If the current transaction start number is greater than or equal to the row valid transaction commit number and less than or equal to the row termination transaction number, it is determined that the current row is visible.

[0025] In the embodiment of the application, according to the current transaction start number, the row valid transaction number and the row termination transaction pointer, the visibility of the current row is judged, including:

[0026] According to the row termination transaction pointer, the row termination transaction commit number of the current row is acquired;

[0027] According to the current transaction start number, the row valid transaction number and the row termination transaction commit number, the visibility of the current row is judged.

[0028] In the embodiment of the application, according to the current transaction start number, the row valid transaction number and the row termination transaction commit number, the visibility of the current row is judged, including:

[0029] If the current transaction start number is greater than or equal to the row valid transaction number and the row termination transaction commit number is equal to zero, it is determined that the current row is visible;

[0030] If the current transaction start number is greater than or equal to the row valid transaction number and less than or equal to the row termination transaction commit number, it is determined that the current row is visible.

[0031] In the embodiment of the application, according to the current transaction start number, the row valid transaction number and the row termination transaction number, the visibility of the current row is judged, including:

[0032] If the current transaction start number is greater than or equal to the row valid transaction number and less than or equal to the row termination transaction number, it is determined that the current row is visible.

[0033] In the embodiment of the application, it further includes:

[0034] When the current row is invisible, according to the row pointer of the current row, the row pointer of the next row is acquired;

[0035] When the row pointer of the next row is not empty, according to the row pointer of the next row, the row state information of the next row, the row effective flag of the next row and the row termination flag of the next row are determined;

[0036] According to the row state information of the next row, and at least one of the current transaction start number, the row effective flag of the next row and the row termination flag of the next row, the visibility of the next row is judged.

[0037] In a second aspect, the application provides a multi-version concurrency control device, which comprises:

[0038] The acquisition module is configured to acquire the current transaction pointer and the current row pointer, and is further configured to acquire the current transaction start number based on the current transaction pointer, and is further configured to acquire the row state information of the current row, the row effective flag of the current row and the row termination flag of the current row based on the row pointer of the current row;

[0039] The judgment module is configured to judge the visibility of the current row according to the row state information, and at least one of the current transaction start number, the row effective flag and the row termination flag.

[0040] In the embodiments of the application,

[0041] If the row effective flag corresponds to the row effective transaction pointer and the row termination flag corresponds to the row termination transaction number, the judgment module is specifically configured to judge the visibility of the current row according to the row state information, and at least one of the current transaction start number, the row effective transaction pointer and the row termination transaction number.

[0042] If the row effective flag corresponds to the row effective transaction number and the row termination flag corresponds to the row termination transaction pointer, the judgment module is specifically configured to judge the visibility of the current row according to the current transaction start number, the row effective transaction number and the row termination transaction pointer.

[0043] If the row effective flag corresponds to the row effective transaction number and the row termination flag corresponds to the row termination transaction number, the judgment module is specifically configured to judge the visibility of the current row according to the current transaction start number, the row effective transaction number and the row termination transaction number.

[0044] In the embodiments of the application, when the judgment module is specifically configured to judge the visibility of the current row according to at least one of the current transaction start number, the row effective transaction number and the row termination transaction pointer, the judgment module specifically comprises:

[0045] When the row state information is that the current row is a deleted row, it is determined that the current row is not visible;

[0046] When the row state information is that the current row is a non-deleted row, and the row effective transaction pointer is the current transaction pointer, it is determined that the current row is visible;

[0047] When the row state information is that the current row is a non-deleted row, and when the row effective transaction pointer is not the current transaction pointer, the visibility of the current row is determined according to at least one of the current transaction start number, the row effective transaction pointer and the row termination transaction number.

[0048] In the embodiment of the present application, when the judging module is used to determine the visibility of the current row according to at least one of the current transaction start number, the row effective transaction pointer and the row termination transaction number, the judging module specifically includes:

[0049] According to the row effective transaction pointer, the row effective transaction commit number of the current row is acquired.

[0050] The visibility of the current row is determined according to at least one of the current transaction start number, the row effective transaction commit number and the row termination transaction number.

[0051] In the embodiment of the present application, when the judging module is used to determine the visibility of the current row according to at least one of the current transaction start number, the row effective transaction commit number and the row termination transaction number, the judging module specifically includes:

[0052] If the row effective transaction commit number is equal to zero, it is determined that the current row is invisible.

[0053] If the current transaction start number is greater than or equal to the row effective transaction commit number and less than or equal to the row termination transaction number, it is determined that the current row is visible.

[0054] In the embodiment of the present application, when the judging module is used to determine the visibility of the current row according to the current transaction start number, the row effective transaction number and the row termination transaction pointer, the judging module specifically includes:

[0055] According to the row termination transaction pointer, the row termination transaction commit number of the current row is acquired.

[0056] The visibility of the current row is determined according to the current transaction start number, the row effective transaction number and the row termination transaction commit number.

[0057] In the embodiment of the present application, when the judging module is used to determine the visibility of the current row according to the current transaction start number, the row effective transaction number and the row termination transaction commit number, the judging module specifically includes:

[0058] If the current transaction start number is greater than or equal to the row effective transaction number and the row termination transaction commit number is equal to zero, it is determined that the current row is visible.

[0059] If the current transaction start number is greater than or equal to the row effective transaction number and less than or equal to the row termination transaction commit number, it is determined that the current row is visible.

[0060] In this embodiment of the application, when the determination module determines the visibility of the current row based on the current transaction start number, the row effective transaction number, and the row termination transaction number, it specifically includes:

[0061] If the start number of the current transaction is greater than or equal to the effective transaction number of the row, and less than or equal to the end transaction number of the row, then the current row is considered visible.

[0062] In this embodiment of the application, the acquisition module and the judgment module are further used for:

[0063] When the judgment module determines that the current line is not visible, the acquisition module is also used to obtain the line pointer of the next line, and the judgment module is also used to determine whether the line pointer of the next line is null;

[0064] When the judgment module determines that the row pointer of the next row is not null, the acquisition module is also used to acquire the row status information, the row activation flag, and the row termination flag of the next row.

[0065] The judgment module is also used to determine the visibility of the next row based on at least one of the row status information of the next row, namely, the current transaction start number, the row effective flag of the next row, and the row termination flag of the next row.

[0066] Thirdly, this application provides an electronic device including a processor and a memory:

[0067] Memory, used to store computer operating instructions;

[0068] A processor is configured to execute the methods shown in any embodiment of the first aspect of this application by invoking computer operation instructions.

[0069] Fourthly, this application provides a computer-readable storage medium storing computer program instructions that are used to cause a computer to execute in order to implement the method shown in any embodiment of the first aspect of this application.

[0070] The beneficial effects of the technical solutions provided in this application are:

[0071] The solution in the embodiments of this application determines the visibility of the current row based on hidden field information on the row, specifically row status information and at least one of the following: current transaction start number, row effective flag, and row termination flag. This achieves row visibility determination solely through hidden fields on the row without needing to obtain the list of currently active transactions, thus improving system performance in MVCC scenarios. Attached Figure Description

[0072] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments of this application will be briefly introduced below.

[0073] Figure 1 A flowchart illustrating a multi-version concurrency control method provided in an embodiment of this application;

[0074] Figure 2 A flowchart illustrating a multi-version concurrency control method provided in another embodiment of this application;

[0075] Figure 3 A schematic diagram of the structure of a multi-version concurrency control device provided in an embodiment of this application;

[0076] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0077] The embodiments of this application are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain this application, and should not be construed as limiting the invention.

[0078] Those skilled in the art will understand that, unless specifically stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the term “comprising” as used in this application means the presence of the stated features, integers, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof. It should be understood that when we say an element is “connected” or “coupled” to another element, it can be directly connected or coupled to the other element, or there may be intermediate elements. Furthermore, “connected” or “coupled” as used herein can include wireless connections or wireless coupling. The term “and / or” as used herein includes all or any units and all combinations of one or more associated listed items.

[0079] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.

[0080] In existing technical solutions, to determine the visibility of data rows, the list of active transactions is retrieved when executing each select (read-only) statement after a transaction begins; or the list of active transactions is retrieved again when executing each select (read-only) statement after a transaction begins; or, in certain scenarios, the list of active transactions is retrieved. In short, these MVCC implementations all involve retrieving the current list of active transactions. However, retrieving the list of active transactions typically involves locking and blocking the start and commit of other transactions, which often leads to performance degradation under high concurrency.

[0081] This application provides a multi-version concurrency control method, apparatus, electronic device, and computer-readable storage medium, which aims to solve the above-mentioned technical problems of the prior art.

[0082] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes will not be described again in some embodiments. The embodiments of this application will be described below with reference to the accompanying drawings.

[0083] In this embodiment, the MVCC row data format is shown in Table 1 below:

[0084] info(1) begin(8) end(8) next(8) record content

[0085] Table 1

[0086] The info field contains 1 byte, which indicates the status of the row, specifically: deleted, free, or in use.

[0087] begin: 8 bytes, representing the transaction number when the row takes effect, specifically: transaction pointer or transaction number;

[0088] end: 8 bytes, representing the transaction number at the end of the row, specifically: transaction pointer or transaction number;

[0089] next: 8 bytes, indicating the next rollback row, specifically: the row_id of the next rollback row or a pointer to the next rollback row.

[0090] In this embodiment of the application, the transaction-related data structure is shown in Table 2 below:

[0091] start_trx_id commit_trx_id

[0092] Table 2

[0093] Among them, start_trx_id: 8 bytes, representing the number at the start of the transaction;

[0094] commit_trx_id: 8 bytes, representing the number when the transaction was committed;

[0095] The rows involved in the embodiments of this application all have the data structure shown in Table 1, but are not limited to the data structure in Table 1.

[0096] As shown above, row status information includes whether a row is idle, deleted, or in use. This embodiment focuses on analyzing the visibility of deleted and currently used rows. To facilitate further analysis, the rows to be analyzed are divided into deleted rows and non-deleted rows. The transactions involved in this embodiment all have the data structure shown in Table 2, but are not limited to the data structure in Table 2.

[0097] This application provides a multi-version concurrency control method, such as... Figure 1 As shown, it includes:

[0098] S101, retrieves the current transaction pointer and the current row pointer.

[0099] When determining the visibility of the current row, it is first necessary to obtain the current transaction object and the row object of the current row. Then, other information is obtained through the objects, and the visibility of the current row is determined based on the obtained information. Specifically, obtaining the current transaction object involves first obtaining a pointer to the current transaction object (i.e., the current transaction pointer), and then obtaining the object pointed to by the current transaction pointer. Similarly, obtaining the row object of the current row involves first obtaining a pointer to the current row object (i.e., the current row pointer), and then obtaining the object pointed to by the current row pointer.

[0100] Since the current operation is a select (read-only operation), the current transaction started is a select transaction (read-only transaction).

[0101] S102, obtain the start number of the current transaction based on the current transaction pointer.

[0102] First, obtain the current transaction object based on the current transaction pointer. The data structure of the current transaction object is shown in Table 2, including the transaction start number start_trx_id.

[0103] The start number is obtained based on the current transaction object, i.e., the start number of the current transaction.

[0104] S103, based on the row pointer of the current row, obtain the row status information, row activation flag, and row termination flag of the current row.

[0105] First, obtain the row object of the current row based on the row pointer of the current row. The data structure of the row object of the current row is shown in Table 1, which includes the row status information info, the row activation flag begin, and the row termination flag end.

[0106] Secondly, based on the row object of the current row, obtain the row status information, row activation flag, and row termination flag of the current row.

[0107] S104. Determine the visibility of the current row based on the row status information and at least one of the current transaction start number, row effective flag, and row termination flag.

[0108] When determining the visibility of the current row, it only needs to obtain the current transaction start number, the row status information, the row activation flag, and the row termination flag. It does not need to obtain the list of currently active transactions, so there is no locking that blocks the start and commit of other transactions. This has a good performance improvement effect when the concurrency is high.

[0109] In another embodiment of this application, the row effective flag and the row termination flag can be either transaction pointers or transaction numbers.

[0110] In this context, the data type of a transaction pointer is a pointer, specifically a memory address. Once an object is successfully created, it is stored in the heap memory. In actual computer operation, direct access to objects in the heap memory is not allowed; objects can only be accessed through a reference, specifically a pointer. An object is retrieved by pointing to it through a pointer, specifically by accessing the starting address of the object pointed to by the pointer.

[0111] The data type of a transaction number is numeric, specifically representing a quantity. The length of the storage unit it occupies is not fixed and varies depending on the numeric type.

[0112] Therefore, determining the visibility of the current row based on the row status information and at least one of the current transaction start number, row effective flag, and row termination flag includes at least the following cases:

[0113] When the row effective flag is the row effective transaction pointer and the row termination flag corresponds to the row termination transaction number, S104 specifically includes: S1041, determining the visibility of the current row based on the row status information and at least one of the current transaction start number, the row effective transaction pointer and the row termination transaction number.

[0114] When the row effective flag is the row effective transaction number and the row termination flag corresponds to the row termination transaction pointer, S104 specifically includes: S1042, determining the visibility of the current row based on the current transaction start number, the row effective transaction number and the row termination transaction pointer.

[0115] When the row effective flag is the row effective transaction number and the row termination flag corresponds to the row termination transaction number, S104 specifically includes: S1043, determining the visibility of the current row based on the current transaction start number, the row effective transaction number, and the row termination transaction number.

[0116] In this embodiment, a specific scheme for determining the visibility of the current row is analyzed, considering whether the row activation flag and row termination flag are transaction numbers or transaction pointers. This determination process does not require obtaining the list of currently active transactions, thus avoiding locking that blocks the start and commit of other transactions. This approach significantly improves performance under high concurrency.

[0117] In another implementation of this application, the row activation flag is a row activation transaction pointer, and the row termination flag corresponds to a row termination transaction number. Specifically, if there is a transaction operation on the current row, further analysis can be performed based on the row status information of the current row. S1041 may include:

[0118] S1041-1. When the row status information indicates that the current row is a deleted row, determine that the current row is not visible.

[0119] For example, the operation currently being performed on the current row is transaction T. The specific process of transaction T is as follows: First, an insert operation is performed, resulting in the insertion of a row S1; second, a delete operation is performed, resulting in the deletion of S1. In other words, the operation currently being performed on the current row by transaction T specifically involves insert and delete operations, resulting in no row being inserted. At this point, whether other transactions or the current transaction reads this row, it is invisible to the current transaction. That is, the current row is invisible to the current transaction.

[0120] S1041-2. When the row status information indicates that the current row is not a deleted row, and the row's effective transaction pointer is the current transaction pointer, then the current row is determined to be visible.

[0121] For example, if the current row is not a deleted row, and the row validity flag for the current row is a pointer, it means that an operation is in progress on the current row. However, if that pointer is the current transaction pointer, it means that the current transaction is already performing a read-only operation on the current row. In other words, the current row is visible to the current transaction.

[0122] S1041-3. When the row status information indicates that the current row is not a deleted row and the row effective pointer is not the current transaction pointer, determine the visibility of the current row based on at least one of the current transaction start number, the row effective transaction pointer, and the row termination transaction number.

[0123] In other words, if the row status information indicates that the current row is neither a deleted row nor an operation performed in the current transaction, then it is necessary to further determine the visibility of the current row based on at least one of the current transaction start number, the row effective transaction pointer, and the row termination transaction number.

[0124] In this embodiment, since the current row status information can be either a deleted row or a non-deleted row, it is first determined whether the current row is a deleted row or a non-deleted row. Then, based on whether the row's effective flag is the row effective transaction pointer and the row's termination flag is the row termination transaction number, the visibility of the current row is further determined. This method does not require obtaining the list of currently active transactions, so there is no locking that blocks the start and commit of other transactions. When the concurrency is large, it has a good effect on improving performance.

[0125] In another implementation of this application, the row activation flag is a row activation transaction pointer, and the row termination flag corresponds to the row termination transaction number. Specifically, the current row has a transaction operation but is not the current transaction operation, and the current row is not a deleted row. S1041-3 specifically includes:

[0126] S1041-31. Obtain the commit number of the current row's effective transaction based on the row effective transaction pointer;

[0127] Since the row-effective transaction pointer is a memory address, specifically used to store the starting address of the object it points to, it is necessary to first obtain the row-effective transaction object through the row-effective transaction pointer, and then obtain the row-effective transaction commit number through the row-effective transaction object.

[0128] S1041-32. Determine the visibility of the current row based on at least one of the current transaction start number, the row-effective transaction commit number, and the row-terminating transaction number. Specifically, this includes:

[0129] 1. If the commit number of the transaction that made the row effective is zero, it is determined that the current row is not visible to the current transaction;

[0130] In other words, the current row is currently undergoing a transaction operation, but the operation has not been committed, and the current row is in a locked state. Therefore, it is determined that the current row is not visible to the current transaction.

[0131] 2. If the start number of the current transaction is greater than or equal to the commit number of the row's effective transaction, and less than or equal to the end number of the row's termination transaction, then the current row is determined to be visible to the current transaction.

[0132] In this embodiment of the application, if the row effective flag of the current row is a transaction pointer, it is necessary to first obtain the row effective transaction commit number based on the row termination transaction pointer, and then further determine the visibility of the current row based on the current transaction commit number, the row effective transaction commit number, and the row termination transaction number. This method does not require obtaining the list of currently active transactions, so there is no locking that blocks the start and commit of other transactions. When the concurrency is large, it has a good effect on improving performance.

[0133] In another implementation of this application, when the row activation flag is the row activation transaction number and the row termination flag corresponds to the row termination transaction pointer. Specifically, the current row has a transaction operation, and the row status information of the current row is a deleted row. S1042 may include:

[0134] S1042-1. Obtain the row termination transaction commit number of the current row based on the row termination transaction pointer;

[0135] Since the row termination transaction pointer is not a specific value, it is necessary to obtain the row termination transaction object through the row termination transaction pointer, and then obtain the row termination transaction commit number through the row termination transaction object.

[0136] When the row termination commit number is 0, it represents infinity. Specifically, 0 can be considered a marker, where the current transaction number is always less than the row termination commit number.

[0137] S1042-2. Determine the visibility of the current row based on the current transaction start number, the row effective transaction number, and the row termination transaction commit number. Specifically, this includes:

[0138] 1. If the start number of the current transaction is greater than or equal to the effective transaction number of the row, and the commit number of the terminated transaction of the row is equal to zero, then the current row is visible to the current transaction.

[0139] 2. If the current transaction start number is greater than or equal to the row's effective transaction number, and less than or equal to the row's terminated transaction commit number, then the current row is determined to be visible.

[0140] In this embodiment of the application, if the row termination flag of the current row is a transaction pointer, it is necessary to first obtain the row termination transaction commit number based on the row termination transaction pointer, and then further determine the visibility of the current row based on the current transaction commit number, the row effective transaction number and the row termination transaction commit number. This method does not require obtaining the list of currently active transactions, so there is no locking that blocks the start and commit of other transactions. When the concurrency is large, it has a good effect on improving performance.

[0141] In another implementation of this application, the row effective flag corresponds to the row effective transaction number, and the row termination flag corresponds to the row termination transaction number. Specifically, the current row has no transaction operation, and the current row is either a deleted row or a non-deleted row. S1043 includes:

[0142] If the start number of the current transaction is greater than or equal to the effective transaction number of the row, and less than or equal to the end transaction number of the row, then the current row is considered visible.

[0143] When the row termination transaction number is 0, it represents infinity. Specifically, 0 can be considered a marker, where the current transaction number is always less than the row termination transaction number.

[0144] In another embodiment of this application, if it is determined that the current row is not visible according to any of the above embodiments, it is necessary to obtain the information of the next rollback row for judgment, until a visible row is obtained or until all rows are not visible, specifically as follows: Figure 2 As shown:

[0145] Following S104, it also includes:

[0146] S105, when the current line is not visible, obtain the line pointer of the next line based on the line pointer of the current line;

[0147] The next line is actually the next rollback line;

[0148] Specifically, based on the row object of the current row, retrieve the row_id stored in the next field of the row data structure shown in Table 1, or a row pointer pointing to the next row. The row pointer pointing to the next row can be obtained through the row_id.

[0149] S106, If the row pointer of the next row is not null, determine the row status information, row activation flag and row termination flag of the next row based on the row pointer of the next row;

[0150] S107. Based on the row status information of the next row, and at least one of the following: the current transaction start number, the row effective flag of the next row, and the row termination flag of the next row, determine the visibility of the next row.

[0151] The process of determining the visibility of the next line is similar to that of determining the visibility of the current line, and will not be elaborated here for the sake of brevity.

[0152] In this embodiment of the application, when it is determined that the current row is not visible, it is necessary to obtain the information of the next rollback row and determine whether the next row is visible, until a visible row is obtained or all rows are not visible. This method does not require obtaining the list of currently active transactions, so there is no locking that blocks the start and commit of other transactions. When the concurrency is large, it has a good effect on improving performance.

[0153] Another implementation of this embodiment will describe in more detail the process of determining the visibility of the current row.

[0154] The operation performed on the current row can be a read-only operation, an insert operation, an update operation, or a delete operation. Therefore, the visibility of the current row at each stage is determined by referring to Tables 3, 4, and 5, which describe the various operations being performed on the current row. All the visibility determinations described below are based on having obtained information about the current transaction, specifically the current transaction number.

[0155] On the one hand, the insertion operation will be described as an example, referring to Table 3 below.

[0156]

[0157]

[0158] Table 3

[0159] Table 3 records the entire process of the current row being inserted, where the current row is not a deleted row.

[0160] In sequence 1, an insert transaction object is created. The system assigns the start number (start_trx_id) of the insert transaction object to transaction number A, and the commit number (commit_trx_id) to 0. The validity and termination flags of the current row are both transaction numbers. At this point, the visibility of the current row can be determined based on the current transaction start number, the row validity flag, and the row termination transaction number.

[0161] In sequence 2, the insert transaction begins. The row activation flag (begin) is the row activation transaction pointer (pTrx), which is a pointer to the insert transaction object. The row termination flag (end) is the row termination transaction number, which is 0. Since the current row is currently undergoing an insert operation, it is locked and therefore invisible.

[0162] Sequence 3, the pre-commit phase of the insert transaction. In this phase, the system assigns the commit number (commit_trx_id) of the insert transaction object to transaction number B. Since the row-effective transaction pointer points to the insert transaction object, the commit number of the insert transaction object, i.e., the row-effective transaction commit number, specifically transaction number B, can be obtained through the row-effective transaction pointer; the row-terminating transaction number is 0. At this point, the visibility of the current row can be determined based on the current transaction number, the row-effective transaction commit number, and the row-terminating transaction number.

[0163] Sequence 4, the formal commit phase. In this phase, the row effectiveness flag (begin) changes from the row effectiveness transaction pointer to the row effectiveness transaction number, and is assigned transaction number B, while the row termination transaction number is 0. After this phase, the data version of the current row becomes [B, 0]. At this point, the visibility of the current row can be determined based on the current transaction number, the row effectiveness transaction number, and the row termination transaction number.

[0164] Sequence 5, Committed Phase. The row's effectiveness flag is the transaction number that enabled the row, specifically transaction number B, and the row's termination flag is the transaction number that terminated the row, specifically 0. The data version of the current row is still [D, 0]. At this point, the visibility of the current row can be determined based on the current transaction number, the transaction number that enabled the row, and the transaction number that terminated the row.

[0165] On the other hand, the update operation will be described as an example, referring to Table 4 below.

[0166]

[0167] Table 4

[0168] Table 4 records the entire process of the update operation being performed on the current row, where the current row is not a deleted row.

[0169] In sequence 1, an update transaction object is created. The system assigns the update transaction object a start number of transaction number C and a commit number of 0. The current row's validity and termination flags are both transaction numbers. At this point, the visibility of the current row can be determined based on the current transaction start number, the row validity flag, and the row termination transaction number.

[0170] In sequence 2, the update transaction begins. The row effectiveness flag is the row effectiveness transaction pointer, specifically a pointer to the update transaction object, and the row termination flag is the row termination transaction number, specifically 0. Since the current row is currently undergoing an update operation, it is in a locked state and can be directly determined that the current row is not visible.

[0171] Sequence 3, the pre-commit phase of the update transaction. In this phase, the system assigns the commit number of the update transaction object to transaction number D. Since the row-effective transaction pointer points to the update transaction object, the commit number of the update transaction object, i.e., the row-effective transaction commit number, is obtained through the row-effective transaction pointer; specifically, it is D. The row-terminating transaction number is 0. At this time, the visibility of the current row can be determined based on the current transaction number, the row-effective transaction commit number, and the row-terminating transaction number.

[0172] Sequence 4, the formal commit phase. In this phase, the row effectiveness flag changes from the row effectiveness transaction pointer to the row effectiveness transaction number, which is assigned the transaction number D, and the row termination transaction number is 0. After this phase, the data version of the current row becomes [D, 0]. At this point, the visibility of the current row can be determined based on the current transaction number, the row effectiveness transaction number, and the row termination transaction number.

[0173] Sequence 5, Committed Phase. The row's effectiveness flag is the transaction number that enabled the row, specifically transaction number D, and the row's termination flag is the transaction number that terminated the row, specifically 0. The data version of the current row is still [D, 0]. At this point, the visibility of the current row can be determined using the current transaction number, the transaction number that enabled the row, and the transaction number that terminated the row.

[0174] When an update operation is performed, a rollback row is generated, which records the row data before the update operation was performed, but the current transaction still determines the visibility of the current row.

[0175] On the other hand, the deletion operation will be described as an example, referring to Table 5 below.

[0176]

[0177] Table 5

[0178] Table 5 records the entire process of the deletion operation performed on the current row, which is the deleted row.

[0179] In sequence 1, a deletion transaction object is created. The system assigns the deletion transaction object a start number of transaction number C and a commit number of 0. Both the row effectiveness flag and the row termination flag are transaction numbers. At this point, the visibility of the current row can be determined based on the current transaction start number, the row effectiveness transaction number, and the row termination transaction number.

[0180] In sequence 2, the deletion transaction begins. The row validity flag is a pointer to the row validity transaction, specifically a pointer to the deletion transaction object. The row termination flag is the row termination transaction number, specifically stored as transaction number 0. Since the current row is currently undergoing a deletion operation, it is locked and therefore invisible.

[0181] Sequence 3, the pre-commit phase of the delete transaction. In this phase, the system assigns the commit number of the delete transaction object to transaction number D. Since the row-effective transaction pointer points to the delete transaction object, the commit number of the delete transaction object, i.e., the row-effective transaction commit number, is obtained through the row-effective transaction pointer, specifically transaction number D; the row-terminating transaction number is 0. At this time, the visibility of the current row can be determined based on the current transaction number, the row-effective transaction commit number, and the row-terminating transaction number.

[0182] Sequence 4, the formal commit phase. In this phase, the row effectiveness flag changes from the row effectiveness transaction pointer to the row effectiveness transaction number, and is assigned the transaction number D. The row termination transaction number remains unchanged. After this phase, the data version of the current row becomes [D, 0]. At this point, the visibility of the current row can be determined based on the current transaction number, the row effectiveness transaction number, and the row termination transaction number.

[0183] Sequence 5, Committed Phase. The row's effectiveness is indicated by the transaction number that enabled the row, specifically transaction number D, and the row's termination is indicated by the transaction number that terminated the row, specifically transaction number 0. The data version of the current row is [D, 0]. At this point, the visibility of the current row can be determined using the current transaction number, the transaction number that enabled the row, and the transaction number that terminated the row.

[0184] It should be noted that the specific situation of the current row is not limited to the situation involved in the embodiments of this application, but also includes many other situations, which will not be elaborated here.

[0185] This application provides a multi-version concurrency control device 20, the structural schematic diagram of which is shown below. Figure 3 As shown, the device 20 includes:

[0186] The acquisition module 201 is used to acquire the current transaction pointer and the current row pointer, and is also used to acquire the current transaction start number based on the current transaction pointer, and to acquire the row status information, row activation flag and row termination flag of the current row based on the row pointer of the current row;

[0187] The judgment module 202 is used to determine the visibility of the current row based on the row status information and at least one of the current transaction start number, row effective flag and row termination flag.

[0188] In the embodiments of this application,

[0189] If the row effective flag corresponds to the row effective transaction pointer and the row termination flag corresponds to the row termination transaction number, the judgment module 202 is specifically used to: determine the visibility of the current row based on the row status information and at least one of the current transaction start number, the row effective transaction pointer and the row termination transaction number;

[0190] If the row effective flag corresponds to the row effective transaction number and the row termination flag corresponds to the row termination transaction pointer, the judgment module 202 is specifically used to: determine the visibility of the current row based on the current transaction start number, the row effective transaction number and the row termination transaction pointer;

[0191] If the row effective flag corresponds to the row effective transaction number and the row termination flag corresponds to the row termination transaction number, the judgment module 202 is specifically used to: determine the visibility of the current row based on the current transaction start number, the row effective transaction number, and the row termination transaction number.

[0192] In this embodiment of the application, the determination module 202 is used to determine the visibility of the current row based on the row status information and at least one of the current transaction start number, the row effective transaction pointer, and the row termination transaction number. Specifically, this includes:

[0193] When the row status information indicates that the current row is a deleted row, it is determined that the current row is not visible;

[0194] When the row status information indicates that the current row is not a deleted row, and the pointer of the transaction in effect for the row is the pointer of the current transaction, the current row is determined to be visible.

[0195] When the row status information indicates that the current row is not a deleted row, and the row effective transaction pointer is not the current transaction pointer, the visibility of the current row is determined based on at least one of the current transaction start number, the row effective transaction pointer, and the row termination transaction number.

[0196] In this embodiment of the application, when the determination module 202 determines the visibility of the current row based on at least one of the current transaction start number, the row effective transaction pointer, and the row termination transaction number, it specifically includes:

[0197] Based on the row-effective transaction pointer, obtain the row-effective transaction commit number for the current row;

[0198] Determine the visibility of the current row based on at least one of the current transaction start number, the row effective transaction commit number, and the row termination transaction number.

[0199] In this embodiment of the application, when the determination module 202 determines the visibility of the current row based on at least one of the current transaction start number, the row effective transaction commit number, and the row termination transaction number, it specifically includes:

[0200] If the commit number of the transaction for which the row took effect is zero, then the current row is not visible.

[0201] If the current transaction start number is greater than or equal to the row's effective transaction commit number, and less than or equal to the row's terminate transaction number, then the current row is considered visible.

[0202] In this embodiment of the application, when the judgment module 202 determines the visibility of the current row based on the current transaction start number, the row effective transaction number, and the row termination transaction pointer, it specifically includes:

[0203] Obtain the row termination transaction commit number of the current row based on the row termination transaction pointer;

[0204] Determine the visibility of the current row based on the current transaction start number, the row effective transaction number, and the row termination transaction commit number.

[0205] In this embodiment of the application, when the judgment module 202 determines the visibility of the current row based on the current transaction start number, the row effective transaction number, and the row termination transaction commit number, it specifically includes:

[0206] If the start number of the current transaction is greater than or equal to the number of the transaction that made the row effective, and the commit number of the transaction that terminated the row is equal to zero, then the current row is considered visible.

[0207] If the current transaction start number is greater than or equal to the row's effective transaction number, and less than or equal to the row's terminated transaction commit number, then the current row is considered visible.

[0208] In this embodiment of the application, when the determination module 202 determines the visibility of the current row based on the current transaction start number, the row effective transaction number, and the row termination transaction number, it specifically includes:

[0209] If the start number of the current transaction is greater than or equal to the effective transaction number of the row, and less than or equal to the end transaction number of the row, then the current row is considered visible.

[0210] In this embodiment of the application, the acquisition module 201 and the judgment module 202 are further configured to:

[0211] When the judgment module 202 determines that the current row is not visible, the acquisition module 201 obtains the row pointer of the next row, and the judgment module 202 then uses it to determine whether the row pointer of the next row is empty;

[0212] When the judgment module 202 determines that the row pointer of the next row is not empty, the acquisition module 201 is also used to acquire the row status information of the next row, the row activation flag of the next row, and the row termination flag of the next row.

[0213] The judgment module 202 is also used to determine the visibility of the next row based on the row status information of the next row, namely at least one of the current transaction start number, the row effective flag of the next row, and the row termination flag of the next row.

[0214] The multi-version concurrency control device of this embodiment can execute the multi-version concurrency control method shown in the foregoing embodiments of this application. Its implementation principle and the effects it can achieve are similar, and will not be described again here.

[0215] This application provides an electronic device comprising: a memory and a processor; and at least one program stored in the memory. When the processor executes the program, it performs the aforementioned determination regarding the visibility of rows.

[0216] Specifically, such as Figure 4 As shown, Figure 4 The illustrated electronic device 30 includes a processor 301 and a memory 303. The processor 301 and the memory 303 are connected, for example, via a bus 302. The structure of this electronic device 30 does not constitute a limitation on the embodiments of this application.

[0217] Processor 301 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 301 may also be a combination that implements computational functions, such as including one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.

[0218] Bus 302 may include a pathway for transmitting information between the aforementioned components. Bus 302 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. Bus 3002 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 4 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.

[0219] The memory 303 may be a ROM (Read Only Memory) or other type of static storage device capable of storing static information and instructions, RAM (Random Access Memory) or other type of dynamic storage device capable of storing information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), CD-ROM (Compact Disc Read Only Memory) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto.

[0220] The memory 303 is used to store application code that executes the solution of this application, and its execution is controlled by the processor 301. The processor 301 is used to execute the application code stored in the memory 303 to implement the content shown in the foregoing method embodiments.

[0221] This application provides a computer-readable storage medium storing a computer program that, when run on a computer, enables the computer to execute the corresponding content in the aforementioned method embodiments.

[0222] It should be understood that although the steps in the flowcharts of the accompanying figures are shown sequentially as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the accompanying figures may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.

[0223] The above are only some embodiments of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A multi-version concurrency control method, characterized in that: Get the current transaction pointer and the current row pointer; Based on the current transaction pointer, obtain the start number of the current transaction; Based on the row pointer of the current row, obtain the row status information, row activation flag, and row termination flag of the current row; The visibility of the current row is determined based on the row status information and at least one of the current transaction start number, the row effective flag, and the row termination flag; The step of determining the visibility of the current row based on the row status information and at least one of the current transaction start number, the row effective flag, and the row termination flag includes: If the row activation flag corresponds to the row activation transaction pointer and the row termination flag corresponds to the row termination transaction number, then when the row status information indicates that the current row is a deleted row, the current row is determined to be invisible; when the row status information indicates that the current row is not a deleted row and the row activation transaction pointer is the current transaction pointer, the current row is determined to be visible; when the row status information indicates that the current row is not a deleted row and the row activation transaction pointer is not the current transaction pointer, the visibility of the current row is determined based on at least one of the current transaction start number, the row activation transaction pointer, and the row termination transaction number. If the row effective flag corresponds to the row effective transaction number and the row termination flag corresponds to the row termination transaction pointer, the visibility of the current row is determined based on the current transaction start number, the row effective transaction number, and the row termination transaction pointer. If the row effective flag corresponds to the row effective transaction number and the row termination flag corresponds to the row termination transaction number, the visibility of the current row is determined based on the current transaction start number, the row effective transaction number, and the row termination transaction number.

2. The multi-version concurrency control method according to claim 1, characterized in that, Determining the visibility of the current row based on at least one of the current transaction start number, the row effective transaction pointer, and the row termination transaction number includes: Based on the row-effective transaction pointer, obtain the row-effective transaction commit number of the current row; The visibility of the current row is determined based on at least one of the current transaction start number, the row effective transaction commit number, and the row termination transaction number.

3. The method according to claim 2, characterized in that, The visibility of the current row is determined based on at least one of the current transaction start number, the row effective transaction commit number, and the row termination transaction number, including: If the commit number of the transaction for which the row took effect is equal to zero, then the current row is determined to be invisible. If the current transaction start number is greater than or equal to the row's effective transaction commit number, and less than or equal to the row's terminated transaction number, then the current row is determined to be visible.

4. The multi-version concurrency control method according to claim 1, characterized in that, The step of determining the visibility of the current row based on the current transaction start number, the row effective transaction number, and the row termination transaction pointer includes: Based on the row termination transaction pointer, obtain the row termination transaction commit number of the current row; The visibility of the current row is determined based on the current transaction start number, the row effective transaction number, and the row termination transaction commit number.

5. The multi-version concurrency control method according to claim 4, characterized in that, The step of determining the visibility of the current row based on the current transaction start number, the row effective transaction number, and the row termination transaction commit number includes: If the current transaction start number is greater than or equal to the row effective transaction number, and the row termination transaction commit number is equal to zero, then the current row is determined to be visible. If the current transaction start number is greater than or equal to the row's effective transaction number, and less than or equal to the row's terminated transaction commit number, then the current row is determined to be visible.

6. The multi-version concurrency control method according to claim 1, characterized in that, The step of determining the visibility of the current row based on the current transaction start number, the row effective transaction number, and the row termination transaction number includes: If the start number of the current transaction is greater than or equal to the effective transaction number of the row, and less than or equal to the termination transaction number of the row, then the current row is determined to be visible.

7. The multi-version concurrency control method according to any one of claims 1-6, characterized in that, The method further includes: When the current row is not visible, obtain the row pointer of the next row based on the row pointer of the current row; When the row pointer of the next row is not null, determine the row status information, row activation flag, and row termination flag of the next row based on the row pointer of the next row. The visibility of the next row is determined based on the row status information of the next row, and at least one of the current transaction start number, the row effective flag of the next row, and the row termination flag of the next row.

8. A multi-version concurrency control device, characterized in that, include: The acquisition module is used to acquire the current transaction pointer and the current row pointer, and is also used to acquire the current transaction start number based on the current transaction pointer, and to acquire the row status information, the row activation flag and the row termination flag of the current row based on the row pointer of the current row; The judgment module is used to determine the visibility of the current row based on the row status information and at least one of the current transaction start number, the row effective flag and the row termination flag; When determining the visibility of the current row based on the row status information and at least one of the current transaction start number, the row effective flag, and the row termination flag, the determination module is used to: If the row activation flag corresponds to the row activation transaction pointer and the row termination flag corresponds to the row termination transaction number, then when the row status information indicates that the current row is a deleted row, it is determined that the current row is not visible. When the row status information indicates that the current row is not a deleted row, and the row's effective transaction pointer is the current transaction pointer, the current row is determined to be visible. When the row status information indicates that the current row is a non-deleted row, and when the row effective transaction pointer is not the current transaction pointer, the visibility of the current row is determined based on at least one of the current transaction start number, the row effective transaction pointer, and the row termination transaction number; If the row effective flag corresponds to the row effective transaction number and the row termination flag corresponds to the row termination transaction pointer, the visibility of the current row is determined based on the current transaction start number, the row effective transaction number, and the row termination transaction pointer. If the row effective flag corresponds to the row effective transaction number and the row termination flag corresponds to the row termination transaction number, the visibility of the current row is determined based on the current transaction start number, the row effective transaction number, and the row termination transaction number.

9. An electronic device, characterized in that, include: Processor and memory; The memory is used to store computer operation instructions; The processor is configured to execute the method of any one of claims 1-7 by invoking the computer operation instructions.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer program instructions for causing the computer to perform the method of any one of claims 1-7.

Citation Information

Patent Citations

  • Efficient methods and systems for consistent read in record-based multi-version concurrency control

    CN106462586A