Index obtaining method, data query method, and related device

By generating the second index set in the blockchain network, the problem of low data query efficiency in the blockchain network is solved, and an efficient data query process is realized.

CN112131226BActive Publication Date: 2025-02-21LENOVO (BEIJING) LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202011045451.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-09-28
Publication Date
2025-02-21
Estimated Expiration
2041-02-21

AI Technical Summary

Technical Problem

Data query in blockchain networks is inefficient, and existing storage methods need to traverse the storage locations of all data to determine the storage locations of the data to be queried.

Method used

By generating a second set of indexes, each second index in the second set of indexes corresponds to at least two first indexes for indicating the storage location of the corresponding at least two first indexes. The second index set is used for querying, reducing the workload of traversing the first index set.

Benefits of technology

Improve the efficiency of data query, reduce the workload of traversing all data storage locations, and improve query speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112131226B_ABST
    Figure CN112131226B_ABST
Patent Text Reader

Abstract

The embodiments of the present application disclose an index obtaining method, a data query method and related devices, wherein the index obtaining method is applied to at least one node in a blockchain network, including: obtaining a first index set stored by the node, wherein any first index in the first index set is used to indicate the storage location of the corresponding target data in the blockchain; generating a second index set based on at least part of the first indexes in the first index set; wherein each second index in the second index set corresponds to at least two of the first indexes, and the corresponding at least two of the first indexes can be determined through the second index.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to index storage technology, and specifically to an index obtaining method, a data query method and related devices. Background Art

[0002] At present, blockchain technology has become a research hotspot. The blockchain network stores data through blocks and records the storage location of the data. When querying data, first determine the storage location of the data, and then read the data from the storage location. It can be understood that there are a lot of data that need to be stored in the blockchain network, and there is an increasing amount of data. This storage method is too rough. When you want to query the data stored in this way, you need to first determine the storage location of the data to be queried from the storage locations of all data. This is equivalent to traversing the storage locations of all data for each query, and then reading the data to be queried from the determined storage location. Obviously, the query efficiency of this query method is not high enough. Summary of the invention

[0003] In order to solve the existing technical problems, the embodiments of the present application provide an index obtaining method, a data query method and related devices.

[0004] The technical solution of the embodiment of the present application is implemented as follows:

[0005] The present application embodiment provides an index obtaining method, which is applied to at least one node in a blockchain network, and the method includes:

[0006] Obtaining a first index set stored by the node, wherein any first index in the first index set is used to indicate a storage location of corresponding target data in the blockchain;

[0007] generating a second index set according to at least part of the first indexes in the first index set;

[0008] Each second index in the second index set corresponds to at least two of the first indexes, and the at least two first indexes corresponding to the second index can be determined through the second index.

[0009] In the above scheme, at least some of the first indexes in the first index set are arranged in layers in the first index set; the second index set is generated based on the first indexes in at least some of the layers in the first index set; and the second index set corresponds to at least two layers in the first index set.

[0010] In the above scheme, the second index is used to indicate the storage position of the target first index in the first index set; the second index is represented as a range value, and the numerical values ​​corresponding to at least two first indexes corresponding to the second index are all within the range value; wherein, the target first index is any first index of the at least two first indexes corresponding to the second index.

[0011] In the above scheme, the first index set is stored in the first storage module; the second index set is stored in the second storage module; wherein the reading performance of the second storage module is greater than the reading performance of the first storage module.

[0012] In the aforementioned scheme, the first index is used to indicate the storage location of the corresponding target data in the blockchain in the node or blockchain.

[0013] In the above scheme, the method further includes:

[0014] Obtain the identifier of the data to be queried;

[0015] Determine a target second index in the second index set according to the identifier of the data to be queried;

[0016] Determine at least two first indexes in the first index set corresponding to the target second index;

[0017] Determine a target first index according to the identifier of the data to be queried and the at least two first indexes;

[0018] The data to be queried is obtained according to the target first index.

[0019] The present application also provides a data query method, which is applied to at least one node in a blockchain network, and the method includes:

[0020] Obtain the identifier of the data to be queried;

[0021] Determine a target second index in the second index set according to the identifier of the data to be queried; wherein the second index set is generated according to at least part of the first indexes in the first index set, and each second index in the second index set corresponds to at least two of the first indexes; any first index in the first index set is used to indicate a storage location of the corresponding target data in the blockchain;

[0022] Determine at least two first indexes in the first index set corresponding to the target second index;

[0023] Determine a target first index according to the identifier of the data to be queried and the at least two first indexes;

[0024] The data to be queried is obtained according to the target first index.

[0025] In the aforementioned solution, the first index is used to indicate the storage location of the data to be queried in the node or blockchain;

[0026] The first index set is stored in a first storage module; the second index set is stored in a second storage module; wherein the reading performance of the second storage module is greater than the reading performance of the first storage module.

[0027] The embodiment of the present application also provides an index obtaining device, including:

[0028] an acquisition unit, configured to acquire a first index set stored by the node, wherein any first index in the first index set is used to indicate a storage location of the corresponding target data in the blockchain;

[0029] a generating unit, configured to generate a second index set according to at least part of the first indexes in the first index set;

[0030] Each second index in the second index set corresponds to at least two of the first indexes, and the at least two first indexes corresponding to the second index can be determined through the second index.

[0031] The present application also provides a data query device, including:

[0032] A first obtaining unit, used to obtain an identifier of the data to be queried;

[0033] A first determining unit is used to determine a target second index in a second index set according to an identifier of the data to be queried; wherein the second index set is generated according to at least part of the first indexes in the first index set, and each second index in the second index set corresponds to at least two of the first indexes; any first index in the first index set is used to indicate a storage location of the corresponding target data in the blockchain;

[0034] A second determining unit, configured to determine at least two first indexes in the first index set corresponding to the target second index;

[0035] A third determining unit, configured to determine a target first index according to the identifier of the data to be queried and the at least two first indexes;

[0036] The second obtaining unit is used to obtain the data to be queried according to the target first index.

[0037] An embodiment of the present application provides an index obtaining method, a data query method and related devices, wherein the index obtaining method is applied to at least one node in a blockchain network, and the method includes: obtaining a first index set stored by the node, wherein any first index in the first index set is used to indicate the storage location of the corresponding target data in the blockchain; generating a second index set based on at least part of the first indexes in the first index set; wherein each second index in the second index set corresponds to at least two of the first indexes, and the corresponding at least two of the first indexes can be determined through the second index.

[0038] By utilizing the first and second index sets in the embodiments of the present application, when one wants to query certain data, there is no need to traverse the storage locations of all the data. One only needs to traverse the second index in the second index set first, and then search the storage location of the data to be queried in the first index set based on the traversal results, and then read the data to be queried from the found storage location. This can greatly reduce the traversal workload and improve query efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0040] Figure 1 The implementation process of the index acquisition method in the embodiment of the present application is shown as follows: Figure 1 ;

[0041] Figure 2 The implementation process of the index acquisition method in the embodiment of the present application is shown as follows: Figure 2 ;

[0042] Figure 3 This is a schematic diagram of the implementation process of the data query method in the embodiment of the present application;

[0043] Figure 4 This is a hierarchical schematic diagram of some first indexes in the first index set in an embodiment of the present application;

[0044] Figure 5 This is a hierarchical schematic diagram of part of the second indexes in the second index set in an embodiment of the present application;

[0045] Figure 6 This is a schematic diagram of an application in an embodiment of the present application;

[0046] Figure 7 This is a schematic diagram of the composition structure of the index obtaining device in the embodiment of the present application;

[0047] Figure 8 This is a schematic diagram of the structure of the data query device in the embodiment of the present application;

[0048] Fig. 9 Schematic diagram of the hardware structure of the index obtaining device and / or data query device in the embodiments of the present application. DETAILED DESCRIPTION

[0049] In order to make the purpose, technical scheme and advantages of the present application clearer, the technical scheme in the embodiment of the present application will be clearly and completely described below in conjunction with the drawings in the embodiment of the present application. Obviously, the described embodiment is only a part of the embodiment of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application. In the absence of conflict, the embodiments in the present application and the features in the embodiments can be combined with each other arbitrarily. The steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions. In addition, although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that here.

[0050] The embodiment of the present application provides an index obtaining method, which uses the first index in the first index set to record the storage location of the data, and uses at least part of the first index in the first index set to generate a second index set, so that the second index set generated can facilitate the rapid query of the stored data. The embodiment of the present application also provides a data query method, which combines the second index set and the first index set to realize the rapid query of the stored data, thereby improving the query efficiency of the data.

[0051] The present application embodiment provides an index obtaining method, which is applied to at least one node in a blockchain network. The node can be any reasonable device in the blockchain network, such as a storage device, a server, etc. Figure 1 As shown, the method includes:

[0052] S101: Obtain a first index set stored by the node, where any first index in the first index set is used to indicate a storage location of corresponding target data in the blockchain;

[0053] In this step, the target data may refer to the data generated in the blockchain network that needs to be stored and / or has been stored in the block. The first index may be used to indicate the storage location of the data that needs to be stored and / or has been stored in the block locally and / or on the blockchain. Exemplarily, the data that needs to be stored includes target data 1 and 2, target data 1 is stored at location A locally (node), and target data 2 is stored at location B locally (node). Then, in the first index set, there is such a (first) index used to indicate that the storage location of target data 1 locally (node) is location A; there is also such a (first) index used to indicate that the storage location of target data 2 locally (node) is location B. On a technical level, the first index may be recorded as the correspondence between target data 1 or the identifier of target data 1 and location A (the storage location of target data 1 locally on the node), and the first index may be recorded as the correspondence between target data 2 or the identifier of target data 2 and location B (the storage location of target data 2 locally on the node), so as to indicate that the storage locations of target data 1 and target data 2 locally are location A and location B. The identifier of the target data may be any information that can uniquely identify the target data, such as the ID of the target data. Considering that the data to be stored in the embodiment of the present application is usually transaction data in a blockchain network, the identifier of the target data may be a transaction ID.

[0054] In this step, the first index set can be obtained by constructing the first index set. Furthermore, the storage location of the transaction data generated in the blockchain network on the blockchain or locally (node) can be read, the identification of the transaction data can be read, and the first index can be constructed based on the read location and the identification of the transaction data. Exemplarily, the correspondence between the identification of the transaction data and the transaction data on the blockchain or locally (node) can be recorded, and the correspondence can be represented by the (first) index. The (first) index of multiple transaction data is constructed according to the above process, and the first index set is formed.

[0055] In this step, the first index set may be one that has been established by other nodes in the blockchain network except the local node. In this case, the first index set can be obtained by directly reading the established first index set.

[0056] S102: Generate a second index set based on at least part of the first indexes in the first index set; wherein each second index in the second index set corresponds to at least two of the first indexes, and the at least two first indexes corresponding to the second index can be determined through the second index.

[0057] In practical applications, the number of first indexes in the first index set is usually multiple, and the second index set is generated based on some or all of the first indexes in the first index set. The second index set includes two or more second indexes, and each second index corresponds to at least two first indexes in the first index set. It can be considered that each second index is generated based on at least two first indexes corresponding to it in the first index set, and the set of multiple generated second indexes constitutes the second index set. Since the second index of the second index set corresponds to at least two first indexes in the first index set, the at least two first indexes corresponding to it can be determined from the first index set through the second index.

[0058] The schemes of S201 and S202 above provide an index obtaining method, which generates a second index set using a first index set for indicating the storage location of each target data. If the first index set is regarded as a scheme for directly indicating the storage location of the target data, then the second index set generated based on the first index set can be regarded as a scheme for indirectly indicating the storage location of the target data. And because each second index in the second index set corresponds to at least two first indexes in the first index set, and each first index in the first index set is used to indicate the storage location of the corresponding target data, each second index in the second index set can indirectly indicate the storage location of two or more target data, which is equivalent to each second index indirectly indicating the storage location of multiple target data. This scheme of indirectly indicating the storage location of multiple target data (locally or on the chain) using one (second) index does not require traversing the storage locations of all data when you want to query a certain data. You only need to traverse the second index in the second index set first, and then find the storage location of the data to be queried in the first index set based on the traversal result, and read the data you want to query from the storage location found, which can greatly reduce the traversal workload and improve query efficiency.

[0059] In an embodiment of the present application, the first index in the first index set is used to indicate the storage location of the corresponding target data locally or on the chain of the node. The second index generated based on at least part of the (first) index in the first index set is used to indicate the storage location of the target first index in the first index set; wherein, the target first index is any first index of at least two first indexes corresponding to the second index. Equivalently, the second index is used to indicate the storage location of each first index corresponding to it in the first index set in the first index set. Exemplarily, assuming that the second index-index 21 in the second index set corresponds to the first index-index 11 and index 12 in the first index set, the second index is used to indicate the location of index 11 and index 12 in the first index set. At the technical level, the location of index 11 and index 12 in the first index set is determined, and the location of index 11 and index 12 in the first index set is recorded to form index 21. It can be considered that index 21 in the second index set is obtained based on the location of index 11 and index 12 in the first index set, that is, index 21 is generated based on the location information of index 11 and index 12 in the first index set. Two or more first indexes corresponding to a second index in the first index set are two or more (first) indexes that can be used to generate the second index. This solution of using the second index to indicate the storage location of the first index in the first index set does not require traversing the storage locations of all data when you want to query a certain data later. You only need to traverse the second index in the second index set first, and then search in the first index set based on the traversal result to determine the storage location of the data to be queried, and then read the data from the storage location, which can greatly reduce the traversal workload and improve query efficiency.

[0060] In an optional solution, at least some of the first indexes in the first index set are hierarchically arranged in the first index set. For example, some of the first indexes in the first index set are hierarchically arranged in the form of a tree in the first index set. Figure 4As shown, index 10 to index 19 are partial indexes in the first index set, and these indexes are layered in the form of a tree, which is divided into four layers in total. Among them, the first layer, that is, the root node of the tree (node ​​0), represents indexes 11 to 18, and the second layer, that is, the child nodes of the root node, is two in number, one of which is node 01 (representing index 11 to index 14), and the other is node 02 (representing index 15 to 18). The third layer is the child nodes of the root node (nodes 000 to 006). The third layer has a total of 7 nodes, node 000 represents index 11, node 001 represents index 12, node 002 represents index 13, and node 003 represents index 14. Node 004 represents index 15 and index 16, node 005 represents index 17, and node 006 represents index 18. The fourth layer has a total of 2 nodes, node 0001 represents index 15, and node 0002 represents index 16. It can be understood that Figure 4 The middle layer is only a specific example and is not limited to all coverage of the embodiments of the present application. Any reasonable one is within the coverage of the present application. Figure 4 The hierarchical structure shown in is only part of the hierarchical structure in the first index set. Other hierarchical structures in the first index set can also be as shown in Figure 4 As shown, these layer structures are combined to form the overall layer structure of the first index set.

[0061] In the embodiment of the present application, the second index set may be generated based on the first index in at least part of the hierarchy of the first index set. Figure 4 As shown, the second index set can be based on Figure 4 The nodes 000 to 003 in the third layer and the nodes 0001 and 0002 in the fourth layer are generated. Figure 4 It is generated by the node 02 of the second layer and the nodes 000-003 of the third layer. It can be understood that Figure 4Four layers are shown, but in actual applications, the number of layers of the second index set is large. The second index set can be generated based on at least part of the first index in at least two layers in the first index set, such as based on at least part of the first index in the 20th to 25th layers (a total of 5 layers) in the first index set, such as based on at least part of the first index in the 11th to 13th layers (a total of 3 layers) in the first index set. The second index set generated in this case corresponds to at least two layers in the first index set. This scheme of generating the second index set using at least part of the first index in at least two layers in the first index set does not require traversing all layers in the first index set when you want to query a certain data later. You only need to traverse the second index set first to find the second index that can indirectly indicate the storage location of the data to be queried, and then determine the storage location of the data to be queried in the first index set based on the found second index, and read the data from the storage location, which can greatly reduce the traversal workload and improve the query efficiency.

[0062] In the embodiment of the present application, in the scheme where the first index set is presented in a hierarchical form, the second index set is equivalent to indicating the position of the at least partially hierarchical first index in the first index set. Since the second index is generated based on at least two first indexes in the first index set, compared with the number of first indexes in the first index set, the number of second indexes in the second index set is generally less than the number of first indexes in the first index set. In the scheme for storing the first and second index sets, the first and second index sets can be stored in different storage modules. Specifically, the first index set is stored in the first storage module; the second index set is stored in the second storage module; wherein the reading performance of the second storage module is greater than the reading performance of the first storage module. Exemplarily, the first storage module can be a storage module such as a disk or hard disk. The second storage module can be a storage module such as a memory or a node external memory. It can be understood that in terms of quantity storage, the number of storage modules such as disks or hard disks that can be stored is usually greater than the storage capacity of memory or external memory; and in terms of reading speed, the reading speed of memory is faster than the reading speed of disks or hard disks. Based on this, in the embodiment of the present application, the first index set with a larger amount of data is stored in a (first) storage module such as a disk or hardware. The second index set is stored in the memory or external memory. The reason for storing the second index set in the memory or external memory is to utilize the fast reading characteristics of the memory or external memory. The fast reading speed can accelerate the query of the desired data in the second index set, thereby improving the query efficiency.

[0063] In the embodiment of the present application, each second index in the second index set is generated based on at least two first indexes in the first index set, and is used to indicate the position of each first index in the at least two first indexes based on it in the first index set. Based on this, it can be considered that the second index is represented as a range value, which can be a continuous value or a discrete value, depending on the specific situation. In the case where the second index is represented as a range value, the numerical values ​​corresponding to at least two first indexes corresponding to the second index are all within the range value. Among them, the numerical value corresponding to the first index can be data used to indicate the position of the first index in the first index set. Exemplarily, it is assumed that index 21 in the second index set corresponds to the first index-index 11 and index 12 in the first index set; and it is assumed that the position of index 11 in the first index set is position A, and the position of index 12 in the first index set is position B. Index 11 can be [the identification of target data 1, the storage position 1 of target data 1 in the node local or on the chain]; index 12 can be [the identification of target data 2, the storage position 2 of target data 2 in the node local or on the chain]. In the case where index 11 and index 12 are as described above, the second index - index 21 generated based on index 11 and index 12 can be [position 1, position 2]; wherein position 1 refers to the position of index 11 in the first index set; position 2 refers to the position of index 12 in the first index set. The second index can also be [transaction ID1, position 1; transaction ID2, position 2]; wherein transaction ID1 is the identifier of target data 1 corresponding to index 11; transaction ID 2 is the identifier of target data 2 corresponding to index 12. The second index can also be [transaction ID1, pointer 1; transaction ID2, pointer 2]; wherein pointer 1 is used to point to the position of index 11 in the first index set; pointer 2 is used to point to the position of index 12 in the first index set. This scheme of using the second index to indicate the position of the first index in the first index set can first determine the position of the first index in the first index set through the second index set when querying the data to be queried, and then use the determined first index to read or query the data to be queried, which can improve query efficiency.

[0064] In an embodiment of the present application, at least two first indexes corresponding to the second index in the first index set may be indexes with certain characteristics. Exemplarily, the transaction ID of the target data corresponding to the (first) index has certain characteristics, such as the hash value of the transaction ID is divisible by 5, the hash value of the transaction ID is divisible by 3, or the remainder of the hash value of the transaction ID is 2 after being divided by 5, etc. The position information of the first index having such characteristics (equivalent to having certain commonalities) in the first index set is indicated using the same second index. From this aspect, it can be considered that each second index in the second index set is used to indicate the position of two or more first indexes in the first index set that have certain commonalities in the first index set. In the case of a subsequent query of a certain data, querying in combination with the second index set and the first index set can improve query efficiency.

[0065] exist Figure 1 Based on the scheme shown, Figure 2 As shown, the method also includes:

[0066] S201: Obtaining the identifier of the data to be queried;

[0067] In this step, the data to be queried can be any data stored locally on the node or on the chain. The identifier of the data to be queried can be any information that can uniquely represent the data, such as the transaction ID of the data to be queried.

[0068] S202: Determine a target second index in the second index set according to the identifier of the data to be queried;

[0069] In this step, the target second index refers to the index in the second index set indicating the position information of the first index of the data to be queried in the first index set. From the second index set, the index with the identifier of the data to be queried is searched, and the found index is regarded as the target second index.

[0070] S203: Determine at least two first indexes in the first index set corresponding to the target second index;

[0071] In this step, in the scheme of obtaining the index, the target second index is generated based on the at least two first indexes corresponding to the first index set. That is, in the second index set, each second index has at least two first indexes corresponding to it. In the scheme of querying, this correspondence is used to determine which first index(es) in the first index set corresponds to the target second index.

[0072] S204: Determine a target first index according to the identifier of the data to be queried and the at least two first indexes;

[0073] In this step, a first index having an identifier of the data to be queried is searched out from at least two first indexes as a target first index.

[0074] S205: Acquire the data to be queried according to the target first index.

[0075] In this step, the data to be queried is read according to the storage address of the data to be queried locally or on the chain indicated by the target first index, thereby realizing the query of the data to be queried.

[0076] In the above S201 to S205, when the first index set is obtained and the second index set is generated based on the first index set, when querying the data to be queried, the target second index is determined from the second index set based on the identifier of the data to be queried, the target first index is determined from at least two first indexes corresponding to the target second index, and the data to be queried is read according to the storage address of the data to be queried locally or on the chain indicated by the target first index. This is equivalent to first determining the target second index from the second index set when querying, and then determining the target first index from at least two first indexes corresponding to the target second index. Compared with the technical solution in the related art that requires traversing the storage locations of all data, it can greatly reduce the traversal workload, speed up the query, and improve the query efficiency.

[0077] The present application also provides a data query method, such as Figure 3 As shown, the method also includes:

[0078] S301: Obtaining the identifier of the data to be queried;

[0079] S302: Determine a target second index in the second index set according to the identifier of the data to be queried;

[0080] S303: Determine at least two first indexes corresponding to the target second index in the first index set;

[0081] S304: Determine a target first index according to the identifier of the data to be queried and the at least two first indexes;

[0082] S305: Acquire the data to be queried according to the target first index.

[0083] S301 to S305 in the embodiment of the present application are data query methods. When the second index set is generated based on the first index set, the generated second index set and the obtained first index set can be used to query the data to be queried. In the query scheme, the target second index is first determined from the second index set, and then the target first index is determined from at least two first indexes corresponding to the target second index, and the data to be queried is read according to the storage location indicated by the target first index. Compared with the technical solution in the related art that requires traversing the storage locations of all data, it can greatly reduce the traversal workload, speed up the query speed, and improve the query efficiency. For the specific description of S301 to S305, please refer to the aforementioned related instructions, and the repeated parts will not be repeated.

[0084] The technical solution of the embodiment of the present application is described in detail below in conjunction with specific application scenarios.

[0085] The first index set is Figure 4 Taking the hierarchical presentation as an example, each (first) index in the first index set can indicate the storage location of the target data in the ledger database in the form of [transaction ID of the target data, storage location of the target data in the ledger database]. Among them, the target data can be regarded as any data in the blockchain network, such as data in the ledger database of the blockchain network. If the relevant technology is used to query a certain data (data to be queried) stored in the ledger database, the query of the data to be queried is performed when the identifier of the data to be queried, such as the transaction ID, is known, then the scheme adopted is: from the first layer of the first index set downward, multiple layers are traversed to find whether the first index of each layer traversed has the transaction ID of the data to be queried. When there is a first index with the transaction ID of the data to be queried in a certain layer traversed, the data to be queried is read out according to the storage location of the data to be queried in the ledger database indicated by the first index, thereby realizing the query of the data to be queried. It can be seen that when using the relevant technology to query the data to be queried, it is necessary to traverse each layer of the first index set until the first index (target first index) with the transaction ID of the data to be queried is found. In some extreme cases, the target first index may not be found until all layers are traversed. It can be seen that the query efficiency of the solution using the first index set for data query in the relevant technology is low.

[0086] The inventor found in the study of storage technology in the blockchain network that since the first index set has recorded the storage location of each stored data, the first index set can be used as the primary key index, and an auxiliary index can be constructed based on the primary key index, and the data is queried by combining the primary key index and the auxiliary index. The index acquisition method in the embodiment of the present application is used to construct or generate an auxiliary index. The auxiliary index is the second index set. Specifically, take the (first) index in the partial layer of the second index set, illustratively, take at least part of the (first) index in the 3rd to 12th layers of the first index set. Divide the hash value of the transaction ID of the data in these (first) indexes by 5, and record the data transaction ID corresponding to each index with a remainder of 1 after division by 5 and the position information of each index in the first index set to form a second index. Record the data transaction ID corresponding to each index with a remainder of 2, 3, and 4 after division by 5 and the position information of each index in the first index set to form the second, third, and fourth second indexes. In this application scenario, assuming that the remainder after dividing the transaction ID of target data 1 to target data 3 by 5 is 1, there is a first index (index 11) in the first index set for indicating the storage location of target data 1 in the ledger database, and the first index can be [transaction ID 1 of target data 1, storage location 11 of target data 1 in the ledger database]. The first index (index 12) for indicating the storage location of target data 2 in the ledger database is [transaction ID 2 of target data 2, storage location 12 of target data 2 in the ledger database]. The first index (index 13) for indicating the storage location of target data 3 in the ledger database is [transaction ID 3 of target data 3, storage location 13 of target data 3 in the ledger database]. The second index - index 21 is generated based on indexes 11, 12 and 13 that have certain commonalities. Exemplarily, index 21 can be [transaction ID1 of target data 1, storage location 21 of index 11 in the first index set; transaction ID2 of target data 2, storage location 22 of index 12 in the first index set; transaction ID3 of target data 3, storage location 23 of index 13 in the first index set]. Among them, transaction ID1, 2 and transaction ID3 are transaction IDs whose remainders are 1 after the hash value of the transaction ID is divided by 5. In the above scheme, the generation process of the second index - index 21 is carried out by taking the hash value of the transaction ID divided by 5 with a remainder of 1 as an example. For the process of generating the corresponding second index when the hash value of the transaction ID is divided by 5 with a remainder of 2, 3 or 4, please refer to the above process of generating index 21, and the repetitions will not be repeated. The above scheme can be regarded as a scheme for constructing an auxiliary index based on the primary key index. The auxiliary index constructed according to this construction scheme can assist the primary key index in realizing fast query of data.

[0087] In a specific implementation, some of the second indexes in the second index set may also be used as follows: Figure 5 The hierarchical structure shown takes a total of three hierarchies as an example. The first hierarchical structure includes node 50, which represents the second index whose remainder after the hash value of the transaction ID is divided by 5 is 0 to 4; the second hierarchical structure includes nodes 501 to 503. Among them, node 501 represents the second index whose remainder after the hash value of the transaction ID is divided by 5 is 0; node 502 represents the second index whose remainder after the hash value of the transaction ID is divided by 5 is 1 and 3; node 503 represents the second index whose remainder after the hash value of the transaction ID is divided by 5 is 2 and 4. The third hierarchical structure includes nodes 5020, 5021 and 5030, 5031. Among them, node 5020 represents the second index whose remainder after the hash value of the transaction ID is divided by 5 is 1; node 5021 represents the second index whose remainder after the hash value of the transaction ID is divided by 5 is 3. Node 5030 represents the second index whose remainder after the hash value of the transaction ID is divided by 5 is 2; node 5031 represents the second index whose remainder after the hash value of the transaction ID is divided by 5 is 4. It can be understood that Figure 5 This is just a specific example and does not represent all hierarchical forms of the second index set. Figure 5 The layered structures shown are all covered within the protection scope of the embodiments of the present application.

[0088] In actual applications, since the pointer can point to a certain position, in this application scenario, the pointer can be used to point to the position of each first index (index 11, 12 and index 13) in the first index set. The second index - index 21 can be [transaction ID1, pointer 1; transaction ID2, pointer 2; transaction ID2, pointer 3]. Among them, pointer 1 is used to point to index 11 in the first index set, that is, it points to the position of index 11 in the first index set. Pointer 2 is used to point to index 12 in the first index set, that is, it points to the position of index 12 in the first index set. Pointer 3 is used to point to index 13 in the second index set, that is, it points to the position of index 13 in the first index set. Refer to Figure 6 As shown, it includes a first index set and a second index set, wherein the node 003 in the third layer of the first index set represents index 11, the node 006 represents index 12, and the node 0002 in the fourth layer represents index 13. The node 501 in the second layer of the second index set represents index 21. It can be understood that Figure 6 It is only a specific example, and all similar variations are within the protection scope of the embodiments of the present application. It can be understood that in the above-mentioned example of index 21, if transaction ID1 and pointer 1 are regarded as the value corresponding to index 11, transaction ID2 and pointer 2 are regarded as the value corresponding to index 12, and transaction ID3 and pointer 3 are regarded as the value corresponding to index 13, then the above-mentioned index 21 can be regarded as indicating the positions of indexes 11, 12 and index 13 in the primary key index in the form of a range value.

[0089] In this application scenario, taking the blockchain network as HyperLedger-Fabric blockchain (a consortium chain) as an example, the account book data in the blockchain network can be stored in an account book database such as LevelDB and / or CoucuDB. The primary key index of this application scenario is used to indicate the position of each data in the account book database in the account book database, and read the data to be queried from the account book database according to the position indicated by the primary key index. After the second index set is constructed or generated according to the first index set, the first index set and the second index set can be used to query the data in the account book data (data to be queried). Assuming that the query personnel want to query data A (data to be queried), the identifier of data A input by the query personnel to the local node, such as the transaction ID, is received. Assuming that the transaction ID of data A is ID3, the node receives the transaction ID of the data A to be queried, and queries it in the memory to find which second index of the auxiliary index (second index set) stored in the memory includes the transaction ID ID3. As a preferred solution, after the node receives the transaction ID of the data A to be queried, it can first use the Bloom filter to confirm whether the transaction ID is included in the second index set. If it is confirmed that the transaction ID of the data to be queried is included in the second index set, the second index including the transaction ID ID3 is searched in the memory. If it is confirmed that the transaction ID of the data to be queried is not included in the second index set, the node searches for the first index with the transaction ID from the first index set according to the relevant technology, and reads data A at the storage location of the account database according to the data A indicated by the first index found, thereby realizing the query of data A.

[0090] In the scheme of searching which second index of the auxiliary index (second index set) stored in the memory includes the transaction ID ID3, if the transaction value ID3 is found in the second index - index 21 in the second index set, then index 21 in the second index set is the target second index. Each pointer in the target second index points to a first index corresponding to the first index set, and the first indexes pointed to by these pointers are at least two first indexes corresponding to index 21 in the first index set. Determine which first index among these first indexes has transaction ID3, and the first index including transaction ID3 is the target index. In this application scenario, index 13 has ID3, then index 13 is the target first index. According to the storage location of data A in the account book database indicated by index 13, such as storage location 13, data A is read out from storage location 13 of the account book database, thereby realizing the query of data A.

[0091] As can be seen from the previous description, in the embodiment of the present application, an auxiliary index is generated or constructed based on the primary key index. With the help of the auxiliary index, the data to be queried can be quickly queried using the primary key index. When you want to query a certain data, you do not need to traverse the storage locations of all data. You only need to traverse the second index in the second index set to determine the target second index, and then determine the target first index based on the pointer pointing in the target second index. The data to be queried can be read out according to the instructions of the target first index. This can greatly reduce the traversal workload and improve query efficiency.

[0092] In this application scenario, the primary key index and the auxiliary index generated based on the primary key index also need to be stored. When storing the primary key index (first index set) and the auxiliary index (second index set), since the amount of data involved in the primary key index is large, the primary key index can be stored in a local hard disk or disk. It can be understood that the auxiliary index in the embodiment of the present application is used to assist the primary key index in data query, which is used to indicate the position information of the first index with certain commonality in the first index set. In this application scenario, in order to shorten the query time and speed up the query speed, the second index set can be stored in the local memory. The reading speed of the memory is faster than the reading speed of the hard disk or disk. The speed of reading the target second index from the second index set stored in the memory is faster, thereby speeding up the query of the data to be queried.

[0093] The present application embodiment provides an index obtaining device, such as Figure 7 As shown, it includes: an acquisition unit 1001 and a generation unit 1002; wherein,

[0094] An acquisition unit 1001 is used to acquire a first index set stored by the node, wherein any first index in the first index set is used to indicate a storage location of the corresponding target data in the blockchain;

[0095] A generating unit 1002, configured to generate a second index set according to at least part of the first indexes in the first index set;

[0096] Each second index in the second index set corresponds to at least two of the first indexes, and the at least two first indexes corresponding to the second index can be determined through the second index.

[0097] In an optional scheme, at least some of the first indexes in the first index set are arranged in layers in the first index set; the second index set is generated based on the first indexes in at least some of the layers in the first index set; and the second index set corresponds to at least two layers in the first index set.

[0098] In an optional solution, the second index is used to indicate the storage position of the target first index in the first index set; wherein the target first index is any first index of at least two first indexes corresponding to the second index.

[0099] In an optional solution, the second index is represented by a range value, and the numerical values ​​corresponding to at least two first indexes corresponding to the second index are all within the range value.

[0100] In an optional solution, the first index set is stored in a first storage module; the second index set is stored in a second storage module; wherein the reading performance of the second storage module is greater than the reading performance of the first storage module.

[0101] In an optional solution, the first index is used to indicate the storage location of the corresponding target data in the blockchain in the node or blockchain.

[0102] In an optional solution, the device further includes: a first obtaining unit, a first determining unit, a second determining unit, a third determining unit and a second obtaining unit; wherein,

[0103] The first obtaining unit is used to obtain the identifier of the data to be queried;

[0104] The first determining unit is used to determine a target second index in the second index set according to an identifier of the data to be queried;

[0105] The second determining unit is used to determine at least two first indexes corresponding to the target second index in the first index set;

[0106] The third determining unit is used to determine a target first index according to the identifier of the data to be queried and the at least two first indexes;

[0107] The second obtaining unit is used to obtain the data to be queried according to the target first index.

[0108] It can be understood that in actual applications, the acquisition unit 1001 and the generation unit 1002 in the device can be implemented by the central processing unit (CPU), digital signal processor (DSP), microcontroller unit (MCU) or programmable gate array (FPGA) of the index acquisition device.

[0109] The present application embodiment provides a data query device, such as Figure 8As shown, it includes: a first obtaining unit 1101, a first determining unit 1102, a second determining unit 1103, a third determining unit 1104 and a second obtaining unit 1105; wherein,

[0110] The first obtaining unit 1101 is used to obtain the identifier of the data to be queried;

[0111] The first determining unit 1102 is used to determine a target second index in the second index set according to an identifier of the data to be queried; wherein the second index set is generated according to at least part of the first indexes in the first index set, and each second index in the second index set corresponds to at least two of the first indexes; any first index in the first index set is used to indicate a storage location of the corresponding target data in the blockchain;

[0112] A second determining unit 1103 is configured to determine at least two first indexes in the first index set corresponding to the target second index;

[0113] A third determining unit 1104 is configured to determine a target first index according to the identifier of the data to be queried and the at least two first indexes;

[0114] The second obtaining unit 1105 is used to obtain the data to be queried according to the target first index.

[0115] In an optional solution, the first index is used to indicate the storage location of the data to be queried in the node or blockchain; the first index set is stored in a first storage module; the second index set is stored in a second storage module; wherein the reading performance of the second storage module is greater than the reading performance of the first storage module.

[0116] It can be understood that the first obtaining unit 1101, the first determining unit 1102, the second determining unit 1103, the third determining unit 1104 and the second obtaining unit 1105 in the data query device can all be implemented by a central processing unit (CPU), a digital signal processor (DSP), a microcontroller unit (MCU) or a programmable gate array (FPGA) of the data query device in actual applications.

[0117] It should be noted that the index acquisition device and data query device of the embodiments of the present application, since the principles of solving the problems by the index acquisition device and data query device are similar to those of the aforementioned index acquisition method and data query method, the implementation process and implementation principles of the index acquisition device and the data query device can all refer to the description of the implementation process and implementation principles of the aforementioned methods, and the repeated parts will not be repeated.

[0118] The present application also provides a computer-readable storage medium having a computer program stored thereon, wherein the program is at least used to execute when executed by a processor Figures 1 to 6 The steps of any of the methods shown. The computer readable storage medium may be a memory. The memory may be Fig. 9 The memory 62 is shown.

[0119] Fig. 9 Schematic diagram of the hardware structure of the index obtaining device and / or data query device of the embodiment of the present application, such as Fig. 9 As shown, the index obtaining device and / or data query device includes: a communication component 63 for data transmission, at least one processor 61 and a memory 62 for storing a computer program that can be run on the processor 61. The various components in the terminal are coupled together through a bus system 64. It can be understood that the bus system 64 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 64 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, Fig. 9 Various buses are labeled as bus system 64.

[0120] Wherein, when the processor 61 executes the computer program, at least Figures 1 to 6 Any of the steps of the method shown.

[0121] It can be understood that the memory 62 can be a volatile memory or a non-volatile memory, and can also include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic random access memory (FRAM), a flash memory, a magnetic surface memory, an optical disk, or a compact disc read-only memory (CD-ROM); the magnetic surface memory can be a disk memory or a tape memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM), synchronous static random access memory (SSRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM, SyncLink Dynamic Random Access Memory), and direct RAM bus random access memory (DRRAM, Direct Rambus Random Access Memory).The memory 62 described in the embodiments of the present application is intended to include, but is not limited to, these and any other suitable types of memory.

[0122] The method disclosed in the above embodiment of the present application can be applied to the processor 61, or implemented by the processor 61. The processor 61 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit in the processor 61 or the instruction in the form of software. The above processor 61 can be a general-purpose processor, a DSP, or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The processor 61 can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiment of the present application. The general-purpose processor can be a microprocessor or any conventional processor, etc. In combination with the steps of the method disclosed in the embodiment of the present application, it can be directly embodied as a hardware decoding processor to execute, or it can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium, which is located in the memory 62, and the processor 61 reads the information in the memory 62 and completes the steps of the above method in combination with its hardware.

[0123] In an exemplary embodiment, the index obtaining device and / or the data query device may be implemented by one or more application specific integrated circuits (ASIC), DSP, programmable logic device (PLD), complex programmable logic device (CPLD), FPGA, general-purpose processor, controller, MCU, microprocessor, or other electronic components to execute the aforementioned index obtaining method and / or data query method.

[0124] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.

[0125] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0126] In addition, all functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may be a separate unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.

[0127] A person skilled in the art can understand that: all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the aforementioned storage medium includes: mobile storage devices, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), disks or optical disks, etc. Various media that can store program codes.

[0128] Alternatively, if the above-mentioned integrated unit of the present application is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the embodiment of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROM, RAM, magnetic disks or optical disks.

[0129] The methods disclosed in several method embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments.

[0130] The features disclosed in several product embodiments provided in this application can be arbitrarily combined without conflict to obtain new product embodiments.

[0131] The features disclosed in several method or device embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments or device embodiments.

[0132] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A method for obtaining an index, applied to at least one node in a blockchain network, the method comprising: Obtaining a first index set stored by the node, wherein any first index in the first index set is used to indicate a storage location of corresponding target data in the blockchain; At least some of the first indexes in the first index set are arranged in layers in the first index set; generating a second index set according to at least part of the first indexes in the first index set; Each second index in the second index set corresponds to at least two of the first indexes, and the at least two first indexes corresponding to the second index can be determined through the second index to determine the storage location of the data to be queried.

2. The method according to claim 1, wherein the second index set is generated based on the first index in at least part of the layers of the first index set; and the second index set corresponds to at least two layers in the first index set.

3. The method according to claim 1, wherein the second index is used to indicate a storage location of a target first index in the first index set; the target first index is any first index of at least two first indexes corresponding to the second index; The second index is represented by a range value, and the numerical values ​​corresponding to at least two of the first indices corresponding to the second index are both within the range value.

4. The method according to any one of claims 1 to 3, storing the first index set in a first storage module; storing the second index set in a second storage module; wherein, The read performance of the second storage module is greater than the read performance of the first storage module.

5. According to the method of claim 4, the first index is used to indicate the storage location of the corresponding target data in the blockchain in the node or blockchain.

6. The method according to claim 1, further comprising: Obtaining an identifier of the data to be queried; Determining a target second index in the second index set according to the identifier of the data to be queried; Determine at least two of the first indexes in the first index set corresponding to the target second index; Determine a target first index according to the identifier of the data to be queried and at least two of the first indexes; The data to be queried is obtained according to the target first index.

7. A data query method, applied to at least one node in a blockchain network, the method comprising: Obtain the identifier of the data to be queried; According to the identifier of the data to be queried, determine the target second index in the second index set; wherein at least part of the first indexes in the first index set are hierarchically arranged in the first index set; the second index set is generated according to at least part of the first indexes in the first index set, and each second index in the second index set corresponds to at least two of the first indexes; any of the first indexes in the first index set is used to indicate the storage location of the corresponding target data in the blockchain; Determine at least two of the first indexes in the first index set corresponding to the target second index to determine a storage location of the data to be queried; Determine a target first index according to the identifier of the data to be queried and at least two of the first indexes; The data to be queried is obtained according to the target first index.

8. According to the method of claim 7, the first index is used to indicate the storage location of the data to be queried in the node or blockchain; The first index set is stored in a first storage module; the second index set is stored in a second storage module; wherein, The read performance of the second storage module is greater than the read performance of the first storage module.

9. An index obtaining device, applied to at least one node in a blockchain network, comprising: an acquisition unit, configured to acquire a first index set stored by the node, wherein any first index in the first index set is used to indicate a storage location of the corresponding target data in the blockchain; At least some of the first indexes in the first index set are arranged in layers in the first index set; a generating unit, configured to generate a second index set according to at least part of the first indexes in the first index set; Each second index in the second index set corresponds to at least two of the first indexes, and the at least two first indexes corresponding to the second index can be determined through the second index to determine the storage location of the data to be queried.

10. A data query device, comprising: A first obtaining unit, used to obtain an identifier of the data to be queried; A first determining unit is configured to determine a target second index in a second index set according to an identifier of the data to be queried; wherein, at least some of the first indexes in the first index set are hierarchically arranged in the first index set, the second index set is generated according to at least some of the first indexes in the first index set, and each second index in the second index set corresponds to at least two of the first indexes; any of the first indexes in the first index set is used to indicate a storage location of the corresponding target data in the blockchain; A second determining unit, configured to determine at least two first indexes corresponding to the target second index in the first index set, so as to determine a storage location of the data to be queried; A third determining unit, configured to determine a target first index according to an identifier of the data to be queried and at least two of the first indexes; The second obtaining unit is used to obtain the data to be queried according to the target first index.

Citation Information

Patent Citations

  • Method for querying data

    CN108427736A