Secondary index table construction method, device, equipment and storage medium

By constructing a secondary index table, the problem of HBase's low efficiency in querying on non-primary key conditions is solved. By combining non-primary key and primary key values, an index table is constructed to speed up queries and achieve efficient retrieval of HBase.

CN115328916BActive Publication Date: 2024-10-11CHINA TELECOM CORP LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202210983862.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-16
Publication Date
2024-10-11
Estimated Expiration
2042-08-16

AI Technical Summary

Technical Problem

When HBase performs non-primary key conditional queries, due to the lack of primary key support, the query efficiency is low and cannot meet the needs of efficient retrieval.

Method used

By constructing a secondary index table, determine the non-primary key and its corresponding value in the data table, obtain the primary key value set corresponding to the non-primary key value, perform combined processing, and use the processed data as the row key, and convert the primary key value The set is stored as a key value in the preset second data table, and an index is built to speed up non-primary key condition queries.

Benefits of technology

Through the construction of secondary index tables, the speed of non-primary key condition query is improved, which meets the efficient retrieval requirements of HBase.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115328916B_ABST
    Figure CN115328916B_ABST
Patent Text Reader

Abstract

The embodiments of the present application disclose a method, device, electronic device and storage medium for constructing a secondary index table. The method includes: determining a non-primary key and a corresponding non-primary key value in a first data table; obtaining a primary key value set corresponding to the non-primary key value from the first data table, the primary key value set including at least one primary key value; combining the non-primary key and the non-primary key value to obtain processed data; using the processed data as a row key and storing the primary key value set as a key value corresponding to the row key in a preset second data table; constructing an index for the processed data, and updating the second data table to obtain a second index table. The embodiments of the present application can improve the query speed of data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for constructing a secondary index table. Background Art

[0002] Hbase is a commonly used distributed database in the field of big data, supporting data storage of hundreds of billions or millions of rows. HBase has established a B+ tree index on its primary key, which is very efficient when using the primary key for querying. However, when performing non-primary key conditional queries, due to the lack of primary key support, HBase must perform a full table scan, resulting in low query efficiency and failure to meet the above requirements. How to improve the retrieval speed of HBase and enable it to support various query operations has become an urgent problem to be solved. Summary of the invention

[0003] To solve the above technical problems, the embodiments of the present application provide a method for constructing a secondary index table, a device for constructing a secondary index table, an electronic device and a computer-readable storage medium, which can improve the data query speed.

[0004] Other features and advantages of the present application will become apparent from the following detailed description, or may be learned in part by the practice of the present application.

[0005] According to one aspect of an embodiment of the present application, a method for constructing a secondary index table is provided, including: determining a non-primary key and a corresponding non-primary key value in a first data table; obtaining a primary key value set corresponding to the non-primary key value from the first data table, the primary key value set including at least one primary key value; combining the non-primary key and the non-primary key value to obtain processed data; using the processed data as a row key and storing the primary key value set as the key value corresponding to the row key in a preset second data table; constructing an index for the processed data, and updating the second data table to obtain a second index table.

[0006] According to one aspect of an embodiment of the present application, using processed data as row keys and storing primary key value sets as key values ​​corresponding to the row keys in a preset second data table includes: determining whether the number of primary key values ​​included in the primary key value set exceeds a preset threshold; if the determination is yes, dividing the primary key value set into a preset number of primary key value subsets, the number of primary key values ​​included in each primary key value subset not exceeding the preset threshold; using each primary key value subset as a key value and the processed data as the row key corresponding to each key value, and storing them in different rows in the second data table.

[0007] According to one aspect of an embodiment of the present application, dividing a primary key value set into a preset number of primary key value subsets includes: sorting the primary key values ​​included in the primary key value set in ascending order; dividing the sorted primary key value set into a preset number of primary key value subsets, wherein the arrangement order of the primary key values ​​included in each primary key value subset remains unchanged.

[0008] According to one aspect of an embodiment of the present application, non-primary keys and non-primary key values ​​are combined and processed to obtain processed data including: non-primary keys, non-primary key values, the largest primary key value in each primary key value subset and the smallest primary key value in the corresponding primary key value subset are combined and processed to obtain processed data.

[0009] According to one aspect of an embodiment of the present application, before using the processed data as the row key and storing the primary key value set as the key value corresponding to the row key in a preset second data table, the method also includes: matching the processed data with the row key column in the second data table to obtain a matching result; if the matching result indicates that no row key matches the processed data, continuing to execute the step of using the processed data as the row key and storing the primary key value set as the key value corresponding to the row key in the preset second data table.

[0010] According to one aspect of an embodiment of the present application, the method also includes: if the matching result indicates that there is a target row key that matches the processed data, then obtaining the target key value corresponding to the target row key; if it is detected that the target key value does not match the primary key value set, if the step of using the processed data as the row key and storing the primary key value set as the key value corresponding to the row key in a preset second data table continues.

[0011] According to one aspect of an embodiment of the present application, a data query method is provided, comprising: obtaining a data query request, wherein the data query request includes index information, and the index information includes a non-primary key and a non-primary key value; obtaining a primary key value set corresponding to the non-primary key value from a second index table based on the index information, wherein the second index table is a second index table constructed by the method shown above; querying a data table based on the primary key value set to obtain data to be queried

[0012] According to one aspect of an embodiment of the present application, a device for constructing a secondary index table is provided, including: a determination module, used to determine a non-primary key and a corresponding non-primary key value in a first data table; an acquisition module, used to obtain a primary key value set corresponding to the non-primary key value from the first data table, the primary key value set including at least one primary key value; a combination processing module, used to combine the non-primary key and the non-primary key value to obtain processed data; a storage module, used to use the processed data as a row key, and store the primary key value set as the key value corresponding to the row key in a preset second data table; a construction module, used to construct an index for the processed data, and update the second data table to obtain a second index table.

[0013] According to one aspect of an embodiment of the present application, an electronic device is provided, including a processor and a memory, wherein computer-readable instructions are stored in the memory, and when the computer-readable instructions are executed by the processor, the method for constructing a secondary index table as described above is implemented.

[0014] According to one aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor of a computer, the computer executes the method for constructing a secondary index table as provided above.

[0015] According to one aspect of the embodiments of the present application, a computer program product or a computer program is provided, the computer program product or the computer program includes a computer instruction, and the computer instruction is stored in a computer-readable storage medium. A processor of a computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the method for constructing a secondary index table provided in the above various optional embodiments.

[0016] The technical solution provided by the embodiment of the present application determines the non-primary key and the corresponding non-primary key value in the data table; obtains the primary key value set corresponding to the non-primary key value from the data table, and the primary key value set includes at least one primary key value; combines the non-primary key and the non-primary key value to obtain the processed data; uses the primary key value set as the key value of the processed data, and constructs an index for the processed data to obtain a second index table. Since the index is constructed for the processed data, the row key and the primary key value set in the secondary index table map the relationship between the non-primary key and the primary key in the data table, which speeds up the query speed of the non-primary key condition query process.

[0017] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present application, and together with the specification, are used to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative work. In the drawings:

[0019] Figure 1 is a flowchart of a method for constructing a secondary index table shown in an exemplary embodiment of the present application;

[0020] Figure 2 yes Figure 1 A schematic flow chart of an exemplary embodiment of step S104 in the illustrated embodiment;

[0021] Figure 3 yes Figure 2 A schematic flow chart of an exemplary embodiment of step S202 in the illustrated embodiment;

[0022] Figure 4 is a schematic diagram of a secondary index table shown in an exemplary embodiment;

[0023] Figure 5 is a schematic diagram of a secondary index table shown in another exemplary embodiment;

[0024] Figure 6 is Figure 1 A schematic diagram of a flow chart of a method for constructing a secondary index table proposed based on the illustrated embodiment;

[0025] Figure 7 is Figure 6 A schematic diagram of a flow chart of a method for constructing a secondary index table proposed based on the illustrated embodiment;

[0026] Figure 8 is a schematic diagram of secondary index table maintenance shown in an exemplary embodiment;

[0027] Fig. 9 is a flowchart of a coprocessor and a secondary index table maintenance operation shown in an exemplary embodiment;

[0028] Fig.10 is a flowchart of a data query method shown in an exemplary embodiment of the present application;

[0029] Fig.11 is a block diagram of a device for constructing a secondary index table shown in an exemplary embodiment of the present application;

[0030] Fig.12 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application is shown. DETAILED DESCRIPTION

[0031] Here, exemplary embodiments will be described in detail, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application as detailed in the attached claims.

[0032] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.

[0033] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.

[0034] It should also be noted that the "multiple" mentioned in this application refers to two or more than two. "And / or" describes the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship.

[0035] After long-term research, the inventors of the present application discovered that a data table includes a primary key and a non-primary key, and usually a primary key index is constructed, but a non-primary key index is not constructed. Therefore, customers can quickly query data in the data table through the primary key index. However, when customers use non-primary keys as query conditions, they need to query through a full table scan, and this method of data query is too inefficient.

[0036] In order to solve the above technical problems, this embodiment proposes a method for constructing a secondary index table, a device for constructing a secondary index table, an electronic device, and a computer-readable storage medium, which are described in detail below.

[0037] See also Figure 1 , Figure 1 This is a flowchart of a method for constructing a secondary index table shown in an exemplary embodiment of the present application. The method for constructing a secondary index table provided in this embodiment can be applied to a coprocessor, which is a processor developed and applied to assist a central processing unit in completing processing tasks that it cannot perform or that are inefficient or ineffective. There are many tasks that a central processing unit cannot perform, such as signal transmission between devices, management of access devices, etc.; and tasks that a central processing unit can perform inefficiently and ineffectively include graphics processing, audio processing, etc.

[0038] like Figure 1 As shown, the method for constructing a secondary index table provided in this embodiment includes steps S101 to S104, and the detailed description is as follows:

[0039] Step S101: determine the first non-primary key and the corresponding first non-primary key value in a data table.

[0040] The primary key is also called the primary key. The primary key is one or more fields in a table whose value is used to uniquely identify a record in the table. In a relationship between two tables, the primary key is used to reference a specific record in one table from another table. The primary key is a unique key that is part of the table definition. The primary key of a table can be composed of multiple keywords, and the primary key column cannot contain null values.

[0041] Non-primary keys are also called non-primary keywords. Non-primary keywords are also one or more fields in the table. They are keywords in the data table other than the primary key.

[0042] In this embodiment, the data table is an Hbase data table. HBase is a distributed, scalable NoSQL database that supports massive data storage. Each row of data in the HBase data table consists of a row key (RowKey, RK) and multiple columns (Column). The data is stored in the dictionary order of the row key, and the data can only be retrieved according to the row key when querying. Among them, the row key is usually set as the primary key, and the column is set as a non-primary key. That is, in this embodiment, there is only one primary key in the data table, and there may be multiple non-primary keys.

[0043] This embodiment determines the first non-primary key and the corresponding first non-primary key value in the data table. It is worth noting that the same first non-primary key may correspond to multiple first non-primary key values. For example, if the first non-primary key is "region", the first non-primary key values ​​corresponding to the first non-primary key include "Beijing", "Shanghai", and "Chongqing".

[0044] Step S102: Obtain a primary key value set corresponding to the first non-primary key value from the data table.

[0045] In this embodiment, the primary key value set corresponding to the first non-primary key value includes at least one first primary key value. Each first primary key value corresponds to a first non-primary key value, and the first non-primary key value corresponding to the first primary key value is the data in the row where the first primary key value is located and the column where the first non-primary key is located in the data table.

[0046] Exemplarily, a primary key value set corresponding to the first non-primary key value is obtained from the data table by full table query.

[0047] Step S103: Combine the first non-primary key and the first non-primary key value to obtain processed data.

[0048] This embodiment does not limit the combination processing method of the first non-primary key and the first non-primary key value. For example, the first non-primary key and the first non-primary key value are directly combined into a set to obtain the processed data. For example, the first non-primary key and the first non-primary key value are subjected to feature fusion, so that the two data are merged into one data to obtain the processed data.

[0049] Feature fusion is the process of fusing multiple features together. The existing feature fusion algorithms can be roughly divided into the following three categories: one is simple feature combination, that is, all feature vectors are combined in a serial or parallel manner to form a new feature vector; the second is feature selection, that is, from the newly combined feature vector, one data with the best classification is selected from each corresponding dimension of data, and finally the selected data is combined into a new feature; the last is feature transformation, that is, all feature vectors are put together and then transformed into a new feature using a certain mathematical method. It can be seen that the fused feature contains relevant feature information of each component feature, that is, it contains information related to the first non-primary key and information related to the first non-primary key value.

[0050] Step S104: using the processed data as the row key and the primary key value set as the key value corresponding to the row key and storing it in a preset second data table.

[0051] In this embodiment, the processed data is used as the row key, and the primary key value set is stored as the key value corresponding to the row key in a preset second data table. After (processed data, primary key value set) is stored as the data of a row of the second data table, the first column of the second data table stores the processed data, and the second column stores the primary key value set. Since the processed data includes non-primary key and non-primary key value information, if the non-primary keys are different and / or the non-primary key values ​​are different, the combined processed data are different, and different processed data are stored as row keys in different rows of the second data table.

[0052] Step S105: construct an index for the processed data, and update the second data table to obtain a second index table.

[0053] In this embodiment, an index is constructed for the processed data by constructing a pointer and pointing to the key value corresponding to the row key, that is, the pointer points to the primary key value set corresponding to the processed data. This embodiment can speed up the query process of non-primary key condition query by mapping the row key in the secondary index table to the primary key value set associated with it.

[0054] In this embodiment, the non-primary key and the corresponding non-primary key value in the data table are determined; the primary key value set corresponding to the non-primary key value is obtained from the data table, and the primary key value set includes at least one primary key value; the non-primary key and the non-primary key value are combined and processed to obtain the processed data; the primary key value set is used as the key value of the processed data, and an index is constructed for the processed data to obtain a second index table. Since the index is constructed for the processed data, the row key and the primary key value set in the secondary index table map the relationship between the non-primary key and the primary key in the data table, which speeds up the query speed of the non-primary key condition query process.

[0055] See also Figure 2 , Figure 2 yes Figure 1 The flowchart of step S104 in the embodiment shown is an exemplary embodiment, as shown in FIG. Figure 2 As shown, step S104 includes steps S201 to S203, which are described in detail as follows:

[0056] Step S201: determine whether the number of primary key values ​​included in the primary key value set exceeds a preset threshold.

[0057] The inventor of the present application has considered that if the number of primary key values ​​included in the primary key value set is too large, it will take too long to traverse the primary key value set when performing data query, resulting in low efficiency in querying data. To solve the above problem, the present embodiment pre-sets a preset threshold for controlling the number of primary key values ​​included in the primary key value set. When it is detected that the number of primary key values ​​included in the primary key value set exceeds the preset threshold, the primary key value set is divided into a preset number of primary key value subsets. In this way, the number of primary key values ​​in the primary key value set can be controlled to remain within a certain range, thereby improving the query speed of the constructed secondary index table.

[0058] Step S202: If the judgment is yes, the primary key value set is divided into a preset number of primary key value subsets.

[0059] In this embodiment, the number of primary key values ​​included in each primary key value subset does not exceed a preset threshold. The number of primary key value subsets into which the primary key value set is divided is preset, and this embodiment can flexibly set the number of primary key value subsets according to actual application scenarios, and is not specifically limited here.

[0060] Exemplarily, this embodiment determines the number of primary key value subsets according to the number of primary key values ​​included in the preset primary key value set, that is, the number of primary key value subsets is determined according to the size of the preset threshold. For example, if the preset threshold is set to 50, if the number of primary key values ​​included in the primary key value set is 149, then in order to save storage resources as much as possible, the number of primary key value subsets is set to 3 when the number of primary key values ​​included in the primary key value subset does not exceed 50.

[0061] See also Figure 3 , Figure 3 yes Figure 2 The flowchart of step S202 in the embodiment shown is an exemplary embodiment, as shown in FIG. Figure 3 As shown, step S202 includes steps S301 to S302, which are described in detail as follows:

[0062] Step S301: sort the primary key values ​​included in the primary key value set in ascending order.

[0063] Step S302: Divide the sorted primary key value set into a preset number of primary key value subsets.

[0064] In this embodiment, the arrangement order of the primary key values ​​included in each primary key value subset remains unchanged, that is, the arrangement order of the primary key values ​​included in each primary key value subset is the same as the arrangement order in the primary key value set. It can be understood that the primary key values ​​in each primary key value subset are also arranged in order from small to large.

[0065] The inventor of the present application has considered that if the primary key values ​​included in a primary key value set or a primary key value subset are arranged in a disorderly manner, then when performing data query, it is necessary to traverse each primary key value in the primary key value set or the primary key value subset to determine whether the target primary key is in the primary key value set. This method is not efficient enough. To solve the above problem, this embodiment sorts the primary key values ​​included in each primary key value subset in ascending order, so that when traversing each primary key value subset, it is only necessary to check the first primary key value and the last primary key value of each primary key value subset. If the target primary key is not located in the interval between the first primary key value and the last primary key value, it is possible to jump directly to other primary key value subsets without traversing other primary key values ​​in the primary key value subset. This method can further improve the efficiency of primary key queries, thereby improving the efficiency of data queries.

[0066] Step S203: using each primary key value subset as a key value, using the processed data as a row key corresponding to each key value, and storing them in different rows in the second data table.

[0067] See also Figure 4 , Figure 4 is a schematic diagram of a secondary index table shown in an exemplary embodiment. Figure 4 As shown, Figure 4 The data table on the left is a secondary index table without limiting the number of primary key values ​​included in the primary key value set. Figure 4The data table on the right is a secondary index table split from the data table on the left under the condition that the number of primary key values ​​included in the primary key value set is limited. In this embodiment, the number of primary key values ​​included in the primary key value set is limited to no more than 2. Obviously, the row key in the secondary index table on the left is (non-primary key: non-primary key value), and the primary key value set corresponding to the row key is {Rowkey-1, Rowkey-2, Rowkey-3, Rowkey-4}. Obviously, the number of primary key values ​​included in the primary key value set is greater than 2. Therefore, this embodiment uses Figure 2 The method shown changes the secondary index table to the secondary index table on the right. The secondary index table on the right includes two rows of data. The row keys of the two rows are (non-primary key: non-primary key value). The primary key value subset corresponding to the row key of the first row is {Rowkey-1, Rowkey-2}, and the primary key value subset corresponding to the row key of the second row is {Rowkey-3, Rowkey-4}. The above two primary key value subsets are derived from Figure 4 The primary key value set of the secondary index table on the left, and the number of primary key values ​​included in the above two primary key value subsets does not exceed 2, which meets the restriction condition.

[0068] Exemplarily, the non-primary key, the non-primary key value, the largest primary key value in each primary key value subset, and the smallest primary key value in the corresponding primary key value subset are combined and processed to obtain processed data.

[0069] See also Figure 5 , Figure 5 is a schematic diagram of a secondary index table shown in another exemplary embodiment. Figure 5 As shown, Figure 5 The data table on the left is a secondary index table without limiting the number of primary key values ​​included in the primary key value set. Figure 5 The data table on the right is a secondary index table split from the data table on the left while limiting the number of primary key values ​​included in the primary key value set. In this embodiment, the number of primary key values ​​included in the primary key value set is pre-restricted to no more than 2. Obviously, the row key in the secondary index table on the left is (non-primary key: non-primary key value: 1:4), and the primary key value set corresponding to the row key is {Rowkey-1, Rowkey-2, Rowkey-3, Rowkey-4}. The secondary index table on the right includes two rows of data, and the row keys of the two rows of data are (non-primary key: non-primary key value: 1:2). The primary key value subset corresponding to the row key of the first row is {Rowkey-1, Rowkey-2}, where "1:2" means that the smallest primary key value in the primary key value subset is 1 and the largest primary key value is 2. The primary key value subset corresponding to the row key of the second row is {Rowkey-3, Rowkey-4:3:4}, where "3:4" means that the smallest primary key value in the primary key value subset is 3 and the largest primary key value is 4. The above two primary key value subsets are both derived from Figure 5 The primary key value of the secondary index table on the left.

[0070] This embodiment adds the largest primary key value and the smallest primary key value to the row key name of the secondary index table, so that when traversing each primary key value subset, the smallest primary key value and the largest primary key value in the primary key value set can be determined by querying the row key. If the target primary key is not in the interval between the smallest primary key value and the largest primary key value, it can be directly determined that the target primary key value is not in the primary key value set, further improving the efficiency of primary key query, and then improving the efficiency of data query.

[0071] For example, see Figure 6 , Figure 6 is Figure 1 A flow chart of a method for constructing a secondary index table proposed based on the embodiment shown in FIG. Figure 6 As shown, the method for constructing a secondary index table provided in the present application includes steps S401 and S402, which are described in detail as follows:

[0072] Step S401: Match the processed data with the row key column in the second data table to obtain a matching result.

[0073] The inventors of the present application have taken into consideration that the processed data is processed by a combination of non-primary keys and non-primary key values, and therefore includes non-primary key information and non-primary key value information. In order to avoid repeatedly adding the processed data and the corresponding primary key value set to the second data table, this embodiment first matches the processed data with the row key column in the second data table before storing the processed data as the row key and the primary key value set as the key value corresponding to the row key in the preset second data table, and determines whether to execute subsequent steps based on the matching results.

[0074] In this embodiment, the processed data can be matched with the row key column in the second data table in a variety of ways, which are not specifically limited here. Exemplarily, the similarity between the processed data and each row key in the row key column is calculated, and if the similarity is greater than a preset threshold, it is determined that the processed data matches the corresponding row key, otherwise, it is determined that the processed data does not match the corresponding row key.

[0075] Step S402: If the matching result indicates that no row key matches the processed data, continue to execute the step of using the processed data as the row key and storing the primary key value set as the key value corresponding to the row key in the preset second data table.

[0076] In this embodiment, if the matching result indicates that no row key matches the processed data, the step of using the processed data as the row key and the primary key value set as the key value corresponding to the row key to store in the preset second data table is continued. In this way, it is possible to avoid repeatedly adding the processed data and the corresponding primary key value set to the second data table, which causes a waste of storage resources and computing power resources.

[0077] For example, see Figure 7 , Figure 7 is Figure 6 A flow chart of a method for constructing a secondary index table proposed based on the embodiment shown in FIG. Figure 7 As shown, the method for constructing the secondary index table provided in the present application further includes steps S501 and S502, which are described in detail as follows:

[0078] Step S501: If the matching result indicates that there is a target row key that matches the processed data, a target key value corresponding to the target row key is obtained.

[0079] This embodiment queries the key value corresponding to the target row key in the second data table and uses the key value as the target key value.

[0080] This embodiment takes into account that if the matching result indicates that there is a target row key that matches the processed data, it cannot be determined that the primary key value set corresponding to the processed data in the current second data table is exactly the same as the primary key value set to be added. For example, if the data in the first data table changes, in order to maintain the second index table, the data in the secondary index table needs to be changed accordingly. That is, this embodiment can be Figure 1 The method shown updates the data in the secondary index table. In this case, if the matching result indicates that there is a target row key that matches the processed data, it is necessary to further determine whether the target key value matches the primary key value set corresponding to the processed data, and determine whether to perform subsequent operations based on the matching result obtained.

[0081] Step S502: If it is detected that the target key value does not match the primary key value set, continue to execute the step of using the processed data as the row key and storing the primary key value set as the key value corresponding to the row key in the preset second data table.

[0082] In this embodiment, if it is detected that the target key value does not match the primary key value set, it means that the primary key value set corresponding to the processed data in the current second data table is not completely the same as the primary key value set to be added, then the primary key value set corresponding to the processed data is added to the second data table for update operation, so as to realize the real-time update of the secondary index table, that is, continue to execute the steps of using the processed data as the row key and storing the primary key value set as the key value corresponding to the row key in the preset second data table. On the contrary, if it is detected that the target key value matches the primary key value set, it means that the primary key value set corresponding to the processed data in the current second data table is almost completely the same as the primary key value set to be added, in this case, in order to avoid repeated addition, the control no longer executes the steps of using the processed data as the row key and storing the primary key value set as the key value corresponding to the row key in the preset second data table, so as to further save computing power resources and storage resources.

[0083] It is understandable that, since this embodiment constructs a secondary index table based on the first data table, it is not difficult to understand that the secondary index table needs to be updated according to the changes in the data in the first data table. Exemplarily, this embodiment periodically detects the data changes in the first data table and performs index maintenance on the second index table according to the data changes.

[0084] In an exemplary embodiment, see Figure 8 , Figure 8 FIG. 1 is a schematic diagram of a secondary index table maintenance shown in an exemplary embodiment. Figure 8 As shown, the Hbase database includes a data table and a secondary index table, and the processor where the Hbase database is located receives a client request submitted by a client, wherein the client request is used to instruct the processor where the Hbase database is located to query, add, update or delete data in the data table. In this embodiment, the client request can be intercepted before the processor where the Hbase database is located executes the client request, and the secondary index table is maintained based on the client request, and then the data in the data table is modified by instructing the processor where the Hbase database is located to execute the client request.

[0085] like Figure 8As shown, this embodiment is based on the coprocessor intercepting the client request and matching the operation type based on the information carried in the client request, wherein the operation type includes index query, index addition, index update and index deletion. After determining the operation type, the coprocessor maintains the secondary index table. Exemplarily, the RegionObserver class of the coprocessor is used to rewrite the prePut(), preGetOp(), preScanOpen() and preDelete() functions in the class, and the addition and update operations of the secondary index table are implemented in the prePut() function. The query operation of the secondary index table is implemented in the preGetOp() and preScanOpen() functions, and the deletion operation of the secondary index table is implemented in the preDelete() function.

[0086] See also Fig. 9 , Fig. 9 FIG. 1 is a flowchart of a coprocessor and a secondary index table maintenance operation shown in an exemplary embodiment. Fig. 9 As shown, the coprocessor intercepts the client request and determines the operation type based on the information included in the client request. Specifically, if it is a scan statement or a get statement, the preScan() function or the preGet() function is used to intercept the client request, and the data query module is used to query the secondary index table, and then the maintenance process of the secondary index table is ended; if it is a delete statement, the coprocessor intercepts it with the preDelete() function, and uses the index deletion module to delete the corresponding index in the secondary index table, and then the maintenance process of the secondary index table is ended; if it is a put statement, the coprocessor intercepts it with the prePut() function to determine whether the corresponding index exists. If it exists, the index update module is used to update the corresponding index in the secondary index table, and then the maintenance process of the secondary index table is ended; if the corresponding index does not exist, the index adding module is used to add the corresponding index to the secondary index table, and then the maintenance process of the secondary index table is ended.

[0087] See also Fig.10 , Fig.10 is a flow chart of a data query method shown in an exemplary embodiment of the present application, such as Fig.10 As shown, the data query method provided by the present application includes steps S601 to S603, which are described in detail as follows:

[0088] Step S601: Obtain a data query request.

[0089] In this embodiment, the data query request includes index information for querying data from a data table, and the index information includes non-primary keys and non-primary key values. In this embodiment, if the index information includes a primary key value, since the data table usually constructs an index for the primary key and the primary key value, in this case, there is no need to query the secondary index table, and the data can be queried based on the primary key value; if the index information includes non-primary keys and non-primary key values, since the data table does not have an index for the non-primary key and the non-primary key value, in order to avoid the problems of long query time and low efficiency caused by a comprehensive query of the data table, this embodiment performs index query by means of a secondary index.

[0090] Step S602: acquiring a primary key value set corresponding to the non-primary key value from the second index table based on the index information.

[0091] In this embodiment, the second index table is a second index table constructed by the method for constructing a secondary index table provided in any of the above embodiments. In this embodiment, after obtaining the primary key value set corresponding to the non-primary key value by querying the secondary index table, data can be queried in the data table based on the primary key value set. Since the row key and the primary key value set in the secondary index table constructed in the above embodiment map the relationship between the non-primary key and the primary key in the data table, the query speed of the non-primary key condition query process can be accelerated.

[0092] Step S603: query the data table based on the primary key value set to obtain the data to be queried.

[0093] This embodiment performs data query based on the second index table constructed by the method for constructing a secondary index table provided in the above embodiment. Since the row key and primary key value set in the secondary index table constructed in the above embodiment maps the relationship between the non-primary key and the primary key in the data table, it can speed up the query speed of the non-primary key condition query process.

[0094] See also Fig.11 , Fig.11 is a block diagram of a device for constructing a secondary index table shown in an exemplary embodiment of the present application. Fig.11 As shown, the secondary index table construction device 700 includes a determination module 701, a first acquisition module 702, a combination processing module 703, a storage module 704 and a construction module 705.

[0095] Among them, the determination module 701 is used to determine the non-primary key and the corresponding non-primary key value in the first data table; the first acquisition module 702 is used to obtain the primary key value set corresponding to the non-primary key value from the first data table, and the primary key value set includes at least one primary key value; the combination processing module 703 is used to combine the non-primary key and the non-primary key value to obtain the processed data; the storage module 704 is used to use the processed data as the row key and the primary key value set as the key value corresponding to the row key in the preset second data table; the construction module 705 is used to build an index for the processed data and update the second data table to obtain a second index table.

[0096] In another exemplary embodiment, the storage module 704 includes a judgment unit, a division unit and a storage unit, wherein the judgment unit is used to judge whether the number of primary key values ​​included in the primary key value set exceeds a preset threshold; the division unit is used to divide the primary key value set into a preset number of primary key value subsets if the judgment is yes, and the number of primary key values ​​included in each primary key value subset does not exceed the preset threshold; the storage unit is used to use each primary key value subset as a key value and the processed data as a row key corresponding to each key value, and store them in different rows in the second data table.

[0097] In another exemplary embodiment, the partitioning unit includes a sorting subunit and a partitioning subunit, wherein the sorting subunit is used to sort the primary key values ​​included in the primary key value set in ascending order; the partitioning subunit is used to divide the sorted primary key value set into a preset number of primary key value subsets, wherein the arrangement order of the primary key values ​​included in each primary key value subset remains unchanged.

[0098] In another exemplary embodiment, the secondary index table construction device 700 provided in this embodiment also includes a matching module and a first execution module, wherein the matching module is used to match the processed data with the row key column in the second data table to obtain a matching result; the first execution module is used to continue to execute the steps of using the processed data as the row key and storing the primary key value set as the key value corresponding to the row key in the preset second data table if the matching result indicates that there is no row key that matches the processed data.

[0099] In another exemplary embodiment, the secondary index table construction device 700 provided in this embodiment also includes a second acquisition module and a second execution module, wherein the second acquisition module is used to obtain the target key value corresponding to the target row key if the matching result indicates that there is a target row key that matches the processed data; the second execution module is used to continue to execute the steps of using the processed data as the row key and storing the primary key value set as the key value corresponding to the row key in a preset second data table if it is detected that the target key value does not match the primary key value set.

[0100] It should be noted that the device provided in the above embodiment and the method provided in the above embodiment belong to the same concept, wherein the specific manner in which each module and unit performs the operation has been described in detail in the method embodiment and will not be repeated here.

[0101] In another exemplary embodiment, the present application provides an electronic device, including a processor and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the method for constructing the secondary index table as described above is implemented. In this embodiment, the electronic device includes but is not limited to a mobile phone, a computer, an intelligent voice interaction device, a smart home appliance, a vehicle-mounted terminal, etc.

[0102] Fig.12 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application is shown.

[0103] It should be noted that Fig.12 The computer system 1000 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0104] like Fig.12 As shown, the computer system 1000 includes a central processing unit (CPU) 1001, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1002 or the program loaded from the storage part 1008 to the random access memory (RAM) 1003, such as executing the information recommendation method in the above embodiment. In the RAM 1003, various programs and data required for system operation are also stored. The CPU 1001, the ROM 1002 and the RAM 1003 are connected to each other through the bus 1004. The input / output (I / O) interface 1005 is also connected to the bus 1004.

[0105] The following components are connected to the I / O interface 1005: an input section 1006 including a keyboard, a mouse, etc.; an output section 1007 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1008 including a hard disk, etc.; and a communication section 1009 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 1009 performs communication processing via a network such as the Internet. A drive 1010 is also connected to the I / O interface 1005 as needed. A removable medium 1011, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1010 as needed so that a computer program read therefrom is installed into the storage section 1008 as needed.

[0106] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section 1009, and / or installed from a removable medium 1011. When the computer program is executed by a central processing unit (CPU) 1001, various functions defined in the system of the present application are executed.

[0107] It should be noted that the computer-readable medium shown in the embodiment of the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by an instruction execution system, device or device or used in combination with it. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a computer-readable computer program is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate, or transmit programs for use by or in conjunction with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.

[0108] It is understandable that in the specific implementation of this application, related data such as user information*** is involved. When the above embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.

[0109] The flowchart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present application. Wherein, each box in the flowchart or block diagram can represent a module, a program segment, or a part of the code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0110] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. The names of these units do not constitute limitations on the units themselves in some cases.

[0111] Another aspect of the present application provides a computer-readable storage medium having computer-readable instructions stored thereon, which, when executed by a processor, implements the method for constructing a secondary index table as in any of the previous embodiments.

[0112] Another aspect of the present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. A processor of a computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the method for constructing a secondary index table provided in each of the above embodiments.

[0113] It should be noted that the computer-readable medium shown in the embodiment of the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it. In the present application, a computer-readable signal medium can include a data signal propagated in a baseband or as a part of a carrier wave, wherein a computer-readable computer program is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate, or transmit programs for use by or in conjunction with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.

[0114] The flowchart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present application. Wherein, each box in the flowchart or block diagram can represent a module, a program segment, or a part of the code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0115] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.

[0116] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. The names of these units do not constitute limitations on the units themselves in some cases.

[0117] The above content is only a preferred exemplary embodiment of the present application and is not intended to limit the implementation scheme of the present application. A person skilled in the art can easily make corresponding changes or modifications based on the main concept and spirit of the present application. Therefore, the scope of protection of the present application shall be based on the scope of protection required by the claims.

Claims

1. A method for constructing a secondary index table, applied to a coprocessor, characterized in that: include: Determine a non-primary key and a corresponding non-primary key value in the first data table; Acquire a primary key value set corresponding to the non-primary key value from the first data table, wherein the primary key value set includes at least one primary key value; Combining the non-primary key and the non-primary key value to obtain processed data; Using the processed data as a row key, and storing the primary key value set as a key value corresponding to the row key in a preset second data table; Building an index for the processed data, and updating the second data table to obtain a second index table; The non-primary key and the non-primary key value are combined and processed to obtain the processed data, including: determining whether the number of primary key values ​​included in the primary key value set exceeds a preset threshold; if the determination is yes, dividing the primary key value set into a preset number of primary key value subsets, and the number of primary key values ​​included in each primary key value subset does not exceed the preset threshold; the non-primary key, the non-primary key value, the largest primary key value in each primary key value subset, and the smallest primary key value in the corresponding primary key value subset are combined and processed to obtain the processed data.

2. The method according to claim 1, characterized in that The using the processed data as a row key and storing the primary key value set as a key value corresponding to the row key in a preset second data table includes: Each primary key value subset is used as a key value, and the processed data is used as a row key corresponding to each key value, and is stored in different rows in the second data table.

3. The method according to claim 1, characterized in that The dividing the primary key value set into a preset number of primary key value subsets comprises: Sorting the primary key values ​​included in the primary key value set in ascending order; The sorted primary key value set is divided into the preset number of primary key value subsets, wherein the arrangement order of the primary key values ​​included in each primary key value subset remains unchanged.

4. The method according to claim 1, characterized in that: Before using the processed data as a row key and storing the primary key value set as a key value corresponding to the row key in a preset second data table, the method further includes: Matching the processed data with the row key column in the second data table to obtain a matching result; If the matching result indicates that no row key matches the processed data, continue to execute the step of using the processed data as the row key and storing the primary key value set as the key value corresponding to the row key in the preset second data table.

5. The method according to claim 4, characterized in that The method further comprises: If the matching result indicates that there is a target row key that matches the processed data, obtaining a target key value corresponding to the target row key; If it is detected that the target key value does not match the primary key value set, continue to execute the step of using the processed data as the row key and storing the primary key value set as the key value corresponding to the row key in the preset second data table.

6. A data query method, characterized in that: include: Obtaining a data query request, wherein the data query request includes index information, and the index information includes a non-primary key and a non-primary key value; Based on the index information, obtain a primary key value set corresponding to the non-primary key value from a second index table, where the second index table is a second index table constructed by any one of the methods of claims 1 to 5; The data table is queried based on the primary key value set to obtain the data to be queried.

7. A device for constructing a secondary index table, characterized in that: include: A determination module, used to determine the non-primary key and the corresponding non-primary key value in the first data table; An acquisition module, configured to acquire a primary key value set corresponding to the non-primary key value from the first data table, wherein the primary key value set includes at least one primary key value; A combination processing module, used for combining the non-primary key and the non-primary key value to obtain processed data; A storage module, used to store the processed data as a row key and the primary key value set as a key value corresponding to the row key in a preset second data table; A construction module, used for constructing an index for the processed data, and updating the second data table to obtain a second index table; The non-primary key and the non-primary key value are combined and processed to obtain the processed data, including: determining whether the number of primary key values ​​included in the primary key value set exceeds a preset threshold; if the determination is yes, dividing the primary key value set into a preset number of primary key value subsets, and the number of primary key values ​​included in each primary key value subset does not exceed the preset threshold; the non-primary key, the non-primary key value, the largest primary key value in each primary key value subset, and the smallest primary key value in the corresponding primary key value subset are combined and processed to obtain the processed data.

8. An electronic device, characterized in that: include: a memory storing computer-readable instructions; A processor reads the computer-readable instructions stored in the memory to execute the method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: Computer-readable instructions are stored thereon, and when the computer-readable instructions are executed by a processor of a computer, the computer is caused to execute the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • HBase non-primary key index building and inquiring method and system

    CN104850572A

  • A data inquiry method based on HBase database

    CN109284351A

  • Mass big data retrieval method and system

    CN110162528A

  • HBase secondary memory index construction method based on coprocessor

    CN112052240A