Data query method, device, equipment, storage medium and program product
By locating the target data group and entry value block in the LSM-Tree based on the attribute type of the key and entry value, reading only the required data and applying a compression algorithm that matches the attribute type, the problem of low query efficiency in LSM-Tree is solved. This achieves efficient partial field querying and data compression, improving query performance and flexibility.
Patent Information
- Application Number
- CN202611200490.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-07
- Publication Date
- 2026-11-24
AI Technical Summary
In existing technologies, LSM-Tree data query methods still require reading the complete value and parsing it when the query request only needs a portion of the value, resulting in low query efficiency and a lack of effective compression and filtering retrieval methods for the value.
By obtaining the attribute types of the keys and entry values to be queried, the target data group and target entry value block are determined. The required data is read only from the target entry value block, and the data is stored and decompressed using an attribute type matching compression algorithm. Combined with filtering conditions, the entry values that meet the requirements are selected, and the query of a specified portion of entry values is supported.
It reduces disk read/output overhead, improves query efficiency, reduces storage space usage and CPU decompression processing overhead, and enhances query performance and flexibility.
Smart Images

Figure CN123157771A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data storage technology, and in particular to a data query method, apparatus, device, storage medium, and program product. Background Technology
[0002] Log-Structured Merge-Tree (LSM-Tree) is a write-optimized data structure widely used in key-value (KV) storage systems because it transforms random writes into sequential writes, significantly improving write throughput. The disk data file SSTable of an LSM-Tree uses a row-like storage method to store multiple KV values: in the data blocks of the SSTable, the key and its corresponding full value are stored adjacently in each KV block, arranged alternately in a Key1-Value1-Key2-Value2...KeyN-ValueN pattern.
[0003] In related technologies, when querying the key-value pairs in an SSTable, the storage location of the target key is first determined within the target data block, and then the value stored immediately adjacent to the target key is read as the target value based on that storage location.
[0004] However, in the above data query methods, when the query request only needs some fields in Value, it is still necessary to read the complete Value first before parsing and extracting fields, which results in low query efficiency. Summary of the Invention
[0005] Therefore, it is necessary to provide a data query method, apparatus, device, storage medium, and program product that can improve query efficiency in response to the above-mentioned technical problems.
[0006] Firstly, this application provides a data query method, which includes:
[0007] In response to a data query request, retrieve the key to be queried and the attribute type of the value of the entry to be queried;
[0008] The query retrieves the target data group corresponding to the key in the data file containing the key to be queried. The data file contains multiple data groups, each containing a key block and at least one entry value block. The key block contains multiple keys, and each entry value block stores multiple entry values of the same attribute type. Each key corresponds to one entry value in a different entry value block.
[0009] Determine the target position of the key in the key block of the target data group based on the key to be queried, and determine the target entry value block based on the attribute type of the entry value to be queried;
[0010] Determine the query results of the data query request based on the target location and the target entry value block.
[0011] In the technical solution provided in this application embodiment, in response to a data query request, the key to be queried and the attribute type of the entry value to be queried are obtained. The target data group corresponding to the key to be queried is then queried in the data file where the key is located. The target position of the key to be queried within the key block of the target data group is then determined based on the key to be queried, and the target entry value block is determined based on the attribute type of the entry value to be queried. Finally, the query result of the data query request is determined based on the target position and the target entry value block. The data file includes multiple data groups, each including a key block and at least one entry value block. Each key block includes multiple keys, and each entry value block stores multiple entry values of the same attribute type. Each key corresponds to one entry value in a different entry value block. In the above method, the corresponding target entry value block is determined based on the attribute type of the entry value to be queried, and the entry value corresponding to the key to be queried is read only from that target entry value block. This supports querying a specified portion of the entry value without reading the complete value data or other entry value blocks unrelated to the entry value to be queried, thereby reducing disk read / write overhead and improving query efficiency.
[0012] In one embodiment, querying the target data group corresponding to the key in the data file containing the key to be queried includes:
[0013] Retrieve the data group index relationship in the data file; the data group index relationship includes the correspondence between key ranges and data groups;
[0014] The data group that matches the key to be queried in the data group index relationship is identified as the target data group.
[0015] In the technical solution provided in this application embodiment, by obtaining the data group index relationship in the data file and determining the data group that matches the key to be queried in the data group index relationship as the target data group, it is possible to quickly locate the target data group based on the key to be queried without traversing the entire data file, thereby greatly reducing the scope and time of data search and improving the efficiency of data query.
[0016] In one embodiment, the key block further includes an entry value block index relationship, determining the target entry value block based on the attribute type of the entry value to be queried, including:
[0017] Retrieve the item value block index relationship in the key block; the item value block index relationship includes the correspondence between attribute types and item value blocks;
[0018] The entry value blocks in the entry value block index relationship that match the attribute type of the entry value to be queried are identified as the target entry value blocks.
[0019] In the technical solution provided in this application embodiment, by obtaining the entry value block index relationship in the key block, and determining the entry value block in the entry value block index relationship that matches the attribute type of the entry value to be queried as the target entry value block, the corresponding target entry value block can be quickly located according to the attribute type of the entry value to be queried, without having to traverse all entry value blocks, thereby reducing the scope and time of data search; at the same time, since only the target entry value block corresponding to the attribute type to be queried needs to be read, and there is no need to read other irrelevant entry value blocks, the amount of disk data read is further reduced, the input and output overhead is reduced, and the query efficiency is improved.
[0020] In one embodiment, determining the query result of the data query request based on the target location and the target entry value block includes:
[0021] Read the target entry value corresponding to the target location from the target entry value block, and determine the query result of the data query request based on the target entry value.
[0022] In the technical solution provided in this application embodiment, by reading the target entry value corresponding to the target position from the target entry value block and determining the query result based on the target entry value, the entry value at the corresponding position can be directly read from the target entry value block according to the arrangement number of the key in the key block. The correspondence between the key and the value is established through the arrangement position, without the need to store additional address pointers or offset information in the key, thus reducing storage overhead. At the same time, only one entry value corresponding to the target position needs to be read from the target entry value block, without the need to read all the data in the target entry value block, further reducing the amount of disk data read, reducing input and output overhead, and improving query efficiency.
[0023] In one embodiment, each entry value block is compressed using a corresponding compression algorithm based on the data characteristics of its respective attribute type during storage.
[0024] In one embodiment, the method further includes:
[0025] Based on the decompression algorithm corresponding to the compression algorithm used when storing the target entry value block, the target entry value block is decompressed to obtain the decompressed target entry value block;
[0026] Based on the target location and target entry value block, determine the query results of the data query request, including:
[0027] Based on the target location and the decompressed target entry value block, determine the query result of the data query request.
[0028] In the technical solution provided in this application embodiment, the target entry value block is decompressed according to the decompression algorithm corresponding to the compression algorithm used when storing the target entry value block, and the query result is determined according to the target location and the decompressed target entry value block. Since each entry value block is compressed using the corresponding compression algorithm according to the data characteristics of its own attribute type when stored, only the decompression algorithm corresponding to the compression algorithm needs to be used to decompress the target entry value block during querying, without decompressing other unrelated entry value blocks, thus reducing the decompression processing overhead of the central processing unit. At the same time, each entry value block is stored according to the corresponding compression algorithm matched to its attribute type, which can achieve a higher compression ratio, reduce the storage space occupied by the data on the disk and the input / output overhead during reading, and further improve the query performance.
[0029] In one embodiment, the data query request further includes filtering conditions to determine the query results of the data query request based on the target location and the target entry value block, including:
[0030] The values of each item in the target item value block are filtered according to the filtering conditions, and at least one target item value that meets the filtering conditions is selected.
[0031] The query results of the data query request are determined based on the values of each target entry.
[0032] In the technical solution provided in this application embodiment, each entry value in the target entry value block is filtered according to the filtering conditions, and at least one target entry value that meets the filtering conditions is selected. The query result is determined based on each target entry value. Since the entry values are filtered according to the filtering conditions at the storage engine level, only the entry values that meet the filtering conditions and their corresponding keys will be read and returned. The data corresponding to the entry values that do not meet the filtering conditions are filtered out at the storage engine level. There is no need to return all the data to the upper-layer business and then have the upper-layer business filter it. This reduces the amount of data processing and memory transfer of the upper-layer business, shrinks the query result set, improves query efficiency, and reduces the consumption of central processing unit and memory resources.
[0033] In one embodiment, the data file further includes at least one data block and a data block index relationship. Each data block includes at least one or more key-value pairs, and the key and its corresponding complete value data are stored contiguously in each key-value pair. The method further includes:
[0034] If the target data group corresponding to the key to be queried is not found in the data file, the target data block corresponding to the key to be queried is determined according to the data block index relationship; the data block index relationship includes the correspondence between the key range and the data block.
[0035] Read the complete target value data immediately adjacent to the key of the target data block;
[0036] The query result of the data query request is determined based on the target entry value in the target complete value data that corresponds to the attribute type of the entry value to be queried.
[0037] In the technical solution provided in this application embodiment, when the target data group corresponding to the key to be queried is not found, the target data block is determined according to the data block index relationship. The target complete value data of the key to be queried is read from the target data block and stored adjacent to it. The query result is determined according to the target entry value in the target complete value data that corresponds to the attribute type of the entry value to be queried. It can be compatible with both columnar and row storage formats. For key ranges that are configured as columnar storage format, columnar storage mode is used for efficient querying. For key ranges that are not configured as columnar storage format, it automatically falls back to row storage mode for querying. This avoids the problem of query failure due to the key not belonging to any columnar storage data group, and improves the flexibility and efficiency of the data query method.
[0038] Secondly, this application also provides a data query device, which includes:
[0039] The retrieval module is used to respond to data query requests and retrieve the key to be queried and the attribute type of the value of the entry to be queried.
[0040] The query module is used to query the target data group corresponding to the key in the data file where the key to be queried is located. The data file includes multiple data groups, each of which includes a key block and at least one entry value block. The key block includes multiple keys, and each entry value block stores multiple entry values of the same attribute type. Each key corresponds to one entry value in a different entry value block.
[0041] The first determining module is used to determine the target position of the key to be queried in the key block of the target data group based on the key to be queried, and to determine the target entry value block based on the attribute type of the entry value to be queried.
[0042] The second determination module is used to determine the query result of the data query request based on the target location and the target entry value block.
[0043] Thirdly, this application also provides a computer device including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the method in any of the embodiments of the first aspect described above.
[0044] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method in any of the embodiments of the first aspect described above.
[0045] Fifthly, this application also provides a computer program product, which includes a computer program that, when executed by a processor, implements the steps of the method in any of the embodiments of the first aspect described above. Attached Figure Description
[0046] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0047] Figure 1 This is a schematic diagram of the LSM-Tree read / write process in related technologies;
[0048] Figure 2 This is a schematic diagram of the SSTable format in related technologies;
[0049] Figure 3 This is a schematic diagram illustrating the format of IndexBlock in SSTable in related technologies;
[0050] Figure 4 This is a schematic diagram illustrating the format of a DataBlock in an SSTable within related technologies.
[0051] Figure 5 This is an internal structural diagram of a computer device in one embodiment;
[0052] Figure 6 This is a flowchart illustrating a data query method in one embodiment;
[0053] Figure 7 This is a schematic diagram of the format of a DataGroup in one embodiment;
[0054] Figure 8 This is a schematic diagram of the KeyBlock format in one embodiment;
[0055] Figure 9 This is a schematic diagram of fixed-length value entry format storage in one embodiment;
[0056] Figure 10 This is a schematic diagram illustrating the storage of variable-length value entry format in one embodiment;
[0057] Figure 11 This is a schematic diagram of the SSTable format in one embodiment;
[0058] Figure 12This is a flowchart illustrating the process of determining the target data group corresponding to the key to be queried in one embodiment;
[0059] Figure 13 This is a flowchart illustrating the process of determining a target entry value block in one embodiment;
[0060] Figure 14 This is a schematic diagram of the process of decompressing the target entry value block in one embodiment;
[0061] Figure 15 This is a flowchart illustrating the process of determining the query result of a data query request in one embodiment.
[0062] Figure 16 This is a schematic diagram of the process of querying row-stored data in one embodiment;
[0063] Figure 17 This is a flowchart illustrating the data query method in another embodiment;
[0064] Figure 18 This is a structural block diagram of a data query device in one embodiment. Detailed Implementation
[0065] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0066] Log-Structured Merge-Tree (LSM-Tree) is a hierarchical, ordered data structure designed for write-heavy, read-light scenarios. Its core idea is to fully utilize the fact that the performance of batch sequential writes on disk is much higher than that of random writes, transforming batch random writes into sequential writes to achieve high-efficiency write performance. It is widely used in key-value (KV) storage systems.
[0067] like Figure 1 The diagram illustrates the LSM-Tree read / write process. The LSM-Tree data consists of two parts: a memory portion and a disk portion. The memory portion comprises a Memtable and multiple Immutable Memtables. The Memtable, representing the LSM-Tree's memory data, is typically in skip list format and is usually used as a write cache; data is first written to the Memtable when it is written. The disk portion consists of multiple levels of SSTables (Sorted String Tables, a type of persistent, immutable, ordered data file).
[0068] See Figure 1 As shown, in LSM-Tree, the write process is as follows: First, the data is written to the Write-Ahead Logging (WAL) file to ensure data persistence safety. Then, the data is written to the Memtable, ending the write process. The data sinking process is as follows: When the Memtable is full, it is converted into a read-only Immutable Memtable, and the data is sinked to the disk Level 0 layer by a background asynchronous thread. Subsequently, it sinks to Level 1 to Level N sequentially according to the configured thresholds. The read process is as follows: the data is searched sequentially from Memtable, Immutable Memtable, Level 0, Level 1, ..., Level N, and returned if found.
[0069] The format of STable is as follows Figure 2 As shown, this includes DataBlocks, Bloom blocks (FilterBlocks), IndexBlocks, and Footers. The process for querying key-value data in this format is as follows: Read the Footer at the end of the file to obtain the positions of the IndexBlocks and Bloom blocks. Then, load the Bloom blocks into memory and quickly determine if the Key exists (if it does not exist, return directly, skipping subsequent steps). If the Bloom blocks determine that the Key exists, continue loading the IndexBlocks into memory. Then, based on the size range of the Key, use binary search to find the specific offset position of the corresponding DataBlock. Finally, read the specific DataBlock and find the specific Value within that block (possibly through binary search or traversal) and return it.
[0070] The format of IndexBlock in SSTable is as follows: Figure 3The diagram illustrates the fine-grained internal storage structure of the index block. To achieve efficient space compression and fast binary search, the index block is designed with three main parts: a data area (using prefix compression), a restart array, and a BlockTrailer. Regarding the data area, since the keys in the SSTable are ordered, adjacent keys often share a long common prefix (e.g., user_001, user_002..., with the common prefix user_00). By recording only the unique parts, several times or even tens of times more storage space can be saved. Regarding the restart array, when searching for a key, the system first performs a binary search on this restart_offset array in memory to find the restart point where the target key is most likely located, and then sequentially scans the corresponding index entries from that restart point. Regarding the BlockTrailer, compressType (1B) indicates whether the index data block has been compressed and which compression algorithm was used (e.g., 0 for no compression, 1 for Snappy compression, etc.), and crc (4B) is the CRC (Cyclic Redundancy Check) checksum.
[0071] The format of a DataBlock in an SSTable is as follows: Figure 4 As shown, it uses the exact same layout design as IndexBlock in its internal structure. This unified format design is for code reuse (such as the BlockBuilder class in LevelDB / RocksDB), but the specific content they store is fundamentally different: DataBlock stores the actual key-value pairs written by the user, while IndexBlock stores metadata pointing to these data blocks.
[0072] In related technologies, LSM-Tree's disk data file SSTable uses a row-like storage method to store multiple key-value pairs: within the SSTable's data blocks, each key-value pair's key and its corresponding complete value are stored adjacently, arranged alternately in a Key1-Value1-Key2-Value2...KeyN-ValueN pattern. When querying a specific key-value pair in the SSTable, the entire key-value pair is the smallest unit of query. The specific query process is as follows: within the target data block, both the indexBlock and DataBlock use a binary search on the restart array to locate the storage location of the target key, and then read the value immediately adjacent to the target key from that location as the target value.
[0073] However, in the above data query methods, when the query request only needs a portion of the fields in the Value, the complete Value still needs to be read first before parsing and field extraction, resulting in low query efficiency. Furthermore, there is no better way to compress and retrieve similar or identical values in the Value; it is only possible to query by key, parse the entire value, and then process it, wasting disk read and parsing time. Additionally, it currently does not support filtering conditions for the Value.
[0074] Based on this, embodiments of this application provide a data query method, apparatus, device, storage medium, and program product. The method determines the corresponding target entry value block according to the attribute type of the entry value to be queried, and reads the entry value corresponding to the key to be queried only from the target entry value block. This supports querying a specified part of the entry value without reading the complete value data or other entry value blocks unrelated to the entry value to be queried, thereby reducing disk read input / output overhead and improving query efficiency.
[0075] The data query method provided in this application embodiment can be applied to, for example... Figure 5 The computer device shown can be a terminal or a server, and its internal structure diagram can be as follows: Figure 5 As shown, the computer device includes a processor, memory, input / output interfaces, a communication interface, a display unit, and an input device. The processor, memory, and input / output interfaces are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interfaces. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The input / output interfaces are used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, Near Field Communication (NFC), or other technologies. When the computer program is executed by the processor, it implements a data query method. The display unit is used to form a visually visible image and can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs, or touchpads set on the casing of the computer device, or external keyboards, touchpads, or mice, etc.
[0076] Those skilled in the art will understand that Figure 5The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0077] In one exemplary embodiment, such as Figure 6 As shown, a data query method is provided, which can be applied to... Figure 1 Taking a computer device as an example, the explanation includes the following steps:
[0078] S201, in response to a data query request, retrieve the key to be queried and the attribute type of the entry value to be queried.
[0079] Before performing data queries, the data storage method in this embodiment will be introduced, including steps 1-3, as detailed below:
[0080] Step 1: In response to a data write request, obtain the key-value pair to be written and the key range corresponding to the key-value pair, and determine the target storage format based on the key range.
[0081] A data write request is used to write data to an LSM-based storage system. A data write request includes key-value pairs (KV) to be written, each consisting of a key and a corresponding value. The value includes the value of at least one attribute. For example, the value of a user record may include values for multiple attributes such as age, height, and weight. An attribute type can be considered an entry, so a user record's value can be understood as including at least one entry value. An entry block stores multiple entry values of the same attribute type; for example, if the entry is age, then the entry block stores the age values of n users.
[0082] A key range is the interval to which a key belongs. The target storage format is how key-value pair data is organized in the data file (SStable), including row-based and column-based formats. One or more key ranges can be pre-configured in the storage system, each associated with a corresponding storage format. For example, a key range might be configured for column-based storage, while other unconfigured key ranges use the original row-based format. Row-based storage is the traditional format that stores the key and the complete value as a whole, i.e., keys and values are stored alternately. Column-based storage is a format that stores the key and each entry value separately, i.e., the key is stored in a separate key block, and each entry value is stored in its corresponding entry value block according to its attribute type. A computer device can determine the key range to which a key belongs based on the key of the key-value pair to be written. The key range is the interval to which the key belongs; for example, [user:1000,user:2000] represents the interval from "user:1000" to "user:2000".
[0083] The specific implementation process is as follows: When a computer device receives a data write request, it can parse the key-value pairs to be written, obtain the key and value, and divide the value into multiple entries according to a preset value segmentation rule. The preset value segmentation rule can be pre-defined by the user through configuration, which specifies the entry value segmentation method for a specific key range and the attribute type of each entry value.
[0084] Then, the key to be written is matched with each preset key range. If the key to be written falls within a configured key range, for example, the key "user:1500" falls within the configured key range "[user:1000,user:2000]", then the target storage format of the key-value pair to be written is determined to be columnar storage format; if the key to be written does not fall within any configured key range, then the target storage format of the key-value pair to be written is determined to be row storage format. Furthermore, when the key-value pairs to be written are batch written, the computer device can group multiple key-value pairs according to the key range to which each key belongs. Key-value pairs belonging to the same key range adopt the same target storage format. For example, in batch-written key-value pairs, the keys "user:1500" and "user:1800" both belong to the configured key range and adopt columnar storage format, while the key "admin:001" does not belong to any configured key range and adopts row storage format.
[0085] Step 2: If the target storage format is columnar, then based on the data group format, organize the key-value pairs to be written into data groups according to the columnar storage format. The data group format includes key blocks and at least one entry value block. Each key block contains the keys of the key-value pairs to be written, and each entry value block stores entry values of the same attribute type from the values of multiple key-value pairs. Each entry value block corresponds to one attribute type.
[0086] like Figure 7 The diagram illustrates the DataGroup format. A DataGroup is a data organization unit in a data file, used to replace the DataBlock in a traditional SSTable. The DataGroup format includes a KeyBlock and at least one ValueEntryBlock. The KeyBlock stores all key information within the DataGroup, while each ValueEntryBlock stores a set of values of a specific attribute type corresponding to all keys within the DataGroup.
[0087] like Figure 8 The diagram illustrates the KeyBlock format. Data within a KeyBlock is arranged sequentially, and adjacent keys are compressed using a prefix compression method (e.g., [sharedLen|unsharedLen|unsharedKey] format). To support fast retrieval, a restart array is located at the end of the KeyBlock for binary search within the KeyBlock. Below (or at the end of) the restart array, the KeyBlock also maintains a set of valueEntryHandles. Each handle records the attribute type identifier (e.g., age, height, etc.) of the corresponding value block, as well as the physical offset and length of that value block within the current data set.
[0088] Each entry value block is specifically designed to store a set of entry values for a particular attribute. For example, value entry block-1 stores only the "age" values corresponding to all keys within this data set; value entry block-2 stores only the "height" values corresponding to all keys. Because the attribute types within the same entry value block are completely consistent, this allows the system to independently select the optimal compression algorithm (such as RLE run-length encoding, dictionary encoding, Snappy, etc.) for columnar compression based on the characteristics of the data (such as number size, repetition rate, string length, etc.).
[0089] Each key within a key block corresponds logically to a value in each value block in the same predetermined order. The system calculates the row index of the target key within the key block by searching within the key block, and then uses this index as a unified index to accurately locate and read the corresponding value in the target value block, thereby achieving efficient on-demand data concatenation and retrieval.
[0090] At the end of the data in both the key block and each entry value block, this scheme includes a fixed-length BlockTrailer. This BlockTrailer contains two core verification and configuration fields: `compressType` (1 byte): occupies 1 byte and records the compression algorithm type used for the current data block (e.g., 0 for no compression, 1 for Snappy, 2 for dictionary compression, etc.). `crc` (4 bytes): occupies 4 bytes and stores the 32-bit Cyclic Redundancy Check (CRC32) code for the current data block. The computer device's processing logic is as follows: When reading a key block or an entry value block from the disk, the device first parses the BlockTrailer at its end. First, it selects the corresponding decompression algorithm based on the `compressType` to restore the data; then, it recalculates the CRC checksum of the restored data and compares it with the original `crc` field. If they match, the data is considered complete and reliable; if they do not match, the data block is determined to be corrupted or tampered with, and the system will trigger exception handling or retry from backup, thus greatly ensuring the consistency and reliability of the underlying data storage and transmission process.
[0091] Optionally, each entry value block can be stored using, for example... Figure 9 The fixed-length value entry format shown is used for storage, or in a format such as Figure 10 The variable-length value entry format is shown. Regarding the fixed-length value entry format, when each specific data value (ValueEntry) of a particular attribute (such as age or rating) occupies the same number of bytes, the entry value block can use a fixed-length storage format. Within the value entry block, only the value entries are arranged sequentially: [V1Entry-n], [V2Entry-n], ..., [VNEntry-n]. There is no need to record the length information for each value separately. Regarding the variable-length value entry format, when the value lengths of a particular attribute vary greatly (such as names, cities, notes, or large binary objects), the entry value block can use a variable-length storage format. Each value entry within the value entry block consists of two parts: [len] (length prefix) and [V1Entry-n] (the actual value content). That is: entry:1[len|V1Entry-n], entry:2[len|V2Entry-n]. When the system reads the Block based on the "line number index", it cannot directly calculate the absolute address of the target value. It must parse the Block sequentially starting from the beginning of the Block: first, read the len field to get the length of the current entry, then read the corresponding VnEntry-n value based on the length, and so on until the target line number is located.
[0092] When a computer device determines that the target storage format is columnar storage, it can organize the key-value pairs to be written into data groups according to the data group format. Specifically, the computer device can obtain preset value segmentation configuration information, which includes entry value segmentation rules for the key range to which the key-value pairs to be written belong. The computer device can then segment the value in the key-value pairs to be written into multiple entry values according to the entry value segmentation rules, with each entry value corresponding to an attribute type. Then, the computer device can extract the keys from the key-value pairs to be written and store them in key blocks; it can also classify the segmented entry values according to their respective attribute types, storing entry values of the same attribute type in the same entry value block. For example, if the value is segmented into three entries: age, height, and weight, then all key age values are stored in the age entry value block (e.g., ValueEntry-1 Block), all key height values are stored in the height entry value block (e.g., ValueEntry-2 Block), and all key weight values are stored in the weight entry value block (e.g., ValueEntry-n Block). Optionally, multiple keys recorded in a key block are sorted according to their size, and the values in each value block are arranged in the same order as the keys in the key block to ensure the correspondence between keys and values. Optionally, for key ranges outside the configuration (i.e., key ranges not configured to use columnar storage format), the computer device still processes and stores them in row-based storage format, that is, the key and the complete value are written into the data block as a whole.
[0093] Step 3: Compress each value block in the target data group and write the compressed target data group into the data file.
[0094] The data file is a persistent file in SSTable format within an LSM-tree. Compression is performed by applying a compression algorithm to each entry value block to reduce the storage space occupied by the data. Since the entry values stored in the same entry value block have the same attribute type and the data redundancy is high, a dedicated columnar storage compression algorithm optimized for this attribute type can be used to achieve a higher compression ratio.
[0095] In this embodiment, after organizing the data into a data group according to the data group format, the computer device can compress each entry value block in the target data group before writing the target data group to the disk. Specifically, the computer device can determine the target compression algorithm matching the attribute type (or data feature) from a pre-configured compression algorithm mapping table based on the attribute type (or data feature) corresponding to each entry value block. Different attribute types can use different compression algorithms. For example, an integer-specific compression algorithm can be used for integer age values, and a string-specific compression algorithm can be used for string name values. The computer device uses the determined target compression algorithm to compress the corresponding entry value block to obtain the compressed entry value block. Optionally, each entry value block can be stored using a fixed-length encoding format or a variable-length encoding format, which can be selected according to the data characteristics of the entry value. For fixed-length entry values (such as integers, timestamps, etc.), a fixed-length encoding format can be used; for variable-length entry values (such as strings), a variable-length encoding format can be used, and the length information of the entry value is recorded before each entry value. Optionally, after compressing each entry value block, the computer device also needs to store the key blocks. Multiple keys can be stored using shared prefix compression. Optionally, after compressing the target data group, the computer device writes the target data group to a data file according to the SSTable format.
[0096] like Figure 11 The diagram illustrates the format of the data file (SSTable) after data has been written. The SSTable includes multiple data groups, Bloom filter blocks, index blocks, and footers. The index blocks record the starting position of each data group and the key range corresponding to each data group, used for quickly locating the target data group during queries. The Bloom filter blocks are used to quickly determine whether a key definitely does not exist in the current data file. The footers record the offset position of the index blocks. Optionally, for key-value pairs stored in row-oriented format (i.e., data corresponding to key ranges outside the configuration), the computer device still writes them to the data file according to the traditional DataBlock format, where keys and values are stored alternately in the DataBlock. Optionally, after writing the target data group to the data file, the computer device can also update the index blocks by adding index entries for the target data group. These index entries record the minimum key, maximum key, and the starting offset address of the target data group in the data file.
[0097] The data storage method in the above embodiments is illustrated by way of example, including: user configuration of the key range segment valueEntry partitioning rules and the type of each valueEntry segment, which can be configured individually to use a suitable compression algorithm; key ranges outside the configuration are still processed and stored according to the original format. When writing the corresponding keyRange range KV to the SSTable on disk, it is processed according to the following... Figure 6 The DataGroup format is used to organize disk writes. Figure 2 Compared to the previous format, IndexBlock, FilterBlock, and footer remain unchanged, but DataBlock is changed to DataGroup format. IndexBlock records the starting position of the DataGroup. Within the DataGroup, values are split according to the configuration of valueEntry, and keys are stored separately in KeyBlocks. Each KeyBlock is followed by a split ValueEntryBlock. All values corresponding to the same key within this DataGroup are stored in the same valueEntryBlock, and can be encoded and stored according to corresponding characteristics, such as... Figure 8 and Figure 9 The encoding and storage methods for fixed-length and variable-length ValueEntries are listed. Then, before the actual write to disk, each ValueEntryBlock is further compressed using a suitable compression algorithm. Because the same valueEntry data type is identical and highly repetitive, the compression ratio of the dedicated columnar compression algorithm far exceeds that of general compression, reducing the amount of data written to disk and improving performance. Furthermore, during queries, only the target column needs to be decompressed, without needing to decompress the entire row of data, reducing IO overhead.
[0098] In this embodiment of the application, when querying data, the data query request is used to request a query for key-value (KV) data stored in the storage system. The key to be queried is the key in the key-value pair to be queried, and the value to be queried is the value of the item that the user expects to query. The attribute type of the item value is the attribute category corresponding to the item value. For example, if user information is stored, the attribute type of the item value may include age, height, weight, education level, etc.
[0099] Computer equipment can receive data query requests from user terminals, applications, or internal scheduling modules of the storage system. The data query request may carry the key to be queried and the attribute type of the entry value the user expects to query, such as querying "age" or "height"; alternatively, the query conditions may include the field name of the entry value the user expects to query, and the computer equipment can determine the corresponding attribute type from pre-stored configuration information based on the field name. Optionally, if the attribute type of the entry value is not explicitly specified in the data query request, the computer equipment may use the attribute types of all entry values contained in the complete value corresponding to the key to be queried as the attribute type of the entry value to be queried. Optionally, after receiving a data query request, the computer equipment may also perform a validity check on the data query request, such as checking whether the request format is correct, whether the key to be queried conforms to the naming convention, and whether the attribute type of the entry value in the query conditions is within the range of types configured in the storage system; if the check passes, subsequent steps are executed; if the check fails, an error message is returned to the requester.
[0100] S202, query the target data group corresponding to the key in the data file where the key to be queried is located.
[0101] The data file (SSTable) comprises multiple data groups, which are the basic units for storing key-value pairs in columnar storage. Each data group includes a key block and at least one value entry block. A key block contains multiple keys. Each value entry block stores multiple value entries of the same attribute type. Each key corresponds to one value entry in a different value entry block. Key blocks store the key information of all key-value records within a data group, with multiple keys arranged in an ordered manner. Each value entry block stores a set of value entries of a specific attribute type from all the values corresponding to the keys within that data group. For example, one value entry block stores all "age" values corresponding to all keys, and another stores all "height" values corresponding to all keys. All value entries stored within the same value entry block have the same attribute type, and each value entry corresponds one-to-one with each key within the key block in a predetermined order; that is, the age value corresponding to the i-th key in a key block is stored at the i-th position in the age value entry block.
[0102] The data file (SSTable) may also include Bloom filter blocks, index blocks, and footers.
[0103] The storage system contains multiple data files, each corresponding to its own key range. After obtaining the key to be queried, the computer device can determine the key range containing that key, and then identify the corresponding data file. Within the data file containing the key to be queried, the computer device can locate the target data group based on the key. Specifically, the computer device first reads the footer of the data file, obtains the offset position of the index block from the footer, and then reads the index block based on the offset position. The index block records the starting position information of multiple data groups in the data file and the key range corresponding to each data group. The computer device can match the key to be queried with the key ranges of each data group, identify the data group corresponding to the matched key range as the target data group, and obtain the offset address of the target data group in the data file. Optionally, before determining the target data group, the computer device can perform a quick filter using a Bloom filter block to determine whether the key to be queried definitely does not exist in the current data file. If the Bloom filter determines that the key to be queried does not exist, the query result can be returned directly as empty, without the need for subsequent data group location operations, thereby reducing unnecessary disk I / O overhead. Optionally, when the key to be queried is a key range query, the computer device can determine multiple data groups covered by the key range as the target data group. Optionally, after determining the starting offset address of the target data group, the computer device can read the data of the target data group from the data file according to the offset address.
[0104] S203, determine the target position of the key to be queried in the key block of the target data group based on the key to be queried, and determine the target entry value block based on the attribute type of the entry value to be queried.
[0105] The target location is the offset address of the key to be queried within the key block, used to locate the entry value corresponding to that key within the target entry value block. The target entry value block is the entry value block corresponding to the attribute type of the entry value to be queried. The key block contains multiple keys and an array of restart points. The restart point array is used to accelerate the binary search of the keys. At the end of the key block, handle information (valueEntryHandle) for each entry value block is recorded. Each handle records the offset position and length of the corresponding entry value block within the data set, as well as the attribute type identifier corresponding to that entry value block.
[0106] After acquiring the target data set, the computer device can parse it to obtain key blocks and at least one entry value block. Then, it searches for the key to be queried within the key block to determine its target position. Specifically, a key block contains multiple keys arranged in a predetermined order (e.g., lexicographical). The key block also contains a restart point array, which records the offset positions of multiple restart points. Each restart point corresponds to a key in the key block, used to accelerate the binary search for the key. The computer device can first perform a binary search on the key block using the restart point array to determine the restart point interval to which the key to be queried belongs. Then, it performs a sequential traversal or a local binary search within the restart point interval to precisely locate the target position of the key to be queried within the key block. Optionally, each key in the key block is stored using a shared prefix compression method, meaning each key entry includes a shared length (sharedLen), a non-shared length (unsharedLen), and non-shared key content (unsharedKey). When performing a key lookup, the computer device needs to reconstruct the key based on the shared length and the content of the previous key, and then compare it with the key to be queried. Optionally, if the key to be queried does not exist in the key block, the computer device can determine that the query result is empty and end the current query process.
[0107] The computer device can simultaneously determine the corresponding target entry value block from the target data group based on the attribute type of the entry value to be queried. Specifically, the key block of the target data group records multiple valueEntryHandles at the end, each valueEntryHandle corresponding to one entry value block, and each valueEntryHandle contains the attribute type identifier of the corresponding entry value block. The computer device can match the attribute type of the entry value to be queried with the attribute type identifiers in each valueEntryHandle, and determine the entry value block whose attribute type matches successfully as the target entry value block. Optionally, if the entry value to be queried has multiple attribute types, the computer device can determine multiple target entry value blocks.
[0108] S204, Determine the query result of the data query request based on the target location and the target entry value block.
[0109] The query result is the value corresponding to the key to be queried, which can include the retrieved value or the retrieved key-value pair. Multiple entry values stored in the entry value block correspond one-to-one with multiple keys in the key block in the same arrangement order. Therefore, the entry value at the corresponding position can be read from the entry value block based on the target position of the key in the key block.
[0110] In this embodiment, after determining the target position of the key to be queried in the key block and the target entry value block, the computer device can read the corresponding entry value from the target entry value block according to the target position. Specifically, since the arrangement of each key in the key block corresponds one-to-one with the arrangement of each entry value in the entry value block, and the Nth key in the key block and the Nth entry value in the target entry value block belong to the same key-value pair, the computer device can read the entry value corresponding to the target position from the decompressed target entry value block according to the target position (i.e., the sequence number of the key to be queried in the key block). For example, if the target position is 3 (meaning the key to be queried is the 3rd position in the key block), the computer device reads the 3rd entry value from the decompressed target entry value block.
[0111] Optionally, the target entry value block can be in a fixed-length encoding format or a variable-length encoding format. If the target entry value block is in a fixed-length encoding format, each entry value occupies a fixed storage length. The computer device can calculate the starting offset address of the target entry value in the target entry value block based on the target location and the fixed length, and then read the entry value from that offset address. If the target entry value block is in a variable-length encoding format, the length information (len) of each entry value is recorded before it. The computer device can start from the beginning of the target entry value block, read the length information of each entry value sequentially, and skip other entry values according to the length information until the entry value corresponding to the target location is located, and then read the content of the entry value according to the length information of that entry value.
[0112] Optionally, if the data in the target entry value block is compressed, the computer device needs to decompress the target entry value block first, and then read the target entry value from the decompressed data. Optionally, if the attribute type of the entry value to be queried is multiple, i.e., there are multiple target entry value blocks, the computer device can read the corresponding entry value from each target entry value block according to the target location, and then combine the multiple entry values into a complete query result according to a preset order. Optionally, if the data query request also includes filtering conditions based on entry values, the computer device can match the target entry value with the filtering conditions after reading the target entry value; if the match is successful, the target entry value is returned as the query result; if the match fails, the query result is determined to be empty or the record is skipped. Optionally, after obtaining the query result, the computer device can encapsulate the query result into response data according to a preset format and return it to the initiator of the data query request.
[0113] The data query method provided in this application, in response to a data query request, obtains the key to be queried and the attribute type of the entry value to be queried, queries the target data group corresponding to the key in the data file where the key is located, then determines the target position of the key in the key block of the target data group based on the key, and determines the target entry value block based on the attribute type of the entry value to be queried, and finally determines the query result of the data query request based on the target position and the target entry value block. The data file includes multiple data groups, each data group including a key block and at least one entry value block. Each key block includes multiple keys, and each entry value block stores multiple entry values of the same attribute type. Each key corresponds to one entry value in different entry value blocks. In the above method, the corresponding target entry value block is determined based on the attribute type of the entry value to be queried, and only the entry value corresponding to the key to be queried is read from that target entry value block. This supports querying a specified portion of the entry value without reading the complete value data or other entry value blocks unrelated to the entry value to be queried, thereby reducing disk read / output overhead and improving query efficiency.
[0114] In one exemplary embodiment, the data file includes a data group index relationship, such as... Figure 12 As shown, the query retrieves the target data group corresponding to the key in the data file containing the key to be queried, including:
[0115] S301, obtain the data group index relationship in the data file; the data group index relationship includes the correspondence between key ranges and data groups.
[0116] Data group indexing is used to record the mapping relationship between each data group and key range in a data file. This data group indexing relationship allows for quick location of the data group containing any key. Specifically, it can be... Figure 9 The index block is defined as an IndexBlock. A data group corresponds to a continuous range of keys, and the index relationship of the data group records the starting key of each data group and the storage location of that data group in the data file.
[0117] After obtaining the key to be queried, the computer device can read the data group index relationship from the index block of the data file. Specifically, the index block of the data file records the starting key of each data group and the offset of that data group in the data file. The computer device can load the starting key and offset of each data group into memory to form the data group index relationship. If the index block of the data file is stored in compressed form, the computer device first decompresses the index block before reading the data group index relationship. The computer device stores the data group index relationship in a cache for use in subsequent steps. Optionally, if the computer device has already read the index block of the data file and cached the data group index relationship in memory, it can directly retrieve the data group index relationship from memory without reading the disk again, thus reducing disk I / O overhead.
[0118] S302, the data group that matches the key to be queried in the data group index relationship is determined as the target data group.
[0119] After obtaining the data group index relationship based on the above steps, the computer device can determine the key range to which the key to be queried belongs based on the key to be queried and the data group index relationship, and thus take the data group corresponding to that key range as the target data group. Specifically, the computer device can compare the key to be queried with the starting key of each data group in the data group index relationship one by one. If the key to be queried is greater than or equal to the starting key of a certain data group and less than the starting key of the next data group (or less than the ending key of that data group), then it is determined that the key to be queried belongs to the key range of that data group, and that data group is taken as the target data group. For example, if the key range of data group A in the data group index relationship is [user_001, user_100], the key range of data group B is [user_101, user_200], and the key to be queried is user_150, then the computer device will compare the key to be queried with the starting key of each data group one by one, determine that the key to be queried belongs to the key range of data group B, and thus take data group B as the target data group. If the starting keys of each data group in the data group index relationship are arranged in order, the computer device can also quickly locate the data group that matches the key to be queried using a binary search, thereby improving query efficiency. After determining the target data group, the computer device can read the data of the target data group from the data file according to the storage location of the target data group recorded in the data group index relationship.
[0120] In this embodiment, by obtaining the data group index relationship in the data file and determining the data group that matches the key to be queried in the data group index relationship as the target data group, the target data group can be quickly located according to the key to be queried without traversing the entire data file, thereby greatly reducing the scope and time of data search and improving the efficiency of data query.
[0121] In an exemplary embodiment, the key block described above further includes an entry value block index relationship, such as... Figure 13 As shown, the target entry value block is determined based on the attribute type of the entry value to be queried, including:
[0122] S401, obtain the entry value block index relationship in the key block; the entry value block index relationship includes the correspondence between attribute types and entry value blocks.
[0123] The entry value block index relationship is used to record the mapping relationship between each entry value block in a data group and the attribute type. This index relationship allows for quick location of the corresponding entry value block based on the attribute type. Specifically, it can be... Figure 8 The value entry handle (valueEntryHandle) is used for entry value block indexing. The entry value block index relationship is stored in the key block, including the attribute type identifier corresponding to each entry value block and the storage location information of the entry value block in the data group (such as the starting offset and length).
[0124] After locating the target data group, the computer device can read the key blocks within the target data group and extract the entry value block index relationships from the key blocks. Specifically, in addition to storing multiple keys and an array of restart points, the key blocks also store the entry value block index relationships. These index relationships can exist in the form of a list of handles, with each handle corresponding to an entry value block, recording the attribute type of that entry value block and its position information within the data group. The computer device can obtain the attribute type identifier and storage location corresponding to each entry value block by parsing the data at preset positions in the key blocks. For example, the key block stores valueEntry-1Handle, valueEntry-2Handle, ..., valueEntry-nHandle, with each handle recording the attribute type of the corresponding entry value block and its starting offset. The computer device loads the attribute types and storage locations of all entry value blocks into memory, forming the entry value block index relationships for use in subsequent steps. Optionally, if the computer device has previously parsed the target data group and cached the entry value block index relationship in memory, it can be retrieved directly from memory without parsing again.
[0125] S402, the entry value block that matches the attribute type of the entry value to be queried in the entry value block index relationship is determined as the target entry value block.
[0126] After obtaining the entry value block index relationship based on the above steps, the computer device can determine the entry value block corresponding to the attribute type of the entry value to be queried and the entry value block index relationship, and use that entry value block as the target entry value block. Specifically, the computer device can match the attribute type of the entry value to be queried with the attribute type identifiers of each entry value block in the entry value block index relationship. If an entry value block corresponding to the attribute type exists in the entry value block index relationship, then that entry value block is used as the target entry value block. For example, if the entry value block index relationship records that the attribute type corresponding to entry value block A is "age" and the attribute type corresponding to entry value block B is "height", and the attribute type of the entry value to be queried is "height", then the computer device will use entry value block B as the target entry value block. If no entry value block corresponding to the attribute type of the entry value to be queried does exist in the entry value block index relationship, the computer device can either return an error message to the user or read the complete value data in row-by-row storage mode and then parse out the corresponding entry value. After determining the target entry value block, the computer device can read the data of the target entry value block from the target data group according to the storage location of the target entry value block recorded in the entry value block index relationship. Optionally, if there is no entry value block in the entry value block index relationship that matches the attribute type of the entry value to be queried, it means that the current target data group does not contain data of the attribute type to be queried, and the computer device can determine that the query result is empty or skip the query for that attribute type. Optionally, when there are multiple attribute types of the entry value to be queried, the computer device can traverse the entry value block index relationship, determine all successfully matched entry value blocks as target entry value blocks, and obtain their respective offset positions and length information so that the data in each target entry value block can be read sequentially thereafter.
[0127] In this embodiment, by obtaining the entry value block index relationship in the key block and determining the entry value block that matches the attribute type of the entry value to be queried as the target entry value block, the corresponding target entry value block can be quickly located according to the attribute type of the entry value to be queried without traversing all entry value blocks, thereby reducing the scope and time of data search; at the same time, since only the target entry value block corresponding to the attribute type to be queried needs to be read, and there is no need to read other unrelated entry value blocks, the amount of disk data read is further reduced, the input and output overhead is reduced, and the query efficiency is improved.
[0128] In an exemplary embodiment, determining the query result of a data query request based on the target location and the target entry value block includes: reading the target entry value corresponding to the target location from the target entry value block, and determining the query result of the data query request based on the target entry value.
[0129] The target entry value is the entry value in the target entry value block that corresponds to the target position; that is, the entry value corresponding to the key to be queried that matches the attribute type of the entry value to be queried. The query results include the target entry values read from the target entry value block.
[0130] After determining the target location and the target entry value block, the computer device can read the corresponding target entry value from the target entry value block based on the target location. Specifically, since the arrangement of keys in a key block corresponds one-to-one with the arrangement of entry values in each entry value block, and the Nth key in a key block and the Nth entry value in the target entry value block belong to the same key-value pair, the computer device can read the entry value corresponding to the target location from the target entry value block based on the target location (i.e., the sequence number of the key to be queried in the key block), and use that entry value as the target entry value. For example, if the target location is 3 (meaning the key to be queried is the 3rd position in the key block), the computer device will read the 3rd entry value from the target entry value block as the target entry value. When reading data from a target entry value block, if the data in the target entry value block is in a fixed-length storage format, the computer device can directly calculate the starting position of the target entry value based on the target location and the fixed length of each entry value, and then read it. If the data in the target entry value block is in a variable-length storage format, the computer device starts from the starting position of the target entry value block and sequentially reads the length field of each entry value, skipping unnecessary entry values based on the length field, until the target entry value corresponding to the target location is located. After reading the target entry value, the computer device uses the target entry value as the query result of the data query request and returns it to the application, server, or internal system scheduler that sent the data query request.
[0131] In this embodiment, by reading the target entry value corresponding to the target position from the target entry value block and determining the query result based on the target entry value, the entry value at the corresponding position can be read directly from the target entry value block according to the arrangement number of the key in the key block. The correspondence between the key and the value is established through the arrangement position, eliminating the need to store additional address pointers or offset information in the key, thus reducing storage overhead. At the same time, only one entry value corresponding to the target position needs to be read from the target entry value block, without having to read all the data in the target entry value block, further reducing the amount of disk data read, lowering input and output overhead, and improving query efficiency.
[0132] In an exemplary embodiment, each of the above-mentioned entry value blocks is compressed using a corresponding compression algorithm based on the data characteristics of its respective attribute type during storage. The compression algorithm used for the entry value block during storage is as follows: when writing the data group, a compression algorithm is selected from multiple compression algorithms based on the data characteristics of the attribute type corresponding to the entry value block (such as integer data, string data, timestamp data, etc.). The decompression algorithm corresponds to the compression algorithm and is used to restore the compressed data to the original data.
[0133] Based on this, such as Figure 14 As shown, a method for decompressing target entry value blocks is provided, including:
[0134] S501, according to the decompression algorithm corresponding to the compression algorithm used when storing the target entry value block, the target entry value block is decompressed to obtain the decompressed target entry value block.
[0135] After identifying the target entry value block, the computer device can first obtain its compression type identifier. Specifically, the target entry value block stores block trailer information, which includes a compression type field (compressType). This field records the type of compression algorithm used when storing the entry value block. The computer device reads this compression type field to determine the compression algorithm used by the target entry value block, and then selects the corresponding decompression algorithm from a variety of locally stored decompression algorithms. For example, if the compression type field indicates that the entry value block uses the ZSTD compression algorithm, the computer device determines the corresponding decompression algorithm to be ZSTD; if the compression type field indicates that the entry value block uses the LZ4 compression algorithm, the computer device determines the corresponding decompression algorithm to be LZ4; if the compression type field indicates that the entry value block does not use a compression algorithm, the computer device does not need to perform a decompression operation. After determining the decompression algorithm, the computer device uses this decompression algorithm to decompress the stored data of the target entry value block, obtaining the decompressed target entry value block.
[0136] Correspondingly, when the computer device executes S204 "Determine the query result of the data query request based on the target location and target entry value block", it specifically performs the following:
[0137] S502, determine the query result of the data query request based on the target location and the decompressed target entry value block.
[0138] After obtaining the decompressed target entry value block, the computer device can read the corresponding entry value from the decompressed target entry value block according to the target position. Specifically, since the arrangement of each key in the key block corresponds one-to-one with the arrangement of the entry values in each entry value block, and the Nth key in the key block and the Nth entry value in the target entry value block belong to the same key-value pair, the computer device can read the entry value corresponding to the target position from the decompressed target entry value block according to the target position (i.e., the sequence number of the key to be queried in the key block).
[0139] The method described in this application decompresses the target entry value block according to the decompression algorithm corresponding to the compression algorithm used when storing the target entry value block, and determines the query result based on the target location and the decompressed target entry value block. Since each entry value block is compressed using a corresponding compression algorithm according to the data characteristics of its respective attribute type during storage, only the decompression algorithm corresponding to the compression algorithm needs to be used to decompress the target entry value block during querying, without decompressing other unrelated entry value blocks, thus reducing the decompression processing overhead of the central processing unit. At the same time, each entry value block is stored according to the corresponding compression algorithm matched to its attribute type, which can achieve a higher compression ratio, reduce the storage space occupied by data on the disk and the input / output overhead during reading, and further improve query performance.
[0140] In one exemplary embodiment, the data query request further includes filtering conditions, such as... Figure 15 As shown, based on the target location and target entry value block, the query results of the data query request are determined, including:
[0141] S601, filter the values of each entry in the target entry value block according to the filtering conditions, and filter out at least one target entry value that meets the filtering conditions.
[0142] Filtering conditions are used to select entry values and include at least one of the following: comparison conditions (such as greater than, less than, equal to, not equal to, etc.), range conditions (such as between two numbers), and fuzzy matching conditions (such as string inclusion, prefix matching, etc.). The target entry value is the entry value in the target entry value block that satisfies the filtering conditions; the number of target entry values obtained after filtering can be one or more.
[0143] In this embodiment, after determining the target entry value block, the computer device can read the data in the target entry value block and filter each entry value in the target entry value block according to the filtering conditions. Specifically, the computer device can first determine whether the target entry value block is compressed. If the target entry value block is compressed during storage, the computer device first decompresses the target entry value block according to the decompression algorithm corresponding to the compression algorithm used during storage, obtaining the decompressed target entry value block. If the target entry value block is not compressed during storage, the computer device directly reads the data in the target entry value block. After obtaining the decompressed target entry value block, the computer device iterates through each entry value in the target entry value block, comparing each entry value with the filtering conditions to determine whether the entry value meets the filtering conditions. For example, if the filtering condition is "greater than 18", the computer device sequentially determines whether each entry value is greater than 18. If the entry value is 25, the filtering condition is met; if the entry value is 15, the filtering condition is not met. If the filter condition is "contains 'Zhang'", the computer device sequentially checks whether each entry value contains the character "Zhang". If the entry value is "Zhang San", the filter condition is met; if the entry value is "Li Si", the filter condition is not met. After traversing all entry values in the target entry value block, the computer device records the entry values that meet the filter condition as at least one target entry value. Simultaneously, the computer device can also record the position number (i.e., sequence number) of each target entry value in the target entry value block for use in subsequent steps. If no entry value in the target entry value block meets the filter condition, the computer device can return an empty result.
[0144] S602, determine the query results of the data query request based on the values of each target entry.
[0145] The query results include the values of each target entry, and may also include the keys corresponding to each target entry value.
[0146] After the computer device filters out at least one target entry value based on the above steps, it can determine the query result of the data query request based on each target entry value. Optionally, the computer device can use each target entry value and its corresponding key together as the query result of the data query request. Optionally, when the query request contains attribute types of multiple entry values to be queried, the computer device can also read other entry values with corresponding bit numbers from other entry value blocks based on the bit numbers of each target entry value, and return the entry values of multiple attribute types together as the query result.
[0147] In this embodiment, the values of each entry in the target entry value block are filtered according to the filtering conditions, and at least one target entry value that meets the filtering conditions is selected. The query result is determined based on each target entry value. Since the entry values are filtered according to the filtering conditions at the storage engine level, only the entry values that meet the filtering conditions and their corresponding keys are read and returned. The data corresponding to the entry values that do not meet the filtering conditions are filtered out at the storage engine level. There is no need to return all the data to the upper-layer business for filtering. This reduces the amount of data processing and memory transfer in the upper-layer business, shrinks the query result set, improves query efficiency, and reduces the consumption of central processing unit and memory resources.
[0148] In one exemplary embodiment, such as Figure 16 As shown, a method for querying row-stored data is provided, including:
[0149] S701, if the target data group corresponding to the key to be queried is not found in the data file, the target data block corresponding to the key to be queried is determined according to the data block index relationship.
[0150] The data file includes key-value pair data stored in columnar storage (i.e., data stored in the aforementioned data group format) and key-value pair data stored in row storage. Specifically, the data file also includes at least one data block and a data block index relationship. A data block is the basic unit for storing key-value pair data in row storage, and each data block contains at least one key-value pair, with the key and its corresponding complete value stored contiguously. The data block index relationship includes the correspondence between key ranges and data blocks, recording the mapping relationship between each data block and the key range. This data block index relationship allows for quick location of the corresponding data block based on the key. The target data block is the data block containing the key to be queried.
[0151] When a computer searches for a target data group corresponding to a key in a data file, if the target data group is not found, it means that the key does not belong to any key range configured with columnar storage format. The data corresponding to this key is still stored in row-oriented storage within the data blocks of the data file. In this case, the computer can obtain the data block index relationship in the data file. This index relationship records the starting key of each data block and its offset within the data file. The computer compares the key to be queried with the starting keys of each data block in the data block index relationship to determine the key range to which the key belongs, thereby locating the storage location of the target data block corresponding to that key range within the data file. For example, if the key range of data block 1 in the data block index relationship is [user_001, user_100], the key range of data block 2 is [user_101, user_200], and the key to be queried is user_150, and this key does not belong to any data group configured with columnar storage format, then the computer device determines that the key to be queried belongs to the key range of data block 2, and thus uses data block 2 as the target data block. If the starting keys of each data block in the data block index relationship are arranged in order, the computer device can also quickly locate the data block that matches the key to be queried using a binary search.
[0152] S702, Read the target complete value data of the key immediately adjacent to the target data block to be queried.
[0153] The target complete value data is the complete value corresponding to the key to be queried. After the computer device determines the target data block, it can read the data of the target data block from the data file according to the storage location of the target data block. In the target data block, multiple key-value pairs are arranged sequentially and continuously, with the key and its corresponding complete value stored adjacent to each other in each key-value pair. The computer device can locate the position of the key to be queried in the target data block. In row-oriented storage, since the key and complete value are stored adjacent to each other, the computer device can read the corresponding complete value from the adjacent position after locating the key to be queried, and use this complete value as the target complete value data. Specifically, the target data block includes a restart point array. The computer device can use the restart point array to perform a binary search in the target data block to locate the storage location of the key to be queried, and then start reading the complete value data stored adjacent to the key from that storage location.
[0154] S703, determine the query result of the data query request based on the target entry value in the target complete value data that corresponds to the attribute type of the entry value to be queried.
[0155] The target entry value is the entry value parsed from the target complete value data that corresponds to the attribute type of the entry value to be queried. The query result includes the target entry value.
[0156] After reading the target complete value data, the computer device may parse the target complete value data according to the attribute type of the to-be-queried entry value, and extract, from the target complete value data, a target entry value corresponding to the attribute type of the to-be-queried entry value. For example, assuming that the target complete value data is "id:1,name:Zhang San,age:25,height:185" and the attribute type of the to-be-queried entry value is "age", the computer device parses out "age:25" from the target complete value data, and determines "25" as the target entry value. After parsing out the target entry value, the computer device uses the target entry value as a query result of the data query request.
[0157] In this application, when target data group corresponding to a to-be-queried key is not queried, a target data block is determined according to a data block index relationship, target complete value data stored adjacent to the to-be-queried key is read from the target data block, and a query result is determined according to a target entry value that is in the target complete value data and that corresponds to the attribute type of the to-be-queried entry value. This can be compatible with both column storage and row storage. For a key range configured as a column storage format, a column storage manner is used for efficient querying. For a key range not configured as a column storage format, a row storage manner is automatically used for querying. This avoids a problem of a query failure caused by a key not belonging to any column storage data group, and improves flexibility and query efficiency of the data query method.
[0158] In an exemplary embodiment, a data query method is provided, as shown in Figure 17 , the method includes:
[0159] S801: Obtain, in response to a data query request, a to-be-queried key and an attribute type of a to-be-queried entry value.
[0160] S802: If target data group corresponding to the to-be-queried key is queried in a data file, obtain a data group index relationship in the data file, and determine a data group matching the to-be-queried key in the data group index relationship as the target data group.
[0161] The data file includes a plurality of data groups, each data group includes a key block and at least one entry value block, the key block includes a plurality of keys, each entry value block stores a plurality of entry values of a same attribute type, and each key corresponds to one entry value in different entry value blocks. The data group index relationship includes a correspondence between key ranges and data groups.
[0162] S803: Determine, according to the to-be-queried key, a target position of the to-be-queried key in a key block of the target data group.
[0163] S804, retrieve the entry value block index relationship in the key block, and determine the entry value block in the entry value block index relationship that matches the attribute type of the entry value to be queried as the target entry value block. The entry value block index relationship includes the correspondence between attribute types and entry value blocks.
[0164] S805, according to the decompression algorithm corresponding to the compression algorithm used when storing the target entry value block, the target entry value block is decompressed to obtain the decompressed target entry value block. Specifically, each entry value block is compressed using a corresponding compression algorithm based on the data characteristics of its respective attribute type during storage.
[0165] S806, filter the values of each entry in the decompressed target entry value block according to the filtering conditions, filter out at least one target entry value that meets the filtering conditions, and determine the query result of the data query request based on each target entry value.
[0166] S807: If the target data group corresponding to the key to be queried is not found in the data file, the target data block corresponding to the key to be queried is determined according to the data block index relationship. The data block index relationship includes the correspondence between key ranges and data blocks.
[0167] S808 reads the target complete value data of the key immediately adjacent to the target data block to be queried.
[0168] S809, determine the query result of the data query request based on the target entry value in the target complete value data that corresponds to the attribute type of the entry value to be queried.
[0169] This application provides a method to transform the KV storage method of SSTable in LSM-Tree into a storage format where each key corresponds to multiple ValueEntries. Values in multiple entries are stored contiguously and compactly, segmented by column, effectively utilizing columnar storage compression to improve compression ratio and reduce IO overhead. It also provides a method in the current KV-stored LSM-Tree storage system where the storage format can be flexibly controlled within a specified KeyRange range based on data characteristics through configuration, achieving mixed row and column storage. Furthermore, it provides a method for retrieving partial values, reducing disk read IO overhead and obtaining accurate query results at a lower cost. Finally, it provides a function that allows filtering queries using specified column fields for values, reducing fuzzy query results and retrieving more accurate query content.
[0170] When querying data, queries within the KeyRange range support specifying a portion of the valueEntry. Irrelevant valueEntry fields do not require disk reads, reducing disk I / O and improving query performance. Queries support specifying valueEntry conditions, filtering out data items that do not meet the conditions at the data level, resulting in more efficient query results, narrowing the query scope, and reducing upper-layer business processing and memory transfer volume. Configurable range storage allows for mixed row and column storage, and business modules can flexibly configure it according to the characteristics of the range of values. Because value columns of the same type are stored contiguously and densely, resulting in high data redundancy, a dedicated columnar storage algorithm can be applied to achieve a high compression rate and reduce I / O overhead. By segmenting values and storing identical segments by column, queries can now include specifying valueEntry fields as query conditions, further filtering out useless data; and it supports partial value queries, eliminating the need to read the entire value.
[0171] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0172] Based on the same inventive concept, this application also provides a data query apparatus for implementing the data query method described above. The solution provided by this apparatus is similar to the implementation scheme described in the above method; therefore, the specific limitations in one or more data query apparatus embodiments provided below can be found in the limitations of the data query method described above, and will not be repeated here.
[0173] In one exemplary embodiment, such as Figure 18 As shown, a data query device is provided, including: an acquisition module 1801, a query module 1802, a first determination module 1803, and a second determination module 1804, wherein:
[0174] The acquisition module 1801 is used to respond to a data query request and obtain the key to be queried and the attribute type of the value of the entry to be queried.
[0175] The query module 1802 is used to query the target data group corresponding to the key in the data file where the key to be queried is located; wherein, the data file includes multiple data groups, each data group includes a key block and at least one entry value block, the key block includes multiple keys, each entry value block stores multiple entry values of the same attribute type, and each key corresponds to an entry value in a different entry value block;
[0176] The first determining module 1803 is used to determine the target position of the key to be queried in the key block of the target data group based on the key to be queried, and to determine the target entry value block based on the attribute type of the entry value to be queried.
[0177] The second determining module 1804 is used to determine the query result of the data query request based on the target location and the target entry value block.
[0178] In an exemplary embodiment, the query module 1802 includes: a first acquisition unit and a first matching unit, wherein:
[0179] The first acquisition unit is used to acquire the data group index relationship in the data file; the data group index relationship includes the correspondence between key ranges and data groups.
[0180] The first matching unit is used to identify the data group in the data group index relationship that matches the key to be queried as the target data group.
[0181] In an exemplary embodiment, the first determining module 1803 includes: a second acquiring unit and a second matching unit, wherein:
[0182] The second acquisition unit is used to acquire the entry value block index relationship in the key block; the entry value block index relationship includes the correspondence between attribute types and entry value blocks.
[0183] The second matching unit is used to identify the target entry value block as the entry value block that matches the attribute type of the entry value to be queried in the entry value block index relationship.
[0184] In an exemplary embodiment, the second determining module 1804 is specifically used to read the target entry value corresponding to the target position from the target entry value block, and determine the query result of the data query request based on the target entry value.
[0185] In one exemplary embodiment, the data query apparatus further includes: a decompression module and a third determination module, wherein:
[0186] The decompression module is used to decompress the target entry value block according to the decompression algorithm corresponding to the compression algorithm used when storing the target entry value block, resulting in a decompressed target entry value block. Specifically, each entry value block is compressed using a corresponding compression algorithm based on the data characteristics of its respective attribute type during storage.
[0187] The third determination module is used to determine the query result of the data query request based on the target location and the decompressed target entry value block.
[0188] In an exemplary embodiment, the second determining module 1804 includes: a filtering unit and a determining unit, wherein:
[0189] The filtering unit is used to filter the values of each entry in the target entry value block according to the filtering conditions, and to filter out at least one target entry value that meets the filtering conditions.
[0190] The determination unit is used to determine the query results of the data query request based on the values of each target entry.
[0191] In an exemplary embodiment, the data query device further includes: a fourth determining module, a reading module, and a fifth determining module, wherein:
[0192] The fourth determination module is used to determine the target data block corresponding to the key to be queried based on the data block index relationship if the target data group corresponding to the key to be queried is not found in the data file. The data block index relationship includes the correspondence between the key range and the data block. The data file also includes at least one data block and a data block index relationship. Each data block includes at least one or more key-value pairs, and the key and its corresponding complete value data are stored contiguously in each key-value pair.
[0193] The read module is used to read the target complete value data of the key immediately adjacent to the target data block to be queried from the target data block.
[0194] The fifth determination module is used to determine the query result of the data query request based on the target entry value in the target complete value data that corresponds to the attribute type of the entry value to be queried.
[0195] Each module in the aforementioned data query device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the operations corresponding to each module.
[0196] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above-described method embodiments.
[0197] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps in the above method embodiments.
[0198] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0199] The computer program product provided in the above embodiments has a similar implementation principle and technical effect to the above method embodiments, and will not be described again here.
[0200] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.
[0201] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0202] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0203] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A data query method, characterized in that, The method includes: In response to a data query request, retrieve the key to be queried and the attribute type of the value of the entry to be queried; The data file containing the key to be queried is used to query the target data group corresponding to the key to be queried; wherein, the data file includes multiple data groups, each data group includes a key block and at least one entry value block, the key block includes multiple keys, each entry value block stores multiple entry values of the same attribute type, and each key corresponds to one entry value in different entry value blocks; The target position of the key to be queried in the key block of the target data group is determined based on the key to be queried, and the target entry value block is determined based on the attribute type of the entry value to be queried. The query result of the data query request is determined based on the target location and the target entry value block.
2. The method according to claim 1, characterized in that, The step of querying the target data group corresponding to the key in the data file containing the key to be queried includes: Obtain the data group index relationship in the data file; the data group index relationship includes the correspondence between key ranges and data groups; The data group that matches the key to be queried in the data group index relationship is determined as the target data group.
3. The method according to claim 1 or 2, characterized in that, The key block also includes an entry value block index relationship. Determining the target entry value block based on the attribute type of the entry value to be queried includes: Obtain the entry value block index relationship in the key block; the entry value block index relationship includes the correspondence between attribute types and entry value blocks; The entry value block that matches the attribute type of the entry value to be queried in the entry value block index relationship is determined as the target entry value block.
4. The method according to claim 1 or 2, characterized in that, Determining the query result of the data query request based on the target location and the target entry value block includes: Read the target entry value corresponding to the target location from the target entry value block, and determine the query result of the data query request based on the target entry value.
5. The method according to claim 1 or 2, characterized in that, Each entry value block is compressed using a corresponding compression algorithm based on the data characteristics of its respective attribute type during storage.
6. The method according to claim 1 or 2, characterized in that, The method further includes: According to the decompression algorithm corresponding to the compression algorithm used when storing the target entry value block, the target entry value block is decompressed to obtain the decompressed target entry value block; Determining the query result of the data query request based on the target location and the target entry value block includes: The query result of the data query request is determined based on the target location and the decompressed target entry value block.
7. The method according to claim 1 or 2, characterized in that, The data query request also includes filtering conditions. Determining the query result of the data query request based on the target location and the target entry value block includes: The values of each entry in the target entry value block are filtered according to the filtering conditions, and at least one target entry value that meets the filtering conditions is selected. The query result of the data query request is determined based on the value of each target entry.
8. The method according to claim 1, characterized in that, The data file also includes at least one data block and a data block index relationship. Each data block includes at least one or more key-value pairs. In each key-value pair, the key and its corresponding complete value are stored adjacently. The method further includes: If the target data group corresponding to the key to be queried is not found in the data file, the target data block corresponding to the key to be queried is determined according to the data block index relationship; the data block index relationship includes the correspondence between the key range and the data block. Read the target complete value data stored immediately adjacent to the key to be queried from the target data block; The query result of the data query request is determined based on the target entry value in the target complete value data that corresponds to the attribute type of the entry value to be queried.
9. A data query device, characterized in that, The device includes: The retrieval module is used to respond to data query requests and retrieve the key to be queried and the attribute type of the value of the entry to be queried. The query module is used to query the target data group corresponding to the key in the data file where the key to be queried is located; wherein, the data file includes multiple data groups, each data group includes a key block and at least one entry value block, the key block includes multiple keys, each entry value block stores multiple entry values of the same attribute type, and each key corresponds to an entry value in a different entry value block; The first determining module is used to determine the target position of the key to be queried in the key block of the target data group based on the key to be queried, and to determine the target entry value block based on the attribute type of the entry value to be queried. The second determining module is used to determine the query result of the data query request based on the target location and the target entry value block.
10. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 8.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 8.
12. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 8.
