A method and device for storing relational data, electronic equipment, and storage medium
By mapping the primary key and row data of the relational data table to the hash table in the Redis database, the problem of complex data storage and inability to utilize Redis high performance in the prior art is solved, and efficient data storage and query are achieved.
Patent Information
- Application Number
- CN202210442099.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-25
- Publication Date
- 2025-03-28
- Estimated Expiration
- 2042-04-25
AI Technical Summary
The prior art requires storing data from Redis database to relational database, which increases the complexity and cost of data storage, and at the same time, it is impossible to take advantage of the high performance advantages of Redis database for data query.
By mapping the table name, primary key and primary key column values of the target relational data table to the primary key hash table in the Redis database, and mapping the row data and primary key hash table values to the row data hash table, the relationship data can be directly stored and queried in the Redis database.
It realizes the storage and query of relational data directly through the Redis database, avoids the process of transferring data to the relational database, makes full use of the high performance advantages of Redis database, and reduces the complexity and cost of data storage and query.
Smart Images

Figure CN114817259B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data storage, and in particular to a method and device for storing relational data, an electronic device, and a storage medium. Background Art
[0002] With the rapid development of Internet technology, the amount of data generated by Web applications is growing exponentially, unstructured data is flooding the entire network platform, and big data processing has attracted more and more attention. As a key-value memory database, Redis database is known for its high performance and is usually used as a cache for large systems, which can relieve the pressure on the underlying database and improve processing efficiency.
[0003] However, the Redis database uses a key-value pair to store data, that is, it can only store key-value pairs, so it cannot store relational data completely, which means that it can only be used to determine whether data exists, but cannot query data based on data relationships. Therefore, the current method of combining relational databases and Redis databases is to store data. After the data is stored in the Redis database, it will be continuously transferred to the relational database for persistent storage. When you need to query data, you can search from the relational database, and the Redis database is only used for temporary caching.
[0004] However, this method also needs to be stored in the Redis database first. Storing data from the Redis database to the relational database not only increases the complexity of data storage, but also increases the cost. If data query does not go through the Redis database, the high performance advantage of the Redis database cannot be utilized. Summary of the invention
[0005] Based on the above-mentioned deficiencies of the prior art, the present application provides a method and device for storing relational data, an electronic device, and a storage medium to solve the problem that the prior art requires a relational database, which is too cumbersome and cannot take advantage of the high performance of the Redis database.
[0006] In order to achieve the above objectives, this application provides the following technical solutions:
[0007] The first aspect of the present application provides a method for storing relational data, comprising:
[0008] Get the target relational data table;
[0009] Map the table name, primary key and value of the primary key column of the target relational data table to the primary key hash table in the Redis database; wherein the value of the key column of the primary key hash table is the table name of the target relational data table, the value of the field column is the value of the primary key column, and the value of the value column is the primary key information of the target relational data table; the primary key information is composed of the table name of the target relational data table, the primary key and a value of the primary key column;
[0010] Map the row data in the target relational data table and the value of the value column in the primary key hash table to the row data hash table in the Redis database; wherein the row data of the target relational data table is each data column and the value of each data column except the primary key and the value of the primary key; the value of the key column of the row data hash table is the value of the value column in the primary key hash table, the value of the field column is each data column of the row data in the target relational data table, and the value of the value column is each data column of the row data in the target relational data table.
[0011] Optionally, in the above-mentioned method for storing relational data, after mapping the row data in the target relational data table and the value of the value column in the primary key hash table to the row data hash table in the Redis database, it further includes:
[0012] Map the table name, foreign key and value of the foreign key column of the associated data table of the target relational data table to the foreign key hash table in the Redis database; wherein the value of the key column of the foreign key hash table is the first foreign key information, the value of the field column is the value of the foreign key column of the associated data table, and the value of the value column is the second foreign key information; the first foreign key information is composed of the table name of the associated data table and the foreign key; the second foreign key information is composed of the table name of the associated data table, the foreign key and a value of the foreign key column;
[0013] Map the values of the field column and the value column of the foreign key hash table to the data key-value table in the Redis database; wherein the value of the key column of the data key-value table is the value of the value column of the foreign key hash table; the value of the value column of the data key-value table is an associated data array; wherein one associated data array includes each associated data of the data column corresponding to the same value of the foreign key column.
[0014] Optionally, in the above-mentioned method for storing relational data, after mapping the row data in the target relational data table and the value of the value column in the primary key hash table to the row data hash table in the Redis database, it further includes:
[0015] Receive a first query request sent by a user; wherein the first query request includes the table name of the target relational data table and the primary key information to be queried;
[0016] Find out a target table name that is consistent with the table name of the target relational data table from the value of the key column of the primary key hash table;
[0017] Find the target primary key information containing the primary key information to be queried from the values of each value column of each row where the target table name is located;
[0018] Find the target primary key information from the value of the key column of the row data hash table;
[0019] The values of each field column and each value column of each row where the target primary key information in the row data flight information table is located are fed back to the user.
[0020] Optionally, in the above-mentioned method for storing relational data, after mapping the value of the field column and the value of the value column of the foreign key hash table to the data key value table in the Redis database, it further includes:
[0021] Receive a second query request sent by a user; wherein the second query request includes the table name of the associated data table and the foreign key information to be queried;
[0022] Find the target first foreign key information including the table name of the associated data table from the value of the key column of the foreign key hash table;
[0023] Find the target second foreign key information containing the foreign key information to be queried from the values of each value column of each row where the target first foreign key information is located;
[0024] Find the target second foreign key information from the value of the key column of the data key value table;
[0025] The associated data array of the value column of the row where the target second foreign key information in the data key-value table is located is fed back to the user.
[0026] A second aspect of the present application provides a storage device for relational data, including:
[0027] An acquisition unit, used for acquiring a target relational data table;
[0028] A first mapping unit is used to map the table name, primary key and value of the primary key column of the target relational data table to a primary key hash table in a Redis database; wherein the value of the key column of the primary key hash table is the table name of the target relational data table, the value of the field column is the value of the primary key column, and the value of the value column is the primary key information of the target relational data table; the primary key information is composed of the table name of the target relational data table, the primary key and a value of the primary key column;
[0029] The second mapping unit is used to map the row data in the target relational data table and the value of the value column in the primary key hash table to the row data hash table in the Redis database; wherein the row data of the target relational data table are the various data columns and the values of the various data columns except the primary key and the value of the primary key; the value of the key column of the row data hash table is the value of the value column in the primary key hash table, the value of the field column is the various data columns of the row data in the target relational data table, and the value of the value column is the value of the various data columns of the row data in the target relational data table.
[0030] Optionally, the above-mentioned storage device for relational data further includes:
[0031] A third mapping unit is used to map the table name, foreign key and foreign key column value of the associated data table of the target relational data table to the foreign key hash table in the Redis database; wherein the value of the key column of the foreign key hash table is the first foreign key information, the value of the field column is the value of the foreign key column of the associated data table, and the value of the value column is the second foreign key information; the first foreign key information is composed of the table name of the associated data table and the foreign key; the second foreign key information is composed of the table name of the associated data table, the foreign key and a value of the foreign key column;
[0032] The fourth mapping unit is used to map the value of the field column and the value of the value column of the foreign key hash table to the data key-value table in the Redis database; wherein the value of the key column of the data key-value table is the value of the value column of the foreign key hash table; the value of the value column of the data key-value table is an associated data array; wherein one associated data array includes each associated data of the data column corresponding to the same value of the foreign key column.
[0033] Optionally, the above-mentioned storage device for relational data further includes:
[0034] A first receiving unit, configured to receive a first query request sent by a user; wherein the first query request includes the table name of the target relational data table and primary key information to be queried;
[0035] A first query unit, configured to search for a target table name that is consistent with the table name of the target relational data table from the value of the key column of the primary key hash table;
[0036] A second query unit is used to find out the target primary key information containing the primary key information to be queried from the values of each value column of each row where the target table name is located;
[0037] A third query unit, configured to search for the target primary key information from the value of the key column of the row data hash table;
[0038] The first feedback unit is used to feed back to the user the value of each field column and the value of each value column of each row where the target primary key information in the row data flight information table is located.
[0039] Optionally, the above-mentioned storage device for relational data further includes:
[0040] A second receiving unit, configured to receive a second query request sent by a user; wherein the second query request includes the table name of the associated data table and the foreign key information to be queried;
[0041] A fourth query unit, configured to search for target first foreign key information including the table name of the associated data table from the value of the key column of the foreign key hash table;
[0042] a fifth query unit, configured to search for target second foreign key information containing the foreign key information to be queried from the values of each value column of each row where the target first foreign key information is located;
[0043] A sixth query unit, used for searching the target second foreign key information from the value of the key column of the data key value table;
[0044] The second feedback unit is used to feed back the associated data array of the value column of the row where the target second foreign key information in the data key-value table is located to the user.
[0045] A third aspect of the present application provides an electronic device, including:
[0046] Memory and processor;
[0047] Wherein, the memory is used to store programs;
[0048] The processor is used to execute the program, and when the program is executed, it is specifically used to implement the storage method of relational data as described in any one of the above.
[0049] A fourth aspect of the present application provides a computer storage medium, characterized in that it is used to store a computer program, and when the computer program is executed, it is used to implement the relational data storage method as described in any one of the above.
[0050] The present application provides a method for storing relational data, which obtains a target relational data table. Then the table name, primary key and value of the primary key column of the target relational data table are mapped to the primary key hash table in the Redis database. Among them, the value of the key column of the primary key hash table is the table name of the target relational data table, the value of the field column is the value of the primary key column, and the value of the value column is the primary key information of the target relational data table. A primary key information is composed of the table name, primary key and a value of the primary key column of the target relational data table, thereby realizing the mapping of the primary key data to a key-value pair and storing it in the Redis database. Then the row data in the target relational data table and the value of the value column in the primary key hash table are mapped to the row data hash table in the Redis database. Among them, the row data of the target relational data table are the various data columns and the values of each data column except the primary key and the value of the primary key, the value of the key column of the row data hash table is the value of the value column in the primary key hash table, the value of the field column is the various data columns of the row data in the target relational data table, and the value of the value column is the value of the various data columns of the row data in the target relational data table, so that the primary key and its corresponding data are mapped to the Redis database, and finally the data of the entire relational data table is mapped to the Redis database, and then it can be directly queried through the Redis database without sending it to the relational database for storage and then queried through the relational database, which fully utilizes the high performance advantage of the Redis database. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] In order to more clearly illustrate the embodiments of the present application 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 application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0052] Figure 1 A flowchart of a method for storing relational data provided in an embodiment of the present application;
[0053] Figure 2 A schematic diagram of an example of mapping a primary key hash table and a row data hash table provided in an embodiment of the present application;
[0054] Figure 3 A flowchart of a data query method provided in an embodiment of the present application;
[0055] Figure 4 A flowchart of a method for storing data in an associated data table provided in an embodiment of the present application;
[0056] Figure 5 A schematic diagram of an example of mapping a foreign key hash table and a data key value table provided in an embodiment of the present application;
[0057] Figure 6 A flowchart of another data query method provided in an embodiment of the present application;
[0058] Figure 7 A schematic diagram of the structure of a storage device for relational data provided in an embodiment of the present application;
[0059] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0060] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0061] In this application, relational terms such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.
[0062] The present application embodiment provides a method for storing relational data, such as Figure 1 As shown, the following steps are included:
[0063] S101. Obtain a target relational data table.
[0064] The target relational data table refers to a relational data table whose data currently needs to be stored in the Redis database.
[0065] S102: Map the table name, primary key, and primary key column value of the target relational data table to the primary key hash table in the Redis database.
[0066] The primary key refers to an attribute or attribute group that uniquely identifies a row in a table. For example, Figure 2 In the relational data table named "class", a student number identifies the attributes of a student, namely name and sex. When the primary key is mentioned in this application, it mainly refers to the name of the primary key.
[0067] The value of the primary key column refers to the values in the column where the primary key is located, for example, Figure 2 "0" and "1" in the No (student number) column in the relational data table named "class".
[0068] It should be noted that the primary key hash table refers to a hash table that stores the mapping relationship of the primary key. The data structure of the hash table is mainly composed of three fields, namely "key", "field" and "Value". This is common knowledge in the field, so it will not be repeated here. In the embodiment of the present application, the key column, field column, and value column refer to the columns where these three fields are located. For example, see Figure 2 The primary key hash table in .
[0069] In an embodiment of the present application, the value of the key column of the mapped primary key hash table is the table name of the target relational data table. The value of the field column of the primary key hash table is the value of the primary key column. The value of the value column of the primary key hash table is the primary key information of the target relational data table. Among them, a primary key information is composed of the table name of the target relational data table, the primary key, and a value of the primary key column. Therefore, there are as many primary key information as there are values in the primary key column of the target relational data. Optionally, the primary key information can adopt a combination of "table name: primary key column: value of primary key column", for example, Figure 2 The values under the value field in the primary key hash table in the table are: "class:No:0" and "class:No:1".
[0070] It should also be noted that in addition to the column requirements, the rows of the primary key hash table also have requirements during the mapping process. The data in the same row should correspond to the data of the same record in the target relational data table. The data in each row of the table name of the key column of the primary key hash table should be the data of the relational data table corresponding to the table name. The values of the field column and the value column in the same row should be consistent. For example, Figure 2 As shown, the data in the two rows of the key column class of the primary key hash table are all data of the relational data table class. In addition, for the 0 in the field column, the primary key information of the same value column: "class: No: 0" also contains the value of the primary key column as 0.
[0071] S103: Map the row data in the target relational data table and the value of the value column in the primary key hash table to the row data hash table in the Redis database.
[0072] The primary key hash table stores the primary key and the value of the primary key column. Other fields in the target relationship data table and the values of these fields also need to be stored in the Redis database, and a corresponding relationship with the primary key hash table is required to implement other data queries in the target relationship data table. Therefore, in this embodiment of the application, it is necessary to further map the row data in the target relationship data table and the value of the value column in the primary key hash table to another hash table, that is, to the row data hash table. Among them, the row data of the target relationship data table refers to each data column and the value of each data column except the primary key and the value of the primary key. For example, Figure 2 The name field and sex field in the relational data table class are shown, as well as the values of the columns where these two fields are located.
[0073] In the embodiment of the present application, the value of the key column of the row data hash table obtained after mapping is the value of the value column in the primary key hash table, the value of the field column is the value of each data column of the row data in the target relational data table, and the value of the value column is the value of each data column of the row data in the target relational data table. Similarly, there are also requirements for the data in the rows of the row data hash table. The data corresponding to the same row needs to be the information in the same record in the target relational data table. For example, Figure 2 The row data hash table shown in the figure. Its key column is two primary key information in the primary key hash table: "class: No: 0" and "class: No: 1". For the two primary key information, in the row data list, the corresponding two rows of data are two records in the target data table, namely, the record information of student "wang" and the record information of student "wu".
[0074] Optionally, for the mapping of the primary key hash table and the mapping of the row data hash table, two hash tables can be generated for each relational data table for mapping, that is, one relational data table corresponds to one primary key hash table and one row data hash table. Of course, data from multiple relational data tables can also be mapped to the same primary key hash table and row data hash table.
[0075] Optionally, after storing the relational data in the Redis database in two hash tables, that is, after executing step S103, the data in the target relational data table can be directly queried from the two hash tables through the Redis database, and there is no need to combine the relational database. Therefore, accordingly, in an embodiment of the present application, a data query method is provided, such as Figure 3 As shown, including:
[0076] S301: Receive a first query request sent by a user.
[0077] The first query request includes the table name of the target relational data table and the primary key information to be queried.
[0078] Specifically, when a certain piece of information needs to be queried, a first query request can be initiated through the corresponding table name and the primary key information to be queried. For example, if the class name is consistent with the table name, the class and student number can be input, and then the first query request can be initiated to query the information of the student with the student number in the class.
[0079] S302: Find a target table name that is consistent with the table name of the target relational data table from the value of the key column of the primary key hash table.
[0080] It should be noted that if the target relational data table corresponds to a primary key hash table alone, step S302 may not be performed. If the primary key hash table stores data of multiple relational data tables, step S302 is required to determine the data in the target relational data table.
[0081] S303: Find the target primary key information containing the primary key information to be queried from the values of each value column of each row where the target table name is located.
[0082] S304: Find the target primary key information from the value of the key column of the row data hash table.
[0083] S305: Feedback the value of each field column and the value of each value column of each row where the target primary key information in the row data flight information table is located to the user.
[0084] It should be noted that some relational database tables are associated with other relational data tables, that is, some relational data tables may include foreign keys, so the embodiment of the present application may further include a method for storing data in the associated data tables, such as Figure 4 As shown, including:
[0085] S401: Map the table name, foreign key, and foreign key column value of the associated data table of the target relational data table to the foreign key hash table in the Redis database.
[0086] If the primary key in table A also exists in table B, then the field is the foreign key of table B and is often used to form integrity constraints. Figure 2 The primary key "No" of the relational data table class shown in the figure also exists in Figure 5 In the associated data table course shown in the figure, "No" in the associated data table course is the foreign key.
[0087] Therefore, the associated data table of the target relational data table refers to the relational data table that contains the primary key of the target relational data table, that is, the associated data table is also a relational data table.
[0088] Since the associated data table of the target relational data table also has a large amount of associated information, when the target relational data table has an associated data table, the data in the associated data table can also be mapped to the Redis database, so that the data in the associated data table can be queried through the Redis database.
[0089] Since foreign keys are usually used for join operations, in the present application, foreign keys in associated data tables are mapped through a hash table, and the hash table is called a foreign key hash table in the embodiment of the present application.
[0090] Specifically, the value of the key column of the mapped foreign key hash table is the first foreign key information, the value of the field column is the value of the foreign key column of the associated data table, and the value of the value column is the second foreign key information.
[0091] The first foreign key information is composed of the table name of the associated data table and the foreign key, which can be specifically combined in the form of "table name: foreign key". For example, Figure 5 As shown in the figure, the name of the associated data table is "course", and the foreign key is "No", so the value of the key column of the foreign key hash table is: "course: No". A second foreign key information consists of the name of the associated data table, the foreign key, and a value of the foreign key column. Similar to the primary key information, the data of the second foreign key information is equal to the number of values contained in the foreign key column. Similarly, the combination can be in the form of "table name: foreign key: foreign key column value". For example, Figure 5 The value column of the foreign key hash table shown has two groups: "course:No:0" and "course:No:1".
[0092] Similarly, there are also requirements for the data in the rows of the foreign key hash table. The data records corresponding to the same row should be unified. It should also be noted that since the foreign keys in the associated data usually have a one-to-many relationship, for example, Figure 5 The foreign key "1" of the association data table course shown in the figure corresponds to three different courseKeys (course identifiers). After mapping, each entity will be combined, so in the mapping process, the value of the same foreign key can be combined into one, so that one foreign key only corresponds to one first foreign key information, and then corresponds to the combined entity combination. For example, Figure 5 As shown, for the three foreign keys "1" of the associated data table course, after being mapped to the foreign key hash table, there is only one "1" in the field column, and correspondingly there is only one first foreign key information "course: No: 1" in the value column in the same row.
[0093] S402: Map the values of the field column and the value column of the foreign key hash table to the data key value table in the Redis database.
[0094] Since the foreign key hash table mainly maps the foreign key information, it is necessary to further map the information corresponding to the foreign key in the associated data table to the Redis database.
[0095] Because foreign keys usually have a one-to-many entity relationship, and the data table of the set data structure is a key-value pair structure, that is, it meets the storage format of the Redis database, and its value can store numerical values, that is, it just meets the one-to-many relationship. Therefore, in the embodiment of the present application, the data table of the set data structure is used to implement foreign key mapping, that is, the data key-value table in the embodiment of the present application refers to the data table of the set data structure. It consists of two fields, key and value, and an array can be stored under the value field.
[0096] Specifically, the value of the key column of the mapped data key-value table is the value of the value column of the foreign key hash table. The value of the value column of the data key-value table is the associated data array.
[0097] Among them, an associated data array includes all the associated data of the data column corresponding to the same value of the foreign key column. And, the array of the value in the same row as the value in the key column consists of all the associated data corresponding to the foreign key contained in the value in the key column. For example, Figure 5As shown in the figure, a value of the key column of the data key-value table is "course: No: 1", that is, the foreign key it contains is "1", and all the associated data corresponding to the data column courseKey corresponding to foreign key 1 in the associated data table are: 1, 2, 3. Therefore, the array of the value column in the same row as "course: No: 1" in the data key-value table is: {1, 2, 3}.
[0098] Similarly, after executing step S402, data query can also be performed through the foreign key hash table and data key value table in the Redis database. Therefore, correspondingly, another data query method provided by another embodiment of the present application is as follows: Figure 6 As shown, including:
[0099] S601: Receive a second query request sent by a user.
[0100] The second query request includes the table name of the associated data table and the foreign key information to be queried.
[0101] S602: Find the target first foreign key information including the table name of the associated data table from the value of the key column of the foreign key hash table.
[0102] S603: Find the target second foreign key information containing the foreign key information to be queried from the values of each value column of each row where the target first foreign key information is located.
[0103] S604: Find the target second foreign key information from the value of the key column of the data key value table.
[0104] S605: Feedback the associated data array of the value column of the row where the target second foreign key information is located in the data key-value table to the user.
[0105] It should be noted that the specific implementation of steps S601 to S605 is similar to that of steps S301 to S305, except that the objects are different. Therefore, the specific implementation of steps S601 to S605 can refer to the implementation of steps S301 to S305 accordingly and will not be repeated here.
[0106] An embodiment of the present application provides a storage method for relational data, which obtains a target relational data table. Then, the table name, primary key, and value of the primary key column of the target relational data table are mapped to the primary key hash table in the Redis database. Among them, the value of the key column of the primary key hash table is the table name of the target relational data table, the value of the field column is the value of the primary key column, and the value of the value column is the primary key information of the target relational data table. A primary key information is composed of the table name, primary key, and a value of the primary key column of the target relational data table, thereby realizing the mapping of the primary key data to a key-value pair and storing it in the Redis database. Then, the row data in the target relational data table and the value of the value column in the primary key hash table are mapped to the row data hash table in the Redis database. Among them, the row data of the target relational data table are the various data columns and the values of each data column except the primary key and the value of the primary key, the value of the key column of the row data hash table is the value of the value column in the primary key hash table, the value of the field column is the various data columns of the row data in the target relational data table, and the value of the value column is the value of the various data columns of the row data in the target relational data table, so that the primary key and its corresponding data are mapped to the Redis database, and finally the data of the entire relational data table is mapped to the Redis database, and then it can be directly queried through the Redis database without sending it to the relational database for storage and then queried through the relational database, which fully utilizes the high performance advantage of the Redis database.
[0107] Another embodiment of the present application provides a storage device for relational data, such as Figure 7 As shown, including:
[0108] The acquisition unit 701 is used to acquire a target relational data table.
[0109] The first mapping unit 702 is used to map the table name, primary key and primary key column value of the target relational data table to the primary key hash table in the Redis database.
[0110] The value of the key column of the primary key hash table is the table name of the target relational data table, the value of the field column is the value of the primary key column, and the value of the value column is the primary key information of the target relational data table. A primary key information consists of the table name of the target relational data table, the primary key, and a value of the primary key column.
[0111] The second mapping unit 703 is used to map the row data in the target relational data table and the value of the value column in the primary key hash table to the row data hash table in the Redis database. The row data in the target relational data table is each data column and the value of each data column except the primary key and the value of the primary key. The value of the key column in the row data hash table is the value of the value column in the primary key hash table, the value of the field column is each data column of the row data in the target relational data table, and the value of the value column is each data column of the row data in the target relational data table.
[0112] Optionally, in the storage device for relational data provided in another embodiment of the present application, the device further includes:
[0113] The third mapping unit is used to map the table name, foreign key and foreign key column value of the associated data table of the target relational data table to the foreign key hash table in the Redis database.
[0114] The value of the key column of the foreign key hash table is the first foreign key information, the value of the field column is the value of the foreign key column of the associated data table, and the value of the value column is the second foreign key information. The first foreign key information consists of the table name of the associated data table and the foreign key. A second foreign key information consists of the table name of the associated data table, the foreign key, and a value of the foreign key column.
[0115] The fourth mapping unit is used to map the value of the field column and the value of the value column of the foreign key hash table to the data key value table in the Redis database. The value of the key column of the data key value table is the value of the value column of the foreign key hash table. The value of the value column of the data key value table is the associated data array.
[0116] Wherein, an associated data array includes each associated data of the data column corresponding to the same value of the foreign key column.
[0117] Optionally, in the storage device for relational data provided in another embodiment of the present application, the device further includes:
[0118] The first receiving unit is used to receive a first query request sent by a user.
[0119] The first query request includes the table name of the target relational data table and the primary key information to be queried.
[0120] The first query unit is used to find a target table name that is consistent with the table name of the target relational data table from the value of the key column of the primary key hash table.
[0121] The second query unit is used to find the target primary key information containing the primary key information to be queried from the values of each value column of each row where the target table name is located.
[0122] The third query unit is used to find out the target primary key information from the value of the key column of the row data hash table.
[0123] The first feedback unit is used to feed back to the user the value of each field column and the value of each value column of each row where the target primary key information in the row data flight information table is located.
[0124] Optionally, in the storage device for relational data provided in another embodiment of the present application, the device further includes:
[0125] The second receiving unit is used to receive a second query request sent by a user, wherein the second query request includes the table name of the associated data table and the foreign key information to be queried.
[0126] The fourth query unit is used to find the target first foreign key information including the table name of the associated data table from the value of the key column of the foreign key hash table.
[0127] The fifth query unit is used to find the target second foreign key information containing the foreign key information to be queried from the values of each value column of each row where the target first foreign key information is located.
[0128] The sixth query unit is used to find out the target second foreign key information from the value of the key column of the data key value table.
[0129] The second feedback unit is used to feed back to the user the associated data array of the value column of the row where the target second foreign key information in the data key-value table is located.
[0130] It should be noted that the specific working process of each unit provided in the above embodiments of the present application can refer to the corresponding steps in the above method embodiments, which will not be repeated here.
[0131] Another embodiment of the present application provides an electronic device, such as Figure 8 As shown, including:
[0132] Memory 801 and processor 802 .
[0133] The memory 801 is used to store programs.
[0134] The processor 802 is used to execute the program stored in the memory 801. When the program is executed, it is specifically used to implement the storage method of relational data provided by any one of the above embodiments.
[0135] Another embodiment of the present application provides a computer storage medium for storing a computer program. When the computer program is executed, it is used to implement the method for storing relational data provided in any of the above embodiments.
[0136] Computer storage media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0137] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0138] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for storing relational data, characterized in that: include: Get the target relational data table; Map the table name, primary key and value of the primary key column of the target relational data table to the primary key hash table in the Redis database; wherein the value of the key column of the primary key hash table is the table name of the target relational data table, the value of the field column is the value of the primary key column, and the value of the value column is the primary key information of the target relational data table; the primary key information is composed of the table name of the target relational data table, the primary key and a value of the primary key column; Map the row data in the target relational data table and the value of the value column in the primary key hash table to the row data hash table in the Redis database; wherein the row data in the target relational data table is each data column and the value of each data column except the primary key and the value of the primary key; the value of the key column in the row data hash table is the value of the value column in the primary key hash table, the value of the field column is each data column of the row data in the target relational data table, and the value of the value column is each data column of the row data in the target relational data table; Receive a first query request sent by a user; wherein the first query request includes the table name of the target relational data table and the primary key information to be queried; Find out a target table name that is consistent with the table name of the target relational data table from the value of the key column of the primary key hash table; Find the target primary key information containing the primary key information to be queried from the values of each value column of each row where the target table name is located; Find the target primary key information from the value of the key column of the row data hash table; The values of each field column and each value column of each row where the target primary key information in the row data hash table is located are fed back to the user.
2. The method according to claim 1, characterized in that After mapping the row data in the target relational data table and the value of the value column in the primary key hash table to the row data hash table in the Redis database, the method further includes: Map the table name, foreign key and value of the foreign key column of the associated data table of the target relational data table to the foreign key hash table in the Redis database; wherein the value of the key column of the foreign key hash table is the first foreign key information, the value of the field column is the value of the foreign key column of the associated data table, and the value of the value column is the second foreign key information; the first foreign key information is composed of the table name of the associated data table and the foreign key; the second foreign key information is composed of the table name of the associated data table, the foreign key and a value of the foreign key column; Map the values of the field column and the value column of the foreign key hash table to the data key-value table in the Redis database; wherein the value of the key column of the data key-value table is the value of the value column of the foreign key hash table; the value of the value column of the data key-value table is an associated data array; wherein one associated data array includes each associated data of the data column corresponding to the same value of the foreign key column.
3. The method according to claim 2, characterized in that After mapping the value of the field column and the value of the value column of the foreign key hash table to the data key value table in the Redis database, the method further includes: Receive a second query request sent by a user; wherein the second query request includes the table name of the associated data table and the foreign key information to be queried; Find the target first foreign key information including the table name of the associated data table from the value of the key column of the foreign key hash table; Find the target second foreign key information containing the foreign key information to be queried from the values of each value column of each row where the target first foreign key information is located; Find the target second foreign key information from the value of the key column of the data key value table; The associated data array of the value column of the row where the target second foreign key information in the data key-value table is located is fed back to the user.
4. A storage device for relational data, characterized in that: include: An acquisition unit, used for acquiring a target relational data table; A first mapping unit is used to map the table name, primary key and value of the primary key column of the target relational data table to a primary key hash table in a Redis database; wherein the value of the key column of the primary key hash table is the table name of the target relational data table, the value of the field column is the value of the primary key column, and the value of the value column is the primary key information of the target relational data table; and the primary key information is composed of the table name of the target relational data table, the primary key and a value of the primary key column; A second mapping unit is used to map the row data in the target relational data table and the value of the value column in the primary key hash table to the row data hash table in the Redis database; wherein the row data in the target relational data table is each data column and the value of each data column except the primary key and the value of the primary key; the value of the key column in the row data hash table is the value of the value column in the primary key hash table, the value of the field column is each data column of the row data in the target relational data table, and the value of the value column is each data column of the row data in the target relational data table; A first receiving unit, configured to receive a first query request sent by a user; wherein the first query request includes the table name of the target relational data table and primary key information to be queried; A first query unit is used to find a target table name that is consistent with the table name of the target relational data table from the value of the key column of the primary key hash table; A second query unit is used to find out the target primary key information containing the primary key information to be queried from the values of each value column of each row where the target table name is located; A third query unit, configured to search for the target primary key information from the value of the key column of the row data hash table; The first feedback unit is used to feed back to the user the value of each field column and the value of each value column of each row where the target primary key information in the row data hash table is located.
5. The device according to claim 4, characterized in that Also includes: A third mapping unit is used to map the table name, foreign key and foreign key column value of the associated data table of the target relational data table to the foreign key hash table in the Redis database; wherein the value of the key column of the foreign key hash table is the first foreign key information, the value of the field column is the value of the foreign key column of the associated data table, and the value of the value column is the second foreign key information; the first foreign key information is composed of the table name of the associated data table and the foreign key; the second foreign key information is composed of the table name of the associated data table, the foreign key and a value of the foreign key column; The fourth mapping unit is used to map the value of the field column and the value of the value column of the foreign key hash table to the data key-value table in the Redis database; wherein the value of the key column of the data key-value table is the value of the value column of the foreign key hash table; the value of the value column of the data key-value table is an associated data array; wherein one associated data array includes each associated data of the data column corresponding to the same value of the foreign key column.
6. The device according to claim 5, characterized in that Also includes: A second receiving unit, configured to receive a second query request sent by a user; wherein the second query request includes the table name of the associated data table and the foreign key information to be queried; A fourth query unit, configured to search for target first foreign key information including the table name of the associated data table from the value of the key column of the foreign key hash table; a fifth query unit, configured to search for target second foreign key information containing the foreign key information to be queried from the values of each value column of each row where the target first foreign key information is located; A sixth query unit, used for searching the target second foreign key information from the value of the key column of the data key value table; The second feedback unit is used to feed back the associated data array of the value column of the row where the target second foreign key information in the data key-value table is located to the user.
7. An electronic device, characterized in that: include: Memory and processor; Wherein, the memory is used to store programs; The processor is used to execute the program, and when the program is executed, it is specifically used to implement the relational data storage method as described in any one of claims 1 to 3.
8. A computer storage medium, characterized in that: Used to store a computer program, which, when executed, is used to implement the method for storing relational data as described in any one of claims 1 to 3.
Citation Information
Patent Citations
Method and system for migrating relational data to HBbase
CN103631907A
A relational realization method, device and system of a real-time database
CN109542892A