Data storage method and device applied to sorting index and electronic equipment

By combining the structure of data, index and trie tree area in KV data storage, and setting pruning fields in trie nodes, the problem of low binary search efficiency and large space consumption of KV data is solved, and efficient query and low storage consumption are achieved. effect.

CN118708115APending Publication Date: 2024-09-27BEIJING BAIGEFEICHI TECH LLC
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410752601.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-12
Publication Date
2024-09-27

AI Technical Summary

Technical Problem

In KV data disk storage, binary search based on sorting index is inefficient, and when only trie trees are used to store KV data, the query efficiency is O(n) and the space consumption is large. How to improve the efficiency of KV data binary search and reduce storage space? consumption.

Method used

When KV data is stored, the data structure of the data area, index index area and trie tree area is combined, the trie tree is used as the secondary index, and the prune field is set in the trie node for dynamic pruning, reducing the number of errors in the trie tree. The number of nodes improves storage and query efficiency.

Benefits of technology

The query efficiency of KV data is improved from O(n) to O(1). At the same time, the consumption of storage space is reduced through pruning, and the efficiency of KV data storage is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118708115A
    Figure CN118708115A
Patent Text Reader

Abstract

The invention discloses a data storage method and device applied to sorting indexing and electronic device.The data storage method applied to sorting indexing comprises the steps that during KV data disk storage, a storage structure of KV data comprises a data area and an entry item used for storing the KV data, the entry item comprises a key value length key Size, a key value and a value value, and the key value length key Size is a fixed-length array; the index area is used for storing the data area offset [i] of the KV data stored in the data area, and the data area offset [i] is a fixed-length array; and in the trie tree region, the key value and the index region offset [j] of the index region corresponding to the key value are stored by adopting a trie tree data structure. According to the KV data storage method, the indexes are sorted according to the key values through the index region, meanwhile, the trie tree is added to the trie tree region to serve as a secondary index, KV data storage is carried out based on the data storage method applied to the sorting indexes, when KV data query is carried out, the query efficiency is the query efficiency o (n) of the trie tree, forward and backward query can be carried out, and the query efficiency of KV data storage is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data storage, and in particular provides a data storage method, device and electronic device for sorting indexes. Background Art

[0002] In KV data disk storage, KV data is generally stored compactly after being sorted by key. At this time, data query based on the sorted index uses binary search, which may store a large number of identical keys. The binary search is inefficient. Therefore, how to improve the efficiency of binary search of KV data is a technical problem to be solved by the present invention.

[0003] In addition, for general business scenarios using KV data, a type of key usually has the same prefix, so a Trie tree is chosen for KV data storage. The Trie tree (also called "prefix tree" or "dictionary tree") is a data structure used to quickly query whether "a certain string / character prefix" exists. The essence of the Trie tree is to use the common prefix between strings to merge repeated prefixes together. Advantages of the Trie tree: minimize unnecessary string comparisons, and the query efficiency is higher than that of the hash table. However, if KV data is stored only based on the Trie tree, the query efficiency is o(n), and the space consumed is relatively large, because the Trie tree itself is a data structure that exchanges space for time.

[0004] Therefore, how to improve the efficiency of binary search of KV data while further reducing the consumption of storage space is another technical problem to be solved by the present invention.

[0005] In view of this, the present invention patent is proposed. Summary of the invention

[0006] In response to the above technical problems, the present invention proposes a data storage method, device and electronic device for sorting indexes to improve the efficiency of binary search of KV data and further reduce the consumption of storage space.

[0007] Specifically, the following technical solutions are adopted:

[0008] In a first aspect, the present invention provides a data storage method for a sorted index, including when KV data is stored on a disk, the storage structure of the KV data includes:

[0009] The data area is used to store the item of KV data. The item includes the key value length keySize, the key value and the value value. The key value length keySize is a fixed-length array.

[0010] The index area is used to store the offset of the KV data stored in the data area, offset[i], which is a fixed-length array.

[0011] The trie tree area uses the trie tree data structure to store the key value and the index area offset offset[j] corresponding to the key value in the index area.

[0012] As an optional implementation of the present invention, the data storage method applied to the sorting index of the present invention includes a KV data writing process:

[0013] When writing a KV key-value pair, calculate the key value length keySize;

[0014] The calculated key value length keySize, key value, and value value are taken as an item and written into the data area. At the same time, the data area offset offset[i] of the item written into the data area is obtained.

[0015] Write the offset of data area offset[i] to the index area in sequence, and get the offset of data area offset[i] and write the offset of index area offset[j] to the index area;

[0016] Write the key value of the KV key-value pair and the index area offset offset[j] into the trie tree area.

[0017] As an optional embodiment of the present invention, in the data storage method applied to sorted indexes of the present invention, for the construction of a trie tree in a trie tree area, each trie node includes a key value field, a prune field, a value field and a child node children field, wherein the key value field stores the characters of the key value, the value field writes the index area offset offset[j] of the key value, and under the child node children field is another trie node, and the prune field stores the path compression information of the current node, that is, the common prefix part of several nodes after the current node, and these common prefix parts are compressed into the prune field of the current node.

[0018] As an optional implementation of the present invention, in the data storage method for sorted indexes of the present invention, the construction process of the trie tree in the trie tree area includes a pruning process:

[0019] Determine whether the prune field of the current trie node matches the remaining characters of the key value;

[0020] If the prune field of the current trie node completely matches the remaining characters of the key value, a pruning operation is performed, that is, the prune field of the current trie node is set to empty, and the remaining characters of the key value are added as new prune fields to the new child trie node;

[0021] If the prune field of the current trie node matches the remaining characters of the key value, a new child trie node is created to store the unmatched part of the prune field of the current trie node and the remaining characters of the key value, and the prune field of the current trie node is updated to match the remaining characters of the key value;

[0022] If the prune field of the current trie node does not match the remaining characters of the key value at all, no pruning operation is performed and the traversal continues downward.

[0023] As an optional embodiment of the present invention, the data storage method applied to the sorted index of the present invention includes a data query process based on the trie tree in the trie tree area:

[0024] When traversing the trie tree, if the length of the prune field of the current trie node is greater than 0, the relationship between the prune field and the remaining keys is determined;

[0025] If the remaining characters of the prune field and the key value completely match, it means that path compression can be performed, that is, the part corresponding to the prune field is skipped and the traversal is directly downward;

[0026] If the prune field matches the remaining characters of the key value, the traversal will continue until a completely matching trie node is found or the entire key is traversed;

[0027] If the remaining characters of the prune field and the key value do not match at all, it means that there is no match and null is returned.

[0028] As an optional embodiment of the present invention, the data storage method applied to the sorting index of the present invention includes a query process of KV data:

[0029] According to the query key value, query in the trie tree in the trie tree area;

[0030] If the query key value can be found, the index area offset offset[j] corresponding to the query key value is obtained. If the query key value cannot be found, the query result is directly returned.

[0031] According to the index area offset offset[j], get the offset of the KV data corresponding to the query key value stored in the data area, data area offset offset[i];

[0032] The length of the KV data item is obtained by calculating the difference between the index area offset offset[j] and the previous index area offset offset[j];

[0033] Get the item data of the KV data according to the data area offset offset[i] of the query key value and the length of the item of the KV data;

[0034] Get the key value size keySize from the item data of the KV data, and get the length of the key value according to the key value size keySize;

[0035] The length of the value is calculated according to the length of the item - the array length of the key value size keySize - the length of the key value, and the value corresponding to the query key value is read from the item data. As an optional embodiment of the present invention, in the data storage method applied to sorted indexes of the present invention, the storage structure of the KV data includes a header area, and the header area stores the offset and length of the data area, index area, and trie tree area in the overall storage structure.

[0036] In a second aspect, the present invention provides a data storage device for sorting indexes, including a data storage module for KV data disk storage, the data storage module including:

[0037] The data area is used to store the item of KV data. The item includes the key value length keySize, the key value and the value value. The key value length keySize is a fixed-length array.

[0038] The index area is used to store the offset of the KV data stored in the data area, offset[i], which is a fixed-length array.

[0039] The trie tree area uses the trie tree data structure to store the key value and the index area offset offset[j] corresponding to the key value in the index area.

[0040] As an optional embodiment of the present invention, the data storage device of the present invention is applied to sorted indexes, and the data storage module includes a header area, and the header area stores the offset and length of the data area, index area, and trie tree area in the overall storage structure.

[0041] In a third aspect, the present invention provides an electronic device comprising a processor and a memory, wherein the memory is used to store a computer executable program, and is characterized in that when the computer program is executed by the processor, the processor executes the data storage method applied to the sorting index.

[0042] Compared with the prior art, the present invention has the following beneficial effects:

[0043] The data storage method for sorting indexes of the present invention is to sort the index area according to the key value, and at the same time add a trie tree as a secondary index through the trie tree area. When performing KV data query based on the data storage method for sorting indexes of the present invention, the query efficiency is the query efficiency o(n) of the trie tree, and forward and backward search is also possible. Therefore, the data storage method for sorting indexes of the present invention is used to perform KV data storage to build a KV database, thereby improving the query efficiency of KV data storage.

[0044] The data storage method for sorting index of the present invention improves the query efficiency of KV data storage by adding a trie tree as a secondary index in a trie tree area. However, since the trie tree itself is a data structure that exchanges space for time, the storage consumption of KV data will be increased. In view of this, the data storage method for sorting index of the present invention supports dynamic pruning in the process of constructing the trie tree in the trie tree area by setting a prune field in the trie node, which greatly reduces the space and improves the efficiency of KV data storage; in addition, the query efficiency o(n) can be increased to o(1) at the maximum. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Figure 1 A data structure diagram of a data storage method for sorting indexes according to an embodiment of the present invention;

[0046] Figure 2 A data writing flow chart of a data storage method applied to sorted indexes according to an embodiment of the present invention;

[0047] Figure 3 A data query flow chart of a data storage method applied to sorted indexes according to an embodiment of the present invention;

[0048] Figure 4A flow chart of pruning a trie tree during data writing in a method for storing sorted indexed data according to an embodiment of the present invention;

[0049] Figure 5 A query flow chart of a trie tree in a data query process of a data storage method for sorted indexes according to an embodiment of the present invention;

[0050] Figure 6 A schematic structural diagram of an electronic device according to an embodiment of the present invention;

[0051] Figure 7 Schematic diagram of a computer-readable recording medium according to an embodiment of the present invention. DETAILED DESCRIPTION

[0052] To make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be described clearly and completely in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them.

[0053] Therefore, the following detailed description of the embodiments of the present invention is not intended to limit the scope of the invention claimed for protection, but merely represents some embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0054] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features and technical solutions in the embodiments may be combined with each other.

[0055] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.

[0056] In the description of the present invention, it should be noted that the orientation or positional relationship indicated by the terms "upper", "lower", etc. is based on the orientation or positional relationship shown in the drawings, or the orientation or positional relationship in which the invention product is usually placed when in use, or the orientation or positional relationship commonly understood by those skilled in the art. Such terms are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", etc. are only used to distinguish the description, and cannot be understood as indicating or implying relative importance.

[0057] Embodiment 1

[0058] See also Figure 1As shown, the data storage method applied to the sorting index in this embodiment includes that when the KV data is stored on a disk, the storage structure of the KV data includes:

[0059] The data area is used to store the item of KV data. The item includes the key value length keySize, the key value and the value value. The key value length keySize is a fixed-length array.

[0060] The index area is used to store the offset of the KV data stored in the data area, offset[i], which is a fixed-length array.

[0061] The trie tree area uses the trie tree data structure to store the key value and the index area offset offset[j] corresponding to the key value in the index area.

[0062] The data storage method for sorted indexes of this embodiment is used to sort the index area according to the key value, and at the same time, a trie tree is added as a secondary index through the trie tree area. When performing KV data query based on the data storage method for sorted indexes of this embodiment, the query efficiency is the query efficiency of the trie tree o(n), and forward and backward search is also possible. Therefore, the data storage method for sorted indexes of this embodiment is used to perform KV data storage to build a KV database, thereby improving the query efficiency of KV data storage.

[0063] Further, see Figure 2 As shown, the data storage method applied to the sorting index in this embodiment includes the KV data writing process:

[0064] When writing a KV key-value pair, calculate the key value length keySize;

[0065] The calculated key value length keySize, key value, and value value are taken as an item and written into the data area. At the same time, the data area offset offset[i] of the item written into the data area is obtained.

[0066] Write the offset of data area offset[i] to the index area in sequence, and get the offset of data area offset[i] and write the offset of index area offset[j] to the index area;

[0067] Write the key value of the KV key-value pair and the index area offset offset[j] into the trie tree area.

[0068] The data storage method applied to the sorted index of the present embodiment improves the query efficiency of KV data storage by adding a trie tree as a secondary index in the trie tree area. However, since the trie tree itself is a data structure that exchanges space for time, the storage consumption of KV data will be increased. In view of this, the data storage method applied to the sorted index of the present embodiment, for the construction of the trie tree in the trie tree area, each trie node includes a key value field, a pruning prune field, a value field and a child node children field, the key value field stores the characters of the key value, the value field writes the index area offset offset[j] of the key value, and the child node children field is another trie node, and the pruning prune field stores the path compression information of the current node, that is, the common prefix part of several nodes after the current node, and these common prefix parts are compressed into the pruning prune field of the current node, thereby reducing the number of nodes in the Trie tree and improving storage and query efficiency.

[0069] The data storage method for sorted indexes of this embodiment supports dynamic pruning by setting a prune field in the trie node during the construction of the trie tree in the trie tree area, thereby reducing the number of nodes in the Trie tree, greatly reducing space, and improving the efficiency of KV data storage; in addition, the query efficiency o(n) can be increased to a maximum of o(1).

[0070] Specifically, see Figure 4 As shown, in the data storage method applied to the sorted index of this embodiment, the construction process of the trie tree in the trie tree area includes the pruning process:

[0071] Determine whether the prune field of the current trie node matches the remaining characters of the key value;

[0072] If the prune field of the current trie node completely matches the remaining characters of the key value, and the length of the prune field of the current trie node is less than or equal to the length of the remaining characters of the key value, a pruning operation is performed, that is, the prune field of the current trie node is set to empty, and the remaining characters of the key value are added as new prune fields to the new child trie node;

[0073] If the prune field of the current trie node matches the remaining characters of the key value, and the length of the prune field of the current trie node is greater than the remaining characters of the key value, a new child trie node is created to store the unmatched part of the prune field of the current trie node and the remaining characters of the key value, and the prune field of the current trie node is updated to match the remaining characters of the key value.

[0074] If the prune field of the current trie node does not match the remaining characters of the key value at all, no pruning operation is performed and the traversal continues downward.

[0075] In the meantime, see Figure 5 As shown, the data storage method applied to the sorted index in this embodiment includes a data query process based on the trie tree in the trie tree area:

[0076] When traversing the trie tree, if the length of the prune field of the current trie node is greater than 0, a series of comparisons and processing logic will be performed, including determining the relationship between the prune field and the remaining keys;

[0077] If the remaining characters of the prune field and the key value completely match, it means that path compression can be performed, that is, the part corresponding to the prune field is skipped and the traversal is directly downward;

[0078] If the prune field matches the remaining characters of the key value, the traversal will continue until a completely matching trie node is found or the entire key is traversed;

[0079] If the remaining characters of the prune field and the key value do not match at all, it means that there is no match and null is returned.

[0080] Also, see Figure 3 As shown, the data storage method applied to the sorting index in this embodiment includes the query process of KV data:

[0081] According to the query key value, query in the trie tree in the trie tree area;

[0082] If the query key value can be found, the index area offset offset[j] corresponding to the query key value is obtained. If the query key value cannot be found, the query result is directly returned.

[0083] According to the index area offset offset[j], get the offset of the KV data corresponding to the query key value stored in the data area, data area offset offset[i];

[0084] The length of the KV data item is obtained by calculating the difference between the index area offset offset[j] and the previous index area offset offset[j];

[0085] Get the item data of the KV data according to the data area offset offset[i] of the query key value and the length of the item of the KV data;

[0086] Get the key value size keySize from the item data of the KV data, and get the length of the key value according to the key value size keySize;

[0087] The length of the value is calculated based on the length of the item - the array length of the key value size keySize - the length of the key value, and the value corresponding to the query key value is read from the item data.

[0088] When performing data query on the KV database formed by the data storage method for sorted index in the present embodiment, after querying the index area offset offset[j] of the query key value in the trie tree in the trie tree area (refer to the above process for the query process of the trie tree), the offset data area offset offset[i] of the KV data corresponding to the query key value stored in the data area can be obtained according to the index area offset offset[j] of the query key value. Since the index area offset offset[j] of the present embodiment is a fixed-length array, the length of the entry item of the KV data can be obtained by calculating the difference between the index area offset offset[j] of the query key value and the previous index area offset offset[j]. Therefore, the entry item data of the KV data stored in the data area is obtained based on the data area offset offset[i] of the query key value and the length of the entry item of the KV data.

[0089] Furthermore, it is necessary to read the value corresponding to the query key value from the entry item data. Since the entry item data contains the key value length keySize, key value and value value, where the key value length keySize is a fixed-length array and the key value, i.e. the query key value length, is known, the length of the value value can be calculated by the overall length of the entry item data - the array length of the key value size keySize - the length of the key value. The value value is read out from the entry item data according to the length of the value value and returned.

[0090] Specifically, the key value length keySize of this embodiment is a uint16 array, and the index area offset offset[j] is a uint32 array. Correspondingly, when querying the index area offset offset[j] of the key value and the previous index area offset offset[j], the length of the entry item of the KV data can be obtained by performing a difference calculation. The index area offset offset[j] of the key value is a uint32 array. Based on the index area offset offset[j] of the query key value, take a uint32 array forward, which is the previous index area offset offset[j]. The difference calculation between the two can obtain the length of the entry item of the KV data. The length of the value value is calculated by the overall length of the entry item data - the array length of the key value size keySize - the length of the key value, where the array length of the key value size keySize is the size of the uint16 array 16.

[0091] Further, see Figure 1 As shown, in the data storage method applied to sorted index described in this embodiment, the storage structure of the KV data includes a header area, and the header area stores the offset and length of the data area, index area, and trie tree area in the overall storage structure.

[0092] This embodiment also provides a data storage device for sorting indexes, including a data storage module for KV data disk storage, the data storage module including:

[0093] The data area is used to store the item of KV data. The item includes the key value length keySize, the key value and the value value. The key value length keySize is a fixed-length array.

[0094] The index area is used to store the offset of the KV data stored in the data area, offset[i], which is a fixed-length array.

[0095] The trie tree area uses the trie tree data structure to store the key value and the index area offset offset[j] corresponding to the key value in the index area.

[0096] In the data storage device for sorting indexes of this embodiment, the index area of ​​the data storage module is sorted and indexed according to the key value, and a trie tree is added as a secondary index through the trie tree area. When performing KV data storage based on the data storage module of this embodiment, the query efficiency is the query efficiency of the trie tree o(n), and forward and backward searches can also be performed. Therefore, the KV database constructed by performing KV data storage based on the data storage device for sorting indexes of this embodiment improves the query efficiency of KV data storage.

[0097] Furthermore, the data storage device for sorting indexes in this embodiment includes a KV data writing module:

[0098] When the KV data writing module receives a KV key-value pair to be written, it calculates the key value length keySize;

[0099] The KV data writing module writes the calculated key value length keySize, key value, and value value as an item into the data area, and obtains the data area offset offset[i] of the item into the data area.

[0100] The KV data writing module writes the data area offset offset[i] to the index area in sequence, and at the same time obtains the index area offset offset[j] written from the data area offset offset[i] to the index area;

[0101] The KV data writing module writes the key value of the KV key-value pair and the index area offset offset[j] into the trie tree area.

[0102] In the data storage device applied to the sorted index of the present embodiment, the data storage module increases the query efficiency of KV data storage by adding a trie tree as a secondary index through the trie tree area. However, since the trie tree itself is a data structure that exchanges space for time, the storage consumption of KV data will be increased. In view of this, in the data storage device applied to the sorted index of the present embodiment, the data storage module constructs the trie tree in the trie tree area, and each trie node includes a key value field, a pruning field, a value field, and a children field of child nodes. The key value field stores the characters of the key value, and the value field writes the index area offset offset[j] of the key value. There is another trie node under the children field of the child node. The pruning field stores the path compression information of the current node, that is, the common prefix part of several nodes after the current node, and these common prefix parts are compressed into the pruning field of the current node.

[0103] The data storage device for sorted indexing of this embodiment supports dynamic pruning by setting a prune field in the trie node during the construction of the trie tree in the trie tree area, thereby greatly reducing space and improving the efficiency of KV data storage; in addition, the query efficiency o(n) can be increased to a maximum of o(1).

[0104] Specifically, in the data storage device for sorting indexes of this embodiment, the data storage module constructs a trie tree in a trie tree area including a pruning process:

[0105] Determine whether the prune field of the current trie node matches the remaining characters of the key value;

[0106] If the prune field of the current trie node completely matches the remaining characters of the key value, a pruning operation is performed, that is, the prune field of the current trie node is set to empty, and the remaining characters of the key value are added as new prune fields to the new child trie node;

[0107] If the prune field of the current trie node matches the remaining characters of the key value, a new child trie node is created to store the unmatched part of the prune field of the current trie node and the remaining characters of the key value, and the prune field of the current trie node is updated to match the remaining characters of the key value;

[0108] If the prune field of the current trie node does not match the remaining characters of the key value at all, no pruning operation is performed and the traversal continues downward.

[0109] At the same time, the data storage device applied to the sorted index of this embodiment includes a data query process based on the trie tree in the trie tree area:

[0110] When traversing the trie tree, if the length of the prune field of the current trie node is greater than 0, a series of comparisons and processing logic will be performed, including determining the relationship between the prune field and the remaining keys;

[0111] If the remaining characters of the prune field and the key value completely match, it means that path compression can be performed, that is, the part corresponding to the prune field is skipped and the traversal is directly downward;

[0112] If the prune field matches the remaining characters of the key value, the traversal will continue until a completely matching trie node is found or the entire key is traversed;

[0113] If the remaining characters of the prune field and the key value do not match at all, it means that there is no match and null is returned.

[0114] In addition, the data storage device for sorting indexes in this embodiment includes a KV data query module:

[0115] The KV data query module queries the trie tree in the trie tree area according to the query key value;

[0116] If the query key value can be found, the index area offset offset[j] corresponding to the query key value is obtained. If the query key value cannot be found, the query result is directly returned.

[0117] The KV data query module obtains the offset of the KV data corresponding to the query key value stored in the data area according to the index area offset offset[j];

[0118] The KV data query module calculates the difference between the index area offset offset[j] and the previous index area offset offset[j] to obtain the length of the KV data item;

[0119] The KV data query module obtains the item data of the KV data according to the data area offset offset[i] of the query key value and the length of the item of the KV data;

[0120] The KV data query module obtains the key value size keySize from the item data of the KV data, and obtains the length of the key value according to the key value size keySize;

[0121] The KV data query module calculates the length of the value based on the length of the item - the array length of the key value size keySize - the length of the key value, and reads the value corresponding to the query key value from the item data.

[0122] When the KV data query module performs data query in the KV database formed by the data storage method for sorted index in the present embodiment, after querying the index area offset offset[j] of the query key value in the trie tree in the trie tree area (refer to the above process for the query process of the trie tree), the offset data area offset offset[i] of the KV data corresponding to the query key value stored in the data area can be obtained according to the index area offset offset[j] of the query key value. Since the index area offset offset[j] of the present embodiment is a fixed-length array, the length of the entry item of the KV data can be obtained by calculating the difference between the index area offset offset[j] of the query key value and the previous index area offset offset[j]. Therefore, the entry item data of the KV data stored in the data area is obtained based on the data area offset offset[i] of the query key value and the length of the entry item of the KV data.

[0123] Furthermore, it is necessary to read the value corresponding to the query key value from the entry item data. Since the entry item data contains the key value length keySize, key value and value value, where the key value length keySize is a fixed-length array and the key value, i.e. the query key value length, is known, the length of the value value can be calculated by the overall length of the entry item data - the array length of the key value size keySize - the length of the key value. The value value is read out from the entry item data according to the length of the value value and returned.

[0124] Specifically, the key value length keySize of this embodiment is a uint16 array, and the index area offset offset[j] is a uint32 array. Correspondingly, when querying the index area offset offset[j] of the key value and the previous index area offset offset[j], the length of the entry item of the KV data can be obtained by performing a difference calculation. The index area offset offset[j] of the key value is a uint32 array. Based on the index area offset offset[j] of the query key value, take a uint32 array forward, which is the previous index area offset offset[j]. The difference calculation between the two can obtain the length of the entry item of the KV data. The length of the value value is calculated by the overall length of the entry item data - the array length of the key value size keySize - the length of the key value, where the array length of the key value size keySize is the size of the uint16 array 16.

[0125] Furthermore, in the data storage device for sorting indexes of this embodiment, the data storage module includes a header area, and the header area stores the offset and length of the data area, the index area, and the trie tree area in the overall storage structure.

[0126] Embodiment 2

[0127] The following describes an electronic device embodiment of the present invention, which can be regarded as a specific physical implementation of the method and device embodiments of the present invention. The details described in the electronic device embodiment of the present invention should be regarded as a supplement to the above method or device embodiments; details not disclosed in the electronic device embodiment of the present invention can be implemented with reference to the above method or device embodiments.

[0128] Figure 6 It is a structural diagram of an electronic device of an embodiment of the present invention, the electronic device includes a processor and a memory, the memory is used to store a computer executable program, when the computer program is executed by the processor, the processor executes the data storage method applied to the sorting index of embodiment one.

[0129] like Figure 6 As shown, the electronic device is presented in the form of a general computing device. The processor may be one or more and work in coordination. The present invention does not exclude distributed processing, that is, the processor may be dispersed in different physical devices. The electronic device of the present invention is not limited to a single entity, but may also be the sum of multiple physical devices.

[0130] The memory stores a computer executable program, which is usually a machine-readable code. The computer-readable program can be executed by the processor to enable the electronic device to perform the method of the present invention, or at least part of the steps in the method.

[0131] The memory includes a volatile memory, such as a random access memory unit (RAM) and / or a cache memory unit, and may also be a non-volatile memory, such as a read-only memory unit (ROM).

[0132] Optionally, in this embodiment, the electronic device further includes an I / O interface, which is used for the electronic device to exchange data with an external device. The I / O interface can represent one or more of several types of bus structures, including a storage unit bus or a storage unit controller, a peripheral bus, a graphics acceleration port, a processing unit, or a local bus using any of a variety of bus structures.

[0133] It should be understood that Figure 6 The electronic device shown is only an example of the present invention, and the electronic device of the present invention may also include elements or components not shown in the above examples. For example, some electronic devices also include display units such as display screens, and some electronic devices also include human-computer interaction elements such as buttons, keyboards, etc. As long as the electronic device can execute the computer-readable program in the memory to implement the method of the present invention or at least part of the steps of the method, it can be considered as an electronic device covered by the present invention.

[0134] Figure 7 Schematic diagram of a computer readable recording medium according to an embodiment of the present invention. Figure 4 As shown, a computer executable program is stored in a computer-readable recording medium, and when the computer executable program is executed, the data storage method for sorting indexes of the first embodiment of the present invention is implemented. The computer-readable recording medium may include a data signal propagated in a baseband or as part of a carrier, which carries a readable program code. This propagated data signal can take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The readable recording medium can also be any readable medium other than a readable recording medium, which can send, propagate or transmit a program for use by an instruction execution system, device or device or in combination with it. The program code contained on the readable recording medium can be transmitted using any suitable medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the above.

[0135] Program code for performing the operations of the present invention may be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).

[0136] Through the above description of the implementation mode, it is easy for those skilled in the art to understand that the present invention can be implemented by hardware capable of executing a specific computer program, such as the system of the present invention, and the electronic processing unit, server, client, mobile phone, control unit, processor, etc. contained in the system. The present invention can also be implemented by computer software that executes the method of the present invention, such as control software executed by a microprocessor, an electronic control unit, a client, a server, etc. However, it should be noted that the computer software that executes the method of the present invention is not limited to being executed by one or a specific hardware entity, and it can also be implemented in a distributed manner by unspecified specific hardware. For computer software, the software product can be stored in a computer-readable recording medium (which can be a CD-ROM, a USB flash drive, a mobile disk, etc.), and can also be distributed and stored on the network, as long as it enables the electronic device to execute the method according to the present invention.

[0137] The above embodiments are only used to illustrate the present invention and are not intended to limit the technical solutions described in the present invention. Although the present invention has been described in detail with reference to the above embodiments, the present invention is not limited to the above specific implementation methods. Therefore, any modification or equivalent replacement of the present invention; and all technical solutions and improvements thereof that do not depart from the spirit and scope of the invention are included in the scope of the claims of the present invention.

Claims

1. A data storage method for sorted indexes, characterized in that: When KV data is stored on disk, the storage structure of KV data includes: The data area is used to store the entry item of KV data, wherein the entry item includes the key value length keySize, the key value and the value value, and the key value length keySize is a fixed-length array; The index area is used to store the offset of the KV data stored in the data area, offset[i], which is a fixed-length array. The trie tree area uses the trie tree data structure to store the key value and the offset [j] of the index index area corresponding to the key value.

2. The data storage method for sorting index according to claim 1, characterized in that: Including KV data writing process: When writing a KV key-value pair, calculate the key value length keySize; The calculated key value length keySize, key value, and value value are taken as an entry item and written into the data area. At the same time, the data area offset offset[i] of the entry item written into the data area is obtained. Write the offset [i] of the data area into the index area in sequence, and get the offset [i] of the data area and write the offset [j] of the index area into the index area; Write the key value of the KV key-value pair and the index area offset offset[j] into the trie tree area.

3. The data storage method for sorting index according to claim 2, characterized in that: For the construction of the trie tree in the trie tree area, each trie node includes a key value field, a prune field, a value field and a children field. The key value field stores the characters of the key value, the value field writes the index area offset offset[j] of the key value, and there is another trie node under the children field. The prune field stores the path compression information of the current node, that is, the common prefix part of several nodes after the current node. These common prefix parts are compressed into the prune field of the current node.

4. The data storage method for sorting index according to claim 3, characterized in that: The construction process of the trie tree in the trie tree area includes the following pruning process: Determine whether the prune field of the current tr ie node matches the remaining characters of the key value; If the prune field of the current trie node completely matches the remaining characters of the key value, a pruning operation is performed, that is, the prune field of the current trie node is set to empty, and the remaining characters of the key value are added as new prune fields to the new child trie node; If the prune field of the current trie node matches the remaining characters of the key value, a new child trie node is created to store the unmatched part of the prune field of the current trie node and the remaining characters of the key value, and the prune field of the current trie node is updated to match the remaining characters of the key value; If the prune field of the current trie node does not match the remaining characters of the key value at all, no pruning operation is performed and the traversal continues downward.

5. The data storage method for sorting index according to claim 4, characterized in that: Including a data query process based on the trie tree in the trie tree area: When traversing the trie tree, if the length of the prune field of the current trie node is greater than 0, the relationship between the prune field and the remaining keys is determined; If the remaining characters of the prune field and the key value completely match, it means that path compression can be performed, that is, the part corresponding to the prune field is skipped and the traversal is directly downward; If the prune field matches the remaining characters of the key value, the traversal will continue until a completely matching trie node is found or the entire key is traversed; If the remaining characters of the prune field and the key value do not match at all, it means that there is no match and null is returned.

6. The data storage method for sorting index according to any one of claims 2 to 5, characterized in that: Including the query process of KV data: According to the query key value, query in the trie tree in the trie tree area; If the query key value can be found, the index area offset offset[j] corresponding to the query key value is obtained. If the query key value cannot be found, the query result is directly returned. According to the index area offset offset[j], get the offset of the KV data corresponding to the query key value stored in the data area, data area offset offset[i]; The length of the KV data entry item is obtained by calculating the difference between the index area offset offset[j] and the previous index area offset offset[j]; Get the entry i tem data of the KV data according to the data area offset offset[i] of the query key value and the length of the entry i tem of the KV data; Get the key value size keySize from the item data of the KV data, and get the length of the key value according to the key value size keySize; The length of the value is calculated according to the length of the entry item - the array length of the key value keySize - the length of the key value, and the value corresponding to the query key value is read from the item data.

7. The data storage method for sorting index according to claim 1, characterized in that: The storage structure of the KV data includes a header area, and the header area stores the offset and length of the data area, the index area, and the trie tree area in the overall storage structure.

8. A data storage device for sorting indexes, characterized in that: It includes a data storage module for KV data disk storage. The data storage module includes: The data area is used to store the entry item of KV data, wherein the entry item includes the key value length keySize, the key value and the value value, and the key value length keySize is a fixed-length array; The index area is used to store the offset of the KV data stored in the data area, offset[i], which is a fixed-length array. The trie tree area uses the trie tree data structure to store the key value and the index area offset offset[j] corresponding to the key value in the index area.

9. The data storage device for sorting index according to claim 8, characterized in that: The data storage module includes a header area, and the header area stores the offset and length of the data area, the index area, and the trie tree area in the overall storage structure.

10. An electronic device comprising a processor and a memory, wherein the memory is used to store a computer executable program, characterized in that: When the computer program is executed by the processor, the processor executes the data storage method applied to sorted indexes as described in any one of claims 1 to 7.