Data processing method and device, and storage medium
By establishing a B-tree index for the data table in the database and preconfiguring the primary and secondary indexes for it, the problem of index update time caused by duplicate data fields in the database is solved, and more efficient index search and update are achieved.
Patent Information
- Application Number
- CN202011394374.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-02
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2040-12-02
AI Technical Summary
There are a large number of fields with duplicate data in the database, which causes the index to be updated too long because it needs to traverse to find duplicate elements.
B-tree index is adopted, and each index element is preconfigured for it, including a primary index and a secondary index. Through a combination of primary index and secondary index, it reduces the number of searches and improves the index update speed.
Through the combination of primary and secondary indexes, the number of searches is reduced, the index update speed is improved, and the problem of long index update time due to duplicate data is solved.
Smart Images

Figure CN114579561B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to computer technology, and more specifically, to a data processing method and device, and a storage medium. Background Art
[0002] The database stores a huge amount of data. To improve the query capability, a field in the data table is usually used as a keyword to create an index for the data table. However, some fields in the data table are special and contain a large amount of duplicate data. The index created using this field contains a large number of duplicate elements. When updating the index, it is necessary to traverse and search, which results in a long update time. Summary of the invention
[0003] One object of the present disclosure is to provide a new data processing method and device, and a storage medium.
[0004] According to a first aspect of the present disclosure, there is provided a data processing method, comprising:
[0005] Inserting a first data record into a data table, wherein the data table includes a first field and a second field;
[0006] Creating an index element for the first data record in a B-tree index according to the first index data; wherein the B-tree index is preconfigured so that each index element includes a primary index corresponding to the first field and a secondary index corresponding to the second field; the first index data includes a first index value and a second index value, the first index value is a value of the first field of the first data record, and the second index value is a value of the second field of the first data record;
[0007] The step of creating an index element for the first data record in a B-tree index according to the first index data includes:
[0008] Determine, according to the first index value and the primary index of the index element in the B-tree index, a first insertion position corresponding to the first index value according to a B-tree insertion algorithm;
[0009] If no index element exists at the first insertion position, create an index element for the first data record at the first insertion position;
[0010] In the case where an index element already exists at the first insertion position, a second insertion position corresponding to the second index value is determined according to the B-tree insertion algorithm based on the second index value and the secondary index of the existing index element at the first insertion position, and an index element is created for the first data record at the second insertion position.
[0011] Optionally, the second field is a primary key field of the data table or a ROWID field of the data table.
[0012] Optionally, the method further comprises:
[0013] Deleting the first data record from the data table;
[0014] After the first data record is deleted, deleting the index element corresponding to the first data record from the B-tree index;
[0015] The deleting the index element corresponding to the first data record from the B-tree index includes:
[0016] According to a B-tree search algorithm, an index element having a primary index having the same value as the first index value is searched in the B-tree index as a candidate index element;
[0017] According to the B-tree search algorithm, an index element having the same secondary index as the second index value is searched from the candidate index elements as the target index element;
[0018] The target index element is deleted from the B-tree index.
[0019] Optionally, the method further comprises:
[0020] Deleting the first data record from the data table;
[0021] After the first data record is deleted, deleting the index element corresponding to the first data record from the B-tree index;
[0022] The deleting the index element corresponding to the first data record from the B-tree index includes:
[0023] According to the B-tree search algorithm, searching the B-tree index for an index element with the same secondary index value as the second index value as the target index element;
[0024] The target index element is deleted from the B-tree index.
[0025] Optionally, the method further comprises:
[0026] Receive a query request sent by a client, where the query request includes a third index value, and the third index value is a value of a first field of a query object;
[0027] According to the B-tree search algorithm, an index element having the same primary index as the third index value is searched in the B-tree index as a target index element;
[0028] According to the pointer corresponding to the target index element, the data record corresponding to the target index element is obtained and returned to the client.
[0029] Optionally, the method further comprises:
[0030] Receive a query request sent by a client, wherein the query request includes a fourth index value and a fifth index value, wherein the fourth index value is a value of a first field of the query object, and the fifth index value is a value of a second field of the query object;
[0031] According to a B-tree search algorithm, searching in the B-tree index for an index element with the same primary index as the fourth index value as a candidate index element;
[0032] According to the B-tree search algorithm, searching for an index element with the same secondary index as the fifth index value in the candidate index elements as the target index element;
[0033] According to the pointer corresponding to the target index element, the data record corresponding to the target index element is obtained and returned to the client.
[0034] Optionally, the method further comprises:
[0035] Receive a query request sent by a client, where the query request includes a sixth index value, and the sixth index value is a value of a second field of a query object;
[0036] According to the B-tree search algorithm, searching in the B-tree index for an index element with the same secondary index value as the sixth index value as the target index element;
[0037] According to the pointer corresponding to the target index element, the data record corresponding to the target index element is obtained and returned to the client.
[0038] According to a second aspect of the present disclosure, there is provided a data processing device, comprising:
[0039] A data record inserting module, used for inserting a first data record into a data table, wherein the data table includes a first field and a second field;
[0040] an index element creation module, configured to create an index element for the first data record in a B-tree index according to first index data; wherein the B-tree index is pre-configured so that each index element includes a primary index corresponding to the first field and a secondary index corresponding to the second field; the first index data includes a first index value and a second index value, the first index value is a value of the first field of the first data record, and the second index value is a value of the second field of the first data record;
[0041] The index element creation module includes:
[0042] A first insertion position determination submodule, configured to determine a first insertion position corresponding to the first index value according to the first index value and the primary index of the index element in the B-tree index and in accordance with a B-tree insertion algorithm;
[0043] A first creation submodule, configured to create an index element for the first data record at a first insertion position if no index element exists at the first insertion position;
[0044] A second insertion position determination submodule, configured to determine, when an index element already exists at the first insertion position, a second insertion position corresponding to the second index value according to the second index value and the secondary index of the existing index element at the first insertion position according to a B-tree insertion algorithm;
[0045] The second creation submodule is used to create an index element for the first data record at the second insertion position if an index element already exists at the first insertion position.
[0046] According to a third aspect of the present disclosure, a data processing device is provided, comprising a processor and a memory; the memory stores computer executable commands, and when the computer executable commands are executed by the processor, the method described in the first aspect of the present disclosure is implemented.
[0047] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided, storing computer-executable commands, and when the computer-executable commands are executed by a processor, the method described in the first aspect of the present disclosure is implemented.
[0048] The data processing method, device, and storage medium provided by the embodiments of the present disclosure can establish a B-tree index for a data table by combining a primary index and a secondary index. When there are duplicates in the primary index, the secondary index can be further searched, thereby reducing the number of searches and improving the index update speed.
[0049] Other features and advantages of the present disclosure will become apparent from the following detailed description of exemplary embodiments of the present disclosure with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate embodiments of the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0051] Figure 1 is a schematic diagram of the hardware configuration of a database server that can be used to implement an embodiment of the present disclosure;
[0052] Figure 2 is a flow chart of a data processing method according to an embodiment of the present disclosure;
[0053] Figure 3 This is a schematic diagram of building a B-tree index using the first field of a data table;
[0054] Figure 4 is a schematic diagram of a B-tree index according to an embodiment of the present disclosure;
[0055] Figure 5 is a schematic diagram of inserting an index element into a B-tree index according to an embodiment of the present disclosure;
[0056] Figure 6 is a schematic diagram of inserting an index element into a B-tree index according to an embodiment of the present disclosure;
[0057] Figure 7 Schematic diagram of a data processing device according to an embodiment of the present disclosure.
[0058] Figure 8 Schematic diagram of a data processing device according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0059] Various exemplary embodiments of the present disclosure will now be described in detail with reference to the accompanying drawings. It should be noted that the relative arrangement of components and steps, numerical expressions and numerical values set forth in these embodiments do not limit the scope of the present disclosure unless otherwise specifically stated.
[0060] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the present disclosure, its application, or uses.
[0061] Technologies, methods, and equipment known to ordinary technicians in the relevant art may not be discussed in detail, but where appropriate, the technologies, methods, and equipment should be considered part of the specification.
[0062] In all examples shown and discussed herein, any specific values should be interpreted as merely exemplary and not as limiting. Therefore, other examples of the exemplary embodiments may have different values.
[0063] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.
[0064] <Hardware Configuration>
[0065] Figure 1 The database system that can be used to implement the embodiments of the present disclosure is shown. The client 103 can access the database server 101 and send operation instructions to the database. The database server 101 performs corresponding operations on the data table according to the operation instructions, such as adding, checking, modifying, and deleting operations.
[0066] The configuration of the database server 101 may include but is not limited to: a processor 1011, a memory 1012, an interface device 1013, a communication device 1014, an input device 1015, and an output device 1016. The processor 1011 may include but is not limited to a central processing unit CPU, a microprocessor MCU, etc. The memory 1012 may include but is not limited to a ROM (read-only memory), a RAM (random access memory), a non-volatile memory such as a hard disk, etc. The interface device 1013 may include but is not limited to a USB interface, a serial interface, a parallel interface, etc. The communication device 1014 may, for example, be capable of wired communication or wireless communication, and may specifically include WiFi communication, Bluetooth communication, 2G / 3G / 4G / 5G communication, etc. The input device 1015 includes but is not limited to a keyboard, a mouse, etc. The output device 1016 includes but is not limited to a display screen, etc. The configuration of the database server 101 may also include only some of the above devices.
[0067] In the embodiments of this specification, the memory 1012 of the database server 101 is used to store instructions, which are used to control the processor 1011 to operate to support the implementation of the method according to any embodiment of this specification. The technician can design instructions according to the scheme disclosed in this specification. How instructions control the processor to operate is well known in the art, so it will not be described in detail here.
[0068] It should be understood by those skilled in the art that although Figure 1 , multiple devices of the database server 101 are shown; however, the database server 101 of the embodiment of this specification may only involve some of the devices, for example, only the processor 1011, the memory 1012 and the communication device 1014.
[0069] Figure 1 The hardware configuration shown is merely illustrative and is in no way intended to limit the present disclosure, its application, or uses.
[0070] <Method Example>
[0071] This embodiment provides a data processing method. The method can be, for example, Figure 1 The database server 101 implementation is shown.
[0072] See also Figure 2 As shown, the data processing method includes steps S102-S104.
[0073] Step S102: insert a first data record into a data table, where the data table includes a first field and a second field.
[0074] Step S104: Create an index element for the first data record in the B-tree index according to the first index data. The first index data includes a first index value and a second index value, the first index value is the value of the first field of the first data record, and the second index value is the value of the second field of the first data record. The B-tree index is pre-configured so that each index element includes a primary index corresponding to the first field and a secondary index corresponding to the second field.
[0075] A data table usually includes a primary key or ROWID. In a data table, the primary key corresponds to a combination of one or more columns in the data table, that is, the primary key field can be a field or a combination of multiple fields. The primary key is used to uniquely identify a row of data in the data table (that is, a data record). The ROWID column is a pseudo column of the data table. ROWID can uniquely identify a row of data (that is, a data record). ROWID is automatically generated when a data record is inserted into the database. There will be no duplication of data in the primary key field or ROWID field of the data table, but there may be duplication of data in other fields.
[0076] Here is an example of a data table:
[0077] ROWID Field Field F1 Field F2 Field F3 1 21 31 147 2 25 32 146 3 17 33 133 4 18 34 134 5 18 35 135 6 20 36 136 7 22 37 137 8 23 38 138 9 23 39 139 10 23 40 132 11 26 41 141 12 27 42 142 13 27 43 131 14 28 44 144
[0078] Data Table 1
[0079] In the data table 1, there are 4 fields, namely, ROWID field, field F1, field F2, and field F3. It can be seen that in the field F1 of the data table 1, there are two data "18", three data "23", and two data "27".
[0080] In the embodiment of the present disclosure, the B-tree index is an index created for a data table. The B-tree is a tree suitable for searching proposed by R. Bayer and E. McCreight, also known as a B-tree.
[0081] If only the data in field F1 is used as the index for data records, the B-tree index created based on data table 1 is as follows: Figure 3 As shown. There are 14 data records in data table 1, and the B-tree index includes 14 index elements. The B-tree index should also include pointers ( Figure 3 It can be seen that since there are three "23"s in the field F1 of data table 1, there are also three index elements of "23" in the B-tree index. In this case, if the data record with ROWID "10" is deleted from data table 1, it is necessary to traverse three times to find the index element corresponding to the deleted data record, and then delete the index element from the B-tree index. This process has a slow update speed of the B-tree index due to the large number of queries.
[0082] In the embodiment of the present disclosure, the index of the data record is set to a combination type, including a primary index and a secondary index, the primary index of the data record is the data of the first field of the data record, and the secondary index of the data record is the data of the second field of the data record. That is, the index type of the data table is pre-specified as a combination type, and the B-tree index is configured so that each index element includes a primary index corresponding to the first field and a secondary index corresponding to the second field.
[0083] In an example of the present disclosure, the first field may be a search field set by the user according to his / her needs. The second field may be a primary key field of a data table or a ROWID field of a data table. In this case, the data in the second field of the data table does not have duplication.
[0084] For example, for the data table 1, the first field is the field F1, and the second field is the ROWID field. According to the data records in the data table 1, inserting index elements into the pre-configured blank B-tree index can obtain the following: Figure 4 The B-tree index shown in Figure 1. There are 14 data records in data table 1, and the B-tree index includes 14 index elements. The B-tree index should also include a pointer ( Figure 4 not shown).
[0085] The following is a description of the process of creating an index element for the first data record in the B-tree index, that is, step S104. Step S104 includes steps S1042-S1048.
[0086] Step S1042: Determine a first insertion position corresponding to the first index value according to the first index value and the primary index of the index element in the B-tree index and in accordance with the B-tree insertion algorithm.
[0087] In this step, according to the B-tree insertion algorithm, the first insertion position is determined according to the comparison relationship between the first index value and the primary index of the index element in the B-tree index.
[0088] Step S1044: If no index element exists at the first insertion position, create an index element for the first data record at the first insertion position.
[0089] Step S1046: When an index element already exists at the first insertion position, determine a second insertion position corresponding to the second index value according to the B-tree insertion algorithm based on the second index value and the secondary index of the existing index element at the first insertion position.
[0090] In this step, according to the B-tree insertion algorithm, the second insertion position is determined according to a comparison relationship between the second index value and the secondary index of the existing index element at the first insertion position.
[0091] Step S1048: Create an index element for the first data record at the second insertion position.
[0092] Below is the data table 1 and Figure 4 Based on the B-tree index shown, two specific examples are given:
[0093] <Example 1>
[0094] Taking data table 1 as an example, the first field is field F1, and the second field is the ROWID field. Assume that the first data record inserted into data table 1 is as follows, the data of the ROWID field is "15", the data of field F1 is "30", the data of field F2 is "35", and the value of field F3 is "145". Then the first index data includes the first index value "30" and the second index value "15".
[0095] ROWID Field Field F1 Field F2 Field F3 15 30 35 145
[0096] Reference Figure 5 As shown, according to the B-tree insertion algorithm, according to the comparison relationship between the first index value "30" and the primary index of the index element in the B-tree index, it can be determined that the first insertion position is position A. If there is no index element at position A, an index element is created for the first data record at position A, and the primary index of the index element is "30" and the secondary index is "15".
[0097] <Example 2>
[0098] Taking data table 1 as an example, the first field is field F1, and the second field is the ROWID field. Assume that the first data record inserted into data table 1 is as follows, the data of the ROWID field is "15", the data of field F1 is "23", the data of field F2 is "32", and the data of field F3 is "143". Then the first index data includes the first index value "23" and the second index value "15".
[0099] ROWID Field Field F1 Field F2 Field F3 15 23 32 143
[0100] See also Figure 6 As shown, according to the B-tree insertion algorithm, according to the comparison relationship between the first index value "23" and the primary index of the index element in the B-tree index, it can be determined that the first insertion position is position B. There are already 3 index elements at position B. According to the B-tree insertion algorithm, according to the comparison relationship between the second index value "15" and the secondary index of the 3 existing index elements at position B, it can be determined that the second insertion position is position C. An index element is created for the first data record at position C, and the primary index of the index element is "23" and the secondary index is "15".
[0101] When a data record is deleted from a data table, the index element corresponding to the deleted data record in the B-tree index should be deleted.
[0102] In the embodiment of the present disclosure, the method may further include steps S202-S204.
[0103] Step S202: Delete the first data record from the data table.
[0104] Step S204: After the first data record is deleted, the index element corresponding to the first data record is deleted from the B-tree index.
[0105] The process of deleting the index element corresponding to the first data record from the B-tree index, that is, step S204, is described below using two examples.
[0106] <Example 1>
[0107] Deleting the index element corresponding to the first data record from the B-tree index includes steps S2041-S2043.
[0108] Step S2041: According to the B-tree search algorithm, search in the B-tree index for an index element whose primary index is the same as the first index value as a candidate index element.
[0109] Step S2042: According to the B-tree search algorithm, search for an index element whose secondary index is the same as the second index value in the candidate index elements as the target index element;
[0110] Step S2043: Delete the target index element from the B-tree index.
[0111] Taking data table 1 as an example, the first field is field F1, and the second field is the ROWID field. Assume that the first data record inserted into data table 1 is as follows, the data of the ROWID field is "15", the data of field F1 is "23", the data of field F2 is "32", and the data of field F3 is "143". Then the first index data includes the first index value "23" and the second index value "15".
[0112] ROWID Field Field F1 Field F2 Field F3 15 23 32 143
[0113] After deleting the data record with ROWID "15" from data table 1, four candidate index elements with primary index "23" can be found according to the B-tree search algorithm. The secondary index of the first candidate index element is "8", the primary index of the second candidate index element is "9", the primary index of the third candidate index element is "10", and the primary index of the fourth candidate index element is "15". According to the B-tree search algorithm, a binary search is performed among the four candidate index elements using the B-tree characteristics to find the index element with secondary index "15" as the target index element, and then the target index element is deleted.
[0114] <Example 2>
[0115] If the second field is the primary key field of the data table or the ROWID field of the data table, in this case, the data of the second field in the data table does not have duplication, then deleting the index element corresponding to the first data record from the B-tree index may include steps S2045-S2046.
[0116] Step S2045: According to the B-tree search algorithm, search the B-tree index for an index element whose secondary index is the same as the second index value as the target index element.
[0117] Step S2046: Delete the target index element from the B-tree index.
[0118] Since there is no duplication of data in the second field of the data table, there will be no duplication of the secondary index in the B-tree index. The secondary index can be directly used to determine the index element corresponding to the deleted data record as the target index element, and then delete the target index element.
[0119] Taking data table 1 as an example, the first field is field F1, and the second field is the ROWID field. Assume that the first data record inserted into data table 1 is as follows, the data of the ROWID field is "15", the data of field F1 is "23", the data of field F2 is "32", and the data of field F3 is "143". Then the first index data includes the first index value "23" and the second index value "15".
[0120] ROWID Field Field F1 Field F2 Field F3 15 23 32 143
[0121] After deleting the data record with ROWID "15" from data table 1, the index element with secondary index "15" is found as the target index element according to the B-tree search algorithm, and then the target index element is deleted.
[0122] The following three examples illustrate how to use B-tree indexes to find data records.
[0123] <Example 1>
[0124] The process of searching for data records using the B-tree index may include steps S302-S306.
[0125] Step S302: Receive a query request sent by a client, where the query request includes a third index value, and the third index value is the value of the first field of the query object.
[0126] Step S304: According to the B-tree search algorithm, an index element having the same primary index as the third index value is searched in the B-tree index as the target index element.
[0127] Step S306: According to the pointer corresponding to the target index element, obtain the data record corresponding to the target index element and return it to the client.
[0128] In this way, all data records that meet the query request can be found.
[0129] Take data table 1 as an example, the first field is field F1, and the second field is the ROWID field. The value of the first field of the query object is "18", that is, the third index value is 18. There are 2 target index elements found from the B-tree index, and there are 2 corresponding data records, specifically:
[0130] ROWID Field Field F1 Field F2 Field F3 4 18 34 134 5 18 35 135
[0131] <Example 2>
[0132] The process of searching for data records using the B-tree index may include steps S402-S408.
[0133] Step S402: Receive a query request sent by the client, where the query request includes a fourth index value and a fifth index value, where the fourth index value is the value of the first field of the query object, and the fifth index value is the value of the second field of the query object.
[0134] Step S404: According to the B-tree search algorithm, search the B-tree index for an index element whose primary index is the same as the fourth index value as a candidate index element.
[0135] Step S406: According to the B-tree search algorithm, search for an index element whose secondary index is the same as the fifth index value in the candidate index elements as the target index element.
[0136] Step S408: According to the pointer corresponding to the target index element, obtain the data record corresponding to the target index element and return it to the client.
[0137] In this way, the only data record that meets the query request can be found.
[0138] Taking data table 1 as an example, the first field is field F1, and the second field is the ROWID field. The value of the first field of the query object is "18", and the value of the second field of the query object is "4", that is, the fourth index value is "18", and the fifth index value is "4", then there are 2 candidate index elements found from the B-tree index. Using the B-tree characteristics to perform a binary search among the 2 candidate index elements, an index element with the same secondary index and the fifth index value is found. Finally, there is 1 target index element determined, and there is 1 corresponding data record, specifically:
[0139] ROWID Field Field F1 Field F2 Field F3 4 18 34 134
[0140] <Example 3>
[0141] If the second field is the primary key field of the data table or the ROWID field of the data table, in this case, the data in the second field of the data table does not have duplication. If the second field is the primary key field of the data table or the ROWID field of the data table, in this case, the data in the second field does not have duplication. The process of searching for data records using the B-tree index may include steps S502-S506.
[0142] Step S502: Receive a query request sent by a client, where the query request includes a sixth index value, and the sixth index value is a value of a second field of the query object.
[0143] Step S504: According to the B-tree search algorithm, an index element having the same secondary index value as the sixth index value is searched in the B-tree index as a target index element.
[0144] Step S506: According to the pointer corresponding to the target index element, obtain the data record corresponding to the target index element and return it to the client.
[0145] Take data table 1 as an example, the first field is field F1, and the second field is the ROWID field. The value of the second field of the query object is "12", that is, the sixth index value is "12", and there is 1 target index element found from the B-tree index, and there is 1 corresponding data record, specifically:
[0146] ROWID Field Field F1 Field F2 Field F3 12 27 42 142
[0147] The data processing method provided by the embodiment of the present disclosure, the B-tree insertion algorithm and the B-tree search algorithm are implemented based on the principle of binary search. When encountering N repeated data in the first field, the number of searches for the second field can be reduced from N times to log2N times.
[0148] The data processing method provided by the embodiment of the present disclosure can establish a B-tree index for a data table by combining a primary index and a secondary index. When there are duplicates in the primary index, the secondary index can be further searched, thereby reducing the number of searches and improving the index update speed.
[0149] The data processing method provided by the embodiment of the present disclosure optimizes the storage format of the database B-tree index and improves the performance of database data update.
[0150] <Device Example>
[0151] See also Figure 7 As shown, the embodiment of the present disclosure provides a data processing device. The data processing device 30 includes the following modules:
[0152] The data record inserting module 10 is used to insert a first data record into a data table, where the data table includes a first field and a second field.
[0153] The index element creation module 20 is used to create an index element for the first data record in a B-tree index according to first index data. The B-tree index is pre-configured so that each index element includes a primary index corresponding to the first field and a secondary index corresponding to the second field. The first index data includes a first index value and a second index value, the first index value is the value of the first field of the first data record, and the second index value is the value of the second field of the first data record.
[0154] The index element creation module 20 includes:
[0155] The first insertion position determination submodule 21 is used to determine a first insertion position corresponding to the first index value according to the first index value and the primary index of the index element in the B-tree index according to the B-tree insertion algorithm.
[0156] The first creation submodule 22 is configured to create an index element for the first data record at the first insertion position if no index element exists at the first insertion position.
[0157] The second insertion position determination submodule 23 is used to determine the second insertion position corresponding to the second index value according to the B-tree insertion algorithm based on the second index value and the secondary index of the existing index element at the first insertion position when an index element already exists at the first insertion position.
[0158] The second creation submodule 24 is configured to create an index element for the first data record at the second insertion position if an index element already exists at the first insertion position.
[0159] Optionally, the second field is a primary key field of the data table or a ROWID field of the data table.
[0160] In an example, the data processing device 30 may also include a data record deletion module and an index element deletion module.
[0161] The data record deletion module is used to delete the first data record from the data table.
[0162] The index element deletion module is used to delete the index element corresponding to the first data record from the B-tree index after the first data record is deleted.
[0163] In one example, the index element deletion module includes a first search submodule, a second search submodule and a first deletion submodule.
[0164] A first search submodule, configured to search the B-tree index for an index element with the same primary index as the first index value as a candidate index element according to a B-tree search algorithm;
[0165] A second search submodule is used to search for an index element whose secondary index is the same as the second index value in the candidate index elements according to a B-tree search algorithm as a target index element;
[0166] The first deletion submodule is used to delete the target index element from the B-tree index.
[0167] In one example, the index element deletion module includes a third search submodule and a second deletion submodule.
[0168] A third search submodule is used to search the B-tree index for an index element with the same secondary index value as the second index value as a target index element according to a B-tree search algorithm;
[0169] The second deletion submodule is used to delete the target index element from the B-tree index.
[0170] In an example, the data processing device 30 may further include a first data query module.
[0171] The first data query module is used to receive a query request sent by a client, wherein the query request includes a third index value, and the third index value is the value of a first field of the query object; according to a B-tree search algorithm, an index element with a first-level index that is the same as the third index value is searched in the B-tree index as a target index element; according to a pointer corresponding to the target index element, a data record corresponding to the target index element is obtained and returned to the client.
[0172] In an example, the data processing device 30 may further include a second data query module.
[0173] The second data query module is used to receive a query request sent by a client, wherein the query request includes a fourth index value and a fifth index value, wherein the fourth index value is the value of a first field of the query object, and the fifth index value is the value of a second field of the query object; according to a B-tree search algorithm, an index element with a first-level index identical to the fourth index value is searched out in the B-tree index as a candidate index element; according to the B-tree search algorithm, an index element with a second-level index identical to the fifth index value is searched out in the candidate index elements as a target index element; and according to a pointer corresponding to the target index element, a data record corresponding to the target index element is obtained and returned to the client.
[0174] In an example, the data processing device 30 may further include a third data query module.
[0175] The third data query module is used to receive a query request sent by a client, wherein the query request includes a sixth index value, and the sixth index value is the value of the second field of the query object; according to a B-tree search algorithm, an index element whose secondary index is the same as the sixth index value is searched in the B-tree index as a target index element; according to a pointer corresponding to the target index element, a data record corresponding to the target index element is obtained and returned to the client.
[0176] See also Figure 8 As shown, an embodiment of the present disclosure provides a data processing device. The data processing device 50 includes a processor 51 and a memory 52. The memory 52 stores computer executable commands, and when the computer executable commands are executed by the processor 51, the data processing method described in the method embodiment of the present disclosure is implemented.
[0177] <Readable Storage Medium Embodiment>
[0178] This embodiment provides a computer-readable storage medium. The computer-readable storage medium stores computer-executable commands, and when the computer-executable commands are executed by a processor, the data processing method described in the method embodiment of the present disclosure is implemented.
[0179] The present disclosure may be a system, a method and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present disclosure.
[0180] A computer-readable storage medium may be a tangible device that can hold and store instructions used by an instruction execution device. A computer-readable storage medium may be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. More specific examples of computer-readable storage media (a non-exhaustive list) include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a raised structure in a groove on which instructions are stored, and any suitable combination of the foregoing. As used herein, a computer-readable storage medium is not to be interpreted as a transient signal per se, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (e.g., a light pulse through a fiber optic cable), or an electrical signal transmitted through a wire.
[0181] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0182] The computer program instructions for performing the operation of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions may be executed entirely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be customized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present disclosure.
[0183] Various aspects of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.
[0184] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0185] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0186] The flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the systems, methods and computer program products according to multiple embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of an instruction, and a part of a module, a program segment or an instruction contains one or more executable instructions for realizing the specified logical function. 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 consecutive boxes 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 and / or the flowchart, and the combination of the boxes in the block diagram and / or the flowchart can be implemented by a dedicated hardware-based system that performs the specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions. It is well known to those skilled in the art that it is equivalent to implement it by hardware, implement it by software, and implement it by combining software and hardware.
[0187] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The choice of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements in the marketplace, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein. The scope of the present disclosure is defined by the appended claims.
Claims
1. A data processing method, characterized in that: include: Inserting a first data record into a data table, wherein the data table includes a first field and a second field; Creating an index element for the first data record in a B-tree index according to the first index data; wherein the B-tree index is preconfigured so that each index element includes a primary index corresponding to the first field and a secondary index corresponding to the second field; the first index data includes a first index value and a second index value, the first index value is a value of the first field of the first data record, and the second index value is a value of the second field of the first data record; The step of creating an index element for the first data record in a B-tree index according to the first index data includes: Determine, according to the first index value and the primary index of the index element in the B-tree index, a first insertion position corresponding to the first index value according to a B-tree insertion algorithm; If no index element exists at the first insertion position, create an index element for the first data record at the first insertion position; In the case where an index element already exists at the first insertion position, a second insertion position corresponding to the second index value is determined according to the B-tree insertion algorithm based on the second index value and the secondary index of the existing index element at the first insertion position, and an index element is created for the first data record at the second insertion position.
2. The method according to claim 1, characterized in that The second field is the primary key field of the data table or the ROWID field of the data table.
3. The method according to claim 1, characterized in that: The method further comprises: Deleting the first data record from the data table; After the first data record is deleted, deleting the index element corresponding to the first data record from the B-tree index; The deleting the index element corresponding to the first data record from the B-tree index includes: According to a B-tree search algorithm, an index element having a primary index having the same value as the first index value is searched in the B-tree index as a candidate index element; According to the B-tree search algorithm, an index element having the same secondary index as the second index value is searched from the candidate index elements as the target index element; The target index element is deleted from the B-tree index.
4. The method according to claim 2, characterized in that: Also includes: Deleting the first data record from the data table; After the first data record is deleted, deleting the index element corresponding to the first data record from the B-tree index; The deleting the index element corresponding to the first data record from the B-tree index includes: According to the B-tree search algorithm, searching the B-tree index for an index element with the same secondary index value as the second index value as the target index element; The target index element is deleted from the B-tree index.
5. The method according to claim 1, characterized in that Also includes: Receive a query request sent by a client, where the query request includes a third index value, and the third index value is a value of a first field of a query object; According to the B-tree search algorithm, an index element having the same primary index as the third index value is searched in the B-tree index as a target index element; According to the pointer corresponding to the target index element, the data record corresponding to the target index element is obtained and returned to the client.
6. The method according to claim 1, characterized in that Also includes: Receive a query request sent by a client, wherein the query request includes a fourth index value and a fifth index value, wherein the fourth index value is a value of a first field of the query object, and the fifth index value is a value of a second field of the query object; According to a B-tree search algorithm, searching in the B-tree index for an index element with the same primary index as the fourth index value as a candidate index element; According to the B-tree search algorithm, searching for an index element with the same secondary index as the fifth index value in the candidate index elements as the target index element; According to the pointer corresponding to the target index element, the data record corresponding to the target index element is obtained and returned to the client.
7. The method according to claim 2, characterized in that Also includes: Receive a query request sent by a client, where the query request includes a sixth index value, and the sixth index value is a value of a second field of a query object; According to the B-tree search algorithm, an index element having the same secondary index as the sixth index value is searched in the B-tree index as a target index element; According to the pointer corresponding to the target index element, the data record corresponding to the target index element is obtained and returned to the client.
8. A data processing device, characterized in that: include: A data record inserting module, used for inserting a first data record into a data table, wherein the data table includes a first field and a second field; an index element creation module, configured to create an index element for the first data record in a B-tree index according to first index data; wherein the B-tree index is pre-configured so that each index element includes a primary index corresponding to the first field and a secondary index corresponding to the second field; the first index data includes a first index value and a second index value, the first index value is a value of the first field of the first data record, and the second index value is a value of the second field of the first data record; The index element creation module includes: A first insertion position determination submodule, configured to determine a first insertion position corresponding to the first index value according to the first index value and the primary index of the index element in the B-tree index and in accordance with a B-tree insertion algorithm; A first creation submodule, configured to create an index element for the first data record at a first insertion position if no index element exists at the first insertion position; A second insertion position determination submodule, configured to determine, when an index element already exists at the first insertion position, a second insertion position corresponding to the second index value according to the second index value and the secondary index of the existing index element at the first insertion position according to a B-tree insertion algorithm; The second creation submodule is used to create an index element for the first data record at the second insertion position if an index element already exists at the first insertion position.
9. A data processing device, characterized in that: The invention comprises a processor and a memory; the memory stores computer executable commands, and when the computer executable commands are executed by the processor, the method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: Computer executable instructions are stored, and when the computer executable instructions are executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Method and device for creating sharing indexes of a plurality of database tables
CN103793401A
Data management method and device, electronic equipment and storage medium
CN110019213A