Database, data query method and device, electronic equipment and storage medium

By adopting a multi-level index structure in the database, including table hopping and Merkel B-tree, quickly locate and verify log records that meet the conditions, the problem of inefficient log-type replica data query is solved, and efficient and accurate data query is achieved.

CN119576983APending Publication Date: 2025-03-07BEIJING OCEANBASE TECHNOLOGY CO LTD

Patent Information

Application Number
CN202510130798.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-05
Publication Date
2025-03-07

AI Technical Summary

Technical Problem

In the prior art, the data query efficiency of log-type replicas is low, and it is difficult to meet the needs of high availability and efficient query.

Method used

A database is designed to store log records using multiple data blocks, and to record the data range (such as table hops) in each data block using primary index information (such as table hops) and secondary index information (such as Merkel B-tree) to record the storage location of log records, so as to achieve rapid positioning and verification of log records that meet query conditions.

Benefits of technology

Through this database, the data query efficiency of log-type replicas can be significantly improved, and the log records that meet the conditions can be quickly positioned and verified, improving the accuracy and efficiency of data query.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119576983A_ABST
    Figure CN119576983A_ABST
Patent Text Reader

Abstract

The invention provides a database, a data query method and device, electronic equipment and a storage medium. The database comprises a plurality of data blocks; a plurality of log records, primary index information and secondary index information are stored in the data block; the first-level index information is used for recording the first-level index information including the data range of each data block in at least one data block of the data block where the first-level index information is located, and the data range comprises the range of data corresponding to all log records in the data block; the secondary index information is used for recording the storage position of each log record in the data block.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] One or more embodiments of the present specification relate to the field of database technology, and in particular, to a database, a data query method and device, an electronic device, and a storage medium. Background Art

[0002] In order to ensure data security and provide high-availability data services, current database systems achieve this goal by physically storing multiple copies of each partitioned data. Replicas are of various types, such as universal replicas, log replicas, encrypted voting replicas, and read-only replicas, to meet the needs of different businesses. Universal replicas, log replicas, and encrypted voting replicas can be used to build consensus protocol groups, such as the Paxos protocol group, while read-only replicas cannot be used to build consensus protocol groups.

[0003] The query methods in the related art are often aimed at replicas for storing data, while the efficiency of data query methods for log-type replicas needs to be improved. Summary of the invention

[0004] In view of this, one or more embodiments of the present specification provide a database, a data query method and device, an electronic device, and a storage medium.

[0005] To achieve the above objectives, one or more embodiments of this specification provide the following technical solutions: According to a first aspect of one or more embodiments of this specification, a database is provided, the database comprising a plurality of data blocks; The data block stores multiple log records, primary index information and secondary index information; The primary index information is used to record: primary index information of a data range of each data block in at least one data block of the data block, wherein the data range includes a range of data targeted by all log records in the data block; The secondary index information is used to record: the storage location of each log record in the data block.

[0006] In one or more embodiments of this specification, the primary index information includes a skip list; For the first data block in the database, the skip list in the data block has a node, and the node is used to record the data range of the data block; For the i-th data block among the first N-1 data blocks in the database, the first i nodes of the skip list in the data block are used to record the data range of the first i data blocks in a one-to-one correspondence, and the other nodes are used to form a multi-level skip list based on the data range recorded in the first i nodes, and the last node is used to record the union of the data ranges recorded in the first i nodes, wherein i is an integer greater than 1 and not greater than N-1, and N is an integer greater than 2; For other data blocks except the first N-1 data blocks in the data block, the first N nodes of the skip list in the data block are used to record the data range of N consecutive data blocks with the database block as the last data block in a one-to-one correspondence, and the other nodes are used to form a multi-level skip list based on the data range recorded in the first N nodes, and the last node is used to record the union of the data ranges recorded in the first N nodes.

[0007] In one or more embodiments of this specification, the database is used to record log records of data with key values ​​within a preset range; The primary index information includes at least one bitmap, the at least one bitmap corresponds one-to-one to at least one data block including the data block, and each bitmap is used to record the data range of the corresponding data block.

[0008] In one or more embodiments of the present specification, the primary index information includes at least one compressed bitmap.

[0009] In one or more embodiments of the present specification, the secondary index information includes a Merkle B-tree.

[0010] In one or more embodiments of the present specification, the database is used to store log copies in a distributed database.

[0011] According to a second aspect of one or more embodiments of this specification, a data query method is proposed, the method comprising: Receiving a log query condition sent by a client, and determining at least one target data block storing a target log record according to primary index information in at least one data block containing the latest data block in the database, wherein the target log record is a log record that meets the log query condition; The target log record in each target data block is determined according to the secondary index information in the target data block, and all the obtained target log records are sent to the client.

[0012] In one or more embodiments of the present specification, the primary index information is in a skip list form; the step of determining at least one target data block storing a target log record according to the primary index information in at least one data block containing the latest data block in the database includes: If the number of data blocks in the database is not greater than N, determining whether a target data block exists in the database according to the last node of the skip list in the latest data block in the database, where N is an integer greater than 2; If the target data block exists in the database, at least one target data block in the data block is determined according to at least one node including the last node in the jump list.

[0013] In one or more embodiments of the present specification, the primary index information is in a skip list form; the step of determining at least one target data block storing a target log record according to the primary index information in at least one data block containing the latest data block in the database includes: If the number of data blocks in the database is greater than N, the latest data block in the database is used as the first index data block, and at least two index data blocks are determined with N as the step length until an index data block recording the data range of the first data block in the data blocks is obtained, where N is an integer greater than 2; At least one target data block in the data block is determined according to at least one node including the last node in the skip list of each index data block.

[0014] In one or more embodiments of the present specification, the secondary index information includes a Merkle B-tree; determining a target log record in the target data block according to the secondary index information in each target data block, and sending all obtained target log records to the client, includes: For each target data block, determine a target log record in the target data block according to the secondary index information in the target data block, and verify whether the target log record has been tampered with according to the Merkle B-tree in the target data block; If all the obtained target log records have not been tampered with, all the obtained target log records are sent to the client.

[0015] In one or more embodiments of this specification, the method further includes: If there is a tampered target log record among all the obtained target log records, a prompt message is sent to the client.

[0016] According to a third aspect of one or more embodiments of this specification, a data query device is provided, the device comprising: A data block screening module, configured to receive a log query condition sent by a client, and determine at least one target data block storing a target log record according to primary index information in at least one data block containing the latest data block in the database, wherein the target log record is a log record that meets the log query condition; The log query module is used to determine the target log record in each target data block according to the secondary index information in the target data block, and send all the obtained target log records to the client.

[0017] According to a fourth aspect of one or more embodiments of this specification, a computer program product is proposed, comprising a computer program / instruction, which implements the steps of the method described in the first aspect when executed by a processor.

[0018] According to a fifth aspect of one or more embodiments of this specification, an electronic device is provided, including: processor; a memory for storing processor-executable instructions; The processor implements the method as described in the first aspect by running the executable instructions.

[0019] According to a sixth aspect of one or more embodiments of the present specification, a computer-readable storage medium is provided, on which computer instructions are stored, and when the instructions are executed by a processor, the steps of the method described in the first aspect are implemented.

[0020] The technical solutions provided by the embodiments of this specification may have the following beneficial effects: The database provided in the embodiment of this specification includes multiple data blocks, each of which stores multiple log records, primary index information for recording the data range of at least one data block containing the data block, and secondary index information for recording the storage location of each log record in the data block. Therefore, the database can query the data range of multiple data blocks through one data block, so as to determine the data blocks where the log records that meet the data query conditions are located with higher efficiency during data query, and further determine the location of the log records that meet the data query conditions through the secondary index information in these data blocks, thereby improving the data query efficiency of log-type copies. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 It is an architectural diagram of a distributed database provided by an exemplary embodiment.

[0022] Figure 2 It is a schematic diagram of the structure of a database provided by an exemplary embodiment.

[0023] Figure 3 It is a flow chart of a data query method provided by an exemplary embodiment.

[0024] Figure 4 It is a structural schematic diagram of a device provided by an exemplary embodiment.

[0025] Figure 5 It is a block diagram of a data query device provided by an exemplary embodiment. DETAILED DESCRIPTION

[0026] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Instead, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.

[0027] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.

[0028] First, some concepts involved in this specification are explained.

[0029] Log-type replica: A replica used only to store log records.

[0030] Index: A fast access technology that organizes and accesses data in one or more fields of a data table. It provides a mechanism for fast data access through specific fields and uses a strategy of trading space for time, which can greatly increase data retrieval speed.

[0031] Bitmap index: A data structure used to store and manage the location and index of data in a bitmap.

[0032] Merkle B-Tree: A data structure used to efficiently store and retrieve large amounts of data. Unlike traditional B-Trees, it also includes the characteristics of Merkle trees. Merkle B-Trees implement data integrity verification by storing Merkle hash values ​​on each node. This means that there is no need to check the entire tree, only the hash value of the root node can be checked to verify the integrity of the entire tree. This makes it particularly useful in distributed systems because data integrity can be verified quickly and efficiently without transmitting the entire data structure.

[0033] Based on the above technical problem, at least one embodiment of this specification provides a database, which is used to store log records. For example, the database can be used to store Figure 1The log replica in the distributed database shown in FIG. The database can provide a more efficient log query to improve the service quality of the log replica.

[0034] The database includes multiple data blocks; multiple log records, primary index information and secondary index information are stored in the data blocks; the primary index information is used to record: primary index information of the data range of each data block in at least one data block of the data block, wherein the data range includes the range of data targeted by all log records in the data block; the secondary index information is used to record: the storage location of each log record in the data block.

[0035] For example, please refer to the attached Figure 2 , the first-level index information includes a skip list (SkipList); for the first data block in the database, the skip list in the data block has a node, and the node is used to record the data range of the data block; for the i-th data block in the first N-1 data blocks in the database, the first i nodes of the skip list in the data block are used to record the data range of the first i data blocks in a one-to-one correspondence, and the other nodes are used to form a multi-level skip list based on the data range recorded in the first i nodes, and the last node is used to record the union of the data ranges recorded in the first i nodes, where i is an integer greater than 1 and not greater than N-1, and N is an integer greater than 2; for other data blocks in the data block except the first N-1 data blocks, the first N nodes of the skip list in the data block are used to record the data range of consecutive N data blocks with the database block as the last data block in a one-to-one correspondence, and the other nodes are used to form a multi-level skip list based on the data range recorded in the first N nodes, and the last node is used to record the union of the data ranges recorded in the first N nodes.

[0036] For example, the database is used to record log records of data with key values ​​within a preset range; the primary index information includes at least one bitmap, the at least one bitmap corresponds one-to-one to at least one data block including the data block, and each bitmap is used to record the data range of the corresponding data block. That is, each node in the jump table in the above example has a bitmap, and the bitmap is used to record the data range of the data block corresponding to the node. If the data block is used to record log records of data with key values ​​within 1-M, the bitmap contains M bits, where the i-th bit is 1, indicating that the corresponding data block has a log record of data with a key value of i, and the i-th bit is 0, indicating that the corresponding data block does not have a log record of data with a key value of i, and i is an integer not less than 1 and not greater than M.

[0037] Further preferably, the first-level index information includes at least one compressed bitmap. That is, part or all of the bitmaps in the first-level index information are compressed bitmaps. If the data block is used to record log records of data with key values ​​within 1-M, the bitmap contains M / x bits, wherein the i-th bit is 1, indicating that the corresponding data block has log records of data with key values ​​within the range of 1+(i-1) x to ix, wherein the i-th bit is 0, indicating that the corresponding data block does not have log records of data with key values ​​within the range of 1+(i-1)x to ix, and i is an integer not less than 1 and not greater than M / x.

[0038] Attached Figure 2 L1 in the table is the first node of the jump table, which is used to record the data block LogBlock. i The data range of L2 is the second node, which is used to record the previous data block LogBlock of the data block. i-1 The data range is calculated by analogy, and the Nth node is reached. The subsequent nodes are multi-level skip table nodes formed based on the first N nodes.

[0039] The skip table in the data block in this example is constructed as follows: When the database starts to store log records, after the first data block is full, a bitmap recording the data range of the data block is generated and saved in the only node of the skip list. After the skip list is saved in the data block, log records are stored in the second data block. After the second data block is full, a bitmap recording the data range of the data block is generated and saved in a node of the skip list. The nodes recording the data range of the first data block and the nodes recording the data range of the second data block are arranged in reverse order (that is, the nodes recording the data range of the first data block are arranged after the nodes recording the data range of the second data block). An upper node is generated based on the two nodes and The upper node is arranged after the node that records the data range of the first data block; and so on, after each subsequent data block is fully recorded, a bitmap that records the data range of the data block is generated and saved in a node of the skip list, and the nodes that record the data range of each previous data block and the nodes that record the data range of the data block are arranged in reverse order (that is, the node that records the data range of the data block is ranked first, and the node that records the data range of the first data block is ranked last), and at least one upper node is generated based on these nodes and the upper node is arranged in reverse order after the node of the data range of the first data block, until the Nth data block is fully recorded and a skip list is generated. Subsequently, iN+1 to (i+1)N are all generated in the same way as the skip list generated in the first data block to the Nth data block, and i is an integer not less than 1. In other words, the nodes at the lower levels in the skip list are ranked higher, and the nodes at the upper levels are ranked lower; for nodes at the same level, the nodes that record the data range of the later data blocks are ranked higher; the nodes at the lower level are used to record the data range of the corresponding data blocks; except for the nodes at the lower level, other nodes record the data range and node identifier of the corresponding child nodes (lower level nodes).

[0040] This example uses a skip table as the primary index information, so that the data block can record the data range of N data blocks at most, that is, the data range of N consecutive data blocks including itself and the previous multiple adjacent data blocks. Therefore, it is possible to quickly determine whether there are log records that meet the data query conditions in multiple data blocks through one data block, that is, to determine whether there are log records that meet the data query conditions in each data block among all data blocks through a small number of data blocks, thereby improving the efficiency of log query. The specific details of log query will be introduced below and will not be repeated here.

[0041] For example, please refer to the attached Figure 2 The secondary index information includes a Merkle B-tree (txRoot in the figure). The Merkle B-tree can not only record the location of each log record in the database, but also be used to verify whether the queried log record has been tampered with, so that when querying the log record, it can be simultaneously verified whether it has been tampered with, thereby improving the effectiveness of log record query.

[0042] The database provided in the embodiment of this specification includes multiple data blocks, each of which stores multiple log records, primary index information for recording the data range of at least one data block containing the data block, and secondary index information for recording the storage location of each log record in the data block. Therefore, the database can query the data range of multiple data blocks through one data block, so as to determine the data blocks where the log records that meet the data query conditions are located with higher efficiency during data query, and further determine the location of the log records that meet the data query conditions through the secondary index information in these data blocks, thereby improving the data query efficiency of log-type copies.

[0043] At least one embodiment of the present specification provides a data query method, which can be applied to the database described in the above embodiment, or other databases in related technologies, and can improve the data query efficiency and accuracy of log-type replicas.

[0044] Please refer to the attached Figure 3 , which exemplarily shows the process of the method, including step S301 to step S302.

[0045] In step S301, a log query condition sent by a client is received, and at least one target data block storing a target log record is determined based on primary index information in at least one data block containing the latest data block in the database, wherein the target log record is a log record that meets the log query condition.

[0046] The log query condition may indicate a specific data key value or a key value range.

[0047] Exemplarily, the primary index information is in the form of a skip table, that is, for the first data block in the database, the skip table in the data block has a node, and the node is used to record the data range of the data block; for the i-th data block among the first N-1 data blocks in the database, the first i nodes of the skip table in the data block are used to record the data range of the first i data blocks in a one-to-one correspondence, and the other nodes are used to form a multi-level skip table based on the data range recorded in the first i nodes, and the last node is used to record the union of the data ranges recorded in the first i nodes, wherein i is an integer greater than 1 and not greater than N-1, and N is an integer greater than 2; for other data blocks in the data block except the first N-1 data blocks, the first N nodes of the skip table in the data block are used to record the data range of consecutive N data blocks with the database block as the last data block in a one-to-one correspondence, and the other nodes are used to form a multi-level skip table based on the data range recorded in the first N nodes, and the last node is used to record the union of the data ranges recorded in the first N nodes.

[0048] Based on this example, this step can be performed as follows: First, if the number of data blocks in the database is not greater than N, it is determined whether a target data block exists in the database according to the last node of the skip list in the latest data block in the database.

[0049] Since the last node of the skip list in the data block is used to record the data range of N consecutive data blocks with the data block where it is located as the last data block, when the number of data blocks in the database is not greater than N, it can be determined that the last node of the skip list in the latest data block records the data range of all data blocks in the database. Therefore, this example uses the last node of the skip list in the latest data block to determine whether there is a target data block in the data block.

[0050] Next, if the target data block exists in the database, at least one target data block in the data block is determined according to at least one node including the last node in the jump list.

[0051] For example, the nodes at the bottom of the skip list are ranked higher, and the nodes at the top of the skip list are ranked lower; the nodes at the same level, the nodes that record the data range of the later data blocks are ranked higher; the nodes at the bottom level are used to record the data range of the corresponding data blocks; except for the nodes at the bottom level, other nodes record the data range and node identifier of the corresponding child nodes (lower level nodes). Then, starting from the last node (i.e. the top node) in the skip list, the nodes whose data ranges meet the data query conditions can be read layer by layer, and finally the bottom node can be located to determine at least one target data block. For example, the jump table in the fourth data block has 7 nodes, the first 4 nodes record the data ranges of the first 4 data blocks respectively, the 5th node is used to record the data ranges and node identifiers of the 1st and 2nd nodes, the 6th node is used to record the data ranges and node identifiers of the 3rd and 4th nodes, and the 7th node is used to record the data ranges and node identifiers of the 5th and 6th nodes; then it can be determined based on the 7th node whether the data range of the 5th node meets the data query condition, and whether the data range of the 6th node meets the data query condition. If the data range of the 5th node meets the data query condition, it is further determined based on the 5th node whether the data block corresponding to the 1st node is the target data block, and whether the data block corresponding to the 2nd node is the target data block.

[0052] Based on this example, this step can be performed as follows: First, if the number of data blocks in the database is greater than N, the latest data block in the database is used as the first index data block, and at least two index data blocks are determined with N as the step length until an index data block recording the data range of the first data block in the data blocks is obtained.

[0053] Since the last node of the skip list in the data block is used to record the data range of N consecutive data blocks with the data block in which it is located as the last data block, when the number of data blocks in the database is greater than N, it can be determined that the last node of the skip list in the latest data block (the jth data block) records the data range of the j-N+1th to jth data blocks in the database, and the last node of the skip list in the jNth data block records the data range of the j-2N+1th to jNth data blocks in the database, and so on, until the last node of the skip list in the j-pNth data block records the data range of the 1st to j-pNth data blocks in the database, where p is an integer greater than 1. Therefore, this example uses the last node of the skip list in the latest data block as the first index data block, and determines at least two index data blocks with N as the step size, until an index data block recording the data range of the first data block in the data block is obtained.

[0054] Next, at least one target data block in the data block is determined according to at least one node including the last node in the skip list of each index data block.

[0055] For example, the nodes at the bottom of the skip list are ranked higher, and the nodes at the top of the skip list are ranked lower; the nodes at the same level, the nodes that record the data range of the later data blocks are ranked higher; the nodes at the bottom level are used to record the data range of the corresponding data blocks; except for the nodes at the bottom level, other nodes record the data range and node identifier of the corresponding child nodes (lower level nodes). The following operations can be performed in each index data block: starting from the last node (i.e. the top node) in the skip list, read the nodes whose data range meets the data query conditions layer by layer, and finally locate the bottom node to determine at least one target data block. If N is 4, the skip list in the index data block has 7 nodes, the first 4 nodes respectively record the data range of themselves and the 3 adjacent data blocks before them, the 5th node is used to record the data range and node identifier of the 1st and 2nd nodes, the 6th node is used to record the data range and node identifier of the 3rd and 4th nodes, and the 7th node is used to record the data range and node identifier of the 5th and 6th nodes; then it can be determined based on the 7th node whether the data range of the 5th node meets the data query condition, and whether the data range of the 6th node meets the data query condition. If the data range of the 5th node meets the data query condition, it is further determined based on the 5th node whether the data block corresponding to the 1st node is the target data block, and whether the data block corresponding to the 2nd node is the target data block.

[0056] In step S302, target log records in each target data block are determined according to the secondary index information in the target data block, and all obtained target log records are sent to the client.

[0057] Exemplarily, the secondary index information includes a Merkle B-tree. A node of the Merkle B-tree may record a key value k, a pointer p, a height h, a hash value, and the like.

[0058] Based on this example, this step can be performed as follows: First, for each target data block, the target log record in the target data block is determined according to the secondary index information in the target data block, and the target log record is verified according to the Merkle B-tree in the target data block. For example, the node can be read layer by layer based on the key value k and pointer p in the node to determine the location of the target log record. For example, it can be determined based on the hash value in the node whether the target log record has been tampered with.

[0059] Next, if all the obtained target log records have not been tampered with, all the obtained target log records are sent to the client; if there is a tampered target log record among all the obtained target log records, a prompt message is sent to the client.

[0060] The data query method provided in the embodiments of this specification determines the target data block based on the primary index information such as the skip list in a small number of data blocks in the database, and further determines the target log record based on the secondary index information such as the Merkel B-tree in the target data block. This process realizes fast, efficient and accurate log query through two-level indexing.

[0061] Figure 4 is a schematic structural diagram of a device provided by an exemplary embodiment. Figure 4 At the hardware level, the device includes a processor 402, an internal bus 404, a network interface 406, a memory 408, and a non-volatile memory 410, and may also include hardware required for other tasks. One or more embodiments of this specification may be implemented based on software, such as the processor 402 reading the corresponding computer program from the non-volatile memory 410 into the memory 408 and then running it. Of course, in addition to the software implementation, one or more embodiments of this specification do not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.

[0062] Please refer to Figure 5 The data query device can be applied to Figure 4 The data query device may include: The data block screening module 501 is used to receive the log query condition sent by the client, and determine at least one target data block storing a target log record according to the primary index information in at least one data block containing the latest data block in the database, wherein the target log record is a log record that meets the log query condition; The log query module 502 is used to determine the target log record in each target data block according to the secondary index information in the target data block, and send all the obtained target log records to the client.

[0063] In one or more embodiments of the present specification, the primary index information is in the form of a skip list; the data block screening module is used to: If the number of data blocks in the database is not greater than N, determining whether a target data block exists in the database according to the last node of the skip list in the latest data block in the database; If the target data block exists in the database, at least one target data block in the data block is determined according to at least one node including the last node in the jump list.

[0064] In one or more embodiments of the present specification, the primary index information is in the form of a skip list; the data block screening module is used to: If the number of data blocks in the database is greater than N, the latest data block in the database is used as the first index data block, and at least two index data blocks are determined with N as the step length, until an index data block recording the data range of the first data block in the data blocks is obtained; At least one target data block in the data block is determined according to at least one node including the last node in the skip list of each index data block.

[0065] In one or more embodiments of the present specification, the secondary index information includes a Merkle B-tree; and the log query module is used to: For each target data block, determine a target log record in the target data block according to the secondary index information in the target data block, and verify whether the target log record has been tampered with according to the Merkle B-tree in the target data block; If all the obtained target log records have not been tampered with, all the obtained target log records are sent to the client.

[0066] In one or more embodiments of the present specification, the device further includes a prompt module, which is used to: If there is a tampered target log record among all the obtained target log records, a prompt message is sent to the client.

[0067] One or more embodiments of the present specification also propose a computer program product, including a computer program / instruction, which implements the steps of the method provided in the second aspect when executed by a processor.

[0068] One or more embodiments of the present specification also propose a computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of the method described in the second aspect.

[0069] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.

[0070] In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0071] Memory may include non-permanent storage in a computer-readable medium, in the form of random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.

[0072] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.

[0073] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0074] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0075] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0076] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this manual are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0077] It should be understood that although the terms first, second, third, etc. may be used to describe various information in one or more embodiments of this specification, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".

[0078] The above description is merely a preferred embodiment of one or more embodiments of the present specification and is not intended to limit one or more embodiments of the present specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present specification shall be included in the scope of protection of one or more embodiments of the present specification.

Claims

1. A database, comprising a plurality of data blocks; The data block stores multiple log records, primary index information and secondary index information; The primary index information is used to record: primary index information of the data range of each data block in at least one data block of the data block, wherein: The data range includes the range of data targeted by all log records in the data block; The secondary index information is used to record: the storage location of each log record in the data block.

2. The database according to claim 1, wherein the primary index information comprises a skip list; For the first data block in the database, the skip list in the data block has a node, and the node is used to record the data range of the data block; For the i-th data block in the first N-1 data blocks in the database, the first i nodes of the skip list in the data block are used to record the data range of the first i data blocks in a one-to-one correspondence, and the other nodes are used to form a multi-level skip list based on the data range recorded in the first i nodes, and the last node is used to record the union of the data ranges recorded in the first i nodes, wherein, i is an integer greater than 1 and not greater than N-1, and N is an integer greater than 2; For other data blocks except the first N-1 data blocks in the data block, the first N nodes of the skip list in the data block are used to record the data range of N consecutive data blocks with the database block as the last data block in a one-to-one correspondence, and the other nodes are used to form a multi-level skip list based on the data range recorded in the first N nodes, and the last node is used to record the union of the data ranges recorded in the first N nodes.

3. The database according to claim 2, wherein the database is used to record log records of data with key values ​​within a preset range; The primary index information includes at least one bitmap, the at least one bitmap corresponds one-to-one to at least one data block including the data block, and each bitmap is used to record the data range of the corresponding data block. The database according to claim 3 , wherein the primary index information comprises at least one compressed bitmap. The database according to claim 1 , wherein the secondary index information comprises a Merkle B-tree.

6. The database according to any one of claims 1 to 5, wherein the database is used to store log copies in a distributed database.

7. A data query method, the method comprising: Receiving a log query condition sent by a client, and determining at least one target data block storing a target log record according to primary index information in at least one data block containing the latest data block in the database, wherein the target log record is a log record that meets the log query condition; The target log record in each target data block is determined according to the secondary index information in the target data block, and all the obtained target log records are sent to the client.

8. The data query method according to claim 7, wherein the primary index information is in the form of a skip list; and determining at least one target data block storing a target log record according to the primary index information in at least one data block containing the latest data block in the database comprises: If the number of data blocks in the database is not greater than N, determining whether a target data block exists in the database according to the last node of the skip list in the latest data block in the database, where N is an integer greater than 2; If the target data block exists in the database, at least one target data block in the data block is determined according to at least one node including the last node in the jump list.

9. The data query method according to claim 7, wherein the primary index information is in the form of a skip list; and determining at least one target data block storing a target log record according to the primary index information in at least one data block containing the latest data block in the database comprises: If the number of data blocks in the database is greater than N, the latest data block in the database is used as the first index data block, and at least two index data blocks are determined with N as the step length until an index data block recording the data range of the first data block in the data blocks is obtained, where N is an integer greater than 2; At least one target data block in the data block is determined according to at least one node including the last node in the skip list of each index data block.

10. The data query method according to claim 7, wherein the secondary index information includes a Merkle B-tree; determining the target log record in the target data block according to the secondary index information in each target data block, and sending all the obtained target log records to the client, comprises: For each target data block, determine a target log record in the target data block according to the secondary index information in the target data block, and verify whether the target log record has been tampered with according to the Merkle B-tree in the target data block; If all the obtained target log records have not been tampered with, all the obtained target log records are sent to the client.

11. The data query method according to claim 10, further comprising: If there is a tampered target log record among all the obtained target log records, a prompt message is sent to the client.

12. A data query device, comprising: A data block screening module, used to receive the log query condition sent by the client, and determine at least one target data block storing a target log record according to the primary index information in at least one data block containing the latest data block in the database, wherein the target log record is a log record that meets the log query condition; The log query module is used to determine the target log record in the target data block according to the secondary index information in each target data block, and send all the obtained target log records to the client.

13. The data query device according to claim 12, wherein the primary index information is in the form of a skip list; and the data block screening module is used to: If the number of data blocks in the database is not greater than N, determining whether a target data block exists in the database according to the last node of the skip list in the latest data block in the database; If the target data block exists in the database, at least one target data block in the data block is determined according to at least one node including the last node in the jump list.

14. The data query device according to claim 12, wherein the primary index information is in the form of a skip list; and the data block screening module is used to: If the number of data blocks in the database is greater than N, the latest data block in the database is used as the first index data block, and at least two index data blocks are determined with N as the step length, until an index data block recording the data range of the first data block in the data blocks is obtained; At least one target data block in the data block is determined according to at least one node including the last node in the skip list of each index data block.

15. The data query device according to claim 12, wherein the secondary index information comprises a Merkle B-tree; and the log query module is used for: For each target data block, determine a target log record in the target data block according to the secondary index information in the target data block, and verify whether the target log record has been tampered with according to the Merkle B-tree in the target data block; If all the obtained target log records have not been tampered with, all the obtained target log records are sent to the client.

16. A computer program product, comprising a computer program / instructions, which when executed by a processor implement the steps of the method according to any one of claims 7 to 11.

17. An electronic device comprising: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 7 to 11 by running the executable instructions.

18. A computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of the method according to any one of claims 7 to 11.

Citation Information

Patent Citations

  • Storage block chain system with optimized index query

    CN114328535A

  • Log management method and device, electronic equipment and computer readable storage medium

    CN115904885A

  • Data query method and device, electronic equipment and storage medium

    CN118349578A

  • Scalable log-based secondary indexes for non-relational databases

    US10853182B1

Cited By

  • Transaction log query processing method and storage node

    CN120469971A