Table data storage method, device, electronic device and storage medium
By determining the corresponding storage strategy based on the column data distribution characteristics of the table data and storing the table data, the problem of wasting memory space in the prior art and the inability to dynamically add column data is solved, and efficient table data storage is achieved.
Patent Information
- Application Number
- CN202111612654.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-27
- Publication Date
- 2025-05-09
- Estimated Expiration
- 2041-12-27
AI Technical Summary
When storing existing table data storage methods, memory space is wasted due to the different lengths of each column data, and column data cannot be dynamically added in non-down state.
By acquiring multiple column data of the table to be stored, a column storage policy of each column data is determined from a plurality of preset storage policies according to the data distribution characteristics of each column data, and a column storage policy of each column data is stored.
It avoids the wasted memory space caused by different lengths of each column data when storing tables by row, and realizes the function of dynamically adding column data in a non-down state.
Smart Images

Figure CN114416729B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of table storage, and in particular to a table data storage method, device, electronic device and storage medium. Background Art
[0002] During the development of large-scale games, a large amount of configuration data needs to be operated. Among them, the amount of data in the game planning configuration table is particularly huge. The existing table data storage method is "row-oriented", that is, the table is stored row by row. Specifically, a structure type is pre-defined, and then each row of the table data is compiled according to the structure type, and then the structure data compiled from each row of data is stored in sequence. Since the memory space occupied by the structure data after each row of data in the table is compiled is the same, the presence of blank cells in the table will cause a waste of memory space. If new column data is added to the table, the definition rules need to be re-determined, and each row of data in the table needs to be re-compiled. At this time, the device must be in a downtime state. Summary of the invention
[0003] In order to overcome the deficiencies of the prior art, embodiments of the present invention provide a table data storage method, device, electronic device, and storage medium.
[0004] The technical solution adopted in the embodiment of the present invention is as follows:
[0005] In a first aspect, an embodiment of the present invention provides a table data storage method, the method comprising:
[0006] Acquire a table to be stored, wherein the table to be stored includes a plurality of columns of data;
[0007] Determining a column storage strategy for each column of data from a plurality of preset storage strategies according to a data distribution feature of each column of data;
[0008] Each of the column data is stored according to a column storage strategy for each of the column data.
[0009] In a possible implementation, the step of determining a column storage strategy for each column of data from a plurality of preset storage strategies according to a data distribution feature of each column of data includes:
[0010] For any target column data among the plurality of column data, dividing the target column data to obtain at least one data unit;
[0011] Determining a unit storage strategy for each of the data units of the target column data from a plurality of preset storage strategies according to a data distribution feature of each of the data units of the target column data;
[0012] All unit storage strategies of each column of data are determined as the column storage strategy of each column of data.
[0013] In a possible implementation, the target column data includes a plurality of non-null value elements, and the step of dividing any target column data among the plurality of column data to obtain at least one data unit includes:
[0014] Determine whether the number of non-null value elements in the target column data is greater than a preset value;
[0015] If the number of non-null value elements of the target column data is not greater than the preset value, all elements of the target column data are taken as a data unit;
[0016] If the number of non-null value elements of the target column data is greater than the preset value, the column data is divided into multiple data units according to the preset value.
[0017] In a possible implementation, each of the preset storage strategies includes a strategy tag, and the step of determining the unit storage strategy of each of the data units of the target column data from a plurality of preset storage strategies according to the data distribution characteristics of each of the data units of the target column data includes:
[0018] For any target data unit in the target column data, determine a plurality of candidate storage strategies according to data distribution characteristics of the target data unit and a strategy label of each of the preset storage strategies;
[0019] Calculating the memory occupied by storing the target data unit according to each of the candidate storage strategies;
[0020] The candidate storage strategy with the smallest memory is determined as the unit storage strategy of the target data unit.
[0021] In a possible implementation, each column of data is pre-divided into at least one data unit, each data unit corresponds to a unit storage strategy, and the step of storing each column of data according to the column storage strategy of each column of data includes:
[0022] For any target data unit of any target column data, generating structure data of the target data unit according to a unit storage strategy of the target data unit;
[0023] The structure data of all the data units of each column of data are stored.
[0024] In a second aspect, an embodiment of the present invention provides a table data storage device, the device comprising:
[0025] An acquisition module, used for acquiring a table to be stored, wherein the table to be stored includes a plurality of columns of data;
[0026] A determination module, configured to determine a column storage strategy for each column of data from a plurality of preset storage strategies according to a data distribution feature of each column of data;
[0027] The storage module is used to store each column of data according to a column storage strategy of each column of data.
[0028] In a possible implementation, when the determining module is used to determine the column storage strategy for each column of data from a plurality of preset storage strategies according to the data distribution characteristics of each column of data, it is specifically used to:
[0029] For any target column data among the plurality of column data, dividing the target column data to obtain at least one data unit;
[0030] Determining a unit storage strategy for each of the data units of the target column data from a plurality of preset storage strategies according to a data distribution feature of each of the data units of the target column data;
[0031] All unit storage strategies of each column of data are determined as the column storage strategy of each column of data.
[0032] In a possible implementation, each column of data is pre-divided into at least one data unit, each of the data units corresponds to a unit storage strategy, and the storage module, when used to store each of the column of data according to the column storage strategy of each of the column of data, is specifically used to:
[0033] For any target data unit of any target column data, generating structure data of the target data unit according to the unit storage strategy of the target data unit;
[0034] The structure data of all the data units of each column of data are stored.
[0035] In a third aspect, an embodiment of the present invention provides an electronic device, comprising a memory and a processor, wherein the memory is used to store a computer program; and the processor is used to execute the method described in the first aspect when calling the computer program.
[0036] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method described in the first aspect.
[0037] Compared with the prior art, the embodiments of the present invention provide a table data storage method, device, electronic device and storage medium. The method obtains a table to be stored containing multiple columns of data, and determines the column storage strategy for each column of data from multiple preset storage strategies according to the data distribution characteristics of each column of data, and then stores each column of data according to the column storage strategy for each column of data. Since the embodiments of the present invention determine the corresponding column storage strategy based on the data distribution characteristics of each column of data, and implement the storage of each column of data according to the column storage strategy of each column of data, it avoids the waste of memory space caused by the different lengths of each column of data when storing the table by row, and the inability to dynamically add column data due to the fixed storage strategy. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0039] Figure 1A A schematic diagram of table data provided by an embodiment of the present invention;
[0040] Figure 1B A schematic diagram of an existing table data storage method provided by an embodiment of the present invention;
[0041] Figure 2 A flow chart of a table data storage method provided by an embodiment of the present invention;
[0042] Figure 3 A flow chart of a method for determining a column storage strategy based on data distribution characteristics of column data provided by an embodiment of the present invention;
[0043] Figure 4 A flow chart of a method for storing column data based on a column storage strategy for column data provided by an embodiment of the present invention;
[0044] Figure 5 A schematic diagram of a table data storage method provided by an embodiment of the present invention;
[0045] Figure 6 A schematic diagram of dynamically adding table column data provided by an embodiment of the present invention;
[0046] Figure 7 A block diagram of a table data storage device provided by an embodiment of the present invention;
[0047] Figure 8A schematic block diagram of the structure of an electronic device provided by an embodiment of the present invention.
[0048] Icons: 100 - table data storage device; 101 - acquisition module; 102 - determination module; 103 - storage module; 200 - electronic device; 210 - memory; 220 - processor. DETAILED DESCRIPTION
[0049] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions 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. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.
[0050] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. 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.
[0051] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0052] In the description of the present invention, it should be noted that if the terms "upper", "lower", "inside", "outside", etc. appear to indicate an orientation or position relationship, they are based on the orientation or position relationship shown in the accompanying drawings, or are the orientation or position relationship in which the product of the invention is usually placed when used. They are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present invention.
[0053] In addition, the terms “first”, “second”, etc., if used, are merely used to distinguish between the descriptions and should not be understood as indicating or implying relative importance.
[0054] It should be noted that, in the absence of conflict, the features in the embodiments of the present invention may be combined with each other.
[0055] Tables can be divided into multiple rows of data by row, or divided into multiple columns of data by column. Please refer to Figure 1A , Figure 1AA schematic diagram of table data provided by an embodiment of the present invention, wherein the table is divided into 20 rows of data by row and 4 columns of data by column, and each row of data and each column of data includes multiple null value elements and non-null value elements. Generally, the data types of multiple non-null value elements in the row data can be different, while the data types of multiple non-null value elements in the column data are generally the same, for example Figure 1A In the example, row data 5 contains 4 non-null value elements, namely 7, 4, ff and a, whose data types are integer (int type), integer (int type), string type (string type) and character type (char type), respectively. Column data 4 contains 19 non-null value elements, all of which have the value of a and whose data type is character type (char type). In the prior art, the storage of tables is performed by rows, please refer to Figure 1B , Figure 1B A schematic diagram of an existing table data storage method provided by an embodiment of the present invention, wherein each row of data is compiled through a predefined structure type, and the generated structure data is stored in sequence, and the memory space occupied is a table resource pool, such as Figure 1B As shown, since row data 17 to row data 20 in the table contain null value elements, the lengths of the columns of data in the table are different. When storing structures 17 to 20, memory space is still allocated for these null value elements, resulting in a waste of memory space. At the same time, the existing table data storage method only supports the dynamic addition of new row data, that is, the device is in a non-downtime state. When adding new column data, a structure type needs to be redefined and the new structure type is used to compile each row of data. At this time, the device must be in a downtime state, that is, only column data can be added statically.
[0056] In view of this, an embodiment of the present invention provides a table data storage method, which can avoid the waste of memory space caused by different lengths of column data and can also dynamically add column data, which will be described in detail below.
[0057] Please refer to Figure 2 , Figure 2 A flow chart of a table data storage method provided by an embodiment of the present invention, the method includes steps S101 to S103.
[0058] Step S101, obtaining a table to be stored, where the table to be stored includes a plurality of columns of data.
[0059] In an embodiment of the present invention, the table to be stored can be divided into multiple columns of data by column, and the data types of each column of data can be different. For example, a table includes three columns of data, the data type of the first column is integer (int type), the data type of the second column is floating point (float type), and the data type of the third column is character (char type).
[0060] Step S102 : determining a column storage strategy for each column of data from a plurality of preset storage strategies according to a data distribution feature of each column of data.
[0061] In the embodiment of the present invention, the data distribution feature of each column of data refers to finding the distribution law of the data through the data analysis method, for example, the values of a column of data are the same, the values of a column of data are increasing, and the value range of a column of data is 0 to 2. 8 Etc., and at the same time, multiple preset storage strategies are pre-set for the data distribution characteristics of all possible column data, each preset storage strategy corresponds to a specific data distribution characteristic, data analysis is performed on each column data, and a preset storage strategy corresponding to its data distribution characteristic is selected from multiple preset storage strategies as the column storage strategy.
[0062] Step S103: storing each column of data according to the column storage strategy of each column of data.
[0063] In the embodiment of the present invention, the column storage strategy for each column of data is the optimal storage strategy for the data distribution characteristics of the column of data, that is, the memory space occupied when storing each column of data according to the column storage strategy for each column of data is minimal.
[0064] The above method provided by the embodiment of the present invention has the beneficial effect that, by storing each column of data according to the column storage strategy of each column of data, it avoids the waste of memory space caused by the different lengths of each column of data when storing the table by row, and the inability to dynamically add column data due to the fixed storage strategy.
[0065] based on Figure 2 The embodiment of the present invention provides a specific implementation method for determining a column storage strategy based on the data distribution characteristics of column data. Please refer to Figure 3 , Figure 3 A flow chart of a method for determining a column storage strategy based on data distribution characteristics of column data provided by an embodiment of the present invention, step S102 includes sub-steps S102 - 1 to S102 - 3.
[0066] Sub-step S102 - 1 , for any target column data among the plurality of column data, divide the target column data to obtain at least one data unit.
[0067] In an embodiment of the present invention, the storage of a table is performed by column, the target column data is the column data currently being stored, each column data includes at least one non-null value element, the non-null value elements contained in the target column data are divided, and the target column data is divided into at least one data unit, and each data unit includes at least one non-null value element.
[0068] As a specific implementation manner, the specific implementation manner of sub-step S102-1 is as follows:
[0069] First, determine whether the number of non-null value elements in the target column data is greater than the preset value;
[0070] If the number of non-null value elements in the target column data is not greater than the preset value, all non-null value elements in the target column data are taken as one data unit;
[0071] If the number of non-null value elements in the target column data is greater than a preset value, the column data is divided into multiple data units according to the preset value.
[0072] In an embodiment of the present invention, a preset value is used as a basis for dividing column data into data units. When the number of non-null value elements of the target column data is not greater than the preset value, that is, the number of non-null value elements is less than or equal to the preset value, all non-null value elements of the target column data are divided into one data unit. When the number of non-null value elements of the target column data is greater than the preset value, starting from the starting position of the column data, each preset value of non-null value elements is divided into one data unit. When the number of undivided non-null value elements of the column data is less than the preset value, all undivided non-null value elements are used as the last data unit of the column data.
[0073] Sub-step S102 - 2 , determining a unit storage strategy for each data unit of the target column data from a plurality of preset storage strategies according to the data distribution characteristics of each data unit of the target column data.
[0074] In an embodiment of the present invention, the preset storage strategy that matches the data distribution characteristics of each data unit may be one or more. When the matching preset storage strategy is one, this preset storage strategy is the unit storage strategy. When the matching preset storage strategy is multiple, the unit storage strategy is determined from these preset storage strategies.
[0075] As a specific implementation manner, the specific implementation manner of sub-step S102-2 is as follows:
[0076] First, for any target data unit in the target column data, multiple candidate storage strategies are determined according to the data distribution characteristics of the target data unit and the strategy label of each preset storage strategy;
[0077] Then, the memory occupied by storing the target data unit according to each candidate storage strategy is calculated;
[0078] Finally, the candidate storage strategy with the smallest memory usage is determined as the unit storage strategy of the target data unit.
[0079] In an embodiment of the present invention, the policy label of each preset storage policy characterizes the data distribution characteristics corresponding to the preset storage policy. When storing the target column data, each data unit in the target column data is stored in turn according to the order in which the data units are divided. The target data unit is the data unit currently being stored. Data analysis is performed on the target data unit to obtain its data distribution characteristics. Since there can be multiple data distribution characteristics of the target data unit, there are also multiple candidate storage strategies. For example, the target data unit contains 32 non-null value elements, of which 16 non-null value elements take the value of 0, and the remaining 16 non-null value elements take the value of 255. At this time, there are two data distribution characteristics of the target data unit, one of which is "the element value is distributed in [0, 2 8 )", which matches the policy label of predicted storage strategy A, and the other is "the element value is two", which matches the policy label of predicted storage strategy B. Predicted storage strategy A and predicted storage strategy B are used as candidate storage strategies for the target data unit. Among the two candidate storage strategies, the memory occupied when storing the target data unit according to predicted storage strategy B is the smallest, so predicted storage strategy B is the unit storage strategy for the target data unit.
[0080] Sub-step S102 - 3 : determining all unit storage strategies of each column of data as the column storage strategy of each column of data.
[0081] In an embodiment of the present invention, when any column of data is divided into a data unit, data analysis on the column of data is data analysis on the data unit, the data distribution characteristics of the column of data are the data distribution characteristics of the data unit, and then the column storage strategy of the column of data is the unit storage strategy of the data unit; when any column of data is divided into multiple data units, the process of data analysis on the column of data is decomposed into data analysis on multiple data units, the data distribution characteristics of the column of data are composed of the data distribution characteristics of multiple data units, and then the column storage strategy of the column of data is composed of the unit storage strategies of multiple data units, and the unit storage strategy of each data unit of the column of data is the optimal storage strategy for the data distribution characteristics of the data unit, so that the memory occupied by each data unit when storing is minimized, and then the memory occupied when storing the column of data is minimized.
[0082] based on Figure 2 The embodiment of the present invention provides a specific implementation method for storing column data based on a column storage strategy for column data. Please refer to Figure 4 , Figure 4 A flow chart of a method for storing column data based on a column storage strategy for column data provided in an embodiment of the present invention, step S103 includes sub-step S103 - 1 and sub-step S103 - 2.
[0083] Sub-step S103 - 1 , for any target data unit of any target column data, generating structure data of the target data unit according to the unit storage strategy of the target data unit.
[0084] In an embodiment of the present invention, the target data unit is compiled according to the structure type defined by the unit storage policy of the target data unit to generate the structure data of the target data unit, wherein the structure data of each data unit includes an information structure and a resource structure, the information structure contains the unit storage strategy information of the data unit and the address of the resource structure, and the resource structure contains the value information of the elements of the data unit.
[0085] Sub-step S103 - 2 , storing the structure data of all data units of each column of data.
[0086] In an embodiment of the present invention, memory space is allocated for the structure data of each data unit of each column of data. The memory occupied by the structure data of all data units of each column of data is a column resource pool. Each column of data corresponds to a column resource pool, and all column resource pools constitute a table resource pool.
[0087] As a specific implementation method, the definition of the structure type used to generate the information structure is as follows:
[0088]
[0089] In order to explain the above content more intuitively, the embodiment of the present invention is as follows Figure 5 The table shown is used as a table to be stored, the preset value for dividing the data unit is 32, and 9 preset storage strategies are shown in the following table for example.
[0090]
[0091]
[0092] Please refer to Figure 5 , Figure 5A schematic diagram of a table data storage method provided by an embodiment of the present invention, wherein the table to be stored contains two columns of data, namely column data 1 and column data 2, each column of data contains 34 non-null value elements, and the data types are all integer (int type), and column data 1 is divided into data units, and the 1st to 32nd non-null value elements are divided into data units 1_1, and the 33rd to 34th non-null value elements are divided into data units 1_2. The data distribution feature of data unit 1_1 is "element values are increasing", and according to the policy labels in the 9 preset storage policies, the preset storage policy II is determined to be the unit storage policy of data unit 1_1, and the data distribution feature of data unit 1_2 is "element values are the same", and according to the policy labels in the 9 preset storage policies, the preset storage policy I is determined to be the unit storage policy of data unit 1_2. According to the structure type defined by the preset storage strategy II, the data unit 1_1 is compiled to generate the resource structure 1_1, that is, increment_32bitincrement1_1={1}, and then according to the address information of the resource structure and the unit storage strategy information of the data unit 1_1, the information structure 1_1 is generated, that is, Cluster cluster1_1={increment_32bit,0}. According to the structure type defined by the preset storage strategy I, the data unit 1_2 is compiled to generate the resource structure 1_2, that is, uniform_32bituniform1_2={33}, and then according to the address information of the resource structure and the unit storage strategy information of the data unit 1_2, the information structure 1_2 is generated, that is, Cluster cluster1_2={uniform_32bit,1}. Memory space is opened for information structure 1_1, information structure 1_2, resource structure 1_1 and resource structure 1_2, namely column resource pool 1. Column data 2 is also stored according to the table data storage method provided in an embodiment of the present invention to obtain column resource 2. Column resource pool 1 and column resource pool 2 constitute a table resource pool after the table is stored.
[0093] See also Figure 6 , Figure 6 A schematic diagram of dynamically adding table column data provided by an embodiment of the present invention, dividing the newly added column data 3 into data units, since the column data 3 contains 25 non-null value elements, which is less than the preset value, all non-null value elements of the column data 3 are divided into a data unit 3_1. The elements of the data unit 3_1 are analyzed numerically, and its data distribution characteristics are "the maximum difference and the minimum difference of the element values are distributed in [0,2 8) interval", according to the policy labels in the 9 preset storage policies, determine that the preset storage policy VI is the unit storage policy of the data unit 3_1, and compile the elements contained in the data unit 3_1 according to the structure type defined by the preset storage policy VI to obtain the resource structure 3_1, that is, diff_8bit diff8bit_3_1={12;{0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11}}, and then generate the information structure 3_1 according to the address information of the resource structure and the unit storage policy information of the data unit 3_1, that is, Cluster cluster3_1={diff_8bit,0}. Memory space is opened for the information structure 3_1 and the resource structure 3_1, and the memory space occupied by them is the column resource pool 3. The column resource pool 1, the column resource pool 2 and the column resource pool 3 constitute the table resource pool after the table is stored.
[0094] The embodiment of the present invention also provides a specific implementation method for reading table data from a table resource pool, and the steps are as follows:
[0095] First, the index of the corresponding data unit is calculated according to the row index and column index of the element to be read in the table;
[0096] Then, according to the index of the data unit, the pointer of the corresponding information structure is determined, and according to the pointer of the information structure, the unit storage strategy information and the address information of the resource structure are read from the information structure;
[0097] Finally, according to the address information of the resource structure, the value information of the element is read from the resource structure, and the value of the element to be read is determined according to the storage strategy information and the element value information.
[0098] In order to execute the corresponding steps in the above embodiment and various possible implementations, an implementation method of the table data storage device 100 is given below. Figure 7 , Figure 7 It should be noted that the basic principle and technical effects of the table data storage device 100 provided in the embodiment of the present invention are the same as those in the above embodiment, and are not mentioned in the embodiment of the present invention for the sake of brief description.
[0099] The table data storage device 100 includes an acquisition module 101 , a determination module 102 and a storage module 103 .
[0100] The acquisition module 101 is used to acquire a table to be stored, where the table to be stored includes a plurality of columns of data.
[0101] The determination module 102 is configured to determine a column storage strategy for each column of data from a plurality of preset storage strategies according to a data distribution feature of each column of data.
[0102] As a specific implementation method, when the determination module 102 is used to determine the column storage strategy for each column of data from multiple preset storage strategies based on the data distribution characteristics of each column of data, it is also specifically used to: for any target column of data in the multiple columns of data, divide the target column data to obtain at least one data unit; determine the unit storage strategy for each data unit of the target column data from multiple preset storage strategies based on the data distribution characteristics of each data unit of the target column data; and determine all the unit storage strategies for each column of data as the column storage strategy for each column of data.
[0103] The storage module 103 is used to store each column of data according to the column storage strategy of each column of data.
[0104] As a specific implementation method, each column of data is pre-divided into at least one data unit, and each data unit corresponds to a unit storage strategy. When the storage module 103 is used to store each column of data according to the storage strategy of each column of data, it is also specifically used to: for any target data unit of any target column of data, generate the structure data of the target data unit according to the unit storage strategy of the target data unit; and store the structure data of all data units of each column of data.
[0105] For further information, please refer to Figure 8 , Figure 8 The present invention provides a schematic structural block diagram of an electronic device 200 according to an embodiment of the present invention. The electronic device 200 may include a memory 210 and a processor 220 .
[0106] The processor 220 may be a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the program execution of the table data storage method provided in the following method embodiment.
[0107] The memory 210 may be a ROM or other type of static storage device that can store static information and instructions, a RAM or other type of dynamic storage device that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory 210 may exist independently and be connected to the processor 220 via a communication bus. The memory 210 may also be integrated with the processor 220. Among them, the memory 210 is used to store machine executable instructions for executing the scheme of the present application. The processor 220 is used to execute the machine executable instructions stored in the memory 210 to implement the aforementioned method embodiment.
[0108] Since the electronic device 200 provided in the embodiment of the present invention is another implementation form of the table data storage method provided in the aforementioned method embodiment, the technical effects that can be obtained can refer to the aforementioned method embodiment and will not be described in detail here.
[0109] An embodiment of the present invention further provides a readable storage medium containing computer executable instructions, which, when executed, can be used to perform relevant operations in the table data storage method provided in the aforementioned method embodiment.
[0110] In summary, the embodiments of the present invention provide a table data storage method, device, electronic device and storage medium. The method obtains a table to be stored containing multiple columns of data, and determines the column storage strategy for each column of data from multiple preset storage strategies based on the data distribution characteristics of each column of data, and then stores each column of data according to the column storage strategy for each column of data. Since the embodiments of the present invention determine the corresponding column storage strategy based on the data distribution characteristics of each column of data, and implement the storage of each column of data according to the column storage strategy for each column of data, it avoids the waste of memory space caused by the different lengths of each column of data when storing the table by row, and the inability to add column data in a non-downtime state due to a fixed storage strategy.
[0111] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A table data storage method, characterized in that: The method comprises: Acquire a table to be stored, wherein the table to be stored includes a plurality of columns of data; Determining a column storage strategy for each column of data from a plurality of preset storage strategies according to a data distribution feature of each column of data; storing each of the column data according to a column storage strategy for each of the column data; Each of the column data is pre-divided into at least one data unit, each of the data units corresponds to a unit storage strategy, and the step of storing each of the column data according to the column storage strategy of each of the column data includes: for any target data unit of any target column data, generating structure data of the target data unit according to the unit storage strategy of the target data unit; storing the structure data of all the data units of each of the column data, specifically: According to the structure type defined by the unit storage strategy, the target data unit is compiled to generate a resource structure, which contains the value information of the elements of the target data unit; then, according to the address information of the resource structure and the unit storage strategy information of the target data unit, an information structure is generated, which contains the unit storage strategy information of the target data unit and the address of the resource structure; memory space is allocated for the information structure and resource structure corresponding to each data unit.
2. The method according to claim 1, characterized in that The step of determining a column storage strategy for each column of data from a plurality of preset storage strategies according to the data distribution characteristics of each column of data comprises: For any target column data among the plurality of column data, dividing the target column data to obtain at least one data unit; Determining a unit storage strategy for each of the data units of the target column data from a plurality of preset storage strategies according to a data distribution feature of each of the data units of the target column data; All unit storage strategies of each column of data are determined as the column storage strategy of each column of data.
3. The method according to claim 2, characterized in that The target column data includes at least one non-null value element, and the step of dividing any target column data among the plurality of column data to obtain at least one data unit includes: Determine whether the number of non-null value elements in the target column data is greater than a preset value; If the number of non-null value elements of the target column data is not greater than the preset value, all non-null value elements of the target column data are taken as a data unit; If the number of non-null value elements of the target column data is greater than the preset value, the column data is divided into multiple data units according to the preset value.
4. The method according to claim 2, characterized in that: Each of the preset storage strategies includes a strategy tag, and the step of determining the unit storage strategy of each of the data units of the target column data from a plurality of preset storage strategies according to the data distribution characteristics of each of the data units of the target column data includes: For any target data unit in the target column data, determine a plurality of candidate storage strategies according to data distribution characteristics of the target data unit and a strategy label of each of the preset storage strategies; Calculating the memory occupied by storing the target data unit according to each of the candidate storage strategies; The candidate storage strategy with the smallest memory is determined as the unit storage strategy of the target data unit.
5. A table data storage device, characterized in that: include: An acquisition module, used for acquiring a table to be stored, wherein the table to be stored includes a plurality of columns of data; A determination module, configured to determine a column storage strategy for each column of data from a plurality of preset storage strategies according to a data distribution feature of each column of data; A storage module, used for storing each column of data according to a column storage strategy of each column of data; Each of the column data is pre-divided into at least one data unit, and each of the data unit corresponds to a unit storage strategy. The storage module is specifically used to: for any target data unit of any target column data, generate the structure data of the target data unit according to the unit storage strategy of the target data unit; store the structure data of all data units of each of the column data, specifically: compile the target data unit according to the structure type defined by the unit storage strategy to generate a resource structure, the resource structure contains the value information of the elements of the target data unit; then generate an information structure according to the address information of the resource structure and the unit storage strategy information of the target data unit, the information structure contains the unit storage strategy information of the target data unit and the address of the resource structure; allocate memory space for the information structure and resource structure corresponding to each data unit.
6. The device according to claim 5, characterized in that When the determining module is used to determine the column storage strategy for each column of data from a plurality of preset storage strategies according to the data distribution characteristics of each column of data, it is specifically used to: For any target column data among the plurality of column data, dividing the target column data to obtain at least one data unit; Determining a unit storage strategy for each of the data units of the target column data from a plurality of preset storage strategies according to a data distribution feature of each of the data units of the target column data; All unit storage strategies of each column of data are determined as the column storage strategy of each column of data.
7. An electronic device, characterized in that: include: A memory and a processor, wherein the memory is used to store a computer program, and the processor is used to execute the method according to any one of claims 1 to 4 when calling the computer program.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Column-storage oriented area-level data compression method
CN102609491A