A data storage method and related device based on perfect hashing

By dividing the data set into multiple data fragments and calculating the perfect hash slot, the problem of inefficient data query in the prior art is solved, and efficient data storage and query are achieved.

CN117891414BActive Publication Date: 2025-03-14ALIPAY (HANGZHOU) INFORMATION TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202410295896.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-14
Publication Date
2025-03-14
Estimated Expiration
2044-03-14

AI Technical Summary

Technical Problem

When existing key-value pair storage systems efficiently organize and store massive KV data, there is a problem of inefficient data query, especially due to multiple IO operations of index and actual data.

Method used

By dividing the target data set to be stored into multiple data fragments and calculating the perfect hash slots for the key-value data in each data fragment, the data fragments are subdivided into multiple data blocks and stored on disk in the order of perfect hash slots.

Benefits of technology

The overall data set is stored on disk in sequentially appended and written, which optimizes the index space size and query efficiency, and reduces IO operations during data query.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117891414B_ABST
    Figure CN117891414B_ABST
Patent Text Reader

Abstract

The present specification provides a data storage method and related equipment based on perfect hashing. The method includes: dividing the target data set to be stored into multiple data fragments matching the data amount of key-value data contained therein, each data fragment containing part of the key-value data in the target data set; calculating the perfect hash slots corresponding to the multiple key-value data included in each data fragment, dividing each data fragment into multiple data blocks matching the data amount of the key-value data contained therein, each data block containing a number of perfect hash slots arranged in sequence, and each perfect hash slot containing at least one key-value data corresponding thereto; storing the multiple data fragments in sequence to the disk, and when storing each data fragment, storing the multiple data blocks in sequence according to the arrangement order of the perfect hash slots.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] One or more embodiments of the present specification relate to the field of database technology, and in particular, to a data storage method and related equipment based on perfect hashing. Background Art

[0002] The key-value (KV) storage system is the backend storage for many service systems. Each time the data is updated, the corresponding key and value data are specified. In the subsequent search process, the previously written value data can be obtained by entering the key.

[0003] Generally speaking, KV storage systems often contain massive KV data sets. How to efficiently organize and store these KV data is related to the final storage space size of the overall data set and will also affect the data query efficiency of the entire KV storage system. Summary of the invention

[0004] In view of this, one or more embodiments of the present specification provide a data storage method and related devices based on perfect hashing.

[0005] In a first aspect, this specification provides a data storage method based on perfect hashing, the method comprising:

[0006] Divide the target data set to be stored into a plurality of data segments that match the amount of key-value data contained therein, each data segment containing part of the key-value data in the target data set;

[0007] Calculate the perfect hash slots corresponding to the multiple key-value data contained in each data fragment, and divide each data fragment into multiple data blocks that match the amount of key-value data contained in the data fragment; each data block contains a number of perfect hash slots arranged in order, and each perfect hash slot contains at least one key-value data corresponding to it;

[0008] The multiple data fragments are stored in the disk in sequence, and when storing each data fragment, the multiple data blocks therein are stored in sequence according to the arrangement order of the perfect hash slots.

[0009] In a second aspect, the present specification provides a data storage device based on perfect hashing, the device comprising:

[0010] A data segment division unit, used for dividing the target data set to be stored into a plurality of data segments matching the amount of key-value data contained therein, each data segment containing part of the key-value data in the target data set;

[0011] A perfect hash calculation unit, used to calculate perfect hash slots corresponding to multiple key-value data contained in each data fragment, and divide each data fragment into multiple data blocks matching the data amount of the key-value data contained therein; wherein each data block contains a number of perfect hash slots arranged in sequence, and each perfect hash slot contains at least one key-value data corresponding thereto;

[0012] The storage unit is used to store the multiple data fragments in the disk in sequence, and when storing each data fragment, store the multiple data blocks therein in sequence according to the arrangement order of the perfect hash slots.

[0013] In a third aspect, this specification provides a data query method based on perfect hashing, the method comprising:

[0014] Parse the received query statement to obtain the target key corresponding to the key-value data to be queried contained in the query statement;

[0015] Calculate a target hash value of the target key, and determine a target data segment corresponding to the target hash value from a plurality of data segments stored in the disk;

[0016] Obtaining perfect hash parameters contained in the target data segment, and calculating a target perfect hash slot corresponding to the target key based on the perfect hash parameters; and,

[0017] The target data block where the target perfect hash slot is located is read from a plurality of data blocks included in the target data fragment, and the key-value data to be queried is obtained from the target perfect hash slot of the target data block.

[0018] In a fourth aspect, the present specification provides a data query device based on perfect hashing, the device comprising:

[0019] A statement parsing unit, used to parse the received query statement to obtain a target key contained in the query statement and corresponding to the key-value data to be queried;

[0020] a determination unit, configured to calculate a target hash value of the target key, and determine a target data segment corresponding to the target hash value from a plurality of data segments stored in the disk;

[0021] a perfect hash calculation unit, configured to obtain a perfect hash parameter contained in the target data segment, and calculate a target perfect hash slot corresponding to the target key based on the perfect hash parameter; and

[0022] An acquisition unit is used to read the target data block where the target perfect hash slot is located from the multiple data blocks included in the target data fragment, and acquire the key-value data to be queried from the target perfect hash slot of the target data block.

[0023] Accordingly, the present specification also provides a computer device, comprising: a memory and a processor; the memory stores a computer program that can be run by the processor; when the processor runs the computer program, it executes the data storage method based on perfect hashing described in the first aspect above, or the data query method based on perfect hashing described in the third aspect.

[0024] Accordingly, the present specification also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the computer program executes the data storage method based on perfect hashing as described in the first aspect above, or the data query method based on perfect hashing as described in the third aspect above.

[0025] Accordingly, the present specification also provides a computer program product, which includes a computer program / instructions. When the computer program / instructions are executed by a processor, the data storage method based on perfect hashing as described in the first aspect above, or the data query method based on perfect hashing as described in the third aspect above is executed.

[0026] In summary, the present application divides the KV data set to be stored into multiple data fragments based on the amount of data in the KV data set. Furthermore, the perfect hash slots corresponding to the multiple key-value data in each data fragment are calculated respectively. And, according to the amount of key-value data contained in each data fragment, the key-value data in several adjacent hash slots in each data fragment are packaged into a data block in the order of the perfect hash slots. In this way, when storing the above-mentioned KV data set, the present application can store each data block in the disk in sequence according to the order of the perfect hash slots, so that the entire data set is stored in the disk in a sequential append write manner. When performing data queries subsequently, the perfect hash slot corresponding to the input key can be calculated, and the corresponding data block can be read from the disk according to the perfect hash slot, thereby achieving a reasonable optimization between the index space size and query efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] Figure 1It is a flowchart of a data storage method based on perfect hashing provided by an exemplary embodiment;

[0028] Figure 2 is a segmented schematic diagram of a data set provided by an exemplary embodiment;

[0029] Figure 3 is a schematic diagram of the internal structure of a data segment provided by an exemplary embodiment;

[0030] Figure 4 is a schematic diagram of the internal structure of a data block provided by an exemplary embodiment;

[0031] Figure 5 It is a schematic diagram of internal data organization of a perfect hash slot provided by an exemplary embodiment;

[0032] Figure 6 is a schematic diagram of internal data organization of another perfect hash slot provided by an exemplary embodiment;

[0033] Figure 7 It is a structural schematic diagram of a data storage device based on perfect hashing provided by an exemplary embodiment;

[0034] Figure 8 It is a structural diagram of a computer device provided by an exemplary embodiment. DETAILED DESCRIPTION

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

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

[0037] It should be noted that the “plurality” mentioned in this application refers to two or more than two.

[0038] In one embodiment shown, a conventional storage engine that organizes data sets based on a log-structured merge tree (LSM-Tree) usually uses a sorted string table (SST) format to sort all key-value data in the KV data set according to the prefix of the key, and stores all key-value data in sequence so that data can be queried using a binary search method later. However, the complexity of the binary search is high, requiring more CPU resources, and there may be multiple IO operations of the index and the actual key-value data during the search process, which is inefficient and cannot meet the actual needs of users.

[0039] Based on this, this specification provides a technical solution to divide the full KV data set into multiple data fragments, calculate a perfect hash index for multiple key-value data in each data fragment, and subdivide each data fragment into multiple appropriate data blocks and save them in sequence, thereby achieving a reasonable optimization between the index space size and query efficiency.

[0040] During implementation, the present application first obtains the target data set to be stored, which may contain multiple key-value data. Then the target data set to be stored is divided into multiple data fragments that match the amount of key-value data contained therein, and each data fragment may include part of the key-value data in the target data set. Furthermore, the present application can calculate the perfect hash slots corresponding to the multiple key-value data included in each data fragment, and divide each data fragment into multiple data blocks that match the amount of key-value data contained therein; wherein each data block contains a number of perfect hash slots arranged in order, and each perfect hash slot contains at least one key-value data corresponding thereto. Finally, the present application can store the above-mentioned multiple data fragments in sequence to the disk, and when storing each data fragment, store the multiple data blocks therein in sequence according to the order of the perfect hash slots.

[0041] In the above technical scheme, the present application divides the KV data set to be stored into multiple data fragments based on the amount of data in the KV data set. Furthermore, the perfect hash slots corresponding to the multiple key-value data in each data fragment are calculated respectively. And, according to the amount of key-value data contained in each data fragment, the key-value data in several adjacent hash slots in each data fragment are packaged into a data block in the order of the perfect hash slots. In this way, when storing the above KV data set, the present application can store each data block in the disk in sequence according to the order of the perfect hash slots, so that the entire data set is stored in the disk in a sequential append write manner. When performing data query subsequently, the perfect hash slot corresponding to the input key can be calculated, and the corresponding data block can be read from the disk according to the perfect hash slot, thereby achieving a reasonable optimization between the index space size and query efficiency.

[0042] See also Figure 1 , Figure 1 FIG. 1 is a flow chart of a data storage method based on perfect hashing provided by an exemplary embodiment. The method can be applied to a storage engine based on perfect hashing index. Figure 1 As shown, the method may specifically include the following steps S101 to S103.

[0043] Step S101 : dividing a target data set to be stored into a plurality of data segments that match the amount of key-value data contained therein, each data segment containing a portion of the key-value data in the target data set.

[0044] First, the storage engine in the database may first obtain the target data set to be stored currently, and the multiple key-value data included in the target data set may be the full amount of key-value data to be stored currently.

[0045] It should be noted that this specification does not specifically limit the specific type of the above-mentioned database. In one illustrated embodiment, the database can be any type of database that stores data in a key-value structure, such as a graph database, etc. This specification does not specifically limit this.

[0046] In an illustrated implementation, the target data set to be stored may be located in a memory managed by a storage engine, to be written to a disk to achieve data persistence.

[0047] It should be noted that the above disk can be a local disk managed by a storage engine, or a cloud disk based on a distributed file system, etc. This specification does not make specific limitations on this.

[0048] Furthermore, the storage engine can divide the target data set to be stored into multiple data segments (Segments), or multiple partitions, that match the amount of key-value data it contains. Each data segment can contain part of the key-value data in the target data set.

[0049] In one illustrated embodiment, the storage engine may specifically divide the target data set into 2N data segments, where N may be an integer greater than or equal to 0. That is, the storage engine may divide the data set into 2, 4, 8 or 16 data segments, etc., and this specification does not specifically limit this.

[0050] It should be understood that, generally, the larger the amount of data contained in the target data set, the more data segments it can be divided into, so as to avoid the problem of too much data in a single data segment; correspondingly, the smaller the amount of data contained in the target data set, the fewer data segments it can be divided into, and even when the target data set is extremely small, it may not be divided, or it may be divided into only a single data segment (that is, N is equal to 0).

[0051] In an illustrated implementation, the storage engine may calculate a hash value corresponding to the key of each key-value data in the target data set. It should be noted that the present application does not specifically limit the specific algorithm for calculating the hash value.

[0052] Furthermore, the storage engine can determine the data segment corresponding to each key-value data according to the calculated hash value, and divide each key-value data into the corresponding data segment.

[0053] In one illustrated embodiment, the present application may select several bits in the hash value corresponding to the key of each key-value data as an index, divide each key-value data into corresponding data segments, and so on. This specification does not make specific limitations on this.

[0054] See also Figure 2 , Figure 2 FIG. 1 is a segmented schematic diagram of a data set provided by an exemplary embodiment. Figure 2 As shown, the storage engine can divide the target data set into four data segments, namely Segment0, Segment1, Segment2, and Segment3.

[0055] like Figure 2As shown, the multiple Segments can be stored in a file on the disk, and footer information (Footer) corresponding to the multiple data segments can be stored at the end of the file, that is, after the last data segment.

[0056] In an illustrated embodiment, the footer information may include the number of the multiple data fragments, the offset address (offset) or the starting address of each data fragment in the file, the length of each data fragment, etc., which is not specifically limited in this specification.

[0057] For example, Figure 2 The footnote information shown may specifically include the following information:

[0058] Footer {

[0059] uint32_t SegmentCount = 4;

[0060] uint32_t Segment0Offset = 0;

[0061] uint32_t Segment0Length = 10240;

[0062] uint32_t Segment1Offset = 10240;

[0063] uint32_t Segment1Length = 4096;

[0064] uint32_t Segment2Offset = 14336;

[0065] uint32_t Segment2Length = 8192;

[0066] uint32_t Segment3Offset = 22528;

[0067] uint32_t Segment3Length = 16384;

[0068] };

[0069] As mentioned above, the footer information describes that the total number of data fragments is 4, the offset address of the first data fragment is 0, and the length is 10240 bytes; the offset address of the second data fragment is 10240, and the length is 4096 bytes; the offset address of the third data fragment is 14336, and the length is 8192 bytes; the offset address of the fourth data fragment is 22528, and the length is 16384 bytes.

[0070] Based on the above division of the target data set, when storing the target data set, each data segment may be stored in the disk in sequence, and corresponding footer information may be further stored after the last stored data segment.

[0071] Furthermore, after completing the storage of the above-mentioned multiple data fragments, the storage engine can calculate its hash value according to the key input during the query, and then determine the corresponding data fragment among the multiple data fragments according to the hash value, and search for the data corresponding to the input key within the data fragment. For details, please refer to the description of subsequent embodiments, which will not be elaborated here.

[0072] Step S102, calculate the perfect hash slots corresponding to the multiple key-value data included in each data fragment, and divide each data fragment into multiple data blocks that match the amount of key-value data contained therein; wherein each data block contains a number of perfect hash slots arranged in order, and each perfect hash slot contains at least one key-value data corresponding thereto.

[0073] Furthermore, within each data slice, the storage engine can perform perfect hash calculation based on the key of multiple key-value data in the data fragment, and specifically can calculate the perfect hash slots corresponding to the multiple key-value data. For example, if the current data fragment contains M key-value data, the number of perfect hash slots in the perfect hash mapping table should be greater than or equal to M, and the total number of perfect hash slots can be marked as SlotCount.

[0074] It should be noted that the present application does not specifically limit the specific implementation method of perfect hash mapping. The present application mainly describes the data organization and storage method based on perfect hash mapping.

[0075] In an illustrated embodiment, the present application may first calculate a common hash value corresponding to the key of each key-value data, and the common hash value may be, for example, the hash value calculated in the above step S101. Furthermore, the present application may perform further calculations based on the common hash value to obtain a perfect hash slot corresponding to each key-value data, that is, the present application may use the calculated common hash value as a new key to calculate a perfect hash.

[0076] Normally, perfect hash mapping can ensure that the perfect hash slots corresponding to each key-value data do not conflict with each other. However, in some extreme cases, if the ordinary hash values ​​of multiple keys are the same, the perfect hash slots corresponding to these multiple keys will also be the same, that is, one perfect hash slot will correspond to multiple key-value data.

[0077] In summary, each data fragment may contain multiple hash slots arranged in order, such as slot0, slot1, slot2, slot3, etc. Each hash slot may contain at least one key-value data, specifically, encoded data (EncodedKVM) obtained by encoding at least one key-value data. M represents metadata (meta) corresponding to KV data.

[0078] Accordingly, in an illustrated embodiment, the present application can sequentially save the key-value data in each perfect hash slot when storing each data fragment. Furthermore, in the specific saving process, the storage engine can uniformly package the key-value data in multiple hash slots into a data block (DataBlock). For example, all key-value data in 2k consecutive hash slots can be packaged into a data block. Among them, k can be an integer greater than or equal to 0. For example, k is 2, which means that every four consecutive perfect hash slots are packaged into a data block.

[0079] In an illustrated embodiment, the storage engine can determine how many data blocks a data segment should be divided into based on the amount of key-value data contained in each data segment, such as the average length of all key-value data contained in each data segment, which is equivalent to determining the number of perfect hash slots contained in each data block in the data segment. Exemplarily, if the key-value data is small, more hash slots can be packed into a single DataBlock as much as possible, that is, fewer data blocks can be divided, so as to achieve higher compression efficiency and reduce the size of the overall memory index space. Exemplarily, if the key-value data is large, fewer hash slots can be packed into a single DataBlock as much as possible, that is, more data blocks can be divided, so as to avoid the problem of too large a single IO during query, thereby reducing query efficiency.

[0080] As described above, on the basis of dividing the target data set into multiple data fragments, the present application can also divide each data fragment into multiple data blocks. Within the data fragment, all key-value data will be stored sequentially in data blocks, and each data block can include multiple perfect hash slots arranged in order, and each perfect hash slot can contain at least one key-value data. Accordingly, when storing each data fragment, DataBlock0, DataBlock1, DataBlock2, etc. can be saved in sequence.

[0081] See also Figure 3 , Figure 3 FIG. 1 is a schematic diagram of the internal structure of a data segment provided by an exemplary embodiment. Figure 3 As shown, each data fragment may include multiple data areas (or fields) arranged in order, which may specifically include: a perfect hash index area, multiple data blocks, a data sharding area, a data block offset address (DataBlockOffsets) area, a hash value area, and a data fragment footer information (Segmentfooter) area.

[0082] like Figure 3 As shown, the perfect hash index area located in the header stores perfect hash parameters (phcontext) corresponding to multiple key-value data in the data segment, and the perfect hash parameters are used to calculate the perfect hash slots corresponding to the multiple key-value data respectively.

[0083] like Figure 3 As shown, the perfect hash index area includes multiple data blocks arranged in order, such as DataBlock1, DataBlock2, etc. In one embodiment shown, when the storage engine saves each data block, it can also compress the data block as a whole or compress part of the key-value data in the data block separately, etc., to reduce the occupied storage space, which is not specifically limited in this specification.

[0084] like Figure 3As shown, an additional data (ExtraData) area follows the last data block, and the additional data area can be used as a data sharding area for storing larger key-value data. In one illustrated embodiment, in response to the length of the target key-value data in the above-mentioned target data set being greater than a preset threshold (for example, 256 bytes or 1024 bytes, etc.), the storage engine can split the target key-value data to obtain multiple data shards. Among them, the target data shards in the multiple data shards (for example, the portion of the target key-value data whose length does not exceed the preset threshold) are stored in the perfect hash slot corresponding to the target key-value data, and the other data shards in the multiple data shards can be stored in the ExtraData area. Furthermore, the perfect hash slot corresponding to the target key-value data can also save the offset addresses of other data shards in the ExtraData area.

[0085] For example, if a key-value data is less than twice the average length of all key-value data, the key-value data can be directly and sequentially stored in the perfect hash slot of the data block. If a key-value data exceeds twice the average length of all key-value data, it can be truncated, and only part of the data is retained in the perfect hash slot of the data block, and the additional truncated redundant data fragments are saved in the ExtraData area, and the offset address of the truncated redundant data fragment in the ExtraData area is recorded in its perfect hash slot.

[0086] like Figure 3 As shown, the hash value area stores the hash value (i.e., the common hash value) of the key in the key-value data in each previous perfect hash slot. In an embodiment shown, the length of each hash value can be 32 bits or 64 bits, etc., and this specification does not make specific limitations on this.

[0087] like Figure 3As shown, at the end of the data segment, footer information corresponding to the data segment is stored. In one illustrated embodiment, the footer information may include a combination of one or more of the following information: the offset address and length of each of the previous data areas (including the perfect hash index area, each DataBlock, ExtraData area, and hash value area) in the data segment; information on whether each data block is compressed; information on whether the key-value data in each hash slot is independently compressed, etc. This specification does not make specific limitations on this. Through the various information summarized in the footer information, the offset address of each data area in the data segment can be obtained, so that the specific data content in each data area in the data segment can be quickly read.

[0088] For further information, see Figure 4 , Figure 4 FIG. 1 is a schematic diagram of the internal structure of a data block provided by an exemplary embodiment. Figure 4 As shown, each data block may include multiple data areas (or fields) arranged in order, which may specifically include: multiple perfect hash slots arranged in order, a hash slot offset address area, a hash slot compression flag (slotCompressFlags) area and a data block control information area.

[0089] like Figure 4 As shown, in each data block, the key-value data corresponding to each perfect hash slot is first stored in sequence. In an embodiment shown, the key-value data stored in each perfect hash slot can specifically be encoded data obtained by encoding the key-value data based on a preset encoding rule, i.e., EncodedKVM.

[0090] like Figure 4 As shown, the last hash slot may be followed by a hash slot offset address area, in which the offset addresses of all previous perfect hash slots in the data block are stored. In one embodiment shown, the size of the perfect hash slot offset address may be 1 byte, 2 bytes, or 4 bytes, etc., and this specification does not specifically limit this. If the total length of all EncodedKVMs is less than 256 bytes, each offset may only occupy 1 byte, which is sufficient to represent the offset addresses of all perfect hash slots; if the total length of all EncodedKVMs is greater than or equal to 256 bytes and less than or equal to 65536 bytes, each offset may occupy 2 bytes; otherwise, if the total length of all EncodedKVMs is greater than 65536 bytes, each offset occupies 4 bytes, so that the memory occupied by the offset address can be reduced according to actual needs.

[0091] like Figure 4 As shown, the hash slot offset address area may be followed by a hash slot compression identification area, and the multiple hash slot compression identifications included in the hash slot compression identification area may be used to indicate whether the key-value data in each perfect hash slot is compressed. Among them, the compression identification of each perfect hash slot may correspond to a bit, and the identification of 0 may indicate that the data of the perfect hash slot is not compressed, and the identification of 1 may indicate that the data of the perfect hash slot has been compressed, and this specification does not make specific limitations on this.

[0092] like Figure 4 As shown, the data block control information area (CtrlByte) located at the end of the data block can store control information of the entire data block. In an illustrated embodiment, the CtrlByte can occupy 1 byte.

[0093] like Figure 4 As shown, the lowest two bits (bit1 and bit0) in CtrlByte can represent the total length of the aforementioned hash slot compression mark area. If bit1 and bit0 are 00 (ie 0x0), it means that there is no hash slot compression mark, which is equivalent to indicating that all key-value data in the data block are not compressed; if bit1 and bit0 are 01 (ie 0x1), it means that the hash slot compression mark area occupies a total of 1 byte, which is equivalent to indicating that each data block contains 8 perfect hash slots; if bit1 and bit0 are 10 (ie 0x2), it means that the hash slot compression mark area occupies a total of 2 bytes, which is equivalent to indicating that each data block contains 16 perfect hash slots; if bit1 and bit0 are 11 (ie 0x3), it means that the hash slot compression mark area occupies a total of 4 bytes, which is equivalent to indicating that each data block contains 32 perfect hash slots.

[0094] like Figure 4 As shown, the 4th and 3rd bits (bit3 and bit2) in CtrlByte can be used to record the size of the space occupied by each hash slot offset address. Figure 4 As shown, bit3 and bit2 are 00 (ie 0x0) to indicate that each hash slot offset address occupies 1 byte; bit3 and bit2 are 01 (ie 0x1) to indicate that each hash slot offset address occupies 2 bytes; bit3 and bit2 are 10 (ie 0x2) to indicate that each hash slot offset address occupies 4 bytes.

[0095] like Figure 4As shown, the remaining 8th to 5th bits (bit7 to bit4) in CtrlByte are reserved areas and can be used to describe any other possible information, which is not specifically limited in this specification.

[0096] For further information, see Figure 5 , Figure 5 FIG. 1 is a schematic diagram of the internal data organization of a perfect hash slot provided by an exemplary embodiment. Figure 5 As shown, if a single perfect hash slot corresponds to only one key-value data, the encoded data stored in the perfect hash slot may specifically include the following multiple contents: control information area, key data area, shard information area, value data area, and metadata area.

[0097] like Figure 5 As shown, the control information area includes control information corresponding to the key-value data included in the encoded data in the perfect hash slot. In an illustrated embodiment, the control information may occupy 1 byte.

[0098] Exemplarily, the highest bit (i.e., bit7) in the control information can be used to indicate whether the perfect hash slot contains only one key-value data. Exemplarily, if bit7 is 0, it means that the perfect hash slot contains only one key-value data, and if bit7 is 1, it means that the perfect hash slot contains multiple key-value data. It should be understood that Figure 5 The following is a diagram of data organization when a single perfect hash slot corresponds to only one key-value data. Figure 5 Bit7 in should be 0.

[0099] Exemplarily, bit6 in the control information can be used to indicate whether the key-value data contained in the perfect hash slot has corresponding metadata, such as the writing time of the key-value data, etc., which is not specifically limited in this specification. Exemplarily, if the bit6 is 0, it means that the key-value data in the perfect hash slot does not contain the corresponding metadata, and if the bit6 is 1, it means that the key-value data in the perfect hash slot contains the corresponding metadata.

[0100] Exemplarily, bit5 in the control information can be used to indicate whether the key-value data contained in the perfect hash slot is a segmented data fragment. Exemplarily, if the bit5 is 0, it means that the key-value data in the perfect hash slot is not a segmented data fragment, and accordingly, the data fragment may not contain the ExtraData area; if the bit5 is 1, it means that the key-value data in the perfect hash slot is a segmented data fragment, and accordingly, the data fragment contains the ExtraData area.

[0101] Exemplarily, bit 4 in the control information may be used to indicate the length occupied by the key data length (keysize) field in the key data area, 0 indicates that the keysize field occupies 1 byte, and 1 indicates that the keysize field occupies 2 bytes.

[0102] Exemplarily, bit 2 and bit 3 in the control information may be used to represent any other possible information, and this specification does not specifically limit this.

[0103] For example, bit0 and bit1 in the control information can be used to indicate the type (ValueType) corresponding to the current value, such as Figure 4 As shown, bit0 and bit1 being 00 may indicate that the value is updated data; bit0 and bit1 being 01 may indicate that the value is overwritten data; bit0 and bit1 being 10 may indicate that the value is deleted data, and this specification does not make any specific limitation on this.

[0104] like Figure 5 As shown, the key data area follows the control information area, and the key data area includes a keysize field for describing the length of the key, and the key data itself.

[0105] like Figure 5 As shown, the key data area is followed by the shard information area, which can store the number of data shards (ExtraCnt) obtained after the aforementioned sharding of the key-value data, as well as the offset address (ExtraDataOffsets) of each data shard in the ExtraData area. Accordingly, when performing data queries, the complete key-value data can be obtained through these shard information (i.e., metadata information of the data shards). It should be understood that if the key-value data in the perfect hash slot is not particularly large, data sharding will not be performed, and accordingly, the shard information area will not exist in the encoded data.

[0106] like Figure 5 As shown, the value data area follows the fragment information area, and the value data area includes the VarValueSize field for describing the length of the value after variable-length encoding, and the value data itself.

[0107] like Figure 5 As shown, the metadata area follows the value data area, and the metadata area can store metadata corresponding to the key-value data in the perfect hash slot, such as the writing time of the key-value data, etc., which is not specifically limited in this specification. It should be understood that if the key-value data in the perfect hash slot does not contain the corresponding metadata (that is, bit6 in the above control information is 0), the metadata area may not exist.

[0108] For further information, see Figure 6 , Figure 6 FIG. 1 is another schematic diagram of internal data organization of a perfect hash slot provided by an exemplary embodiment. Figure 6 As shown, if a single perfect hash slot corresponds to multiple key-value data, the data stored in the perfect hash slot may include the following multiple contents: control information area, and the encoding data of each of the multiple key-value data (refer to the above Figure 5 The description of the corresponding embodiment), and before the encoded data of each key-value data, a KVsize field for describing the length of the encoded data is also included. For example, Figure 6 As shown, each KVsize field can occupy 4 bytes, and this specification does not make any specific limitation on this.

[0109] like Figure 6 As shown, the control information area includes control information corresponding to the key-value data included in the encoded data in the perfect hash slot. In an illustrated embodiment, the control information may occupy one byte.

[0110] like Figure 6 As shown, the highest bit (i.e., bit7) in the control information can be used to indicate whether the perfect hash slot contains only one key-value data. For example, if bit7 is 0, it means that the perfect hash slot contains only one key-value data, and if bit7 is 1, it means that the perfect hash slot contains multiple key-value data. It should be understood that Figure 6 The following is a diagram of data organization when a single perfect hash slot corresponds to multiple key-value data. Figure 6 Bit7 in should be 1.

[0111] like Figure 6 As shown, bit0 to bit3 in the control information can represent the number of key-value data contained in the perfect hash slot. In addition, bit4 to bit6 in the control information can represent any possible information, which is not specifically limited in this specification.

[0112] Step S103, storing the multiple data fragments in the disk in sequence, and, when storing each data fragment, storing multiple data blocks therein in sequence according to the arrangement order of the perfect hash slots.

[0113] According to the above data organization method, the present application can store multiple data fragments of the target data set in sequence on the disk, and when storing each data fragment, multiple data blocks therein can be stored in sequence on the disk in the order of perfect hash slots, thereby realizing the storage of the entire data set on the disk in a sequential append write manner.

[0114] Below, the data query method provided by this application will be explained based on the above data organization and storage method.

[0115] First, the application can receive a query statement initiated by a user, and parse the query statement to obtain a target key contained in the query statement that corresponds to the key-value data to be queried.

[0116] Then, the storage engine can use the same hash calculation method as that used in the above data segmentation to calculate the target hash value of the target key, and determine the target data segment corresponding to the target hash value from the multiple data segments stored in the disk. Exemplarily, several bits in the hash value of the target key can be selected as indexes to determine the target data segment corresponding to the target hash value, and so on, which is not specifically limited in this specification.

[0117] Furthermore, the storage engine may first read the perfect hash parameters stored in the perfect hash index area of ​​the target data segment, and based on the perfect hash parameters, calculate the target perfect hash slot corresponding to the target key, such as SlotIndex.

[0118] Furthermore, the storage engine may read the hash value corresponding to the target perfect hash slot stored in the hash value area of ​​the target data segment, namely, Hashes[SlotIndex].

[0119] In one illustrated embodiment, the storage engine may first read the footer information (Segmentfooter) at the end of the target data segment, and locate the hash value area in the target data segment according to the offset address and length of the hash value area in the data segment recorded in the footer information, and further obtain the hash value Hashes[SlotIndex] corresponding to the target perfect hash slot from the hash value area, and so on. This specification does not make any specific limitations on this.

[0120] Furthermore, the storage engine can determine whether the currently read hash value Hashes[SlotIndex] is consistent with the target hash value calculated above.

[0121] In an illustrated implementation, if the read hash value Hashes[SlotIndex] is inconsistent with the calculated target hash value, it means that the target key to be queried does not exist in the data set and the query fails.

[0122] In one illustrated embodiment, if the read hash value Hashes[SlotIndex] is consistent with the calculated target hash value, the storage engine can further determine the target data block where the target perfect hash slot is located from the multiple data blocks included in the target data segment.

[0123] Furthermore, the storage engine may obtain the offset address of the target data block in the data segment from the data block offset address area of ​​the data segment, so as to read out the target data block according to the offset address.

[0124] For example, if every 4 hash slots are packed into a data block, the starting position of the data block can be obtained through DataBlockOffsets[SlotIndex / 4-1], and DataBlockOffsets[SlotIndex / 4]-DataBlockOffsets[SlotIndex / 4 - 1] represents the length of the data block.

[0125] Furthermore, after reading the target data block, the storage engine can obtain the key-value data to be queried from the target perfect hash slot of the target data block. Specifically, the storage engine can first obtain the offset address corresponding to the target perfect hash slot stored in the target data block, and read the encoded data EncodedKVM in the target perfect hash slot from the target data block according to the offset address.

[0126] Furthermore, the storage engine may decode the encoded data EncodedKVM based on a decoding rule corresponding to the above encoding rule to obtain at least one key-value data contained in the target perfect hash slot.

[0127] Further, the storage engine may determine whether a key in the at least one key-value data is the same as a target key input by the query.

[0128] In an illustrated embodiment, if the target perfect hash slot contains only one key-value data, the key stored in the key-value data can be directly compared to see if it matches the input target key, that is, to see if the two are the same. Exemplarily, if the key in the key-value data matches the input target key, it can be determined that the key-value data is the key-value data to be queried this time, and the Value and Meta data therein can be directly returned. Otherwise, if the key in the key-value data does not match the input target key, the query fails, and an indication of the query failure is returned.

[0129] In an illustrated implementation, if the target perfect hash slot contains multiple key-value data, the key in each key-value data is compared in turn to see if it matches the input target Key. If the key in any key-value data matches the input target Key, it can be determined that the key-value data is the key-value data to be queried this time, and the Value and Meta data therein are directly returned. If the keys in multiple key-value data do not match the target Key, the query fails, and an indication of the query failure is returned.

[0130] Corresponding to the implementation of the above method flow, the embodiment of this specification also provides a data storage device based on perfect hashing. Figure 7 , Figure 7 FIG. 7 is a schematic diagram of a data storage device based on perfect hashing provided by an exemplary embodiment. The device 70 can be applied to a storage engine in a database. Figure 7 As shown, the device 70 includes:

[0131] A data segment division unit 701 is used to divide the target data set to be stored into a plurality of data segments that match the amount of key-value data contained therein, each data segment containing part of the key-value data in the target data set;

[0132] The perfect hash calculation unit 702 is used to calculate the perfect hash slots corresponding to the multiple key-value data contained in each data segment, and divide each data segment into multiple data blocks matching the data amount of the key-value data contained therein; wherein each data block contains a plurality of perfect hash slots arranged in sequence, and each perfect hash slot contains at least one key-value data corresponding thereto;

[0133] The storage unit 703 is used to store the multiple data fragments in the disk in sequence, and when storing each data fragment, store the multiple data blocks therein in sequence according to the arrangement order of the perfect hash slots.

[0134] In an illustrated embodiment, the data segment division unit 701 is specifically configured to:

[0135] According to the amount of key-value data contained in the target data set to be stored, determine the number of data fragments that match it;

[0136] Calculate a hash value corresponding to the key of each key-value data contained in the target data set;

[0137] According to the calculated hash value, each key-value data is divided into corresponding data fragments.

[0138] In an illustrated embodiment, the apparatus 70 further includes a footnote information storage unit 704, which is used to:

[0139] After the last data fragment stored in the disk, footer information corresponding to the multiple data fragments is stored; wherein the footer information includes a combination of one or more information shown below: the number of the multiple data fragments, the offset address of each data fragment, and the length of each data fragment.

[0140] In one illustrated embodiment, each data fragment also includes a perfect hash index area located before the first data block; wherein the perfect hash index area contains perfect hash parameters for calculating perfect hash slots corresponding to multiple key-value data in the data fragment.

[0141] In one illustrated embodiment, each data fragment also includes: a data block offset address area and a hash value area located after the last data block; wherein the data block offset address area contains the offset address of each data block in the data fragment; and the hash value area contains hash values ​​corresponding to the keys of multiple key-value data in each data fragment.

[0142] In an illustrated embodiment, the data fragment further includes a data fragmentation area; the device 70 further includes a data fragmentation unit 705, which is used to:

[0143] In response to the length of the target key-value data in the target data set being greater than a preset threshold, the target key-value data is segmented to obtain multiple data shards; wherein the target data shard among the multiple data shards is stored in a perfect hash slot corresponding to the target key-value data, and other shards are stored in the data shard area.

[0144] In an illustrated embodiment, the at least one key-value data included in each perfect hash slot includes: encoded data obtained by encoding the at least one key-value data based on a preset encoding rule.

[0145] In an illustrated embodiment, the encoded data in each perfect hash slot includes control information corresponding to the key-value data, and the control information includes a combination of one or more of the following information:

[0146] Whether the perfect hash slot contains only one key-value data;

[0147] Whether the key-value data contained in the perfect hash slot has corresponding metadata;

[0148] Whether the key-value data contained in the perfect hash slot is a segmented data fragment.

[0149] In one illustrated embodiment, each data block further includes: a hash slot offset address area located after the last perfect hash slot; wherein the hash slot offset address area includes the offset address of each perfect hash slot in the data block.

[0150] In an illustrated embodiment, the device 70 further includes a data query unit 706, which is used to:

[0151] Parse the received query statement to obtain the target key corresponding to the key-value data to be queried contained in the query statement;

[0152] Calculating a target hash value of the target key, and determining a target data segment corresponding to the target hash value from among the multiple data segments;

[0153] Obtaining perfect hash parameters stored in a perfect hash index area in the target data segment, and calculating a target perfect hash slot corresponding to the target key based on the perfect hash parameters; and

[0154] The target data block where the target perfect hash slot is located is read from a plurality of data blocks included in the target data fragment, and the key-value data to be queried is obtained from the target perfect hash slot of the target data block.

[0155] In an illustrated embodiment, the data query unit 706 is specifically configured to:

[0156] Obtaining an offset address corresponding to the target perfect hash slot stored in the target data block, and reading the encoded data in the target perfect hash slot from the target data block based on the offset address;

[0157] Decoding the encoded data based on a decoding rule corresponding to the encoding rule to obtain at least one key-value data;

[0158] Determine whether a key in the at least one key-value data is the same as the target key;

[0159] If the key in any key-value data is the same as the target key, the key-value data is determined to be the key-value data to be queried.

[0160] The implementation process of the functions and effects of each unit in the above device 70 is detailed in the above Figure 1-Figure 6 The description of the corresponding embodiment will not be repeated here. It should be understood that the above-mentioned device 70 can be implemented by software, or by hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by the processor (CPU) of the device where it is located reading the corresponding computer program instructions into the memory and running them. From the hardware level, in addition to the CPU and memory, the device where the above-mentioned device is located usually also includes other hardware such as chips for wireless signal transmission and reception, and / or other hardware such as boards for realizing network communication functions.

[0161] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the units or modules may be selected according to actual needs to achieve the purpose of the scheme of this specification. Those of ordinary skill in the art may understand and implement it without creative work.

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

[0163] Corresponding to the above method embodiment, the embodiment of this specification also provides a computer device. Figure 8 , Figure 8 FIG. 1 is a schematic diagram of a computer device provided by an exemplary embodiment. Figure 8 As shown, the computer device includes a processor 1001 and a memory 1002, and may further include an input device 1004 (such as a keyboard, etc.) and an output device 1005 (such as a display, etc.). The processor 1001, the memory 1002, the input device 1004, and the output device 1005 may be connected via a bus or other means. Figure 8 As shown, the memory 1002 includes a computer-readable storage medium 1003, which stores a computer program that can be run by the processor 1001. The processor 1001 can be a CPU, a microprocessor, or an integrated circuit for controlling the execution of the above method embodiment. When the processor 1001 runs the stored computer program, it can execute the various steps of the data storage method based on perfect hash in the embodiment of this specification, including: dividing the target data set to be stored into multiple data fragments matching the data volume of the key-value data contained therein, each data fragment containing part of the key-value data in the target data set; calculating the perfect hash slots corresponding to the multiple key-value data contained in each data fragment, and dividing each data fragment into multiple data blocks matching the data volume of the key-value data contained therein; wherein each data block contains a number of perfect hash slots arranged in order, and each perfect hash slot contains at least one key-value data corresponding thereto; the multiple data fragments are stored in sequence in the disk, and when storing each data fragment, the multiple data blocks therein are stored in sequence according to the arrangement order of the perfect hash slots, and so on.

[0164] For a detailed description of each step of the above-mentioned perfect hash-based data storage method, please refer to the previous content and will not be repeated here.

[0165] Corresponding to the above method embodiment, the embodiment of this specification also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by the processor, it executes the various steps of the data storage method based on perfect hash in the embodiment of this specification. Figure 1-Figure 6 The description of the corresponding embodiments will not be repeated here.

[0166] The above description is only a preferred embodiment of this specification and is not intended to limit this specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of this specification should be included in the scope of protection of this specification.

[0167] In a typical configuration, a terminal device includes one or more CPUs, input / output interfaces, network interfaces, and memory.

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

[0169] Computer readable media include permanent and non-permanent, removable and non-removable media and can store information by any method or technology. The information can be computer readable instructions, data structures, program modules or other data.

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

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

[0172] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems or computer program products. Therefore, the embodiments of this specification may take the form of complete hardware embodiments, complete software embodiments or embodiments combining software and hardware. Moreover, the embodiments of this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.

Claims

1. A data storage method based on perfect hashing, characterized in that: The method comprises: Divide the target data set to be stored into a plurality of data segments that match the amount of key-value data contained therein, each data segment containing part of the key-value data in the target data set; Calculate the perfect hash slots corresponding to the multiple key-value data contained in each data fragment, and divide each data fragment into multiple data blocks that match the amount of key-value data contained in the data fragment; each data block contains a number of perfect hash slots arranged in order, and each perfect hash slot contains at least one key-value data corresponding to it; The multiple data fragments are stored in the disk in sequence. When storing each data fragment, the multiple data blocks therein are stored in sequence according to the arrangement order of the perfect hash slots. If the length of the target key-value data in the multiple key-value data contained in the data fragment is greater than a preset threshold, the target key-value data is split, and the target data fragment among the multiple data fragments obtained by the splitting is stored in the perfect hash slot corresponding to the target key-value data, and other data fragments are stored in the data fragment area preset in the data fragment.

2. The method according to claim 1, characterized in that: The step of dividing the target data set to be stored into a plurality of data segments that match the amount of key-value data contained therein includes: According to the amount of key-value data contained in the target data set to be stored, determine the number of data fragments that match it; Calculate a hash value corresponding to the key of each key-value data contained in the target data set; According to the calculated hash value, each key-value data is divided into corresponding data fragments.

3. The method according to claim 1, characterized in that The method further comprises: After the last data fragment stored in the disk, footer information corresponding to the multiple data fragments is stored; wherein the footer information includes a combination of one or more information shown below: the number of the multiple data fragments, the offset address of each data fragment, and the length of each data fragment.

4. The method according to claim 2, characterized in that: Each data fragment also includes a perfect hash index area located before the first data block; wherein the perfect hash index area contains perfect hash parameters for calculating perfect hash slots corresponding to multiple key-value data in the data fragment.

5. The method according to claim 4, characterized in that Each data fragment also includes: a data block offset address area and a hash value area located after the last data block; wherein the data block offset address area contains the offset address of each data block in the data fragment; the hash value area contains hash values ​​corresponding to the keys of multiple key-value data in each data fragment.

6. The method according to claim 5, characterized in that The at least one key-value data contained in each perfect hash slot includes: encoded data obtained by encoding the at least one key-value data based on a preset encoding rule.

7. The method according to claim 6, characterized in that The encoded data in each perfect hash slot contains control information corresponding to the key-value data, and the control information contains a combination of one or more of the following information: Whether the perfect hash slot contains only one key-value data; Whether the key-value data contained in the perfect hash slot has corresponding metadata; Whether the key-value data contained in the perfect hash slot is a segmented data shard.

8. The method according to claim 7, characterized in that Each data block also includes: a hash slot offset address area located after the last perfect hash slot; wherein the hash slot offset address area contains the offset address of each perfect hash slot in the data block.

9. The method according to claim 8, characterized in that The method further comprises: Parse the received query statement to obtain the target key corresponding to the key-value data to be queried contained in the query statement; Calculating a target hash value of the target key, and determining a target data segment corresponding to the target hash value from among the multiple data segments; Obtaining perfect hash parameters stored in a perfect hash index area in the target data segment, and calculating a target perfect hash slot corresponding to the target key based on the perfect hash parameters; and The target data block where the target perfect hash slot is located is read from a plurality of data blocks included in the target data fragment, and the key-value data to be queried is obtained from the target perfect hash slot of the target data block.

10. The method according to claim 9, characterized in that The obtaining the key-value data to be queried from the target perfect hash slot of the target data block includes: Obtaining an offset address corresponding to the target perfect hash slot stored in the target data block, and reading the encoded data in the target perfect hash slot from the target data block based on the offset address; Decoding the encoded data based on a decoding rule corresponding to the encoding rule to obtain at least one key-value data; Determine whether a key in the at least one key-value data is the same as the target key; If the key in any key-value data is the same as the target key, the key-value data is determined to be the key-value data to be queried.

11. A data storage device based on perfect hashing, characterized in that: The device comprises: A data segment division unit, used for dividing the target data set to be stored into a plurality of data segments matching the amount of key-value data contained therein, each data segment containing part of the key-value data in the target data set; A perfect hash calculation unit, used to calculate perfect hash slots corresponding to multiple key-value data contained in each data fragment, and divide each data fragment into multiple data blocks matching the data amount of the key-value data contained therein; wherein each data block contains a number of perfect hash slots arranged in sequence, and each perfect hash slot contains at least one key-value data corresponding thereto; A storage unit is used to store the multiple data fragments in the disk in sequence. When storing each data fragment, multiple data blocks therein are stored in sequence according to the arrangement order of the perfect hash slots. If the length of the target key-value data in the multiple key-value data contained in the data fragment is greater than a preset threshold, the target key-value data is segmented, and the target data fragment among the multiple data fragments obtained by segmentation is stored in the perfect hash slot corresponding to the target key-value data, and other data fragments are stored in the data fragment area preset in the data fragment.

12. A data query method based on perfect hashing, characterized in that: The method comprises: Parse the received query statement to obtain the target key corresponding to the key-value data to be queried contained in the query statement; Calculate a target hash value of the target key, and determine a target data segment corresponding to the target hash value from a plurality of data segments stored in the disk; Obtaining perfect hash parameters contained in the target data segment, and calculating a target perfect hash slot corresponding to the target key based on the perfect hash parameters; and, The target data block where the target perfect hash slot is located is read out from the multiple data blocks included in the target data fragment, and the key-value data to be queried is obtained from the target perfect hash slot of the target data block; if the length of the key-value data to be queried is greater than a preset threshold, obtaining the key-value data to be queried from the target perfect hash slot of the target data block includes: obtaining a target data fragment from the multiple data fragments obtained after segmentation of the key-value data to be queried from the target perfect hash slot of the target data block, and obtaining other data fragments from a preset data fragment area in the target data fragment.

13. A data query device based on perfect hashing, characterized in that: The device comprises: A statement parsing unit, used to parse the received query statement to obtain a target key contained in the query statement and corresponding to the key-value data to be queried; a determination unit, configured to calculate a target hash value of the target key, and determine a target data segment corresponding to the target hash value from a plurality of data segments stored in the disk; a perfect hash calculation unit, configured to obtain a perfect hash parameter contained in the target data segment, and calculate a target perfect hash slot corresponding to the target key based on the perfect hash parameter; and An acquisition unit is used to read the target data block where the target perfect hash slot is located from the multiple data blocks included in the target data fragment, and obtain the key-value data to be queried from the target perfect hash slot of the target data block; if the length of the key-value data to be queried is greater than a preset threshold, obtaining the key-value data to be queried from the target perfect hash slot of the target data block includes: obtaining a target data fragment from the multiple data fragments obtained after segmentation of the key-value data to be queried from the target perfect hash slot of the target data block, and obtaining other data fragments from a preset data fragment area in the target data fragment.

14. A computer device, characterized in that: include: Memory and processor; The memory stores a computer program executable by the processor; When the processor runs the computer program, the processor performs the method according to any one of claims 1 to 10 or 12.

15. A computer-readable storage medium, characterized in that: A computer program / instruction is stored thereon, and when the computer program / instruction is executed by a processor, the method according to any one of claims 1 to 10 or 12 is implemented.

16. A computer program product, characterized in that The computer program product comprises a computer program / instruction, and when the computer program / instruction is executed by a processor, the method according to any one of claims 1 to 10 or 12 is implemented.

Citation Information

Patent Citations

  • Data processing method and device, equipment and storage medium

    CN116450656A