A method, apparatus, device, and storage medium for processing secondary index records

By adding a rollback record address to the secondary index record, the problem of low visibility judgment of secondary index record is solved, and efficient visibility judgment of directly reading the rollback record address is realized, and database query performance is improved.

CN116340318BActive Publication Date: 2025-07-29SHANGHAI DAMENG DATABASE
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310276213.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-17
Publication Date
2025-07-29
Estimated Expiration
2043-03-17

AI Technical Summary

Technical Problem

In relational databases, the lack of rollback record address of secondary index records leads to low visibility judgment efficiency, and it is necessary to traverse clustered index records to obtain rollback record address, affecting query efficiency.

Method used

Add a rollback record address to the secondary index record, and directly read the rollback record address to judge visibility by obtaining the target data, line number, transaction identification and operation type of the current operation.

Benefits of technology

It improves the visibility judgment efficiency of secondary index records, reduces dependence on clustered indexes, and improves data query speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116340318B_ABST
    Figure CN116340318B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, apparatus, device and storage medium for processing secondary index records. The method includes: obtaining target data, a row number, a transaction identifier and an operation type corresponding to a current operation; processing a rollback record address of the secondary index record according to the target data, the row number, the transaction identifier and the operation type corresponding to the current operation. Through the technical solution of the present invention, a rollback record address can be added to the secondary index record, so that when it is necessary to traverse the rollback record linked list to find whether there is a visible rollback record, the rollback record address can be directly read from the secondary index record, thereby improving the efficiency of visibility judgment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to the field of computer technologies, and in particular, to a method, apparatus, device, and storage medium for processing secondary index records. Background Art

[0002] In a relational database, an index is a separate, physical storage structure that sorts the values of one or more columns in a data table. Using an index can effectively improve the data query efficiency. There are multiple types of indexes. Each table in the database has exactly one clustered index, and other indexes except the clustered index are called secondary indexes. Each table in the database can have multiple secondary indexes.

[0003] As Figure 1 shown, each time data on the table is updated, the latest data is synchronously updated to the clustered index record corresponding to this data, and at the same time, a rollback record is generated to save the data before the update. Among them, the ROWID field is the row number corresponding to the updated data in the table, the TID field represents the transaction number of the data update operation, the RPTR field points to the latest rollback record, and all rollback records corresponding to each clustered index record form a singly linked list.

[0004] To improve the query efficiency of specific columns on the table, a secondary index can be created for specific columns. As Figure 2 shown, the format of the secondary index record is similar to that of the clustered index record, except that it lacks the RPTR field. It should be noted that when updating the clustered index record, the corresponding record on the secondary index needs to be synchronously updated.

[0005] The database supports concurrent execution of multiple transactions. To avoid data errors caused by multiple transactions modifying the same data at the same time, it is necessary to perform visibility judgment on the records. Only when the record is visible to the current transaction can the current transaction continue to execute the corresponding operation. When performing visibility judgment on the clustered index, it can be judged whether the clustered index record is visible to the current transaction according to the TID field on the clustered index record. If it is not visible, the rollback record linked list is traversed according to the RPTR field of the clustered index record to find whether there is a visible rollback record.

[0006] If a transaction involves a secondary index, visibility judgment also needs to be performed on the secondary index. The TID field is also used to judge visibility. When the secondary index record is visible to the current transaction, the current transaction can continue to execute the corresponding operation. Otherwise, the rollback record linked list needs to be traversed to find whether there is a visible rollback record. Since the secondary index record lacks the RPTR field and the rollback record cannot be directly obtained, it is necessary to first retrieve the clustered index to find the corresponding clustered index record, read the RPTR field to obtain the rollback record address, and then further traverse the rollback record linked list. The operation of retrieving the clustered index will greatly reduce the efficiency of the visibility judgment of the secondary index. Summary of the Invention

[0007] An embodiment of the present invention provides a method, apparatus, device, and storage medium for processing secondary index records, which can add a rollback record address to the secondary index record so that when it is necessary to traverse the rollback record linked list to check whether there is a visible rollback record, the rollback record address can be directly read from the secondary index record, thereby improving the efficiency of visibility judgment.

[0008] According to one aspect of the present invention, there is provided a method for processing secondary index records, including:

[0009] Obtaining target data, a row number, a transaction identifier, and an operation type corresponding to the current operation;

[0010] Processing the rollback record address of the secondary index record according to the target data, row number, transaction identifier, and operation type corresponding to the current operation.

[0011] According to another aspect of the present invention, there is provided a secondary index record processing apparatus, which includes:

[0012] An obtaining module, configured to obtain target data, a row number, a transaction identifier, and an operation type corresponding to the current operation;

[0013] A processing module, configured to process the rollback record address of the secondary index record according to the target data, row number, transaction identifier, and operation type corresponding to the current operation.

[0014] According to another aspect of the present invention, there is provided an electronic device, where the electronic device includes:

[0015] At least one processor; and

[0016] A memory communicatively connected to the at least one processor; wherein,

[0017] The memory stores a computer program executable by the at least one processor, and when the computer program is executed by the at least one processor, the at least one processor can execute the secondary index record processing method according to any embodiment of the present invention.

[0018] According to another aspect of the present invention, there is provided a computer-readable storage medium, where the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the secondary index record processing method according to any embodiment of the present invention when executed.

[0019] In an embodiment of the present invention, by obtaining target data, a line number, a transaction identifier, and an operation type corresponding to a current operation, and processing the rollback record address of a secondary index record according to the target data, the line number, the transaction identifier, and the operation type corresponding to the current operation, it is possible to add a rollback record address to the secondary index record, so that when it is necessary to traverse the rollback record linked list to check whether there is a visible rollback record, the rollback record address can be directly read from the secondary index record, thereby improving the efficiency of visibility judgment.

[0020] It should be understood that the content described in this part is not intended to identify the key or important features of the embodiments of the present invention, nor is it used to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] To more clearly illustrate the technical solutions of the embodiments of the present invention, the following will briefly introduce the drawings required for use in the embodiments. It should be understood that the following drawings only show some embodiments of the present invention, and thus should not be regarded as limiting the scope. For those of ordinary skill in the art, without creative efforts, other relevant drawings can also be obtained based on these drawings.

[0022] Figure 1 is a schematic diagram of a clustered index record and a rollback record in the prior art;

[0023] Figure 2 is a schematic diagram of a secondary index record in the prior art;

[0024] Figure 3 is a flowchart of a method for processing a secondary index record in an embodiment of the present invention;

[0025] Figure 4 is a schematic diagram of modifying an index record when performing a data operation in the prior art;

[0026] Figure 5 is a schematic diagram of modifying an index record when performing a data operation in the prior art;

[0027] Figure 6 is a schematic diagram of modifying an index record when performing a data operation in the prior art;

[0028] Figure 7 is a schematic diagram of a secondary index record in an embodiment of the present invention;

[0029] Figure 8 is a schematic structural diagram of a device for processing a secondary index record in an embodiment of the present invention;

[0030] Figure 9It is a schematic structural diagram of an electronic device in an embodiment of the present invention. Detailed implementation manners

[0031] In order to enable those skilled in the art to better understand the solution of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

[0032] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily need to be used to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device including a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.

[0033] It can be understood that before using the technical solutions disclosed in the embodiments of the present disclosure, the types, usage scopes, usage scenarios, etc. of the personal information involved in the present disclosure should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations.

[0034] Embodiment 1

[0035] Figure 3 It is a flowchart of a method for processing secondary index records provided in an embodiment of the present invention. This embodiment is applicable to the situation of processing secondary index records. This method can be executed by a secondary index record processing device in an embodiment of the present invention. The device can be implemented in a software and / or hardware manner, such as Figure 3 As shown, the method specifically includes the following steps:

[0036] S110, obtain target data, line number, transaction identifier, and operation type corresponding to the current operation.

[0037] Wherein, the operation type can be any one of a data insertion operation, a data update operation, a data deletion operation, an undo data insertion operation, an undo data update operation, and an undo data deletion operation.

[0038] Among them, the target data corresponding to the current operation may be at least one of data to be inserted, data before update, data after update, data to be deleted, inserted data, and deleted data. It should be noted that if the current operation is a data insertion operation, the target data may be the data to be inserted; if the current operation is a data update operation, the target data may be the data before update and the data after update; if the current operation is a data deletion operation, the target data may be the data to be deleted; if the current operation is to revoke a data insertion operation, the target data may be the inserted data; if the current operation is to revoke a data update operation, the target data may be the data before update and the data after update; if the current operation is to revoke a data deletion operation, the target data may be the deleted data.

[0039] Among them, the transaction identifier may be a transaction number.

[0040] S120. Process the rollback record address of the secondary index record according to the target data, row number, transaction identifier, and operation type corresponding to the current operation.

[0041] Specifically, the method of processing the rollback record address of the secondary index record according to the target data, row number, transaction identifier, and operation type corresponding to the current operation may be: if the current operation is a DML operation, process the rollback record address of the secondary index record according to the processing rules corresponding to the DML operation, the target data, row number, and transaction identifier corresponding to the current operation. For example, if the operation type corresponding to the current operation is an insertion operation, insert a first secondary index record according to the target data, row number, and transaction identifier corresponding to the current operation, and set the rollback record address of the first secondary index record to be empty; if the operation type corresponding to the current operation is an update operation, and it is determined according to the target data, row number, and transaction identifier corresponding to the current operation that the current operation involves changing the key value of the secondary index record corresponding to the data to be updated, add a deletion mark to the secondary index record corresponding to the data to be updated, set the rollback record address of the secondary index record corresponding to the data to be updated to the target address, and insert a second secondary index record, where the target address is the address of the rollback record corresponding to the current operation; if the operation type corresponding to the current operation is a deletion operation, determine the secondary index record corresponding to the data to be deleted according to the target data, row number, and transaction identifier corresponding to the current operation, add a deletion mark to the secondary index record corresponding to the data to be deleted, and set the rollback record address of the secondary index record corresponding to the data to be deleted to the target address.

[0042] If the current operation is a rollback operation, the rollback record address of the secondary index record is processed according to the processing rules corresponding to the rollback operation, the target data corresponding to the current operation, the line number, and the transaction identifier. For example, if the operation type corresponding to the current operation is to revoke a data insertion operation, the newly inserted secondary index record is determined according to the target data, line number, and transaction identifier corresponding to the current operation, and the newly inserted secondary index record is deleted; if the operation type corresponding to the current operation is to revoke a data update operation, and it is determined according to the target data, line number, and transaction identifier corresponding to the current operation that the index column of the secondary index record is not updated, the rollback record address of the secondary index record with the unupdated index column is set to the rollback record address of the clustered index; if the operation type corresponding to the current operation is to revoke a data update operation, and it is determined according to the target data, line number, and transaction identifier corresponding to the current operation that the index column of the secondary index record is updated, the secondary index record with the updated index column is deleted, the deletion mark of the fourth secondary index record with the deletion mark added is cancelled, and the rollback record address of the fourth secondary index record is set to the rollback record address of the clustered index; if the operation type corresponding to the current operation is to revoke a data deletion operation, the secondary index record corresponding to the data to be deleted is determined according to the target data, line number, and transaction identifier corresponding to the current operation, the deletion mark of the secondary index record corresponding to the data to be deleted is cancelled, and the rollback record address of the secondary index record corresponding to the data to be deleted is updated to the rollback record address of the clustered index record corresponding to the data to be deleted.

[0043] It should be noted that when performing a DML operation, a rollback record is generated first, then the clustered index record is updated, and the RPTR field of the rollback record address is set to point to the latest rollback record. When the DML operation involves a secondary index, the secondary index record needs to be updated synchronously. This embodiment of the present invention will focus on introducing how to update the content of the RPTR field of the secondary index record when updating the secondary index record. The update strategy of other field contents is the same as the pre-optimization strategy, and this embodiment of the present invention will not introduce it in detail. Transaction rollback means revoking all operations performed by the current transaction. When rolling back a transaction, the clustered index is first modified according to the newly generated rollback record when performing the transaction operation, then the newly generated rollback record is cleared, and then if the current transaction involves a secondary index, the secondary index also needs to be modified synchronously.

[0044] For easy understanding, the following uses a simple example to show the modifications made to the corresponding index records when performing data operations in the prior art.

[0045] Execute the following two statements:

[0046] CREATE TABLE test(a int);

[0047] CREATE INDEX idx_test ON test(a);

[0048] Create table test, and create a secondary index idx_test on column a of table test. Take the DML operations (inserting, deleting, or modifying data in the table) performed on this table as an example to demonstrate the changes of clustered index records and secondary index records. (The system will automatically create a clustered index for this table when creating table test).

[0049] As Figure 4 shown, start a transaction with TID = 100, insert a row of data into table test, and the data value is 1. At this time, a record is inserted into both the clustered index and the secondary index, and the data value in the record is 1. This transaction then updates the row data in table test, changing the data value from 1 to 2. At this time, the latest data value 2 is saved in the clustered index record, and a rollback record is generated. The data value 1 before the update is saved in the rollback record, and the RPTR field of the clustered index record points to the newly generated rollback record; for the secondary index, a new record will be inserted, and the data value in this record is 2. The old record with the data value of 1 will be set with a delete mark to indicate that the record has been deleted.

[0050] As Figure 5 shown, start a transaction with TID = 200, and further update the data in table test, changing the data value from 2 to 3. At this time, the latest data value 3 is saved in the clustered index record, and a rollback record is generated. The data value 2 before the update is saved in the rollback record, and the RPTR field of the clustered index record points to the newly generated rollback record; for the secondary index, a new record will be inserted, and the data value in this record is 3. The old record with the data value of 2 will be set with a delete mark to indicate that the record has been deleted. This transaction then executes the ROLLBACK statement (i.e., the transaction rollback statement, indicating to revoke the data update operation). At this time, the index state returns to the state before the update.

[0051] As Figure 6 shown, start a transaction with TID = 300, and update the data in table test again, changing the data value from 2 to 1. At this time, the latest data value 1 is saved in the clustered index record, and a rollback record is generated. The data value 2 before the update is saved in the rollback record, and the RPTR field of the clustered index record points to the newly generated rollback record; for the secondary index, since there is already a record with the data value of 1, no new record will be inserted, the delete mark of the record with the data value of 1 will be cancelled, and the delete mark will be set for the record with the data value of 2.

[0052] Optionally, process the rollback record address of the secondary index record according to the target data, row number, transaction identifier, and operation type corresponding to the current operation, including:

[0053] If the operation type corresponding to the current operation is an insert operation, insert the first and second level index records according to the target data, row number, and transaction identifier corresponding to the current operation, and set the rollback record address of the first and second level index records to be empty;

[0054] If the operation type corresponding to the current operation is an update operation, and it is determined according to the target data, row number, and transaction identifier corresponding to the current operation that the current operation involves a change to the key value of the second level index record corresponding to the data to be updated, then add a deletion mark to the second level index record corresponding to the data to be updated, set the rollback record address of the second level index record corresponding to the data to be updated to the target address, and insert the second second level index record, where the target address is the address of the rollback record corresponding to the current operation;

[0055] If the operation type corresponding to the current operation is a delete operation, determine the second level index record corresponding to the data to be deleted according to the target data, row number, and transaction identifier corresponding to the current operation, add a deletion mark to the second level index record corresponding to the data to be deleted, and set the rollback record address of the second level index record corresponding to the data to be deleted to the target address.

[0056] Among them, the first and second level index records are newly generated second level index records according to the current operation.

[0057] Among them, the key value of the index record can be determined according to the target data and the ROWID field of the row number in the index record, and the key value can uniquely identify each record in the index.

[0058] Among them, the target address is the address of the rollback record corresponding to the current operation, that is, the address of the newly generated rollback record.

[0059] Specifically, the method for determining whether the current operation involves a change to the key value of the second level index record corresponding to the data to be updated can be: obtain the key value of the second level index record corresponding to the data to be updated, obtain the target data and row number corresponding to the current operation, determine the key value corresponding to the current operation according to the target data and row number corresponding to the current operation. If the key value corresponding to the current operation is the same as the key value of the second level index record corresponding to the data to be updated, it is determined that the current operation does not involve a change to the key value of the second level index record corresponding to the data to be updated. If the key value corresponding to the current operation is different from the key value of the second level index record corresponding to the data to be updated, it is determined that the current operation involves a change to the key value of the second level index record corresponding to the data to be updated.

[0060] It should be noted that if the operation type corresponding to the current operation is an update operation, and it is determined according to the target data, row number, and transaction identifier corresponding to the current operation that the current operation does not involve a change to the key value of the second level index record corresponding to the data to be updated, then there is no need to modify the RPTR field of the second level index record corresponding to the data to be updated.

[0061] Optionally, insert a second secondary index record, including:

[0062] Determine the key value of the secondary index record to be inserted according to the target data and line number corresponding to the current operation;

[0063] If there is a third secondary index record with the same key value as the secondary index record to be inserted among the secondary index records with deletion marks, cancel the deletion mark of the third secondary index record, and set the rollback record address of the third secondary index record to the target address to obtain the second secondary index record;

[0064] If the key values of the secondary index records with deletion marks are all different from the key value of the secondary index record to be inserted, insert the second secondary index record according to the target data, line number, and transaction identifier corresponding to the current operation, and set the rollback record address of the second secondary index record to null.

[0065] It should be noted that find all existing secondary index records with deletion marks currently. If there is a secondary index record with the same key value as the secondary index record to be inserted, determine the secondary index record with the deletion mark and the same key value as the secondary index record to be inserted as the third secondary index record, cancel the deletion mark of the third secondary index record, and set the rollback record address of the third secondary index record to the address of the newly generated rollback record, and no new secondary index record is inserted.

[0066] If the key values of the secondary index records with deletion marks are all different from the key value of the secondary index record to be inserted, directly insert a new secondary index record, and set the RPTR field of the new secondary index record to null.

[0067] In a specific example, when performing data insertion operations, data update operations, and data deletion operations, the processing of the RPTR field of the secondary index record is as follows:

[0068] When performing a data insertion operation, the processing of the RPTR field of the secondary index record is as follows:

[0069] Directly insert a new secondary index record, and set the RPTR field of the new secondary index record to null.

[0070] When performing a data update operation, the processing of the RPTR field of the secondary index record is as follows:

[0071] Retrieve the secondary index, find the secondary index record corresponding to the data to be updated, and determine whether the data update operation involves a change in the key value of this secondary index record. If there is no key value change, there is no need to modify the RPTR field of this secondary index record; if there is a key value change, delete this secondary index record and insert a new secondary index record at the same time.

[0072] The above-mentioned deletion of this secondary index record: Set a deletion mark for this secondary index record, and set the RPTR field of this secondary index record to the address of the newly generated rollback record.

[0073] The above-mentioned insertion of a new secondary index record: First, search for all existing secondary index records with deletion marks. If there is a secondary index record among them whose key value is the same as the key value of the currently to-be-inserted secondary index record, cancel the deletion mark of this secondary index record, set its RPTR field to the address of the newly generated rollback record, and no longer insert a new secondary index record; otherwise, directly insert a new secondary index record and set the RPTR field of the new secondary index record to be empty.

[0074] When performing a data deletion operation, the processing for the RPTR field of the secondary index record is as follows:

[0075] Retrieve the secondary index, find the secondary index record corresponding to the data to be deleted, set a deletion mark for this secondary index record, and set the RPTR field of this secondary index record to the address of the newly generated rollback record.

[0076] Optionally, it also includes:

[0077] If the operation type corresponding to the current operation is to revoke a data insertion operation, determine the newly inserted secondary index record based on the target data, row number, and transaction identifier corresponding to the current operation, and delete the newly inserted secondary index record;

[0078] If the operation type corresponding to the current operation is to revoke a data update operation, and it is determined according to the target data, row number, and transaction identifier corresponding to the current operation that the index column of the secondary index record is not updated, then set the rollback record address of the secondary index record with the unupdated index column to the rollback record address of the clustered index;

[0079] If the operation type corresponding to the current operation is to revoke a data update operation, and it is determined according to the target data, row number, and transaction identifier corresponding to the current operation that the index column of the secondary index record is updated, then delete the secondary index record with the updated index column, cancel the deletion mark of the fourth secondary index record with the deletion mark added, and set the rollback record address of the fourth secondary index record to the rollback record address of the clustered index;

[0080] If the operation type corresponding to the current operation is to undo a data deletion operation, determine the secondary index record corresponding to the data to be deleted according to the target data, row number, and transaction identifier corresponding to the current operation, cancel the deletion mark of the secondary index record corresponding to the data to be deleted, and update the rollback record address of the secondary index record corresponding to the data to be deleted to the rollback record address of the clustered index record corresponding to the data to be deleted.

[0081] Specifically, the way to set the rollback record address of the secondary index record with the index column not updated to the rollback record address of the clustered index can be: reset the RPTR field of the secondary index record with the index column not updated, so that the RPTR field of the secondary index record with the index column not updated points to the next rollback record.

[0082] Among them, the fourth secondary index record is the old secondary index record. For example, when an update operation is executed, a deletion mark is set on the old secondary index record and a new secondary index record is inserted. Then, when the undo data update operation is executed, the newly inserted secondary index record needs to be deleted, and at the same time, the deletion mark on the old secondary index record is reset.

[0083] It should be noted that if the index column of the secondary index record is updated, it means that the update operation involves the secondary index record. If the index column of the secondary index record is not updated, it means that the update operation does not involve the secondary index record.

[0084] It should be noted that when the rollback operation is executed, the clustered index RPTR will be updated to point to the next rollback record, and the current rollback record will be deleted after the rollback is completed.

[0085] Optionally, deleting the secondary index record with the index column updated includes:

[0086] If there is a first rollback record in the rollback record linked list with the same key value as the secondary index record with the index column updated, add a deletion mark to the secondary index record with the index column updated, and set the rollback record address of the secondary index record with the index column updated to the address corresponding to the first rollback record;

[0087] If the key values of the rollback records in the rollback record linked list are all different from the key value of the secondary index record with the index column updated, delete the secondary index record with the index column updated.

[0088] It should be noted that when deleting a secondary index record updated by deleting an index column, first check whether there is an older rollback record that matches the secondary index record updated by the index column: traverse the rollback record linked list in sequence, and determine whether the old record on the rollback record is equal to the key value of the secondary index record. If they are equal, it is considered a match. If there is no matching rollback record, directly delete the secondary index record; otherwise, set a deletion mark on the secondary index record and set the RPTR field to point to the matching rollback record.

[0089] In a specific example, the processing for the secondary index when undoing data insertion, data update, and data deletion operations will be introduced separately below. Only the processing for the RPTR field of the secondary index record is introduced, and the modification strategy for other field contents remains the same as the pre-optimization strategy. The embodiments of the present invention do not introduce this in detail.

[0090] 1. When undoing a data insertion operation, directly delete the newly inserted secondary index record (this is a real deletion here, not setting a deletion mark).

[0091] 2. When undoing a data update operation, the processing for the secondary index is as follows:

[0092] 1) If the update operation does not involve the secondary index record, only need to reset the RPTR field to point to the next rollback record (consistent with the RPTR field of the clustered index).

[0093] 2) If the update operation involves the secondary index record (when the update operation is executed, a deletion mark is set on the old secondary index record and a new secondary index record is inserted), then it is necessary to delete the newly inserted secondary index record and at the same time reset the deletion mark on the old secondary index record.

[0094] When deleting the newly inserted secondary index record, first check whether there is an older rollback record that matches the secondary index record: traverse the rollback record linked list in sequence, and determine whether the old record on the rollback record is equal to the key value of the secondary index record. If they are equal, it is considered a match. If there is no matching rollback record, directly delete the secondary index record; otherwise, set a deletion mark on the secondary index record and set the RPTR field to point to the matching rollback record.

[0095] When resetting the deletion mark of the old secondary index record, at the same time set the RPTR field to point to the next rollback record (consistent with the clustered index).

[0096] 3. When canceling a data deletion operation, cancel the deletion mark of the secondary index record corresponding to the data to be deleted, record the RPTR field of this secondary index record as RPTR_1, then obtain the RPTR field of the clustered index record corresponding to the data to be deleted, record it as RPTR_2, and then modify RPTR_1 to RPTR_2.

[0097] Optionally, after processing the rollback record address of the secondary index record according to the target data, line number, transaction identifier, and operation type corresponding to the current operation, it further includes:

[0098] When a transaction executes a data operation, obtain the target secondary index record corresponding to the data operation;

[0099] If the target secondary index record is invisible to the current transaction, obtain the target rollback record address of the target secondary index record;

[0100] If it is determined that there is a rollback record visible to the current transaction according to the target rollback record address, allow the current transaction to continue to execute the corresponding operation.

[0101] Among them, the target secondary index record includes: a rollback record address field.

[0102] In a specific example, the storage format of the reformed secondary index record is as Figure 7 shown. The secondary index record provided by the embodiment of the present invention adds an RPTR field to point to the latest rollback record. When it is necessary to access the rollback record to judge visibility, the rollback record address can be directly obtained by reading this field.

[0103] Optionally, if it is determined that there is a rollback record visible to the current transaction according to the target rollback record address, allowing the current transaction to continue to execute the corresponding operation includes:

[0104] Load the target rollback record according to the target rollback record address;

[0105] If the transaction identifier of the target rollback record meets the preset conditions, and the key value of the target rollback record is the same as the key value of the target secondary index record, it is determined that the target rollback record is visible to the current transaction, and the current transaction is allowed to continue to execute the corresponding operation.

[0106] Among them, the way to allow the current transaction to continue to execute the corresponding operation can be: allowing the current transaction to continue to execute the operation corresponding to the current transaction.

[0107] Among them, the preset condition is a condition preset for judging whether a record is visible to the current transaction.

[0108] It should be noted that if the transaction identifier of the target rollback record meets the preset conditions and the key value of the target rollback record is different from the key value of the target secondary index record, it is determined that the target rollback record is invisible to the current transaction. If the transaction identifier of the target rollback record does not meet the preset conditions, it is determined that the target rollback record is invisible to the current transaction.

[0109] In a specific example, when performing a data operation, if a secondary index is involved, it is necessary to first find the secondary index record corresponding to the current operation and perform a visibility judgment on the current secondary index record. If the current secondary index record is visible to the current transaction, the current transaction is allowed to continue to perform the corresponding operation. If the current secondary index record is invisible to the current transaction, the RPTR field of the current secondary index record is read to obtain the rollback record address, and it is judged whether there is a rollback record visible to the current transaction. If there is, the current transaction is allowed to continue to perform the corresponding operation. Otherwise, the current transaction needs to wait for a certain period of time and then perform a visibility judgment again until the current secondary index record is visible to the current transaction or there is a rollback record visible to the current transaction, and then the current transaction can continue to perform the corresponding operation.

[0110] Among them, the process of obtaining the rollback record address according to the RPTR field of the current secondary index record and judging whether there is a rollback record visible to the current transaction is as follows:

[0111] 1. Read the RPTR field of the current secondary index record to obtain the rollback record address, and execute step 2;

[0112] 2. If the rollback record address is empty, it is considered that there is no visible rollback record. Otherwise, execute step 3;

[0113] 3. Load the rollback record according to the rollback record address, read the TID field of the current rollback record and judge the visibility. If the current rollback record is invisible, execute step 4, otherwise execute step 5;

[0114] 4. Read the RPTR field of the current rollback record to obtain the address of the next rollback record, and jump to step 2 to continue execution;

[0115] 5. Judge whether the current rollback record matches the current secondary index record: obtain the key values of the current rollback record and the current secondary index record, and compare whether the two key values are equal. If they are equal, it is considered that the current rollback record is visible and a visible rollback record is found; otherwise, it is considered that the current rollback record is invisible and there is no visible rollback record.

[0116] The technical solution of this embodiment can process the rollback record address of the secondary index record by obtaining the target data, line number, transaction identifier, and operation type corresponding to the current operation, and can add the rollback record address to the secondary index record, so that when it is necessary to traverse the rollback record linked list to check whether there is a visible rollback record, the rollback record address can be directly read from the secondary index record, thereby improving the efficiency of visibility judgment.

[0117] Embodiment 2

[0118] Figure 8 FIG. is a schematic structural diagram of a secondary index record processing device provided by an embodiment of the present invention. This embodiment is applicable to the situation of secondary index record processing. The device can be implemented in software and / or hardware, and can be integrated in any device that provides secondary index record processing functions, such as Figure 8 As shown, the secondary index record processing device specifically includes: an acquisition module 210 and a processing module 220.

[0119] Among them, the acquisition module is used to acquire the target data, line number, transaction identifier, and operation type corresponding to the current operation;

[0120] The processing module is used to process the rollback record address of the secondary index record according to the target data, line number, transaction identifier, and operation type corresponding to the current operation.

[0121] The above product can execute the method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the executed method.

[0122] Embodiment 3

[0123] Figure 9 FIG. shows a schematic structural diagram of an electronic device 10 that can be used to implement an embodiment of the present invention. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are only examples and are not intended to limit the implementation of the present invention described and / or claimed herein.

[0124] Such as Figure 9As shown, the electronic device 10 includes at least one processor 11 and a memory communicatively connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc. The memory stores a computer program executable by the at least one processor. The processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 into the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0125] Multiple components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disc, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.

[0126] The processor 11 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as the secondary index record processing method.

[0127] In some embodiments, the secondary index record processing method can be implemented as a computer program tangibly embodied in a computer-readable storage medium, such as the storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed onto the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the secondary index record processing method described above can be executed. Alternatively, in other embodiments, the processor 11 can be configured to execute the secondary index record processing method by any other appropriate means (e.g., by means of firmware).

[0128] The various embodiments of the systems and techniques described above in this document can be implemented in digital electronic circuitry, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on a chip (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special-purpose or general-purpose programmable processor that receives data and instructions from a storage system, at least one input device, and at least one output device, and transmits the data and instructions to the storage system, the at least one input device, and the at least one output device.

[0129] The computer programs for implementing the methods of the present invention can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus such that the computer programs, when executed by the processor, cause the functions / operations specified in the flowchart and / or block diagram to be implemented. The computer programs can be executed entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine or entirely on the remote machine or server.

[0130] In the context of the present invention, a computer-readable storage medium can be a tangible medium that can contain or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. The computer-readable storage medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, the computer-readable storage medium can be a machine-readable signal medium. More specific examples of the machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0131] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or a trackball) through which the user can provide input to the electronic device. Other kinds of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0132] The systems and techniques described herein can be implemented in a computing system including backend components (e.g., as a data server), or a computing system including middleware components (e.g., an application server), or a computing system including frontend components (e.g., a user computer having a graphical user interface or a web browser through which the user can interact with an implementation of the systems and techniques described herein), or a computing system including any combination of such backend components, middleware components, or frontend components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local area network (LAN), wide area network (WAN), blockchain network, and the Internet.

[0133] A computing system can include a client and a server. The client and the server are generally far from each other and typically interact through a communication network. The client-server relationship is created by computer programs running on respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or a cloud host, which is a host product in the cloud computing service system and solves the defects of difficult management and weak business scalability existing in traditional physical hosts and VPS services.

[0134] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps recited in the present invention can be executed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of the present invention can be achieved, and no limitation is made herein.

[0135] The above specific embodiments do not constitute a limitation on the protection scope of the present invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.

Claims

1. A method for processing secondary index records, characterized in that, Including: Obtain the target data, line number, transaction identifier, and operation type corresponding to the current operation; Process the rollback record address of the secondary index record according to the target data, line number, transaction identifier, and operation type corresponding to the current operation; Processing the rollback record address of the secondary index record according to the target data, line number, transaction identifier, and operation type corresponding to the current operation, including: If the operation type corresponding to the current operation is an insert operation, insert the first secondary index record according to the target data, line number, and transaction identifier corresponding to the current operation, and set the rollback record address of the first secondary index record to be empty; If the operation type corresponding to the current operation is an update operation, and it is determined according to the target data, line number, and transaction identifier corresponding to the current operation that the current operation involves a change to the key value of the secondary index record corresponding to the data to be updated, add a deletion mark to the secondary index record corresponding to the data to be updated, set the rollback record address of the secondary index record corresponding to the data to be updated to the target address, and insert the second secondary index record, where the target address is the address of the rollback record corresponding to the current operation; If the operation type corresponding to the current operation is a delete operation, determine the secondary index record corresponding to the data to be deleted according to the target data, line number, and transaction identifier corresponding to the current operation, add a deletion mark to the secondary index record corresponding to the data to be deleted, and set the rollback record address of the secondary index record corresponding to the data to be deleted to the target address; Inserting the second secondary index record includes: Determine the key value of the secondary index record to be inserted according to the target data and line number corresponding to the current operation; If there is a third secondary index record with the same key value as the secondary index record to be inserted among the secondary index records with deletion marks, cancel the deletion mark of the third secondary index record and set the rollback record address of the third secondary index record to the target address to obtain the second secondary index record; If the key values of the secondary index records with deletion marks are all different from the key value of the secondary index record to be inserted, insert the second secondary index record according to the target data, line number, and transaction identifier corresponding to the current operation, and set the rollback record address of the second secondary index record to be empty.

2. The method according to claim 1, wherein Also including: If the operation type corresponding to the current operation is to revoke the data insert operation, determine the newly inserted secondary index record according to the target data, line number, and transaction identifier corresponding to the current operation, and delete the newly inserted secondary index record; If the operation type corresponding to the current operation is to revoke the data update operation, and it is determined according to the target data, line number, and transaction identifier corresponding to the current operation that the index column of the secondary index record has not been updated, set the rollback record address of the secondary index record with the unupdated index column to the rollback record address of the clustered index; If the operation type corresponding to the current operation is an operation to revoke data update, and it is determined that there is an update to the index column of the secondary index record based on the target data, row number, and transaction identifier corresponding to the current operation, then delete the secondary index record with the index column update, cancel the deletion mark of the fourth secondary index record with the deletion mark added, and set the rollback record address of the fourth secondary index record to the rollback record address of the clustered index; If the operation type corresponding to the current operation is an operation to revoke data deletion, then determine the secondary index record corresponding to the data to be deleted based on the target data, row number, and transaction identifier corresponding to the current operation, cancel the deletion mark of the secondary index record corresponding to the data to be deleted, and update the rollback record address of the secondary index record corresponding to the data to be deleted to the rollback record address of the clustered index record corresponding to the data to be deleted.

3. The method according to claim 2, wherein Deleting the secondary index record with the index column update includes: If there is a first rollback record in the rollback record linked list with the same key value as the secondary index record with the index column update, then add a deletion mark to the secondary index record with the index column update, and set the rollback record address of the secondary index record with the index column update to the address corresponding to the first rollback record; If the key values of the rollback records in the rollback record linked list are all different from the key value of the secondary index record with the index column update, then delete the secondary index record with the index column update.

4. The method according to claim 1, characterized in that, After processing the rollback record address of the secondary index record according to the target data, row number, transaction identifier, and operation type corresponding to the current operation, it further includes: When the transaction executes a data operation, obtain the target secondary index record corresponding to the data operation; If the target secondary index record is not visible to the current transaction, then obtain the target rollback record address of the target secondary index record; If it is determined that there is a rollback record visible to the current transaction based on the target rollback record address, then allow the current transaction to continue to execute the corresponding operation.

5. The method according to claim 4, characterized in that, If it is determined that there is a rollback record visible to the current transaction based on the target rollback record address, then allowing the current transaction to continue to execute the corresponding operation includes: Loading the target rollback record according to the target rollback record address; If the transaction identifier of the target rollback record meets the preset conditions, and the key value of the target rollback record is the same as the key value of the target secondary index record, then determine that the target rollback record is visible to the current transaction, and allow the current transaction to continue to execute the corresponding operation.

6. A secondary index record processing device, characterized in that, It includes: An acquisition module, configured to acquire the target data, row number, transaction identifier, and operation type corresponding to the current operation; A processing module, configured to process the rollback record address of the secondary index record according to the target data, row number, transaction identifier, and operation type corresponding to the current operation; Specifically, the processing module is used for: If the operation type corresponding to the current operation is an insert operation, then insert a first secondary index record according to the target data, row number, and transaction identifier corresponding to the current operation, and set the rollback record address of the first secondary index record to be empty; If the operation type corresponding to the current operation is an update operation, and it is determined, based on the target data, line number, and transaction identifier corresponding to the current operation, that the current operation involves a change to the key value of the secondary index record corresponding to the data to be updated, then add a deletion mark to the secondary index record corresponding to the data to be updated, set the rollback record address of the secondary index record corresponding to the data to be updated to the target address, and insert a second secondary index record, where the target address is the address of the rollback record corresponding to the current operation; If the operation type corresponding to the current operation is a deletion operation, then determine the secondary index record corresponding to the data to be deleted based on the target data, line number, and transaction identifier corresponding to the current operation, add a deletion mark to the secondary index record corresponding to the data to be deleted, and set the rollback record address of the secondary index record corresponding to the data to be deleted to the target address; The processing module is further configured to: Determine the key value of the secondary index record to be inserted based on the target data and line number corresponding to the current operation; If there is a third secondary index record with the same key value as the secondary index record to be inserted among the secondary index records with deletion marks, then cancel the deletion mark of the third secondary index record, set the rollback record address of the third secondary index record to the target address, and obtain a second secondary index record; If the key values of the secondary index records with deletion marks are all different from the key value of the secondary index record to be inserted, then insert a second secondary index record based on the target data, line number, and transaction identifier corresponding to the current operation, and set the rollback record address of the second secondary index record to be empty.

7. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and when the computer program is executed by the at least one processor, the at least one processor is enabled to execute the secondary index record processing method according to any one of claims 1-5.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing a processor to implement the secondary index record processing method according to any one of claims 1-5 when executed.

Citation Information

Patent Citations

  • Structured data deduplication method and device based on MapDB, equipment and medium

    CN111651438A

  • Transaction execution method and device, computing equipment and storage medium

    CN115113989A