Data storage method and device based on relational database, equipment and medium
By using the string table compression algorithm and the dictionary update mechanism in the relational database to compress the data to be compressed, the problem of low data compression efficiency in the existing technology is solved, and efficient storage space utilization and storage performance improvement are achieved.
Patent Information
- Application Number
- CN202410620299.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-17
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2044-05-17
AI Technical Summary
When existing databases compress massive data, the compression efficiency is not high and they occupy a lot of storage resources, making it difficult to effectively save storage space and improve storage efficiency.
A string table compression algorithm based on a relational database is used to compress the data to be compressed using a preset initial dictionary and the suffix string of the target tag. By updating the dictionary and adjusting the tag frequency, the data compression efficiency and storage efficiency are improved.
Significantly improves data compression efficiency, saves storage space, and further improves the compression efficiency of repeated phrases by optimizing dictionary configuration efficiency.
Smart Images

Figure CN118535655A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of database technology, and in particular to a data storage method, device, equipment and medium based on a relational database. Background Art
[0002] With the continuous development of the Internet and information technology, the importance of databases has become increasingly prominent. Databases are a technology used to store and manage data, and can be used in a variety of application scenarios, such as commercial applications, government applications, and personal applications. The current database data scale is getting larger and larger, and a massive amount of data needs to be stored. For example, the scale of raw data that needs to be stored every day can reach hundreds of GB or even thousands of GB. The amount of data is too large and the storage resources are limited, so it is necessary to compress and store the raw data, thereby greatly reducing the volume of the raw data and saving storage space.
[0003] At present, cluster systems mostly use row-based methods for real-time data collection and caching, such as Figure 1 As shown, the compression of massive data generally uses compression methods such as row compression, page compression and dictionary compression to compress data in order to save disk space and improve data storage efficiency; such as the following steps: 1. In order to record data information in the cluster system, a non-relational database is deployed separately on each node; 2. Row compression and page compression are implemented in the non-relational database through table design and indexing, and dictionary compression is implemented by using specific data types; 3. The data of each node is recorded and written into the system memory, and the data is recorded for up to half an hour, and the data is covered in a loop, and the non-relational database is called through the database plug-in to record the data into the database table. Since the compression efficiency of database row compression, page compression and dictionary compression is not high, it occupies more storage resources; therefore, how to improve data compression efficiency, save storage space and improve storage efficiency is an urgent problem to be solved today. Summary of the invention
[0004] The purpose of the present invention is to provide a data storage method, device, equipment and computer-readable storage medium based on a relational database to improve data compression efficiency, save storage space and improve storage efficiency.
[0005] In order to solve the above technical problems, the present invention provides a data storage method based on a relational database, comprising:
[0006] Obtain data to be compressed from a relational database;
[0007] According to the preset initial dictionary and the suffix strings corresponding to each stored target mark, the data to be compressed is compressed using a string table compression algorithm to obtain encoded data; wherein the target mark is a mark added to the preset initial dictionary during the compression process, and the suffix string includes the characters behind each target mark when it is added to the preset initial dictionary;
[0008] The encoded data is stored in the relational database.
[0009] On the other hand, the method of compressing the data to be compressed by using a string table compression algorithm according to the preset initial dictionary and the suffix strings corresponding to each stored target tag to obtain the encoded data includes:
[0010] The preset initial dictionary is updated according to the suffix matching length corresponding to the current target mark matched by the current string; wherein the suffix matching length is the number of characters with the same position content in the suffix string corresponding to the current target mark stored after the current string.
[0011] On the other hand, updating the preset initial dictionary according to the suffix matching length corresponding to the current target tag matched by the current string includes:
[0012] If the current string matches the current target tag, a new character is added to the current string to obtain the updated current string;
[0013] Determine whether the updated current character string matches the tag in the preset initial dictionary;
[0014] If the updated current string does not match the tag in the preset initial dictionary, the current string is matched using the stored suffix string corresponding to the current target tag to obtain a suffix matching result;
[0015] If the suffix matching result is a match, a new character is added to the current string to obtain an updated current string, and the step of using the stored suffix string corresponding to the current target mark to match the current string to obtain the suffix matching result is performed;
[0016] If the suffix matching result is no match, determine the suffix matching length of the current target tag corresponding to the current string, output the first tag in the encoding stream, and add the second tag of the suffix matching length quantity corresponding to the current string to the preset initial dictionary; wherein the prefix of the first tag is the current target tag, and the suffix is the suffix matching length quantity; the second tag is the tag of the string corresponding to the current target tag and the matched number of suffix characters.
[0017] On the other hand, the method further comprises: compressing the data to be compressed by using a string table compression algorithm according to the preset initial dictionary and the suffix strings corresponding to the stored target tags to obtain the encoded data;
[0018] According to the usage frequency of each new mark in the preset initial dictionary, the new mark in the preset initial dictionary is adjusted.
[0019] On the other hand, the suffix character string includes a preset number of characters following each of the target tags when the target tags are added to the preset initial dictionary.
[0020] On the other hand, obtaining the data to be compressed from the relational database includes:
[0021] According to the storage time of the data stored in the database table of the relational database, the stored data is divided into respective corresponding partition tables;
[0022] The stored data in each target partition table is used as the data to be compressed; wherein the storage time of the stored data in the target partition table is later than the storage time of the stored data in the non-target partition table; and the partition table includes the target partition table and the non-target partition table.
[0023] On the other hand, the step of using the stored data in each target partition table as the data to be compressed includes:
[0024] Determine a merged partition table in the target partition table; wherein the storage time of the stored data in the merged partition table is earlier than the storage time of the stored data in the non-merged partition table; the target partition table includes the merged partition table and the non-merged partition table;
[0025] Convert each target multiple rows of data in the merged partition table into corresponding single-row compressed data to obtain a converted merged partition table;
[0026] The stored data in each of the non-merged partition tables and the converted merged partition table is used as the data to be compressed.
[0027] The present invention also provides a data storage device based on a relational database, comprising:
[0028] An acquisition module, used for acquiring data to be compressed from a relational database;
[0029] A compression module, used to compress the data to be compressed using a string table compression algorithm according to a preset initial dictionary and the suffix characters corresponding to each stored target mark, to obtain encoded data; wherein the target mark is a mark added to the preset initial dictionary during the compression process, and the suffix characters include the characters following each target mark when it is added to the preset initial dictionary;
[0030] A storage module is used to store the encoded data in the relational database.
[0031] The present invention also provides a data storage device based on a relational database, comprising:
[0032] Memory for storing computer programs;
[0033] A processor is used to implement the steps of the data storage method based on a relational database as described above when executing the computer program.
[0034] In addition, the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the data storage method based on a relational database as described above are implemented.
[0035] The present invention provides a data storage method based on a relational database, comprising: obtaining data to be compressed from a relational database; compressing the data to be compressed using a string table compression algorithm according to a preset initial dictionary and suffix strings corresponding to each stored target tag to obtain encoded data; wherein the target tag is a tag added to the preset initial dictionary during the compression process, and the suffix string includes the characters behind each target tag when it is added to the preset initial dictionary; and storing the encoded data in the relational database;
[0036] It can be seen that the present invention uses a string table compression algorithm to compress the data to be compressed in a relational database, which can improve data compression efficiency, save storage space and improve storage efficiency; and by calling the suffix string corresponding to each target tag during the compression process, it can improve the configuration efficiency of the tags in the dictionary and further improve the compression efficiency of repeated phrases. In addition, the present invention also provides a data storage device, equipment and computer-readable storage medium based on a relational database, which also have the above-mentioned beneficial effects. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0038] Figure 1 A schematic diagram of a conventional data compression storage method for a cluster system;
[0039] Figure 2 A flowchart of a data storage method based on a relational database provided by an embodiment of the present invention;
[0040] Figure 3 A schematic diagram of a flow chart of another data storage method based on a relational database provided by an embodiment of the present invention;
[0041] Figure 4 A flowchart of a dictionary update process of another data storage method based on a relational database provided by an embodiment of the present invention;
[0042] Figure 5 A structural block diagram of a data storage device based on a relational database provided by an embodiment of the present invention;
[0043] Figure 6 A simplified structural diagram of a data storage device based on a relational database provided by an embodiment of the present invention;
[0044] Figure 7 The present invention provides a schematic diagram of the specific structure of a data storage device based on a relational database according to an embodiment of the present invention. DETAILED DESCRIPTION
[0045] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0046] Please refer to Figure 2 , Figure 2 A flowchart of a data storage method based on a relational database provided by an embodiment of the present invention. The method may include:
[0047] Step 101: Obtain data to be compressed from a relational database.
[0048] The relational database in this embodiment may be a database that uses a relational model to organize and manage data. The data in the relational database is represented in the form of a two-dimensional table, each row in the table represents a data record, and each column in the table represents a data attribute. This embodiment does not limit the specific database type of the relational database, such as a PostgreSQL (an object-relational database management system) database, or other types of relational databases.
[0049] Correspondingly, the data to be compressed in this embodiment may be data that needs to be compressed and stored in a relational database, such as data on a node (such as a server) of a cluster system. Figure 3 As shown, in this implementation example, a PostgreSQL database (i.e., a relational database) can be deployed and installed on the nodes of the cluster system; the data generation module can be used to collect and generate data regularly and write it into the memory, such as recording data within half an hour in the memory and overwriting it in a loop; through the PostgreSQL database plug-in, the deployed PostgreSQL database is called to record the data into the database table to compress and store the data in the database table (i.e., stored data). In other words, before this step, the step of deploying and installing a relational database on the nodes of the cluster system can also be included.
[0050] Correspondingly, the specific method for the processor to obtain the data to be compressed of the relational database in this step can be set by the designer according to the usage scenario and user needs. For example, the processor can directly store the data in the database table of the relational database as the data to be compressed. Since the computing time required for any query or update of the database is related to the scale of the data. The smaller the data scale, the smaller the computing time required; for massive data, the divide-and-conquer idea can be adopted in this embodiment to divide and conquer the data. Therefore, in this embodiment, the data in the database table can be stored in the form of a partition table, that is, by splitting a larger database table into multiple smaller partition tables, using the partition table to divide the original database table containing the full amount of time data into several database tables (i.e., partition tables) according to time periods, each partition table only contains data of a fixed time, and the data items are arranged in the original time order; thereby improving the query performance and data management efficiency, and different partition tables can be compressed independently to further achieve data compression.
[0051] For example, in this step, the processor can divide the stored data into respective corresponding partition tables according to the storage time of the data stored in the database table of the relational database; the stored data in each target partition table is used as the data to be compressed; wherein the storage time of the stored data in the target partition table is later than the storage time of the stored data in the non-target partition table; the partition table includes a target partition table and a non-target partition table; that is, in this embodiment, the stored data in the target partition table can be compressed using a string table compression algorithm (LZW algorithm), and for the stored data in the non-target partition table, since its storage time is relatively long, a lossless compression algorithm or a lossy compression algorithm with a lower compression rate can be used for compressed storage to reduce storage space.
[0052] In order to further reduce the compression rate, in this embodiment, multiple rows of stored data in the database table can be merged into a single row of stored data. For example, the above process of using the stored data in each target partition table as the data to be compressed may include: determining a merged partition table in the target partition table; wherein the storage time of the stored data in the merged partition table is earlier than the storage time of the stored data in the non-merged partition table; the target partition table includes a merged partition table and a non-merged partition table; converting each target multiple row of data in the merged partition table into their corresponding single row of compressed data to obtain a converted merged partition table; using the stored data in each non-merged partition table and the converted merged partition table as the data to be compressed. That is, in this embodiment, the target partition table that needs to use the LZW algorithm to compress the stored data in the table can be divided into a non-merged partition table that can be directly compressed and a merged partition table that needs to be merged and compressed, so as to convert multiple rows (such as 1000 rows) of data in the merged partition table with a longer storage time into a single row of data (i.e., a single row of compressed data). Correspondingly, in this embodiment, the single row of compressed data can also be segmented according to a specific column so that each compressed row corresponds to the data of a single business item.
[0053] Correspondingly, for the above-mentioned conversion of each target multi-row data in the merged partition table into the corresponding single-row compressed data, the specific method of obtaining the converted merged partition table, that is, the specific method of determining the target multi-row data, can be set by the designer. For example, the multi-row data of the same node (node) can be determined as the target multi-row data, as shown in Tables 1 and 2 below, and the multi-row data corresponding to node 1 is converted into a single-row data.
[0054] Table 1 Merged partition table before merging
[0055] Table 2 Merged partition table after merging
[0056] like Figure 3As shown, the table partitioning module and the data merging module can be used to periodically partition historical data and merge multiple rows of data, further reducing the data compression rate and improving processing efficiency.
[0057] Step 102: compress the data to be compressed using a string table compression algorithm according to the preset initial dictionary and the corresponding suffix strings of each stored target tag to obtain encoded data; wherein the target tag is a tag added to the preset initial dictionary during the compression process, and the suffix string includes the characters behind each target tag when it is added to the preset initial dictionary.
[0058] It can be understood that the string table compression algorithm (LZW algorithm) in this embodiment is an algorithm that achieves lossless compression of data by establishing a string table and using shorter codes to represent longer strings. The LZW algorithm has three important objects: data stream, encoding stream and compilation table (i.e., string table); when encoding, the data stream is the input object, and the encoding stream (encoded data after compression operation) is the output object; when decoding, the encoding stream is the input object, and the data stream is the output object; and the compilation table is an object that needs to be used in both encoding and decoding. The preset initial dictionary in this embodiment can be a compilation table in the initial state during encoding and decoding, and the preset initial dictionary can include all possible roots (ROOT).
[0059] Correspondingly, in order to increase the data compression rate to save disk space and improve the storage efficiency of data, the extended function of the relational database (such as a custom function) is used in this embodiment to implement the function of the string table compression algorithm, that is, the external table function of the relational database is combined with a program that supports LZW algorithm compression to compress and process data, thereby realizing lossless compression and lossless decompression of data. The compression process of the LZW algorithm can be as follows: ① At the beginning, the preset initial dictionary can contain all possible roots. At this time, the prefix string P and the current character C are both empty. ② Read in the new character C and merge it with P to form the string P+C. ③ Determine whether P+C is in the dictionary; if "yes", then P=P+C, return to step ②; if "no"; then output the mapping of P, P=P+C, add the tag of the prefix string P to the dictionary, establish a mapping, and let P=C / / (now P only contains one character C). ④ Determine whether there are still codewords to be translated in the codeword stream; if "yes"; then return to step ②; if "no"; then output the codeword representing the current prefix P to the codeword stream; the process ends.
[0060] In this embodiment, in order to improve the configuration efficiency of the tags in the dictionary and further improve the compression efficiency of repeated phrases, the matching rules of the LZW algorithm can be optimized by using the suffix strings corresponding to each stored target tag in this embodiment, so as to improve the configuration efficiency of the tags in the dictionary by calling and matching the suffix strings corresponding to each target tag during the compression process. For example, in this step, the preset initial dictionary can be updated according to the suffix matching length corresponding to the current target tag matched by the current string; wherein the suffix matching length is the number of characters with the same position content in the suffix string corresponding to the stored current target tag after the current string.
[0061] For example, in some embodiments, after the processor finds that the tag match has ended, it may not end the match immediately, but instead searches in a sliding window for a better match in the stored suffix string. If there is a better match, it is written into the output stream (such as the encoded stream) in the form of a {position, suffix match length} group, and the matched strings are added as tags one by one. For example, if there is a "vdisk" character at the beginning of the data to be compressed, the following tag flag1: {v,d} will be generated for the first time. If the matching process matches "vdisk" again, the conventional LZW algorithm will only match flag1: {v,d}, and add a tag flagX: {vd,i}, that is, vdi; in this way, "vdisk" must appear multiple times to put the entire word into a tag. In order to optimize this problem, when flag1: {v,d} is generated for the first time when "vdisk" appears, the suffix string corresponding to flag1 (such as isk, or complete vdisk) can be stored; after the second appearance of "vdisk", after matching flag1{v,d} (that is, the current target tag), if the vdi string with the newly added i character does not have a matching tag in the dictionary, flag1 is not output directly, but the suffix string corresponding to flag1 is searched backward to see if there are more matches. If more matches are found, a tag of {flag1, suffix matching length} is output in the encoded stream, and the 3 (that is, suffix matching length) tags {vd,i}, {vdi,s}, {vdis,k} corresponding to "vdisk" are added to the dictionary as new tags. In this way, when "vdisk" is matched again, the corresponding tag can be directly output.
[0062] It should be noted that the target tag in this embodiment can be all or part of the tags (i.e., newly added tags) added to the preset initial dictionary during the compression process. For example, the target tag can be part of the newly added tags. For example, during the compression process, the current string has only been matched with the initial tags in the preset initial dictionary (such as all possible roots) and has not been matched with the newly added tags. In this case, when the current string cannot be matched with the tags in the preset initial dictionary, the tag of the current string (i.e., the newly added tag) can be added to the preset initial dictionary, and the tag can be used as the target tag to store the suffix string corresponding to the current string.
[0063] Correspondingly, the specific content of the suffix string corresponding to each target tag stored in this embodiment can be set by the designer. For example, the suffix string corresponding to each target tag can include the preset number of characters behind each target tag when it is added to the preset initial dictionary, that is, the preset number of characters behind each position; it can also include the latter part of the word where each target tag is located when it is added to the preset initial dictionary. Correspondingly, the suffix string corresponding to each target tag stored can also include the character content of each target tag itself. This embodiment does not impose any restrictions on this.
[0064] Among them, in this step, the pre-stored words or phrases (i.e., preset strings) can be further utilized to improve the configuration efficiency of the tags in the dictionary and further improve the compression efficiency of repeated phrases. For example, in this embodiment, the processor can read the preset string corresponding to the string configuration instruction into the memory according to the acquired string configuration instruction, so that the compressed data can be compressed using the string table compression algorithm according to the preset initial dictionary and the preset string in the memory and the suffix string corresponding to each target tag to obtain the encoded data. In other words, the user can configure the corresponding preset string through the string configuration instruction according to the business scenario of the data required to be compressed and stored in the relational database, so as to further improve the data compression efficiency. Correspondingly, the processor can also update the preset initial dictionary according to the preset string matching length matched by the current string; wherein the matching length is the number of characters with the same position content as the matched preset string after the current string.
[0065] Furthermore, in this embodiment, after step 102, the newly added tags in the preset initial dictionary may be adjusted according to the usage frequency of each newly added tag in the preset initial dictionary. That is, in this embodiment, after compression is completed, the entire dictionary, i.e., the preset initial dictionary with the newly added tags, may not be directly cleared, but the newly added tags with lower usage frequency may be cleared according to the usage frequency of the newly added tags in the dictionary, and the newly added tags with higher usage rate may be retained, so as to increase the efficiency of subsequent data compression and decompression.
[0066] Step 103: Store the encoded data in a relational database.
[0067] It can be understood that, in this embodiment, the processor can store the encoded stream (ie, encoded data) compressed by the LZW algorithm in the relational database to improve the storage performance of the relational database.
[0068] Accordingly, in this embodiment, after the processor stores the coded data in the relational database, it can also organize the coded data (such as indexing) to facilitate subsequent calls. Figure 3 As shown, the processor can organize the data files corresponding to all partition tables to ensure data consistency.
[0069] In this embodiment, the embodiment of the present invention uses a string table compression algorithm in a relational database to compress the data to be compressed, which can improve data compression efficiency, save storage space and improve storage efficiency; and by calling the suffix strings corresponding to each target tag during the compression process, it can improve the configuration efficiency of the tags in the dictionary and further improve the compression efficiency of repeated phrases.
[0070] Based on the above method embodiment, the specific process of updating the preset initial dictionary according to the suffix matching length corresponding to the current target tag matched by the current string in the above embodiment can be as follows: Figure 4 As shown, including:
[0071] Step 1021: If the current character string matches the current target tag, a new character is added to the current character string to obtain an updated current character string.
[0072] Step 1022: Determine whether the updated current character string matches a tag in the preset initial dictionary; if not, proceed to step 1023.
[0073] Step 1023: Use the stored suffix string corresponding to the current target tag to match the current string and obtain the suffix matching result; if yes, proceed to step 1024; if not, proceed to step 1025.
[0074] Step 1024: If the suffix matching result is a match, a new character is added to the current string to obtain an updated current string, and then the process goes to step 1023;
[0075] Step 1025: If the suffix matching result is no match, determine the suffix matching length of the current target tag corresponding to the current string, output the first tag in the encoding stream, and add a second tag of the suffix matching length corresponding to the current string to the preset initial dictionary.
[0076] The prefix of the first tag is the current target tag, and the suffix is the suffix matching length; the second tag is the tag of the string corresponding to the current target tag and the matching suffix characters of each number.
[0077] It can be understood that in this embodiment, when the current string (such as the current character C mentioned above) does not match the tag in the preset initial dictionary, and the last match was the target tag in the preset initial dictionary (i.e., the current target tag), the suffix string corresponding to the current target tag stored in the memory can be used to match the current string and subsequent characters in sequence to improve the configuration efficiency of the tags in the dictionary.
[0078] Corresponding to the above method embodiment, an embodiment of the present invention further provides a data storage device based on a relational database. The data storage device based on a relational database described below and the data storage method based on a relational database described above can refer to each other.
[0079] Please refer to Figure 5 , Figure 5 This is a structural block diagram of a data storage device based on a relational database provided by an embodiment of the present invention. The device may include:
[0080] An acquisition module 10 is used to acquire the data to be compressed from the relational database;
[0081] The compression module 20 is used to compress the data to be compressed using a string table compression algorithm according to the preset initial dictionary and the suffix characters corresponding to each stored target mark to obtain encoded data; wherein the target mark is the mark added to the preset initial dictionary during the compression process, and the suffix characters include the characters following each target mark when it is added to the preset initial dictionary;
[0082] The storage module 30 is used to store the coded data in a relational database.
[0083] In some embodiments, the compression module 20 may include:
[0084] The dictionary update submodule is used to update the preset initial dictionary according to the suffix matching length corresponding to the current target tag matched by the current string; wherein the suffix matching length is the number of characters with the same position content in the suffix string corresponding to the stored current target tag after the current string.
[0085] In some embodiments, the dictionary update submodule may include:
[0086] A first updating unit is used for adding a new character to the current string if the current string matches the current target mark to obtain an updated current string;
[0087] A judging unit, used to judge whether the updated current character string matches a tag in a preset initial dictionary;
[0088] A suffix matching unit, for matching the current string with the suffix string corresponding to the stored current target tag to obtain a suffix matching result if the updated current string does not match the tag in the preset initial dictionary;
[0089] A second updating unit is used for adding a new character to the current string if the suffix matching result is a match, obtaining an updated current string, and sending a start signal to the suffix matching unit;
[0090] A dictionary updating unit is used to determine the suffix matching length of the current target tag corresponding to the current string if the suffix matching result is not matched, output a first tag in the encoding stream, and add a second tag of the suffix matching length quantity corresponding to the current string to a preset initial dictionary; wherein the prefix of the first tag is the current target tag, and the suffix is the suffix matching length quantity; the second tag is the tag of the string corresponding to the current target tag and the matched number of suffix characters.
[0091] In some embodiments, the apparatus may further include:
[0092] The adjustment module is used to adjust the newly added tags in the preset initial dictionary according to the usage frequency of each newly added tag in the preset initial dictionary.
[0093] In some embodiments, the suffix character string includes a preset number of characters following each target tag when it is added to the preset initial dictionary.
[0094] In some embodiments, the acquisition module 10 includes:
[0095] The partitioning submodule is used to divide the stored data into corresponding partition tables according to the storage time of the data stored in the database table of the relational database;
[0096] A submodule is determined, which is used to use the storage data in each target partition table as data to be compressed; wherein the storage time of the storage data in the target partition table is later than the storage time of the storage data in the non-target partition table; and the partition table includes the target partition table and the non-target partition table.
[0097] In some embodiments, using the stored data in each target partition table as data to be compressed includes:
[0098] A merge determination unit, used to determine a merge partition table in a target partition table; wherein the storage time of the stored data in the merge partition table is earlier than the storage time of the stored data in the non-merged partition table; the target partition table includes the merge partition table and the non-merged partition table;
[0099] A data merging unit, used for converting each target multiple-row data in the merged partition table into corresponding single-row compressed data, to obtain a converted merged partition table;
[0100] The data determination unit is used to use the stored data in each non-merged partition table and the converted merged partition table as data to be compressed.
[0101] In this embodiment, the embodiment of the present invention uses a string table compression algorithm in a relational database to compress the data to be compressed, which can improve data compression efficiency, save storage space and improve storage efficiency; and by calling the suffix strings corresponding to each target tag during the compression process, it can improve the configuration efficiency of the tags in the dictionary and further improve the compression efficiency of repeated phrases.
[0102] Corresponding to the above method embodiment, an embodiment of the present invention also provides a data storage device based on a relational database. The data storage method device based on a relational database described below and the data storage method based on a relational database described above can be referenced to each other.
[0103] Please refer to Figure 6 , Figure 6 A simplified structural diagram of a data storage device based on a relational database provided by an embodiment of the present invention. The device may include:
[0104] A memory D1, for storing computer programs;
[0105] The processor D2 is used to implement the steps of the data storage method based on a relational database provided by the above method embodiment when executing a computer program.
[0106] Accordingly, please refer to Figure 7 , Figure 7A specific structural diagram of a data storage device based on a relational database provided in an embodiment of the present invention, the data storage device 310 may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 322 (for example, one or more processors) and memory 332, one or more storage media 330 (for example, one or more mass storage devices) storing application programs 342 or data 344. Among them, the memory 332 and the storage medium 330 can be short-term storage or permanent storage. The program stored in the storage medium 330 may include one or more units (not shown in the figure), and each unit may include a series of instruction operations on the host. Furthermore, the central processor 322 can be configured to communicate with the storage medium 330 and execute a series of instruction operations in the storage medium 330 on the data storage device 310.
[0107] The data storage device 310 may further include one or more power supplies 326, one or more wired or wireless network interfaces 350, one or more input and output interfaces 358, and / or one or more operating systems 341, such as Linux system.
[0108] The data storage device 310 in this embodiment may specifically be a node device in a cluster system where a relational database is deployed, such as a server.
[0109] The steps in the data storage method based on a relational database described above can be implemented by the structure of a data storage device based on a relational database.
[0110] Corresponding to the above method embodiment, the embodiment of the present invention further provides a computer program product. The computer program product described below and the data storage method based on a relational database described above can refer to each other.
[0111] A computer program product includes a computer program / instruction, which, when executed by a processor, implements the steps of the data storage method based on a relational database provided in the above method embodiment.
[0112] Corresponding to the above method embodiment, the embodiment of the present invention further provides a computer-readable storage medium. The computer-readable storage medium described below and the data storage method based on a relational database described above can refer to each other.
[0113] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the data storage method based on a relational database of the above method embodiment.
[0114] The computer-readable storage medium may be a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc., which can store program codes.
[0115] The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other. For the devices, equipment, computer program products and computer-readable storage media disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple, and the relevant parts can be referred to the method part description.
[0116] The above is a detailed introduction to a data storage method, device, equipment and computer-readable storage medium based on a relational database provided by the present invention. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present invention, the present invention can also be improved and modified, and these improvements and modifications also fall within the scope of protection of the present invention.
Claims
1. A data storage method based on a relational database, characterized in that: include: Obtain data to be compressed from a relational database; According to the preset initial dictionary and the suffix strings corresponding to each stored target mark, the data to be compressed is compressed using a string table compression algorithm to obtain encoded data; wherein the target mark is a mark added to the preset initial dictionary during the compression process, and the suffix string includes the characters behind each target mark when it is added to the preset initial dictionary; The encoded data is stored in the relational database.
2. The data storage method based on a relational database according to claim 1, characterized in that: The method of compressing the data to be compressed by using a string table compression algorithm according to the preset initial dictionary and the suffix strings corresponding to each stored target tag to obtain encoded data includes: The preset initial dictionary is updated according to the suffix matching length corresponding to the current target mark matched by the current string; wherein the suffix matching length is the number of characters with the same position content in the suffix string corresponding to the current target mark stored after the current string.
3. The data storage method based on relational database according to claim 2 is characterized in that: The updating of the preset initial dictionary according to the suffix matching length corresponding to the current target tag matched by the current character string includes: If the current string matches the current target tag, a new character is added to the current string to obtain the updated current string; Determine whether the updated current character string matches the tag in the preset initial dictionary; If the updated current string does not match the tag in the preset initial dictionary, the current string is matched using the stored suffix string corresponding to the current target tag to obtain a suffix matching result; If the suffix matching result is a match, a new character is added to the current string to obtain an updated current string, and the step of using the stored suffix string corresponding to the current target mark to match the current string to obtain the suffix matching result is performed; If the suffix matching result is no match, determine the suffix matching length of the current target tag corresponding to the current string, output the first tag in the encoding stream, and add the second tag of the suffix matching length quantity corresponding to the current string to the preset initial dictionary; wherein the prefix of the first tag is the current target tag, and the suffix is the suffix matching length quantity; the second tag is the tag of the string corresponding to the current target tag and the matched number of suffix characters.
4. The data storage method based on a relational database according to claim 1, characterized in that: After compressing the data to be compressed by using a string table compression algorithm according to the preset initial dictionary and the suffix strings corresponding to each stored target tag to obtain the encoded data, the method further includes: According to the usage frequency of each new mark in the preset initial dictionary, the new mark in the preset initial dictionary is adjusted.
5. The data storage method based on relational database according to claim 1, characterized in that: The suffix character string includes a preset number of characters following each of the target marks when the target mark is added to the preset initial dictionary.
6. The data storage method based on a relational database according to any one of claims 1 to 5, characterized in that: The step of obtaining the data to be compressed from the relational database includes: According to the storage time of the data stored in the database table of the relational database, the stored data is divided into respective corresponding partition tables; The stored data in each target partition table is used as the data to be compressed; wherein the storage time of the stored data in the target partition table is later than the storage time of the stored data in the non-target partition table; and the partition table includes the target partition table and the non-target partition table.
7. The data storage method based on relational database according to claim 6 is characterized in that: The step of using the stored data in each target partition table as the data to be compressed includes: Determine a merged partition table in the target partition table; wherein the storage time of the stored data in the merged partition table is earlier than the storage time of the stored data in the non-merged partition table; the target partition table includes the merged partition table and the non-merged partition table; Convert each target multiple rows of data in the merged partition table into corresponding single-row compressed data to obtain a converted merged partition table; The stored data in each of the non-merged partition tables and the converted merged partition table is used as the data to be compressed.
8. A data storage device based on a relational database, characterized in that: include: An acquisition module, used for acquiring data to be compressed from a relational database; A compression module, used to compress the data to be compressed using a string table compression algorithm according to a preset initial dictionary and the suffix characters corresponding to each stored target mark, to obtain encoded data; wherein the target mark is a mark added to the preset initial dictionary during the compression process, and the suffix characters include the characters following each target mark when it is added to the preset initial dictionary; A storage module is used to store the encoded data in the relational database.
9. A data storage device based on a relational database, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the data storage method based on a relational database as described in any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the data storage method based on a relational database as described in any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Multi-character combination lossless data compression method for binary data
CN102122960A
Method for packing data, method for unpacking data, coder and decoder
CN103326732A
Compression method, decompression method, compression device and decompresssion device
CN105846825A
Telemetry data-oriented data search method and device
CN110598057A
Data compression method
US20120130965A1
