WO2020223901A1 - 查询数据的方法和服务器 - Google Patents

查询数据的方法和服务器 Download PDF

Info

Publication number
WO2020223901A1
WO2020223901A1 PCT/CN2019/085865 CN2019085865W WO2020223901A1 WO 2020223901 A1 WO2020223901 A1 WO 2020223901A1 CN 2019085865 W CN2019085865 W CN 2019085865W WO 2020223901 A1 WO2020223901 A1 WO 2020223901A1
Authority
WO
WIPO (PCT)
Prior art keywords
target
index
block
databases
query
Prior art date
Application number
PCT/CN2019/085865
Other languages
English (en)
French (fr)
Inventor
周桢堡
Original Assignee
比特大陆科技有限公司
周桢堡
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 比特大陆科技有限公司, 周桢堡 filed Critical 比特大陆科技有限公司
Priority to PCT/CN2019/085865 priority Critical patent/WO2020223901A1/zh
Publication of WO2020223901A1 publication Critical patent/WO2020223901A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication

Definitions

  • Blockchain is a new application mode of computer technology such as distributed data storage, point-to-point transmission, consensus mechanism, encryption algorithm, etc. It is a kind of chain data structure that combines data blocks in sequence in a chronological order. It is non-tamperable and non-forgery guaranteed by cryptography, has the characteristics of decentralization, openness, and non-tamperable information, and can be widely used in a variety of IoT scenarios.
  • the embodiment of the present disclosure provides a method for querying data.
  • the method includes: providing a target query result corresponding to the target query condition based on a target database corresponding to a target query condition in a plurality of databases, wherein the target query condition corresponds to a region At least one characteristic value of the block.
  • the providing the target query result corresponding to the target query condition based on the target database corresponding to the target query condition in the multiple databases includes: obtaining the target query condition; determining the target query condition from the N databases Target database; from the target database, determine the target query result.
  • the block information in the above technical solution indicates the address of the block, and does not store all the data of the block.
  • the database used to provide the query result indicates the address of the storage block instead of the block itself. In this way, the size of the database can be effectively reduced, so that more databases for providing query results can be stored in an effective storage space.
  • the above technical solution can establish a corresponding index entry based on a block, so that it is convenient to find related information of the block based on the established index entry.
  • the above technical solution can establish a query database.
  • the query database can be used to find the database where the query results that need to be queried are stored. In this way, the search speed for searching block information can be accelerated.
  • the processing module is specifically configured to: obtain the target query condition; determine the target database from the N databases; determine the target query result from the target database.
  • the processing module is specifically configured to: determine the first target index value corresponding to the target query condition from the K index values included in the first query database, wherein the K index values and There is a one-to-one correspondence between K pieces of position information, each piece of the K pieces of position information is used to indicate the position of the corresponding index value in the N databases, and K is a positive integer greater than or equal to 1; according to the corresponding target The location information of the index value determines the target database from the N databases.
  • the processing module is further configured to determine the target index value corresponding to the target query condition from the K index values included in the first query database, according to the type of the target query condition , Determining the first query database from N query databases, where the N query databases are respectively used to determine the positions of the N types of query conditions in the N databases.
  • the processing module is specifically configured to: determine the target block according to the block information corresponding to the target index entry; according to preset conditions, determine at least one of the multiple feature values included in the target block A characteristic value is the target query result.
  • the processing module is specifically configured to create index entries in the multiple databases based on the target block.
  • the target block includes a plurality of characteristic values
  • the type of each characteristic value of the plurality of characteristic values is at least one of the N types
  • the plurality of characteristic values includes the N types of Feature values
  • N databases correspond to the N types in a one-to-one correspondence
  • the type of the feature values corresponding to any two index values in each of the N databases is the same
  • the N databases respectively store N index entries
  • Each of the N index entries includes at least one index value
  • the N index entries have a one-to-one correspondence with N sets of index feature values
  • each set of index feature values in the N sets of index feature values includes the multiple features
  • the N groups of index feature values correspond to the N types one-to-one
  • the type of feature value included in each group of index feature values in the N groups of index feature values corresponds to each group of index feature values type.
  • the processing module is also used to: determine the position of each index value in the N index entries in the N databases; and place each index value in the N index entries in the The positions in the N databases are stored in N query databases, where the N query databases correspond to the N index entries one-to-one, and each query database in the N query databases includes each of the corresponding index entries. Index values and the position of each index value in the N databases.
  • the embodiments of the present disclosure also provide a computer program product, the computer program product includes a computer program stored on a computer-readable storage medium, the computer program includes program instructions, when the program instructions are executed by a server, the server executes the foregoing The method of querying data.
  • Figure 1 is a schematic diagram of the operation of the blockchain.
  • Fig. 2 is a method for querying data according to an embodiment of the present disclosure.
  • FIG. 6 is a schematic structural block diagram of another server provided according to an embodiment of the present disclosure
  • FIG. 1 is a schematic diagram of the operation of the blockchain.
  • the network is characterized by decentralization.
  • the data exchange between each device in the blockchain network does not require mutual trust.
  • the operating rules of the entire blockchain network are open and transparent, and all data content is open, so it is within the scope of the rules of the blockchain network Within the time frame, devices cannot and cannot deceive other devices. Therefore, the blockchain network has the characteristic of trustlessness.
  • the total data block of the blockchain network is jointly maintained by all the equipment with maintenance functions in the entire system, and these equipment with maintenance functions can be participated by anyone.
  • the block header may include a block separator with a size of 4 bytes and a block size with a size of 4 bytes.
  • the block header can include the following information: the version number, usually 4 bytes; the parent block hash value, usually 32 bytes, used to refer to the hash value of the parent block in the blockchain; Merkel (Merkle) hash value, used to record the hash value of the Merkle tree root of the transaction in the block; timestamp, usually 4 bytes, used to identify the approximate time when the block was generated; a number used only once (number used once, Nonce, can also be called a random number), usually 4 bytes, used for proof of work algorithm.
  • the block body mainly includes transaction information.
  • the transaction information can include multiple transaction information.
  • the information of each transaction mainly includes: input information and output information.
  • Input information includes: version number, usually 4 bytes; input quantity, usually 1 to 9 bytes, used to record the input quantity of the transaction; reference transaction hash value, usually 32 bytes, used to reference the transaction The hash value of a certain input; the length of the unlocking script, usually 1 to 9 bytes, used to record the script for unlocking the Bitcoin transaction model.
  • Output information includes: output quantity, usually 1 to 9 bytes, used to record the output quantity of the transaction; digital voucher quantity, usually 8 bytes; lock script, used to use a certain output of the transaction and must be unlocked. script.
  • the block height can also be called the block height, the block height, etc.
  • the height of the first block (the genesis block) in the blockchain is 0, the height of the second block is 1, and so on.
  • the height of a certain block is 386357, which means that the longest chain block from the creation block to the current block is 386357+1.
  • the blockchain has a total of 386357+1 blocks from the creation block to the block. Therefore, the block height can be used to determine the position of the block in the blockchain.
  • a node in the blockchain network receives a block, it will dynamically identify the location of the block in the blockchain (ie, the block height).
  • Blockchain is a data structure linked by blocks in order from back to front. Each block points to the previous block. It can be stored as a file containing records of non-relative relationships or in a simple database.
  • the blockchain can be regarded as a stack, the height represents the distance between the block and the first block, and the top or the top represents the latest block.
  • Encrypting each block header (for example, secure hash algorithm (SHA)) can generate a hash value. Through this hash value, the corresponding block in the blockchain can be identified.
  • SHA secure hash algorithm
  • the embodiments of the present disclosure provide methods for querying data. More specifically, the method of querying data can be applied to query related information of a block.
  • the method for querying data provided by the embodiments of the present disclosure can provide a target query result corresponding to the target query condition based on a target database corresponding to a target query condition in multiple databases, wherein the target query condition corresponds to at least one feature of a block value.
  • the feature value of the block referred to in the embodiment of the present disclosure may be some information in the data structure of the block.
  • the information included in the data structure of the block as shown in Table 1.
  • the parent block hash value, timestamp, reference transaction hash value, public key data, etc.
  • a block can include multiple pieces of information. Therefore, the block can include multiple feature values.
  • the data structure of the block may also include other information, such as the hash value of the block, the height of the block, transaction information, and address information.
  • the above information (that is, the hash value of the block, the height of the block, transaction information and address information) may also be the characteristic value of the block.
  • the multiple feature values included in the block can be divided into N types, and N is a positive integer greater than or equal to 2.
  • Each characteristic value of the plurality of characteristic values may be at least one of N types.
  • the feature value of the block can be divided into three categories, the first type of feature value is some information related to the block header or the attribute of the block itself, and the second type of feature value is related to Some information related to the transaction information of the block, the third type of characteristic value may be some information related to the address.
  • this method of dividing characteristic value types is called the first method of dividing characteristic value types.
  • the first type feature value may include one or more of the following feature values: a timestamp used to identify the generation time of the block in the block header, the hash value of the block, and the zone The height of the block, the random number of the block (ie Nounce), the hash value of the parent block of the block, version information, the block size or the Merkle root hash value, etc.
  • the second type of feature value may include one or more of the following feature values: script public key (scripPubkey), public key hash value (pubkeyHash), public key type (pubkeyType) , Script signature (scripsig) or transaction amount, etc.
  • the third type of characteristic value may include one or more of the following characteristic values: public key hash value (pubkeyHash) or transaction hash value (txHash), etc.
  • the feature value of the block can be divided into three types according to the location of the feature value.
  • the first type of feature value is the information in the block header, and the second type of feature value is related to the block body.
  • the third type of feature value can be information that is not in the data structure of the block.
  • this method of dividing characteristic value types is referred to as the second method of dividing characteristic value types.
  • the first type of feature value may include one or more of the following feature values: a hash value of the parent block, a timestamp, or a random number.
  • the second type of feature value may include one or more of the following feature values: script public key (scripPubkey), public key hash value (pubkeyHash), public key type (pubkeyType), script signature (scripsig), or transaction amount, etc. .
  • the third type of feature value may include one or more of the following feature values: the hash value of the block or the height of the block.
  • the characteristic value may be divided according to whether the characteristic value is a hash value.
  • the feature values in the block can be divided into two types of feature values: the first type of feature value is the feature value of the hash value, and the second type of feature value is the feature value of the non-hash value.
  • this method of dividing characteristic value types is referred to as the third method of dividing characteristic value types.
  • the first type of characteristic value may include one or more of the following characteristic values: the hash value of the block, the hash value of the parent block, or the hash value of the public key.
  • the second type of feature value may include one or more of the following feature values: block height, timestamp or random number, etc.
  • one feature value in the block may be one type of feature value or multiple types of feature values.
  • the public key hash value (pubkeyHash) is the second type of feature value and also the third type of feature value.
  • the height of the block is only the first type of characteristic value.
  • one feature value in the block can only be classified as one type of feature value.
  • hash values such as the hash value of the block, the hash value of the parent block, etc.
  • non-hash values such as Block height, timestamp, etc.
  • the N databases are respectively used to provide query results for the N types of query conditions, where the type of the query condition is the same as the type of the feature value corresponding to the query condition.
  • the type of the query condition is the same as the type of the feature value corresponding to the query condition.
  • the query condition is a timestamp
  • the type of the query condition is the type of the timestamp, that is, the first type of feature value
  • the query condition is the height of the block
  • the type of query condition is the type of block height, that is, the first type of feature value
  • the query condition is public key hash value
  • the type of the query condition is the type of public key hash value, that is, the second type feature value
  • the third type of characteristic value is possible.
  • the providing the target query result corresponding to the target query condition based on the target database corresponding to the target query condition in the multiple databases may include: obtaining the target query condition; from the N databases Determine the target database in the database; determine the target query result from the target database.
  • Fig. 2 is a method for querying data according to an embodiment of the present disclosure.
  • the method shown in Figure 2 can be executed by a server.
  • the target query condition may be input by the user.
  • a user can log in to a blockchain browser through a terminal device (such as a mobile phone, computer, tablet, etc.), and enter the target query condition in the blockchain browser.
  • the terminal device will send the target query condition to the server.
  • the server can receive the target query condition sent by the terminal device.
  • the target query condition may be self-generated from another device and sent to the server.
  • the device or terminal device in the blockchain will generate the target query condition by itself in the process of transmitting the block or processing the digital certificate in the block, and send the target query condition to the server.
  • device A is processing a block with a block height of 15659
  • device A will generate a target query condition for querying the previous block of the block (that is, the block height is 15658).
  • the target query condition may be one or more values that are exactly the same as the feature value of the block.
  • the target query condition may be: 15658, which means that the block whose height is 15658 needs to be queried.
  • the target query condition can be 15658, 15659, and 15660, which means that three blocks with the height of 15658, 15659, and 15660 need to be queried.
  • the target query condition may be one or more values that are fuzzy matching with the feature value of the block.
  • the target query condition can be 156*8, where "*" represents any numerical value.
  • the target query condition is to query ten blocks with a height of 15608 to 15698.
  • the target query condition may be not exactly the same as the feature value of the block but can uniquely match the feature value of a block.
  • the target query condition may be a hash value omitting the first few 0s.
  • the target database corresponding to the target query condition can be determined directly according to the query database.
  • the determining the target database from the N databases may include: determining the first target index value corresponding to the target query condition from the K index values included in the first query database, wherein the K The index value has a one-to-one correspondence with K pieces of position information. Each piece of position information in the K pieces of position information is used to indicate the position of the corresponding index value in the N databases.
  • K is a positive integer greater than or equal to 1; Based on the position information of the target index value, the target database is determined from the N databases.
  • the first target index value corresponding to the target query condition may be exactly the same value as the target query condition.
  • the target query condition may be the height of a block, such as 15658.
  • the first target index value is also 15658.
  • the first target index value corresponding to the target query condition may be the same value as the part of the target query condition.
  • the target query condition may be a fuzzy value.
  • the target query condition is a value for the height of the query block, and the value is 156*8, where "*" represents any value.
  • the first target index value corresponding to the target query condition may be 15608 to 15698.
  • Figure 3 is a schematic diagram of the first query database.
  • the first query database includes multiple index entries, and each index entry includes one index value and one location information.
  • Height 1 represents the height of a block
  • Nnounce 1 represents the random number of a block
  • txHash 1 represents the transaction hash value of a block
  • PubkeyHash 1 represents the public key of a block. Hope value.
  • the height of the block represented by Height 1 is 15658.
  • the index value of 15658 is the first target index value corresponding to the target query condition.
  • the location information corresponding to the first target index value is database 1.
  • the target database corresponding to the target query condition among the N databases is database 1.
  • the content in the location information corresponding to the index value may be a database including the first target index value.
  • the location information in the query database shown in FIG. 3 only has database information.
  • the query database shown in FIG. 3 only indicates the database where the index value is located.
  • the content in the location information corresponding to the index value may include a specific location in the database in addition to database information.
  • the specific location may include the first target index value.
  • the location information corresponding to the first target index value 15658 is "database 1, 1566".
  • the index entry with the index value of 1556 in the database 1 contains an index value of 15658.
  • the specific location may contain a target query result corresponding to the target query condition.
  • the location information corresponding to the first target index value 15658 is "database 1, 1566".
  • the index entry with the index value of 1556 in the database 1 contains the target query result corresponding to the target query condition.
  • the query database used to determine the target query condition may include N.
  • the query database including the location information of the target database may be determined first, and then the query database Determine the target database in the database.
  • the method may further include: determining the target query condition according to the feature value type corresponding to the target query condition According to the type of the target query condition, the first query database is determined from N query databases, where the N query databases are respectively used to determine the positions of the N types of query conditions in the N databases.
  • the value of N is 3, the type used to determine the target query condition in the three query databases is the target database corresponding to the first type of feature value, and the type of target query condition Is the target database corresponding to the second type of feature value, and the target query condition is the target database corresponding to the third type of feature value.
  • the target query condition is the height of the block
  • the target database corresponding to the target query condition can be determined from the query database 1.
  • the target query condition is a script public key
  • the target database corresponding to the target query condition can be determined from the query data block 2.
  • the target query condition is a transaction hash value
  • the target database corresponding to the target query condition can be determined from the query database 3.
  • determining the target database from N databases includes: determining the type of the target query condition according to the type of the feature value corresponding to the target query condition; and according to the type of the target query condition, Determine the target database from the N databases.
  • the type of the target query condition may be determined according to the content of the target query condition.
  • the type of the target query condition can be determined according to the length or format of the target query condition.
  • the feature value corresponding to the target query condition can also be acquired.
  • the characteristic value corresponding to the target query condition For example, the user can select the height of the block after inputting 15658.
  • the target query condition is the height of the query block, so it can be determined that the type of the target query condition is the first type feature value.
  • the target database includes M index entries, each of the M index entries includes at least one index value, and the M index entries are one-to-one with M pieces of block information.
  • the determining the target query result from the target database includes: determining a target index entry from the M index entries, the target index entry includes a second target index value corresponding to the target query condition; according to the target index entry corresponding Block information to determine the target query result.
  • the second target index value corresponding to the target query condition may be exactly the same value as the target query condition.
  • the target query condition may be the height of a block, such as 15658.
  • the second target index value is also 15658.
  • the second target index value corresponding to the target query condition may be part of the same value as the target query condition.
  • the target query condition may be a fuzzy value.
  • the target query condition is a value for the height of the query block, and the value is 156*8, where "*" represents any value.
  • the second target index value corresponding to the target query condition may be 15608 to 15698.
  • each of the M index entries may include multiple index values, and the multiple index values are characteristic values of the same block.
  • the block information corresponding to the target index entry may be all or part of the index value included in the target factor entry.
  • Table 2 is an illustration of index entries.
  • Table 2 shows three index entries. As shown in Table 2, each index entry can include three index values, which are the height of the block, the random number and the hash value of the parent block. For ease of description, the height of a block is represented by Height in Table 2. , Nnounce represents the random number of the block, PreHash represents the hash value of the parent block of the block.
  • each of the M index entries may include multiple index values and one address.
  • the multiple index values are characteristic values of the same block.
  • the address is the block information corresponding to the target index entry.
  • the block information in the M index entries is used to indicate an address.
  • determining the target query result according to the block information corresponding to the target index entry may include: determining the target block according to the block information corresponding to the target index entry; and determining the target area according to a preset condition At least one of the multiple feature values included in the block is the target query result.
  • Table 3 is an illustration of index entries.
  • Nnounce 2 is the random number of block 2
  • PreHash 2 is the hash value of the parent block of block 2
  • Height 3 is the block height of block 3
  • Nnounce 3 is the random number of block 3
  • PreHash 3 is the block The hash value of the parent block of block 3.
  • the block information in the index entry with the index value of 1556 in Table 4 is the block information corresponding to the target query condition.
  • the target query result corresponding to the target query condition may be all or part of the information in the block information.
  • searching for the target query result corresponding to the target query condition as shown in FIG. 2 can be implemented by using a full-text index/search engine (Lucene).
  • a full-text index/search engine (Lucene).
  • it can be implemented using elasticsearch or Apache Solr.
  • the providing a target query result corresponding to the target query condition based on the target database corresponding to the target query condition in the multiple databases includes: establishing the target database in the multiple databases based on the target block Index entry.
  • some related information of the block may not be stored in the data structure of the block as shown in Table 1.
  • the only relevant information not stored in the data structure of the block is the hash of the block and the height of the block.
  • the block file, the hash value of the block, and the height of the block are collectively referred to as block related information below.
  • the block related information obtained by traversal can be stored in a multi-level cache.
  • the multi-level cache includes a three-level cache
  • the first-level cache can only store a small amount of block-related information, such as five million pieces of block-related information;
  • the second-level cache can store more block-related information, such as four
  • the third level cache can store all the block related information traversed.
  • the block related information saved in the first level cache can be the latest block related information traversed.
  • the block-related information stored in the secondary cache may be block-related information traversed earlier.
  • the second-level cache can use a Key-Value database (for example, using Redis) to store block-related information, or a distributed cache system (for example, memcache) storage area Related Information.
  • the third-level cache can use Key-Value databases (for example, RocksDB, LevelDB, etc.) to store block-related information.
  • the target block is any one of all the blocks that need to be processed.
  • the target block includes a plurality of characteristic values, and the type of each characteristic value of the plurality of characteristic values is at least one of the N types, and the plurality of characteristic values includes the characteristic values of the N types.
  • the N databases have a one-to-one correspondence with the N types, and the feature values corresponding to any two index values in each of the N databases are of the same type.
  • the N databases respectively store N index entries.
  • Each index bar in the index entries includes at least one index value
  • the N index entries correspond to N groups of index feature values one-to-one
  • each group of index feature values in the N groups of index feature values includes the multiple features At least one feature value in the value
  • the N groups of index feature values correspond to the N types in a one-to-one correspondence
  • the feature value types included in each group of index feature values in the N groups of index feature values are corresponding to each group of index feature values Types of.
  • the index entry established based on the target block can be applied to the method for querying data as shown in FIG. 2. Therefore, the target block has the same characteristics as the block provided by the N databases for query services. In other words, if the target query condition in the method for querying data shown in FIG. 2 is a feature value of the target block stored in the N databases, it can be determined from the N databases corresponding to the target Related information of the target block of the query condition.
  • Fig. 4 is a schematic flowchart of a method for establishing an index entry provided according to an embodiment of the present disclosure.
  • obtaining the target block includes obtaining block-related information of the target block.
  • the block-related information of the target block can be obtained from the above-mentioned multi-level cache.
  • the block-related information of the target block is searched from the second-level cache; if the second-level cache If the block related information of the target block is still not included in the target block, the block related information of the target block is obtained from the third-level cache.
  • the index entry is determined according to the third set of index feature values, and the index entry includes the public key hash value (pubkeyHash 1) of the target block and the transaction hash value (txHash) of the target block.
  • the first row of index entries can be saved in database 1
  • the second row of index entries can be saved in database 2
  • the third row of index entries can be saved in database 3. .
  • an index entry based on the target block can be established.
  • the establishment of the N databases can be completed.
  • database 1 can include multiple index entries, and each index entry can include a block timestamp and block The desired value, the height of the block and the random number;
  • database 2 can include multiple index entries, and each index entry can include a block’s script public key, public key hash value, and public key type;
  • database 3 can include multiple Index entries, each index entry can include a block’s public key hash value and transaction hash value.
  • the operations of determining N sets of index feature values, determining N index entries, and storing N index entries in N databases may be asynchronous.
  • the index feature values of the first group can be determined according to the first group of index feature values without waiting for the determination of the index feature values.
  • the index entry of the first set of index feature values can be written into the corresponding database without waiting for the second and/or third index entry to be determined.
  • the processing module 510 is configured to provide a target query result corresponding to the target query condition based on the target database corresponding to the target query condition in the multiple databases, wherein the target query condition corresponds to at least one feature value of the block.
  • the block includes a plurality of characteristic values, the type of each characteristic value in the plurality of characteristic values is at least one of N types, and N is a positive integer greater than or equal to 2, and the N databases are respectively used To provide query results for the N types of query conditions, where the type of the query condition is the same as the type of the feature value corresponding to the query condition.
  • the processing module 510 is specifically configured to: obtain the target query condition; determine the target database from the N databases; determine the target query result from the target database.
  • the processing module 510 is further configured to determine the target index value corresponding to the target query condition from among the K index values included in the first query database, according to the type of the target query condition, from N
  • the first query database is determined in two query databases, and the N query databases are respectively used to determine the positions of the N types of query conditions in the N databases.
  • the processing module 510 is specifically configured to determine the type of the target query condition according to the type of the characteristic value corresponding to the target query condition; and determine the target database from the N databases according to the type of the target query condition.
  • the target database includes M index entries, each of the M index entries includes at least one index value, and the M index entries correspond to M pieces of block information one-to-one.
  • the processing module 510 It is specifically used to determine a target index entry from the M index entries, where the target index entry includes a second target index value corresponding to the target query condition; determine the target query according to the block information corresponding to the target index entry result.
  • the processing module 510 is specifically configured to: determine the target block according to the block information corresponding to the target index entry; determine at least one characteristic value among the multiple characteristic values included in the target block according to a preset condition Query results for the target.
  • the processing module 510 is specifically configured to create index entries in the multiple databases based on the target block.
  • the target block includes a plurality of characteristic values
  • the type of each characteristic value of the plurality of characteristic values is at least one of the N types
  • the plurality of characteristic values includes the N types of characteristic values
  • N databases correspond to the N types in a one-to-one relationship
  • the feature values corresponding to any two index values in each of the N databases are of the same type.
  • the N databases store N index entries respectively, and the N Each index entry in the index entries includes at least one index value, and the N index entries correspond to N sets of index feature values one-to-one, and each set of index feature values in the N sets of index feature values includes one of the plurality of feature values.
  • the N groups of index feature values correspond to the N types in a one-to-one correspondence
  • the type of the feature value included in each group of index feature values in the N groups of index feature values is the type corresponding to each group of index feature values.
  • the processing module 510 is specifically configured to: obtain the target block; determine N sets of index feature values from the multiple feature values; determine the N index entries according to the N sets of index feature values; Each index entry is stored in the N databases.
  • the processing module 510 is further configured to: determine the position of each index value in the N index entries in the N databases; and store each index value in the N index entries in the N databases The position in is stored in N query databases, where the N query databases correspond to the N index entries one-to-one, and each query database in the N query databases includes each index value in the corresponding index entry And the position of each index value in the N databases.
  • the aforementioned database, query database and/or block can be stored in a storage module provided in the server.
  • the aforementioned database, query database and/or block may also be stored in one or more dedicated storage devices independent of the server.
  • the server can access the dedicated storage device, obtain the corresponding database, query the database and/or block and other information.
  • the embodiment of the present disclosure also provides a computer-readable storage medium that stores computer-executable instructions, and the computer-executable instructions are configured to execute the aforementioned method of querying data.
  • the embodiments of the present disclosure also provide a computer program product, the computer program product includes a computer program stored on a computer-readable storage medium, the computer program includes program instructions, when the program instructions are executed by a server, the server executes the foregoing The method of querying data.
  • the embodiment of the present disclosure also provides a server, the structure of which is shown in FIG. 6, and the server 600 includes:
  • At least one processor (processor) 610 one processor 610 is taken as an example in FIG. 6; and a memory (memory) 620, which may also include a communication interface (Communication Interface) 630 and a bus 640. Among them, the processor 610, the communication interface 630, and the memory 620 can communicate with each other through the bus 640. The communication interface 630 can be used for information transmission. The processor 610 may call the logical instructions in the memory 620 to execute the data query method of the foregoing embodiment.
  • processor 610 may call the logical instructions in the memory 620 to execute the data query method of the foregoing embodiment.
  • the above-mentioned logical instructions in the memory 620 can be implemented in the form of a software functional unit and when sold or used as an independent product, they can be stored in a computer readable storage medium.
  • the memory 620 can be used to store software programs and computer-executable programs, such as program instructions/modules corresponding to the methods in the embodiments of the present disclosure.
  • the processor 610 executes functional applications and data processing by running software programs, instructions, and modules stored in the memory 620, that is, implements the method for querying data in the foregoing method embodiment.
  • the memory 620 may include a program storage area and a data storage area.
  • the program storage area may store an operating system and an application program required by at least one function; the data storage area may store data created according to the use of the terminal device, and the like.
  • the memory 620 may include a high-speed random access memory, and may also include a non-volatile memory.
  • the technical solutions of the embodiments of the present disclosure can be embodied in the form of a software product.
  • the computer software product is stored in a storage medium and includes one or more instructions to enable a computer device (which can be a personal computer, a server, or a network). Equipment, etc.) execute all or part of the steps of the method described in the embodiments of the present disclosure.
  • the aforementioned storage medium may be a non-transitory storage medium, including: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disk or optical disk, etc.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本申请提供了一种查询数据的方法、服务器、计算机可读存储介质和计算机程序产品,该方法包括:基于多个数据库中与目标查询条件对应的目标数据库,提供对应于该目标查询条件的目标查询结果,其中该目标查询条件对应于区块的至少一个特征值。上述技术方案可以提高区块链信息的查询速度,并且可以同时为更多的查询条件提供对应的查询结果。

Description

查询数据的方法和服务器 技术领域
本申请涉及信息技术领域,更具体地,涉及查询数据的方法和服务器。
背景技术
区块链是分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式,是一种按照时间顺序将数据区块以顺序相连的方式组合成的一种链式数据结构,并以密码学方式保证的不可篡改和不可伪造,具有去中心化、开放性、信息不可篡改等特征,可广泛应用于多种物联网场景。
区块链是由区块组成的。用户可以通过区块链浏览器查询区块的相关信息。区块链浏览器可以用来检索查询每个区块所记载的所有内容。区块链浏览器主要通过直接调用远程过程调用协议(remote procedure call,RPC)接口进行查询,然后将查询到的信息展示给用户。然而,RPC接口的扩展性不好,当用户请求量大时,RPC接口无法抵抗用户请求大的压力。因此,在区块链信息查询方面仍有进一步提升的空间。
发明内容
本公开实施例提供一种查询数据的方法,该方法包括:基于多个数据库中与目标查询条件对应的目标数据库,提供对应于该目标查询条件的目标查询结果,其中该目标查询条件对应于区块的至少一个特征值。
利用对应于目标查询条件的目标数据库为目标查询条件提供查询结果,可以提高区块链信息的查询速度。此外,查询对应于该目标查询条件的目标查询结果可以只使用该目标数据库,而不需要使用除该目标数据库以外其他数据库。与目前的技术方案相比,需要查找的数据量相应减少了,相应的,需要用于查询一个查询结果的运算资源降低了。因此,在总的用于查询区块链的运算资源不变的情况下,利用上述技术方案可以同时为更多的查询条件提供对应的查询结果。
在某些实现方式中,该区块包括多个特征值,该多个特征值中的每个特 征值的类型为N个类型中的至少一个,N为大于或等于2的正整数,N个数据库分别用于为该N个类型的查询条件提供查询结果,其中该查询条件的类型与该查询条件对应的特征值的类型相同。
N个数据库可以分别为N个类型的查询条件提供查询结果。这样,在查询区块信息时,可以根据查询条件的类型选择对应的数据库,从而提高区块链信息的查询速度。
在某些实现方式中,该基于多个数据库中与目标查询条件对应的目标数据库,提供对应于该目标查询条件的目标查询结果,包括:获取该目标查询条件;从该N个数据库中确定该目标数据库;从该目标数据库中,确定该目标查询结果。
上述技术方案中的目标数据库可以提供的查询结果是该目标查询条件的类型的查询结果。换句话说,该目标数据库是一个专用的数据库,该数据库为类型与该目标查询条件的类型相同的查询条件提供查询结果。通过使用专用的数据库查询与该目标查询条件对应的目标查询结果,可以快速提高区块链信息的查询速度。
在某些实现方式中,该从该N个数据库中确定该目标数据库,包括:从第一查询数据库中包括的K个索引值中,确定对应于该目标查询条件的第一目标索引值,其中该K个索引值与K个位置信息一一对应,该K个位置信息中的每个位置信息用于指示对应的索引值在该N个数据库中的位置,K为大于或等于1的正整数;根据对应于该目标索引值的位置信息,从该N个数据库中确定该目标数据库。
利用该第一查询数据库可以更快的确定该目标数据库,从而进一步加速查找到该目标查询结果的查询速度。
在某些实现方式中,在该从第一查询数据库中包括的K个索引值中,确定对应于该目标查询条件的目标索引值之前,该方法还包括:根据该目标查询条件对应的特征值的类型,确定该目标查询条件的类型;根据该目标查询条件的类型,从N个查询数据库中确定该第一查询数据库,其中该N个查询数据库分别用于确定该N种类型的查询条件在该N个数据库中的位置。
上述技术方案中,由于不同的查询条件的类型对应的查询数据库也可以是不同的。因此,可以使用与该目标查询条件的类型对应的查询数据库确定 该目标数据库。这样,在确定该目标数据库的过程中需要查找的数据量降低了,从而可以更进一步提高查询速度。此外,由于需要查找的数量降低,对于运算资源的要求也降低了。因此,可以同时为更多的查询条件提供对应的查询结果。
在某些实现方式中,该从该N个数据库中确定该目标数据库,包括:根据该目标查询条件对应的特征值的类型,确定该目标查询条件的类型;根据该目标查询条件的类型,从该N个数据库中确定该目标数据库。
通过上述技术方案可以直接利用该目标查询条件确定该目标数据库。换句话说,上述技术方案无需通过查询数据库来确定该目标数据库。在此情况下,服务器中可以不需要保存该查询数据库。这样可以节省该服务器的存储资源。
在某些实现方式中,该目标数据库中包括M个索引条目,该M个索引条目中的每个索引条目包括至少一个索引值,该M个索引条目与M个区块信息一一对应,该从该目标数据库中,确定该目标查询结果,包括:从该M个索引条目中,确定目标索引条目,其中该目标索引条目包括对应于该目标查询条件的第二目标索引值;根据该目标索引条目对应的区块信息,确定该目标查询结果。
在某些实现方式中,该M个区块信息中的每个区块信息用于指示一个区块的地址,该根据该目标索引条目对应的区块信息,确定该目标查询结果,包括:根据该目标索引条目对应的区块信息,确定目标区块;根据预设条件,确定该目标区块包括的多个特征值中的至少一个特征值为该目标查询结果。
上述技术方案中的区块信息指示的是区块的地址,而并非保存的是区块的全部数据。换句话说,用于提供查询结果的数据库中指示保存区块的地址而非区块本身。这样,可以有效降低该数据库的大小,从而可以使得在有效的存储空间中保存更多的用于提供查询结果的数据库。
在某些实现方式中,该基于多个数据库中与目标查询条件对应的目标数据库,提供对应于该目标查询条件的目标查询结果,包括:基于目标区块,建立该多个数据库中的索引条目。
上述技术方案可以基于区块建立对应的索引条目,从而便于基于所建立的索引条目查找的该区块的相关信息。
在某些实现方式中,该目标区块包括多个特征值,该多个特征值中的每个特征值的类型为N个类型中的至少一个,该多个特征值包括该N个类型的特征值,N个数据库与该N个类型一一对应,该N个数据库中的每个数据库中的任意两个索引值对应的特征值的类型相同,该N个数据库分别保存N个索引条目,该N个索引条目中的每个索引条目包括至少一个索引值,该N个索引条目与N组索引特征值一一对应,该N组索引特征值中的每组索引特征值包括该多个特征值中的至少一个特征值,该N组索引特征值与该N个类型一一对应,该N组索引特征值中的每组索引特征值包括的特征值的类型为该每组索引特征值对应的类型。
在某些实现方式中,该基于目标区块,建立该多个数据库中的索引条目,包括:获取该目标区块;从该多个特征值中确定N组索引特征值;根据该N组索引特征值,确定该N个索引条目;将该N个索引条目分别保存至该N个数据库中。
通过上述技术方案,该目标区块中的特征值所对应的不同类型的索引条目保存在不同的数据库中。这样,在查询该目标区块时,可以基于查询条件确定对应的数据库,从而可以加快查找区块信息的查找速度。
在某些实现方式中,该方法还包括:确定该N个索引条目中的每个索引值在该N个数据库中的位置;将该N个索引条目中的每个索引值在该N个数据库中的位置保存至N个查询数据库中,其中该N个查询数据库与该N个索引条目一一对应,该N个查询数据库中的每个查询数据库中包括对应的索引条目中的每个索引值以及该每个索引值在该N个数据库中的位置。
上述技术方案可以建立查询数据库。利用该查询数据库可以查找保存需要查询的查询结果所在的数据库。这样,可以加速查找区块信息的查找速度。
本公开实施例还提供一种服务器,该服务器包括:处理模块,用于基于多个数据库中与目标查询条件对应的目标数据库,提供对应于该目标查询条件的目标查询结果,其中该目标查询条件对应于区块的至少一个特征值。
在某些实现方式中,该区块包括多个特征值,该多个特征值中的每个特征值的类型为N个类型中的至少一个,N为大于或等于2的正整数,N个数据库分别用于为该N个类型的查询条件提供查询结果,其中该查询条件的类型与该查询条件对应的特征值的类型相同。
在某些实现方式中,该处理模块,具体用于:获取该目标查询条件;从该N个数据库中确定该目标数据库;从该目标数据库中,确定该目标查询结果。
在某些实现方式中,该处理模块,具体用于:从第一查询数据库中包括的K个索引值中,确定对应于该目标查询条件的第一目标索引值,其中该K个索引值与K个位置信息一一对应,该K个位置信息中的每个位置信息用于指示对应的索引值在该N个数据库中的位置,K为大于或等于1的正整数;根据对应于该目标索引值的位置信息,从该N个数据库中确定该目标数据库。
在某些实现方式中,该处理模块,还用于在从该第一查询数据库中包括的K个索引值中,确定对应于该目标查询条件的目标索引值之前,根据该目标查询条件的类型,从N个查询数据库中确定该第一查询数据库,其中该N个查询数据库分别用于确定该N种类型的查询条件在该N个数据库中的位置。
在某些实现方式中,该处理模块,具体用于根据该目标查询条件对应的特征值的类型,确定该目标查询条件的类型;根据该目标查询条件的类型,从该N个数据库中确定该目标数据库。
在某些实现方式中,该目标数据库中包括M个索引条目,该M个索引条目中的每个索引条目包括至少一个索引值,该M个索引条目与M个区块信息一一对应,该处理模块,具体用于从该M个索引条目中,确定目标索引条目,其中该目标索引条目包括对应于该目标查询条件的第二目标索引值;根据该目标索引条目对应的区块信息,确定该目标查询结果。
在某些实现方式中,该处理模块,具体用于:根据该目标索引条目对应的区块信息,确定目标区块;根据预设条件,确定该目标区块包括的多个特征值中的至少一个特征值为该目标查询结果。
在某些实现方式中,该处理模块,具体用于基于目标区块,建立该多个数据库中的索引条目。
在某些实现方式中,该目标区块包括多个特征值,该多个特征值中的每个特征值的类型为N个类型中的至少一个,该多个特征值包括该N个类型的特征值,N个数据库与该N个类型一一对应,该N个数据库中的每个数据库中的任意两个索引值对应的特征值的类型相同,该N个数据库分别保存N个 索引条目,该N个索引条目中的每个索引条目包括至少一个索引值,该N个索引条目与N组索引特征值一一对应,该N组索引特征值中的每组索引特征值包括该多个特征值中的至少一个特征值,该N组索引特征值与该N个类型一一对应,该N组索引特征值中的每组索引特征值包括的特征值的类型为该每组索引特征值对应的类型。
在某些实现方式中,该处理模块,具体用于:获取该目标区块;从该多个特征值中确定N组索引特征值;根据该N组索引特征值,确定该N个索引条目;将该N个索引条目分别保存至该N个数据库中。
在某些实现方式中,该处理模块,还用于:确定该N个索引条目中的每个索引值在该N个数据库中的位置;将该N个索引条目中的每个索引值在该N个数据库中的位置保存至N个查询数据库中,其中该N个查询数据库与该N个索引条目一一对应,该N个查询数据库中的每个查询数据库中包括对应的索引条目中的每个索引值以及该每个索引值在该N个数据库中的位置。
本公开实施例还提供一种服务器,包括:至少一个处理器;以及与该至少一个处理器通信连接的存储器;其中,该存储器存储有可被该至少一个处理器执行的指令,该指令被该至少一个处理器执行时,使该至少一个处理器执行上述查询数据的方法。
本公开实施例还提供一种计算机可读存储介质,存储有计算机可执行指令,该计算机可执行指令设置为执行上述查询数据的方法。
本公开实施例还提供一种计算机程序产品,该计算机程序产品包括存储在计算机可读存储介质上的计算机程序,该计算机程序包括程序指令,当该程序指令被服务器执行时,使该服务器执行上述查询数据的方法。
附图说明
图1是区块链的运行原理图。
图2是根据本公开实施例提供的一种查询数据的方法。
图3是一个第一查询数据库的示意图。
图4是根据本公开实施例提供的建立索引条目的方法的示意性流程图。
图5是根据本公开实施例提供的服务器的示意性结构框图。
图6是根据本公开实施例提供的另一服务器的示意性结构框图
具体实施方式
为了能够更加详尽地了解本公开实施例的特点与技术内容,下面结合附图对本公开实施例的实现进行详细阐述,所附附图仅供参考说明之用,并非用来限定本公开实施例。在以下的技术描述中,为方便解释起见,通过多个细节以提供对所披露实施例的充分理解。然而,在没有这些细节的情况下,一个或多个实施例仍然可以实施。在其它情况下,为简化附图,熟知的结构和装置可以简化展示。
本公开实施例中所称的至少一个可以是一个或者多个,多个是指两个或者两个以上。本公开实施例中所称的A、B或C中的至少一个,或者类似的表述,例如包括以下中的一个或多个:A、B或者C,又如,A、B和/或C,可以包括以下任意组合:A、B、C中的一个;A、B、C中的两个;A、B、C中的全部。A、B、C可以是单个,也可以是多个。另外,除非特殊说明,本公开实施例中所称的“第一”、“第二”等描述并不对执行顺序、先后顺序和数量进行限定。
为了方便理解本公开实施例,在描述本公开实施例的方法之前,首先在此具体介绍一下区块链网络、区块链网络中的几个要素以及区块链网络中的设备。
图1是区块链的运行原理图。区块链网络中没有中心化的硬件或者管理机构,任意设备之间的权利和义务都是均等的,且任意设备的损坏或者丢失都不影响整个区块链网络的运作,因此,区块链网络具有去中心化的特点。区块链网络中的每个设备之间进行数据交换是无需互相信任的,整个区块链网络的运作规则是公开透明的,所有的数据内容是公开的,因此在区块链网络的规则范围和时间范围内,设备之间是不能也无法欺骗其他设备的,因此,区块链网络具有去信任的特征。区块链网络总的数据区块由整个系统中所有具有维护功能的设备共同维护,而这些具有维护功能的设备是任何人都可以参与的,因此,区块链网络具有集体维护的特征。区块链网络通过分数据库的形式,让每个参与设备都能获得一份完整数据库的拷贝。除非能够同时控制整个网络中超过51%的设备,否则单个设备上对数据库的修改时无效的,也无法影响其他设备上的数据内容。因此,区块链网络具有可靠的数据库。
区块,是一个被包含在区块链中的聚合了数据的容器数据结构,它由区 块头和区块体组成。
表1是一个区块的数据结构的示意图。表1示出了区块的数据结构中所包括的信息。区块的数据结构也可以称为区块存储文件、区块文件等。
如表1所示,区块头之前可以包括大小为4字节的区块分隔符和大小为4字节的区块大小。
区块头可以包括以下信息:版本号,通常为4字节;父区块哈希值,通常为32字节,用于引用区块链中父区块的哈希(hash)值;梅克尔(Merkle)哈希值,用于记录该区块中交易的Merkle树根的哈希值;时间戳,通常为4字节,用于标识区块产生的近似时间;只使用一次的数字(number used once,Nonce,也可以称为随机数),通常为4字节,用于工作量证明算法。
区块体中主要包括交易信息。交易信息中可以包括多个交易的的信息。每个交易的信息中主要包括:输入信息和输出信息。输入信息包括:版本号,通常为4字节;输入数量,通常为1至9字节,用于记录该交易的输入数量;引用交易哈希值,通常为32字节,用于引用该交易某一输入的哈希值;解锁脚本长度,通常为1至9字节,用于记录解锁比特币交易模型的脚本。输出信息包括:输出数量,通常为1至9字节,用于记录该交易的输出数量;数字凭证数量,通常为8字节;锁定脚本,用于使用该交易某一输出而必须解锁的锁定脚本。
表1
Figure PCTCN2019085865-appb-000001
Figure PCTCN2019085865-appb-000002
可以理解的是,如表1所示的区块的数据结构只是为了帮助本领域技术人员理解区块的含义所列出的一种常见的区块的数据结构。不同类型的区块的数据结构可能并不相同。本公开实施例对区块的具体数据结构并不限定。换句话说,本公开实施例除了可以应用到如表1所示的区块外,还可以应用到其他类型的区块中。
此外,区块的一些相关信息可以不保存在如表1所示的数据结构中。例如,区块的哈希值、区块高度(height)等。以区块高度为例,区块高度也可以称为块的高度,区块的高度等。区块链中的第一个区块(即创世区块)的高度为0,第二个区块的高度为1,以此类推。例如,某一个区块的高度为386357,意味着从创世区块到当前的这个区块最长的链条区块数为386357+1个。换句话说,该区块链从创世区块到该区块为止共有386357+1个区块。因此,区块高度可以用于确定该区块在区块链中的位置。区块链网络中的节点在接收到区块时会动态地识别该区块在区块链中的位置(即区块高度)。
区块链,是由区块从后向前有序链接起来的数据结构,每个区块都指向前一个区块。它可以被存储为一种包含非相对关系记录的文件,或是存储在一个简单的数据库中。可以将区块链看成一个堆栈,高度就表示区块与首区块之间的距离,以及顶部或顶端表示最新的区块。对每个区块头进行加密哈(例如,安全散列算法(secure hash algorithm,SHA)),可生成一个哈希值。通过这个哈希值可以识别区块链中的对应区块。
本公开实施例提供查询数据的方法。更具体地,该查询数据的方法可以应用到查询区块的相关信息。本公开实施例提供的查询数据的方法可以基于多个数据库中与目标查询条件对应的目标数据库,提供对应于该目标查询条件的目标查询结果,其中该目标查询条件对应于区块的至少一个特征值。
本公开实施例中所称的区块的特征值可以是区块的数据结构中的一些信息。例如,如表1所示的区块的数据结构中包括的信息。例如,父区块哈希值、时间戳、引用交易哈希值、公钥数据等。如表1所示,区块中可以包括多个信息。因此,区块可以包括多个特征值。此外,区块的数据结构中除了如表1中所示的信息外,还可以包括其他信息,例如区块的哈希值,区块的高度、交易信息和地址信息等。上述信息(即区块的哈希值、区块的高度、交易信息和地址信息)也可以是区块的特征值。
区块中包括的多个特征值可以划分为N个类型,N为大于或等于2的正整数。该多个特征值中的每个特征值可以是N个类型中的至少一个。
可选的,在一些实施例中,区块的特征值可以被划分为三类,第一类特征值是与区块头相关或者区块本身的属性相关的一些信息,第二类特征值是与区块的交易信息相关的一些信息,第三类特征值可以是与地址相关的一些 信息。为便于描述以下称这种划分特征值类型的方式为第一种划分特征值类型的方式。可选的,在一些实施例中,该第一类特征值可以包括以下特征值中的一个或多个:区块头中用于标识区块产生时间的时间戳、区块的哈希值、区块的高度、区块的随机数(即Nounce)、区块的父区块的哈希值、版本信息、区块大小或者Merkle根哈希值等。可选的,在一些实施例中,该第二类特征值可以包括以下特征值中的一个或多个:脚本公钥(scripPubkey)、公钥哈希值(pubkeyHash)、公钥类型(pubkeyType)、脚本签名(scripsig)或者交易金额等。可选的,在一些实施例中,该第三类特征值可以包括以下特征值中的一个或多个:公钥哈希值(pubkeyHash)或交易哈希值(txHash)等。
可选的,在另一些实施例中,区块的特征值可以按照特征值所在的位置被划分为三类,第一类特征值是区块头中信息,第二类特征值是与区块体中的信息,第三类特征值可以是不在区块的数据结构中的信息。为便于描述以下称这种划分特征值类型的方式为第二种划分特征值类型的方式。例如,该第一类特征值可以包括以下特征值中的一个或多个:父区块哈希值、时间戳或随机数等。该第二类特征值可以包括以下特征值中的一个或多个:脚本公钥(scripPubkey)、公钥哈希值(pubkeyHash)、公钥类型(pubkeyType)、脚本签名(scripsig)或者交易金额等。该第三类特征值可以包括以下特征值中的一个或多个:区块的哈希值或者区块的高度。
可选的,在另一些实施例中,可以根据特征值是否是哈希值划分特征值。在此情况下,区块中的特征值可以被划分为两种类型的特征值:第一类特征值是哈希值的特征值,第二类特征值是非哈希值的特征值。为便于描述以下称这种划分特征值类型的方式为第三种划分特征值类型的方式。例如,该第一类特征值可以包括以下特征值中的一个或多个:区块的哈希值、父区块的哈希值或公钥哈希值等。该第二类特征值可以包括以下特征值中的一个或多个:区块的高度、时间戳或随机数等。
可以理解的是,除了上述三种特征值类型的划分方式外,还可以包括其他特征值类型的划分方式,在此就不一一列举。
可选的,在一些实施例中,区块中的一个特征值可以是一种类型的特征值,也可以是多种类型的特征值。例如,在上述第一种划分特征值类型的方式中,公钥哈希值(pubkeyHash)是第二类特征值,也是第三类特征值。区 块的高度仅是第一类特征值。
可选的,在另一些实施例中,区块中的一个特征值仅能被划归为一种类型的特征值。例如,在上述第三种划分特征值类型的方式中,哈希值(例如区块的哈希值、父区块的哈希值等)仅是第一类特征值,非哈希值(例如区块的高度、时间戳等)仅是第二类特征值。
N个数据库分别用于为该N个类型的查询条件提供查询结果,其中该查询条件的类型与查询条件对应的特征值的类型相同。以第一种划分特征值类型的方式为例,若查询条件是时间戳,则该查询条件的类型就是时间戳的类型,即第一类特征值;若查询条件是区块的高度,则该查询条件的类型就是区块的高度的类型,即第一类特征值;若查询条件是公钥哈希值,则该查询条件的类型就是公钥哈希值的类型,即第二类特征值和第三类特征值。
可选的,在一些实施例中,该基于多个数据库中与目标查询条件对应的目标数据库,提供对应于该目标查询条件的目标查询结果可以包括:获取该目标查询条件;从该N个数据库中确定该目标数据库;从该目标数据库中确定该目标查询结果。
下面将结合图2对如何查询该目标查询结果进行描述。
图2是根据本公开实施例提供的一种查询数据的方法。图2所示的方法可以由服务器执行。
201,获取目标查询条件。
可选的,在一些实施例中,该目标查询条件可以是用户输入的。例如,用户可以通过终端设备(例如移动电话、计算机、平板电脑等)登陆区块链浏览器,在区块链浏览器中输入该目标查询条件。该终端设备会将该目标查询条件发送至该服务器。换句话说,该服务器可以接收该终端设备发送的该目标查询条件。
可选的,在另一些实施例中,该目标查询条件可以是从其他设备自行生成并发送至该服务器中的。例如,区块链中的设备或者终端设备在传输区块或者对区块中的数字凭证进行处理的过程中会自行生成该目标查询条件,并将该目标查询条件发送至该服务器。例如,设备A在处理区块的高度为15659的区块,设备A会生成用于查询该区块的前一区块(即区块的高度为15658)的目标查询条件。
可选的,在一些实施例中,该目标查询条件可以是与区块的特征值完全相同的一个或多个值。例如,该目标查询条件可以是:15658,即表示需要查询区块的高度为15658的区块。又如,该目标查询条件可以是15658,15659,15660,即表示需要查询区块的高度为15658,15659,15660的三个区块。
可选的,在一些实施例中,该目标查询条件可以是与区块的特征值模糊匹配的一个或多个值。例如,该目标查询条件可以是156*8,其中“*”表示任意数值。在此情况下,该目标查询条件是需要查询区块的高度为15608至15698的十个区块。
可选的,在另一些实施例中,该目标查询条件可以是与区块的特征值不完全相同但是能唯一匹配到一个区块的特征值。例如,该目标查询条件可以是一个省略了前几位0的哈希值。
202,从N个数据库中确定该目标数据库。
可选的,在一些实施例中,用于确定该目标查询条件的查询数据库可以只有一个,在此情况下,可以直接根据该查询数据库确定对应于该目标查询条件的目标数据库。
在此情况下,该从N个数据库中确定该目标数据库可以包括:从第一查询数据库中包括的K个索引值中,确定对应于该目标查询条件的第一目标索引值,其中该K个索引值与K个位置信息一一对应,该K个位置信息中的每个位置信息用于指示对应的索引值在该N个数据库中的位置,K为大于或等于1的正整数;根据对应于该目标索引值的位置信息,从该N个数据库中确定该目标数据库。
可选的,在一些实施例中,对应于该目标查询条件的第一目标索引值可以是与该目标查询条件完全相同的值。例如,该目标查询条件可以是一个区块的高度,例如15658。该第一目标索引值也为15658。
可选的,在一些实施例中,对应于该目标查询条件的第一目标索引值可以是与该目标查询条件部分相同的值。例如,该目标查询条件可以是一个模糊值。例如,该目标查询条件是用于查询区块的高度的值,该值为156*8,其中“*”表示任意数值。在此情况下,对应于该目标查询条件的第一目标索引值可以是15608至15698。
例如,图3是一个第一查询数据库的示意图。该第一查询数据库中包括 多个索引条目,每个索引条目包括1个索引值和1个位置信息。为便于描述,图3中以Height 1表示一个区块的高度,Nnounce 1表示一个区块的随机数,txHash 1表示一个区块的交易哈希值,以PubkeyHash 1表示一个区块的公钥哈希值。假设Height 1表示的区块的高度为15658。在获取到的目标查询条件为15658的情况下,可以从如图3所示的第一查询数据库中确定索引值为15658为对应于该目标查询条件的第一目标索引值。从图3中可以看出,该第一目标索引值对应的位置信息为数据库1。在此情况下,可以确定出该N个数据库中对应于该目标查询条件的目标数据库为数据库1。
可选的,在一些实施例中,对应于索引值的位置信息中的内容可以是包括该第一目标索引值的数据库例如,如图3所示的查询数据库中的位置信息仅有数据库信息。换句话说,图3所示的查询数据库中仅指示了索引值所在的数据库。
可选的,在另一些实施例中,对应于索引值的位置信息中的内容除了数据库信息外,还可以包含该数据库中的具体位置。可选的,在一些实施例中,该具体位置中可以包含该第一目标索引值。例如,对应于第一目标索引值15658的位置信息为“数据库1,1566”。在此情况下,数据库1中的索引值为1556的索引条目中包含有值为15658的索引值。可选的,在另一些实施例中,该具体位置中可以包含有对应于该目标查询条件的目标查询结果。例如,对应于第一目标索引值15658的位置信息为“数据库1,1566”。在此情况下,数据库1中的索引值为1556的索引条目中包含对应于该目标查询条件的目标查询结果。
可选的,在另一些实施例中,用于确定该目标查询条件的查询数据库可以包括N个,在此情况下,可以先确定出包括该目标数据库的位置信息的查询数据库,然后再从该数据库中确定该目标数据库。
在此情况下,该从第一查询数据库中包括的K个索引值中,确定对应于该目标查询之前,该方法还可以包括:根据该目标查询条件对应的特征值类型,确定该目标查询条件的类型;根据该目标查询条件的类型,从N个查询数据库中确定该第一查询数据库,其中该N个查询数据库分别用于确定N中类型的查询条件在该N个数据库中的位置。
以第一种划分特征值类型的方式为例,N的取值为3,三个查询数据库 中分别用于确定目标查询条件的类型为第一类特征值对应的目标数据库,目标查询条件的类型为第二类特征值对应的目标数据库,目标查询条件为第三类型特征值对应的目标数据库。例如,假设该目标查询条件是区块的高度,则可以从查询数据库1中确定对应于该目标查询条件的目标数据库。又如,假设该目标查询条件是脚本公钥,则可以从查询数据块2中确定对应于该目标查询条件的目标数据库。又如,假设该目标查询条件是交易哈希值,则可以从查询数据库3中确定对应于该目标查询条件的目标数据库。
可选的,在一些实施例中,该从N个数据库中确定该目标数据库,包括:根据该目标查询条件对应的特征值的类型,确定该目标查询条件的类型;根据目标查询条件的类型,从该N个数据库中确定该目标数据库。
可选的,在一些实施例中,可以根据目标查询条件的内容确定出该目标查询条件的类型。例如,可以根据目标查询条件的长度或者格式来确定出该目标查询条件的类型。
可选的,在另一些实施例中,在获取该目标查询条件时,还可以获取选择该目标查询条件对应的特征值。例如,用户利用区块链浏览器查询区块时,在输入目标查询条件时,还可以选择该目标查询条件对应的特征值。例如,用户在输入15658后可以选择区块的高度。在此情况下,在获取到该目标查询条件后可以确定出该目标查询条件是用于查询区块的高度,因此可以确定出该目标查询条件的类型是第一类特征值。
203,从该目标数据库中,确定该目标查询结果。
可选的,在一些实施例中,该目标数据库中包括M个索引条目,该M个索引条目中的每个索引条目包括至少一个索引值,该M个索引条目与M个区块信息一一对应。该从目标数据库中确定目标查询结果,包括:从该M个索引条目中,确定目标索引条目,该目标索引条目包括对应于该目标查询条件的第二目标索引值;根据该目标索引条目对应的区块信息,确定目标查询结果。
可选的,在一些实施例中,对应于该目标查询条件的第二目标索引值可以是与该目标查询条件完全相同的值。例如,该目标查询条件可以是一个区块的高度,例如15658。该第二目标索引值也为15658。
可选的,在一些实施例中,对应于该目标查询条件的第二目标索引值可 以是与该目标查询条件部分相同的值。例如,该目标查询条件可以是一个模糊值。例如,该目标查询条件是用于查询区块的高度的值,该值为156*8,其中“*”表示任意数值。在此情况下,对应于该目标查询条件的第二目标索引值可以是15608至15698。
可选的,在一些实施例中,该M个索引条目中的每个索引条目可以包括多个索引值,该多个索引值是同一个区块的特征值。该目标索引条目所对应的区块信息可以是该目标因条目中包括的全部或者部分索引值。例如,表2是个索引条目的示意。
表2
Height 1 Nnounce 1 PreHash 1
Height 2 Nnounce 2 PreHash 2
Height 3 Nnounce 3 PreHash 3
表2示出了三个索引条目。如表2所示,每个索引条目可以包括三个索引值,分别为区块的高度、随机数和父区块的哈希值,为便于描述,表2中以Height表示一个区块的高度,Nnounce表示该区块的随机数,PreHash表示该区块的父区块的哈希值。换句话说,Height 1是区块1的区块高度,Nnounce 1是区块1的随机数,PreHash 1是区块1的父区块的哈希值;Height2是区块2的区块高度,Nnounce 2是区块2的随机数,PreHash 2是区块2的父区块的哈希值;Height 3是区块3的区块高度,Nnounce 3是区块3的随机数,PreHash 3是区块3的父区块的哈希值。假设该目标索引条件为Height1,则与该目标索引条件对应的目标索引条目是如表2所示第三个索引条目中的第一个索引条目。对应于该目标索引条目的区块信息可以是该目标索引条目中包括的全部或部分信息。
可选的,在一些实施例中,该M个索引条目中的每个索引条目可以包括多个索引值以及一个地址。该多个索引值是同一个区块的特征值。该地址就是该目标索引条目对应的区块信息。换句话说,该M个索引条目中的区块信息用于指示一个地址。在此情况下,该根据该目标索引条目对应的区块信息,确定该目标查询结果可以包括:根据该目标索引条目对应的区块信息,确定目标区块;根据预设条件,确定该目标区块包括的多个特征值中的至少一个特征值为该目标查询结果。例如,表3是个索引条目的示意。
表3
Height 1 Nnounce 1 PreHash 1 地址1
Height 2 Nnounce 2 PreHash 2 地址2
Height 3 Nnounce 3 PreHash 3 地址3
表3示出了三个索引条目。如表3所示,每个索引条目可以包括三个索引值和一个地址,该三个索引值分别为区块的高度、随机数和父区块的哈希值,为便于描述,表3中以Height表示一个区块的高度,Nnounce表示该区块的随机数,PreHash表示该区块的父区块的哈希值。换句话说,Height 1是区块1的区块高度,Nnounce 1是区块1的随机数,PreHash 1是区块1的父区块的哈希值;Height 2是区块2的区块高度,Nnounce 2是区块2的随机数,PreHash 2是区块2的父区块的哈希值;Height 3是区块3的区块高度,Nnounce3是区块3的随机数,PreHash 3是区块3的父区块的哈希值。通过查询区块的高度、随机数和/或父区块的哈希值可以确定出相应的地址。地址1是保存有区块1的所有相关信息的地址,地址2是保存有区块2的所有相关信息的地址,地址3是保存有区块3的所有相关信息的地址。假设该目标索引条件为Height 1,则与该目标索引条件对应的目标索引条目是如表3所示第三个索引条目中的第一个索引条目。对应于该目标索引条目的区块信息是地址1。在此情况下,可以根据地址1获取区块1的相关信息,并根据预设条件,确定该目标区块包括的多个特征值中的至少一个特征值为该目标查询结果。例如该预设条件可以是将该目标区块的区块头的全部信息作为该查询结果。在此情况下,对应于该目标查询条件的目标查询结果为区块1的区块头中的全部信息。又如,该预设条件可以是将该目标区块的全部交易信息作为该查询结果。在此情况下,对应于该目标查询条件的目标查询结果可以是区块1的数据结构中的全部交易信息。
如上所述,在利用查询数据库确定该目标数据库的情况下,查询数据库中的位置信息中的内容除了数据库信息外,还可以包含该索引值在该数据库中的具体位置。因此,在一些实施例中,该M个索引条目中的每个索引条目中可以仅包括一个索引值,该索引值就是该索引条目在该数据库中的行数。该索引条目中的其他内容就是该索引条目对应的区块信息。例如,表4是个索引条目的示意。
表4
1556 Height 1 Nnounce 1 PreHash 1
1557 Height 2 Nnounce 2 PreHash 2
1558 Height 3 Nnounce 3 PreHash 3
表4示出了三个索引条目。如表4所示,每个索引条目中的第一项为索引值,其余项为对应于该索引值的区块信息。如表4所示的索引值分别为1556、1557和1558。为便于描述,表4中以Height表示一个区块的高度,Nnounce表示该区块的随机数,PreHash表示该区块的父区块的哈希值。换句话说,Height 1是区块1的区块高度,Nnounce 1是区块1的随机数,PreHash1是区块1的父区块的哈希值;Height 2是区块2的区块高度,Nnounce 2是区块2的随机数,PreHash 2是区块2的父区块的哈希值;Height 3是区块3的区块高度,Nnounce 3是区块3的随机数,PreHash 3是区块3的父区块的哈希值。通过查询数据库,可以确定出对应于该目标查询条件的第一目标索引值在数据库中的位置信息,该位置信息包括该第一目标索引值所在的数据库以及位于数据库中的位置。例如,对应于索引值为15658的位置信息为(数据库1,1566)。假设表4是数据库1中的一部分。在此情况下,可以确定表4中索引值为1556的索引条目中的区块信息(即Height 1,Nnounce 1和PreHash 1)为与该目标查询条件对应的区块信息。对应于该目标查询条件的目标查询结果可以是该区块信息中的全部信息或者部分信息。
在具体实现上,如图2所示的查找对应于该目标查询条件的目标查询结果可以利用全文索引/检索引擎(Lucene)实现。例如,可以利用elasticsearch或Apache Solr实现。
可选的,在一些实施例中,该基于多个数据库中与目标查询条件对应的目标数据库,提供对应于该目标查询条件的目标查询结果,包括:基于目标区块,建立该多个数据库中的索引条目。
如上所述,区块的一些相关信息(例如区块的哈希和区块的高度等)可以不保存在如表1所示的区块的数据结构中。为便于描述,以下假设不保存在区块的数据结构中的相关信息只有区块的哈希和区块的高度。
在建立索引条目之前,先遍历所有的区块文件,记录区块文件、区块的哈希值和区块的高度之间的对应关系。这样可以便于提取同一个区块的需要 保存在数据库中的特征值。为便于描述,以下将区块文件、区块的哈希值和区块的高度统称为区块相关信息。
遍历得到的区块相关信息可以保存至多级缓存中。假设该多级缓存包括三级缓存,第一级缓存可以只保存少量的区块相关信息,例如五百万条区块相关信息;第二级缓存可以保存较多的区块相关信息,例如四千万条区块相关信息,第三级缓存可以保存遍历出的所有的区块相关信息,其中,第一级缓存所包括保存的区块相关信息可以是最新遍历出的区块相关信息,第二级缓存保存的区块相关信息可以是较早遍历出的区块相关信息。
可选的,在一些实施例中,第二级缓存可以利用键值(Key-Value)数据库(例如使用Redis)保存区块相关信息,也可以使用分布式的高速缓存系统(例如memcache)保存区相关信息。第三级缓存可以利用键值(Key-Value)数据库(例如使用RocksDB、LevelDB等)保存区块相关信息。
该目标区块是所有需要处理的区块中的任意一个。该目标区块包括多个特征值,该多个特征值中的每个特征值的类型为N个类型中的至少一个,该多个特征值包括该N个类型的特征值。该N个数据库与该N个类型一一对应,该N个数据库中的每个数据库中的任意两个索引值对应的特征值的类型相同,该N个数据库分别保存N个索引条目,该N个索引条目中的每个索引条某包括至少一个索引值,该N个索引条目与N组索引特征值一一对应,该N组索引特征值中的每组索引特征值中包括该多个特征值中的至少一个特征值,该N组索引特征值与该N个类型一一对应,该N组索引特征值中的每组索引特征值包括的特征值类型为该每组索引特征值对应的类型。基于该目标区块建立的索引条目能够应用到如图2所示的查询数据的方法中。因此,该目标区块与由该N个数据库提供查询服务的区块具有相同的特征。换句话说,若图2所示的查询数据的方法中的目标查询条件是该目标区块的一个保存在该N个数据库中的特征值,则可以从该N个数据库中确定对应于该目标查询条件的该目标区块的相关信息。
下面结合图4对如何建立对应于该目标区块的索引条目进行描述。
图4是根据本公开实施例提供的建立索引条目的方法的示意性流程图。
401,获取目标区块。
如上所述,获取目标区块包括获取该目标区块的区块相关信息。该目标 区块的区块相关信息可以从上述多级缓存中获取。还以三级缓存为例,若第一级缓存中不包括该目标区块的区块相关信息,则从第二级缓存中查找该目标区块的区块相关信息;若该第二级缓存中仍没有包括该目标区块的区块相关信息,则从第三级缓存中获取该目标区块的区块相关信息。
402,从该目标区块包括的多个特征值中确定N组索引特征值。
例如,假设N取值为3,该多个特征值包括:时间戳、区块的哈希值、区块的高度、区块的随机数、脚本公钥(scripPubkey)、公钥哈希值(pubkeyHash)、公钥类型(pubkeyType)、和交易哈希值(txHash)。假设特征值类型的划分方式是上述第一种划分特征值类型的方式。在此情况下,该目标区块中包括的多个特征值可以划分为三组索引特征值,第一组索引特征值包括:该目标区块的时间戳、目标区块的区块的哈希值、目标区块的高度和目标区块的随机数;第二组索引特征值包括该目标区块的脚本公钥、该目标区块的公钥哈希值和该目标区块的公钥类型;第三组索引特征值包括该目标区块的公钥哈希值和交易哈希值。
403,根据该N组索引特征值,确定该N个索引条目。
如图2所示的方法中的描述,索引条目可以有不同的表现形式(例如表2至表4)。因此,可以根据该N组索引特征值,确定N个索引条目。可以理解的是,该N个数据库中索引条目的表现形式可以是相同的。以表2所示的表现形式为例,该N个索引条目与该N组索引特征值可以是相同的。例如,表5示出了根据上述假设的三组索引特征值确定的三个索引条目。
表5
Time 1 Hash 1 Height 1 Nnounce 1
scripPubkey 1 pubkeyHash 1 pubkeyType 1  
pubkeyHash 1 txHash 1    
为便于描述,表5中以Time表示时间戳、Hash表示区块的哈希值,Height表示区块的高度以此类推。如表5所示的第一行索引条目是根据第一组索引特征值确定的,该索引条目中包括该目标区块的时间戳(即Time 1),该目标区块的区块的哈希值(即Hash 1)、该目标区块的高度(即Height 1)和该目标区块的随机数(即Nnounce 1);第二行索引条目是根据第二组索引特征值确定的,该索引条目中包括该目标区块的脚本公钥(即scripPubkey 1)、该目 标区块的公钥哈希值(即pubkeyHash 1)和该目标区块的公钥类型(即pubkeyType 1);第三行索引条目是根据第三组索引特征值确定的,该索引条目中包括该目标区块的公钥哈希值(pubkeyHash 1)和该目标区块的交易哈希值(txHash)。
404,将该N个索引条目分别保存至该N个数据库中。
还以如表5所示的三个索引条目为例,第一行索引条目可以保存至数据库1中,第二行索引条目可以保存至数据库2中,第三行索引条目可以保存至数据库3中。
通过上述步骤401至步骤404,可以建立基于该目标区块的索引条目。采用相同的方法,可以完成该N个数据库的建立。还以如表5所示的三行索引条目为例,在三个数据库建立完成后,数据库1可以包括多个索引条目,每个索引条目中可以包括一个区块的时间戳,区块的哈希值、区块的高度和随机数;数据库2可以包括多个索引条目,每个索引条目中可以包括一个区块的脚本公钥、公钥哈希值和公钥类型;数据库3可以包括多个索引条目,每个索引条目中可以包括一个区块的公钥哈希值和交易哈希值。
可以理解的是,上述实施例中,确定N组索引特征值、确定N个索引条目以及将N个索引条目保存至N个数据库中的操作可以是异步的。还以上述三组索引特征值为例,假设第一组索引特征值已经确定,无需等待第二组和/或第三组索引特征值确定完就可以根据该第一组索引特征值确定对应于该第一组索引特征值的索引条目。类似的,在确定出第一个索引条目后,无需等待第二个和/或第三个索引条目确定完成,就可以将该索引条目写入到对应的数据库中。
此外,若该目标区块的区块相关信息是从第一级缓存或第二级缓存中获取的,则在确定出对应于该目标区块的索引条目后,可以从缓存中删除该目标区块的区块相关信息(但是此时第三级缓存中仍然保存该目标区块的区块相关信息)。
上文结合图2至图4,详细描述了本公开的方法实施例,下面结合图5至图6,详细描述本公开的装置实施例。方法实施例的描述与装置实施例的描述相互对应,因此,未详细描述的部分可以参见前面方法实施例。
本公开实施例还提供一种服务器。如图5所示,服务器500包括处理模 块510。
处理模块510,用于基于多个数据库中与目标查询条件对应的目标数据库,提供对应于该目标查询条件的目标查询结果,其中该目标查询条件对应于区块的至少一个特征值。
可选的,该区块包括多个特征值,该多个特征值中的每个特征值的类型为N个类型中的至少一个,N为大于或等于2的正整数,N个数据库分别用于为该N个类型的查询条件提供查询结果,其中该查询条件的类型与该查询条件对应的特征值的类型相同。
可选的,处理模块510,具体用于:获取该目标查询条件;从该N个数据库中确定该目标数据库;从该目标数据库中,确定该目标查询结果。
可选的,处理模块510,具体用于:从第一查询数据库中包括的K个索引值中,确定对应于该目标查询条件的第一目标索引值,其中该K个索引值与K个位置信息一一对应,该K个位置信息中的每个位置信息用于指示对应的索引值在该N个数据库中的位置,K为大于或等于1的正整数;根据对应于该目标索引值的位置信息,从该N个数据库中确定该目标数据库。
可选的,处理模块510,还用于在从该第一查询数据库中包括的K个索引值中,确定对应于该目标查询条件的目标索引值之前,根据该目标查询条件的类型,从N个查询数据库中确定该第一查询数据库,其中该N个查询数据库分别用于确定该N种类型的查询条件在该N个数据库中的位置。
可选的,处理模块510,具体用于根据该目标查询条件对应的特征值的类型,确定该目标查询条件的类型;根据该目标查询条件的类型,从该N个数据库中确定该目标数据库。
可选的,该目标数据库中包括M个索引条目,该M个索引条目中的每个索引条目包括至少一个索引值,该M个索引条目与M个区块信息一一对应,处理模块510,具体用于从该M个索引条目中,确定目标索引条目,其中该目标索引条目包括对应于该目标查询条件的第二目标索引值;根据该目标索引条目对应的区块信息,确定该目标查询结果。
可选的,处理模块510,具体用于:根据该目标索引条目对应的区块信息,确定目标区块;根据预设条件,确定该目标区块包括的多个特征值中的至少一个特征值为该目标查询结果。
可选的,处理模块510,具体用于基于目标区块,建立该多个数据库中的索引条目。
可选的,该目标区块包括多个特征值,该多个特征值中的每个特征值的类型为N个类型中的至少一个,该多个特征值包括该N个类型的特征值,N个数据库与该N个类型一一对应,该N个数据库中的每个数据库中的任意两个索引值对应的特征值的类型相同,该N个数据库分别保存N个索引条目,该N个索引条目中的每个索引条目包括至少一个索引值,该N个索引条目与N组索引特征值一一对应,该N组索引特征值中的每组索引特征值包括该多个特征值中的至少一个特征值,该N组索引特征值与该N个类型一一对应,该N组索引特征值中的每组索引特征值包括的特征值的类型为该每组索引特征值对应的类型。
可选的,处理模块510,具体用于:获取该目标区块;从该多个特征值中确定N组索引特征值;根据该N组索引特征值,确定该N个索引条目;将该N个索引条目分别保存至该N个数据库中。
可选的,处理模块510,还用于:确定该N个索引条目中的每个索引值在该N个数据库中的位置;将该N个索引条目中的每个索引值在该N个数据库中的位置保存至N个查询数据库中,其中该N个查询数据库与该N个索引条目一一对应,该N个查询数据库中的每个查询数据库中包括对应的索引条目中的每个索引值以及该每个索引值在该N个数据库中的位置。
可选的,上述数据库、查询数据库和/或区块可以保存在设置在该服务器内的存储模块。可选的,上述数据库、查询数据库和/或区块也可以保存在一个或多个独立于该服务器的专用存储设备中。该服务器可以访问该专用存储设备,获取相应的数据库、查询数据库和/或区块等信息。
本公开实施例还提供一种计算机可读存储介质,存储有计算机可执行指令,该计算机可执行指令设置为执行上述查询数据的方法。
本公开实施例还提供一种计算机程序产品,该计算机程序产品包括存储在计算机可读存储介质上的计算机程序,该计算机程序包括程序指令,当该程序指令被服务器执行时,使该服务器执行上述查询数据的方法。
本公开实施例还提供了一种服务器,其结构如图6所示,服务器600包括:
至少一个处理器(processor)610,图6中以一个处理器610为例;和存储器(memory)620,还可以包括通信接口(Communication Interface)630和总线640。其中,处理器610、通信接口630、存储器620可以通过总线640完成相互间的通信。通信接口630可以用于信息传输。处理器610可以调用存储器620中的逻辑指令,以执行上述实施例的查询数据的方法。
此外,上述的存储器620中的逻辑指令可以通过软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。
存储器620作为一种计算机可读存储介质,可用于存储软件程序、计算机可执行程序,如本公开实施例中的方法对应的程序指令/模块。处理器610通过运行存储在存储器620中的软件程序、指令以及模块,从而执行功能应用以及数据处理,即实现上述方法实施例中的查询数据的方法。
存储器620可包括存储程序区和存储数据区,其中,存储程序区可存储操作系统、至少一个功能所需的应用程序;存储数据区可存储根据终端设备的使用所创建的数据等。此外,存储器620可以包括高速随机存取存储器,还可以包括非易失性存储器。
本公开实施例的技术方案可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括一个或多个指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本公开实施例所述方法的全部或部分步骤。而前述的存储介质可以是非暂态存储介质,包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等多种可以存储程序代码的介质,也可以是暂态存储介质。
当用于本申请中时,虽然术语“第一”、“第二”等可能会在本申请中使用以描述各元件,但这些元件不应受到这些术语的限制。这些术语仅用于将一个元件与另一个元件区别开。比如,在不改变描述的含义的情况下,第一元件可以叫做第二元件,并且同样第,第二元件可以叫做第一元件,只要所有出现的“第一元件”一致重命名并且所有出现的“第二元件”一致重命名即可。第一元件和第二元件都是元件,但可以不是相同的元件。
本申请中使用的用词仅用于描述实施例并且不用于限制权利要求。如在 实施例以及权利要求的描述中使用的,除非上下文清楚地表明,否则单数形式的“一个”(a)、“一个”(an)和“所述”(the)旨在同样包括复数形式。类似地,如在本公开实施例中所使用的术语“和/或”是指包含一个或一个以上相关联的列出的任何以及所有可能的组合。另外,当用于本公开实施例中时,术语“包括”(comprise)及其变型“包括”(comprises)和/或包括(comprising)等指陈述的特征、整体、步骤、操作、元素,和/或组件的存在,但不排除一个或一个以上其它特征、整体、步骤、操作、元素、组件和/或这些的分组的存在或添加。
所描述的实施例中的各方面、实施方式、实现或特征能够单独使用或以任意组合的方式使用。所描述的实施例中的各方面可由软件、硬件或软硬件的结合实现。所描述的实施例也可以由存储有计算机可读代码的计算机可读介质体现,该计算机可读代码包括可由至少一个计算装置执行的指令。所述计算机可读介质可与任何能够存储数据的数据存储装置相关联,该数据可由计算机系统读取。用于举例的计算机可读介质可以包括只读存储器、随机存取存储器、CD-ROM、HDD、DVD、磁带以及光数据存储装置等。所述计算机可读介质还可以分布于通过网络联接的计算机系统中,这样计算机可读代码就可以分布式存储并执行。
上述技术描述可参照附图,这些附图形成了本公开实施例的一部分,并且通过描述在附图中示出了依照所描述的实施例的实施方式。虽然这些实施例描述的足够详细以使本领域技术人员能够实现这些实施例,但这些实施例是非限制性的;这样就可以使用其它的实施例,并且在不脱离所描述的实施例的范围的情况下还可以做出变化。比如,流程图中所描述的操作顺序是非限制性的,因此在流程图中阐释并且根据流程图描述的两个或两个以上操作的顺序可以根据若干实施例进行改变。作为另一个例子,在若干实施例中,在流程图中阐释并且根据流程图描述的一个或一个以上操作是可选的,或是可删除的。另外,某些步骤或功能可以添加到所公开的实施例中,或两个以上的步骤顺序被置换。所有这些变化被认为包含在所公开的实施例以及权利要求中。
另外,上述技术描述中使用术语以提供所描述的实施例的透彻理解。然而,并不需要过于详细的细节以实现所描述的实施例。因此,实施例的上述 描述是为了阐释和描述而呈现的。上述描述中所呈现的实施例以及根据这些实施例所公开的例子是单独提供的,以添加上下文并有助于理解所描述的实施例。上述说明书不用于做到无遗漏或将所描述的实施例限制到本公开的精确形式。根据上述教导,若干修改、选择适用以及变化是可行的。在某些情况下,没有详细描述为人所熟知的处理步骤以避免不必要地影响所描述的实施例。

Claims (27)

  1. 一种查询数据的方法,其特征在于,所述方法包括:
    基于多个数据库中与目标查询条件对应的目标数据库,提供对应于所述目标查询条件的目标查询结果,其中所述目标查询条件对应于区块的至少一个特征值。
  2. 如权利要求1所述的方法,其特征在于,所述区块包括多个特征值,所述多个特征值中的每个特征值的类型为N个类型中的至少一个,N为大于或等于2的正整数,
    N个数据库分别用于为所述N个类型的查询条件提供查询结果,其中所述查询条件的类型与所述查询条件对应的特征值的类型相同。
  3. 如权利要求2所述的方法,其特征在于,所述基于多个数据库中与目标查询条件对应的目标数据库,提供对应于所述目标查询条件的目标查询结果,包括:
    获取所述目标查询条件;
    从所述N个数据库中确定所述目标数据库;
    从所述目标数据库中,确定所述目标查询结果。
  4. 如权利要求3所述的方法,其特征在于,所述从所述N个数据库中确定所述目标数据库,包括:
    从第一查询数据库中包括的K个索引值中,确定对应于所述目标查询条件的第一目标索引值,其中所述K个索引值与K个位置信息一一对应,所述K个位置信息中的每个位置信息用于指示对应的索引值在所述N个数据库中的位置,K为大于或等于1的正整数;
    根据对应于所述目标索引值的位置信息,从所述N个数据库中确定所述目标数据库。
  5. 如权利要求4所述的方法,其特征在于,在所述从第一查询数据库中包括的K个索引值中,确定对应于所述目标查询条件的目标索引值之前,所述方法还包括:
    根据所述目标查询条件对应的特征值的类型,确定所述目标查询条件的类型;
    根据所述目标查询条件的类型,从N个查询数据库中确定所述第一查询数据库,其中所述N个查询数据库分别用于确定所述N种类型的查询条件在所述N个数据库中的位置。
  6. 如权利要求3所述的方法,其特征在于,所述从所述N个数据库中确定所述目标数据库,包括:
    根据所述目标查询条件对应的特征值的类型,确定所述目标查询条件的类型;
    根据所述目标查询条件的类型,从所述N个数据库中确定所述目标数据库。
  7. 如权利要求3至6中任一项所述的方法,其特征在于,所述目标数据库中包括M个索引条目,所述M个索引条目中的每个索引条目包括至少一个索引值,所述M个索引条目与M个区块信息一一对应,
    所述从所述目标数据库中,确定所述目标查询结果,包括:
    从所述M个索引条目中,确定目标索引条目,其中所述目标索引条目包括对应于所述目标查询条件的第二目标索引值;
    根据所述目标索引条目对应的区块信息,确定所述目标查询结果。
  8. 如权利要求7所述的方法,其特征在于,所述M个区块信息中的每个区块信息用于指示一个区块的地址,所述根据所述目标索引条目对应的区块信息,确定所述目标查询结果,包括:
    根据所述目标索引条目对应的区块信息,确定目标区块;
    根据预设条件,确定所述目标区块包括的多个特征值中的至少一个特征值为所述目标查询结果。
  9. 如权利要求1所述的方法,其特征在于,所述基于多个数据库中与目标查询条件对应的目标数据库,提供对应于所述目标查询条件的目标查询结果,包括:
    基于目标区块,建立所述多个数据库中的索引条目。
  10. 如权利要求9所述的方法,其特征在于,所述目标区块包括多个特征值,所述多个特征值中的每个特征值的类型为N个类型中的至少一个,所述多个特征值包括所述N个类型的特征值,
    N个数据库与所述N个类型一一对应,所述N个数据库中的每个数据库 中的任意两个索引值对应的特征值的类型相同,所述N个数据库分别保存N个索引条目,
    所述N个索引条目中的每个索引条目包括至少一个索引值,所述N个索引条目与N组索引特征值一一对应,
    所述N组索引特征值中的每组索引特征值包括所述多个特征值中的至少一个特征值,所述N组索引特征值与所述N个类型一一对应,所述N组索引特征值中的每组索引特征值包括的特征值的类型为所述每组索引特征值对应的类型。
  11. 如权利要求10所述的方法,其特征在于,所述基于目标区块,建立所述多个数据库中的索引条目,包括:
    获取所述目标区块;
    从所述多个特征值中确定N组索引特征值;
    根据所述N组索引特征值,确定所述N个索引条目;
    将所述N个索引条目分别保存至所述N个数据库中。
  12. 如权利要求11所述的方法,其特征在于,所述方法还包括:
    确定所述N个索引条目中的每个索引值在所述N个数据库中的位置;
    将所述N个索引条目中的每个索引值在所述N个数据库中的位置保存至N个查询数据库中,其中所述N个查询数据库与所述N个索引条目一一对应,所述N个查询数据库中的每个查询数据库中包括对应的索引条目中的每个索引值以及该每个索引值在所述N个数据库中的位置。
  13. 一种服务器,其特征在于,所述服务器包括:
    处理模块,用于基于多个数据库中与目标查询条件对应的目标数据库,提供对应于所述目标查询条件的目标查询结果,其中所述目标查询条件对应于区块的至少一个特征值。
  14. 如权利要求13所述的服务器,其特征在于,所述区块包括多个特征值,所述多个特征值中的每个特征值的类型为N个类型中的至少一个,N为大于或等于2的正整数,
    N个数据库分别用于为所述N个类型的查询条件提供查询结果,其中所述查询条件的类型与所述查询条件对应的特征值的类型相同。
  15. 如权利要求14所述的服务器,其特征在于,所述处理模块,具体用 于:
    获取所述目标查询条件;
    从所述N个数据库中确定所述目标数据库;
    从所述目标数据库中,确定所述目标查询结果。
  16. 如权利要求15所述的服务器,其特征在于,所述处理模块,具体用于:
    从第一查询数据库中包括的K个索引值中,确定对应于所述目标查询条件的第一目标索引值,其中所述K个索引值与K个位置信息一一对应,所述K个位置信息中的每个位置信息用于指示对应的索引值在所述N个数据库中的位置,K为大于或等于1的正整数;
    根据对应于所述目标索引值的位置信息,从所述N个数据库中确定所述目标数据库。
  17. 如权利要求16所述的服务器,其特征在于,所述处理模块,还用于在从所述第一查询数据库中包括的K个索引值中,确定对应于所述目标查询条件的目标索引值之前,根据所述目标查询条件的类型,从N个查询数据库中确定所述第一查询数据库,其中所述N个查询数据库分别用于确定所述N种类型的查询条件在所述N个数据库中的位置。
  18. 如权利要求15所述的服务器,其特征在于,所述处理模块,具体用于根据所述目标查询条件对应的特征值的类型,确定所述目标查询条件的类型;
    根据所述目标查询条件的类型,从所述N个数据库中确定所述目标数据库。
  19. 如权利要求15至18中任一项所述的服务器,其特征在于,所述目标数据库中包括M个索引条目,所述M个索引条目中的每个索引条目包括至少一个索引值,所述M个索引条目与M个区块信息一一对应,
    所述处理模块,具体用于从所述M个索引条目中,确定目标索引条目,其中所述目标索引条目包括对应于所述目标查询条件的第二目标索引值;
    根据所述目标索引条目对应的区块信息,确定所述目标查询结果。
  20. 如权利要求19所述的服务器,其特征在于,所述处理模块,具体用于:根据所述目标索引条目对应的区块信息,确定目标区块;
    根据预设条件,确定所述目标区块包括的多个特征值中的至少一个特征值为所述目标查询结果。
  21. 如权利要求13所述的服务器,其特征在于,所述处理模块,具体用于基于目标区块,建立所述多个数据库中的索引条目。
  22. 如权利要求21所述的服务器,其特征在于,所述目标区块包括多个特征值,所述多个特征值中的每个特征值的类型为N个类型中的至少一个,所述多个特征值包括所述N个类型的特征值,
    N个数据库与所述N个类型一一对应,所述N个数据库中的每个数据库中的任意两个索引值对应的特征值的类型相同,所述N个数据库分别保存N个索引条目,
    所述N个索引条目中的每个索引条目包括至少一个索引值,所述N个索引条目与N组索引特征值一一对应,
    所述N组索引特征值中的每组索引特征值包括所述多个特征值中的至少一个特征值,所述N组索引特征值与所述N个类型一一对应,所述N组索引特征值中的每组索引特征值包括的特征值的类型为所述每组索引特征值对应的类型。
  23. 如权利要求22所述的服务器,其特征在于,所述处理模块,具体用于:
    获取所述目标区块;
    从所述多个特征值中确定N组索引特征值;
    根据所述N组索引特征值,确定所述N个索引条目;
    将所述N个索引条目分别保存至所述N个数据库中。
  24. 如权利要求23所述的服务器,其特征在于,所述处理模块,还用于:
    确定所述N个索引条目中的每个索引值在所述N个数据库中的位置;
    将所述N个索引条目中的每个索引值在所述N个数据库中的位置保存至N个查询数据库中,其中所述N个查询数据库与所述N个索引条目一一对应,所述N个查询数据库中的每个查询数据库中包括对应的索引条目中的每个索引值以及该每个索引值在所述N个数据库中的位置。
  25. 一种服务器,其特征在于,包括:
    至少一个处理器;以及
    与所述至少一个处理器通信连接的存储器;其中,
    所述存储器存储有可被所述至少一个处理器执行的指令,所述指令被所述至少一个处理器执行时,使所述至少一个处理器执行权利要求1-12任一项所述的方法。
  26. 一种计算机可读存储介质,其特征在于,存储有计算机可执行指令,所述计算机可执行指令设置为执行权利要求1-12任一项所述的方法。
  27. 一种计算机程序产品,其特征在于,所述计算机程序产品包括存储在计算机可读存储介质上的计算机程序,所述计算机程序包括程序指令,当所述程序指令被服务器执行时,使所述服务器执行权利要求1-12任一项所述的方法。
PCT/CN2019/085865 2019-05-07 2019-05-07 查询数据的方法和服务器 WO2020223901A1 (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
PCT/CN2019/085865 WO2020223901A1 (zh) 2019-05-07 2019-05-07 查询数据的方法和服务器

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2019/085865 WO2020223901A1 (zh) 2019-05-07 2019-05-07 查询数据的方法和服务器

Publications (1)

Publication Number Publication Date
WO2020223901A1 true WO2020223901A1 (zh) 2020-11-12

Family

ID=73050968

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/085865 WO2020223901A1 (zh) 2019-05-07 2019-05-07 查询数据的方法和服务器

Country Status (1)

Country Link
WO (1) WO2020223901A1 (zh)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140331044A1 (en) * 2011-12-01 2014-11-06 Hitachi, Ltd. Secure search method and secure search device
CN108304475A (zh) * 2017-12-28 2018-07-20 北京比特大陆科技有限公司 数据查询方法、装置及电子设备
CN108304491A (zh) * 2018-01-09 2018-07-20 北京比特大陆科技有限公司 数据查询方法、装置及电子设备
CN109582473A (zh) * 2018-10-26 2019-04-05 阿里巴巴集团控股有限公司 基于区块链的跨链数据访问方法和装置

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140331044A1 (en) * 2011-12-01 2014-11-06 Hitachi, Ltd. Secure search method and secure search device
CN108304475A (zh) * 2017-12-28 2018-07-20 北京比特大陆科技有限公司 数据查询方法、装置及电子设备
CN108304491A (zh) * 2018-01-09 2018-07-20 北京比特大陆科技有限公司 数据查询方法、装置及电子设备
CN109582473A (zh) * 2018-10-26 2019-04-05 阿里巴巴集团控股有限公司 基于区块链的跨链数据访问方法和装置

Similar Documents

Publication Publication Date Title
WO2021000671A1 (zh) 数据库的查询方法、装置、服务器及介质
Fu et al. Enabling central keyword-based semantic extension search over encrypted outsourced data
US8725730B2 (en) Responding to a query in a data processing system
US11283616B2 (en) Method for index-based and integrity-assured search in a blockchain
US20210224412A1 (en) User permission data query method and apparatus, electronic device and medium
JP2010027058A (ja) コンピュータによって実現される方法、コンピュータ読取可能媒体およびデータベースから情報を抽出するための装置
US10936559B1 (en) Strongly-consistent secondary index for a distributed data set
US11244073B2 (en) Method and system for anonymising data stocks
US10275486B2 (en) Multi-system segmented search processing
JP2017515183A (ja) データ型に関連するデータプロファイリング操作の管理
US11983169B2 (en) Optimization of database write operations by combining and parallelizing operations based on a hash value of primary keys
US9069817B2 (en) Database row access control
CN111221785A (zh) 一种多源异构数据的语义数据湖构建方法
US11163801B2 (en) Execution of queries in relational databases
WO2016175880A1 (en) Merging incoming data in a database
WO2020223901A1 (zh) 查询数据的方法和服务器
US10885157B2 (en) Determining a database signature
US20230418825A1 (en) Database system, database structure, and associated methods
US11836130B2 (en) Relational database blockchain accountability
JP7173165B2 (ja) 履歴管理装置、履歴管理方法及びプログラム
US11797521B1 (en) Associating a function with a table in a database system
US11954068B2 (en) Data indexing for distributed query execution and aggregation
US20240211436A1 (en) Distributed query execution and aggregation with custom code execution
US11138275B1 (en) Systems and methods for filter conversion
Pinkas et al. A simple recursive tree oblivious ram

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19927904

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19927904

Country of ref document: EP

Kind code of ref document: A1