Method for creating an index tree and terminal
By using concurrent threads and binary search to sort and partition database table records, generating and merging subtrees, the problem of long index tree creation time is solved, improving index tree creation efficiency and database query performance.
Patent Information
- Application Number
- CN202311052247.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-21
- Publication Date
- 2025-11-28
- Estimated Expiration
- 2043-08-21
AI Technical Summary
In existing technologies, the index tree creation process is time-consuming, which affects database query efficiency.
By employing concurrent thread technology, multiple subtrees are generated by sorting and partitioning the records in the database table, and then merged into an index tree. The binary search method is used to improve efficiency.
Significantly reduces index tree creation time, improves creation efficiency, and enhances database query performance.
Smart Images

Figure CN117216054B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of database data processing, and in particular to an index tree creation method and terminal. BACKGROUND
[0002] At present, all systems have the need to store data, and therefore need to rely on databases. Among the types of databases, there are relational databases and non-relational databases, and as the amount of data increases, there are also higher requirements for data queries. Generally, databases already have various indexes that can quickly provide data queries. Taking mysql as an example, it uses innodb as the database index structure, and innodb uses B+ tree as the data structure for index storage. The characteristics of B+ tree are that non-leaf nodes are used to store index data, leaf nodes are used to store specific data, and the front and rear pointers are used to associate data, which can effectively improve the efficiency of range queries. As an important data mechanism of innodb, the index tree provides the function of fast index query, but in general, creating an index tree is a time-consuming operation. It mainly scans the data one by one, places it in the index tree according to the index field in each piece of data, sorts it according to the sorting result, and changes and splits the branches of the entire index tree, that is, the addition of new indexes to the index tree may cause changes to the entire index tree, which consumes a lot of time. SUMMARY
[0003] The technical problem to be solved by the present application is to provide an index tree creation method and terminal that can improve the efficiency of index tree creation.
[0004] To solve the above technical problems, one technical solution adopted by the present application is:
[0005] An index tree creation method, comprising:
[0006] receiving an index tree creation request, the index tree creation request including the fields of the library table of the index tree to be created;
[0007] sorting all records in the library table based on the fields, and dividing all sorted records into multiple record sets according to the fields;
[0008] starting concurrent threads matching the number of record sets, and each thread generating a corresponding sub-tree according to the record set it matches;
[0009] merging all generated sub-trees into an index tree.
[0010] To solve the above technical problems, another technical solution adopted by the present application is:
[0011] An index tree creation terminal comprises a memory, a processor and a computer program stored in the memory and executable on the processor, and the processor implements the following steps when executing the computer program:
[0012] receiving an index tree creation request, the index tree creation request comprising a field of a library table to be created into an index tree;
[0013] sorting all records in the library table based on the field, and dividing all sorted records into a plurality of record sets according to the field;
[0014] starting concurrent threads matching the number of the record sets, each thread generating a corresponding sub-tree according to the record set matched by the thread;
[0015] merging all generated sub-trees into an index tree.
[0016] The present application has the beneficial effect that, when creating an index tree, the field content of a library table to which an index needs to be added is sorted, then the overall data of the library table is divided into a plurality of data ranges according to the sorting result, then a sub-tree is created for data in different data ranges through a corresponding number of concurrent processes, and finally the final index tree is assembled according to a plurality of sub-trees. Through this way of sorting and concurrently creating sub-trees, the time consumption for creating the entire index tree can be greatly reduced, and the creation efficiency of the index tree can be greatly improved. BRIEF DESCRIPTION OF DRAWINGS
[0017] Figure 1 A step flow chart of an index tree creation method according to an embodiment of the present application;
[0018] Figure 2 A structure schematic diagram of an index tree creation terminal according to an embodiment of the present application;
[0019] Figure 3 A schematic diagram of an index tree constructed in an index tree creation method according to an embodiment of the present application. DETAILED DESCRIPTION
[0020] The technical content, purposes and effects of the present application will be described in detail below in combination with the embodiments and the accompanying drawings.
[0021] Please refer to Figure 1 An index tree creation method comprises the following steps:
[0022] receiving an index tree creation request, the index tree creation request comprising a field of a library table to be created into an index tree;
[0023] sort all records in the library table based on the field, and divide all sorted records into a plurality of record sets according to the field;
[0024] start concurrent threads matching the number of record sets, and each thread generates a corresponding sub-tree according to the record set matched by the thread;
[0025] merge all generated sub-trees into an index tree.
[0026] As can be seen from the above description, the beneficial effects of the present application are that when creating an index tree, the field content of the library table that needs to be added to the index is sorted, then the overall data of the library table is divided into multiple data ranges according to the sorting result, and then the creation of sub-trees is performed by a corresponding number of concurrent processes for data in different data ranges, and finally the final index tree is assembled according to multiple sub-trees. Through this way of sorting and concurrently creating sub-trees, the time-consuming of creating the entire index tree can be greatly reduced, and the creation efficiency of the index tree can be greatly improved.
[0027] Further, the dividing of all sorted records into a plurality of record sets according to the field comprises:
[0028] adopting a binary method to divide all sorted records into a plurality of record sets according to the field.
[0029] As can be seen from the above description, by dividing all sorted records in the library table by the binary method, on the one hand, the division efficiency can be improved, and on the other hand, the division operation is also simplified, which is convenient and fast.
[0030] Further, the merging of all generated sub-trees into an index tree comprises:
[0031] determining the division nodes corresponding to the plurality of record sets;
[0032] sorting all generated sub-trees according to their corresponding fields to form a sub-tree queue;
[0033] taking out corresponding sub-trees from the sub-tree queue in order in groups of two sub-trees, for each group of sub-trees taken out, determining their corresponding division nodes as target division nodes corresponding to each group of sub-trees, determining the target division nodes as parent nodes of each group of sub-trees, and the parent nodes store the values of the fields corresponding to the target division nodes;
[0034] after determining the parent nodes of all sub-trees, sorting the currently determined parent nodes according to their corresponding fields to form a parent node queue;
[0035] sequentially taking out corresponding parent nodes from the parent node queue in order with two parent nodes as a group, for each group of taken-out parent nodes, determining their corresponding partition nodes as target partition nodes corresponding to each group of parent nodes, determining the target partition nodes as upper-level parent nodes of each group of parent nodes, and the upper-level parent nodes storing values of fields corresponding to the target partition nodes;
[0036] returning to performing the step of sorting the currently determined parent nodes according to their corresponding fields until reaching the root node.
[0037] As can be seen from the above description, on the basis of dividing all sorted records into multiple record sets according to the index field by the dichotomy method and concurrently generating corresponding index sub-trees for each record set, when the index sub-trees are merged into an index tree, in the direction from the leaf node to the root node, two data objects are taken as a group, and each level of parent nodes is iteratively generated upwards until the root node, thereby completing the merging of the entire index tree, which is simple and convenient.
[0038] Further, the merging of all generated sub-trees into an index tree comprises:
[0039] determining partition nodes corresponding to the multiple record sets;
[0040] sorting the partition nodes according to their corresponding fields to form a partition node queue;
[0041] determining a partition node arranged in a middle position in the partition node queue as a root node, and the root node storing a value of a field corresponding to the determined partition node;
[0042] adding the root node to a reference node set, dividing a field queue composed of the fields into a corresponding number of sub-queues according to the reference node set, determining a partition node arranged in a middle position in each sub-queue as a child node of the root node, and the child node storing a value of a field corresponding to the determined partition node;
[0043] adding the child node to the reference node set, dividing the field queue into a corresponding number of sub-queues according to the reference node set, and determining a partition node arranged in a middle position in each sub-queue as a child node of the child node, and the child node storing a value of a field corresponding to the determined partition node;
[0044] returning to performing the step of adding the child node to the reference node set until reaching a sub-tree.
[0045] As can be known from the above description, on the basis that all the sorted records are divided into a plurality of record sets according to the index field by dichotomy, each record set concurrently generates a corresponding index sub-tree, when the index tree is combined according to the sub-trees, in the direction from the root node to the leaf node, each level of the sub-nodes is iteratively generated by dichotomy in turn until the leaf node, so that the combination of the whole index tree is completed, and the operation is simple and convenient.
[0046] Further, the index tree is a B+ tree.
[0047] As can be known from the above description, by constructing the B+ tree as the index tree, the non-leaf nodes in the index tree store the index values, i.e., the key values, and the leaf nodes store the index values and the corresponding data values, i.e., the records, and the leaf nodes are associated by using the chain table, so that the range of data query can be reduced and the query efficiency is improved.
[0048] Please refer to Figure 2 An index tree creation terminal, comprising a memory, a processor and a computer program stored in the memory and executable on the processor, when the processor executes the computer program, the following steps are implemented:
[0049] receiving an index tree creation request, the index tree creation request comprising a field of a library table to be created as an index tree;
[0050] sorting all the records in the library table based on the field, and dividing all the sorted records into a plurality of record sets according to the field;
[0051] starting a concurrent thread matched with the number of the record sets, and each thread generates a corresponding sub-tree according to the matched record set;
[0052] combining all the generated sub-trees into an index tree.
[0053] As can be known from the above description, the beneficial effects of the present application are as follows: when the index tree is created, the library table field content to which the index needs to be added is sorted, then the overall data of the library table is divided into a plurality of data ranges according to the sorting result, then the sub-trees are created by a corresponding number of concurrent processes for the data in different data ranges, and finally the final index tree is assembled according to the plurality of sub-trees, by this way of sorting and concurrently creating the sub-trees, the time consumption for creating the whole index tree can be greatly reduced, and the creation efficiency of the index tree is greatly improved.
[0054] Further, the dividing of all the sorted records into a plurality of record sets according to the field comprises:
[0055] dividing all the sorted records into a plurality of record sets according to the field by dichotomy.
[0056] From the above description, by dividing all records in the sorted library table by dichotomy, on the one hand, the division efficiency can be improved, and on the other hand, the division operation is simplified, convenient and fast.
[0057] Further, the merging of all generated sub-trees into an index tree comprises:
[0058] determining the division nodes corresponding to the plurality of record sets;
[0059] sorting all generated sub-trees according to their corresponding fields to form a sub-tree queue;
[0060] taking out corresponding sub-trees from the sub-tree queue in order in groups of two sub-trees, for each group of sub-trees taken out, determining their corresponding division nodes as target division nodes corresponding to each group of sub-trees, determining the target division nodes as parent nodes of each group of sub-trees, and the parent nodes store values of fields corresponding to the target division nodes;
[0061] after the parent nodes of all sub-trees are determined, sorting the currently determined parent nodes according to their corresponding fields to form a parent node queue;
[0062] taking out corresponding parent nodes from the parent node queue in order in groups of two parent nodes, for each group of parent nodes taken out, determining their corresponding division nodes as target division nodes corresponding to each group of parent nodes, determining the target division nodes as upper-level parent nodes of each group of parent nodes, and the upper-level parent nodes store values of fields corresponding to the target division nodes;
[0063] returning to the step of sorting the currently determined parent nodes according to their corresponding fields until the root node is reached.
[0064] From the above description, on the basis of dividing all sorted records into a plurality of record sets according to index fields by dichotomy and concurrently generating corresponding index sub-trees for each record set, when merging sub-trees into an index tree, in the direction from leaf nodes to the root node, two data objects are taken as a group, and each level of parent nodes is iteratively generated upwards until the root node, thereby completing the merging of the entire index tree, which is simple and convenient.
[0065] Further, the merging of all generated sub-trees into an index tree comprises:
[0066] determining the division nodes corresponding to the plurality of record sets;
[0067] sorting the division nodes according to their corresponding fields to form a division node queue;
[0068] Determine the partition node arranged in the middle position in the queue as a root node, and the root node stores the value of the field corresponding to the determined partition node;
[0069] Add the root node to a reference node set, divide a field queue composed of the fields into a corresponding number of sub-queues according to the reference node set, determine the partition node arranged in the middle position in each sub-queue as a child node of the root node, and the child node stores the value of the field corresponding to the determined partition node;
[0070] Add the child node to the reference node set, divide the field queue into a corresponding number of sub-queues according to the reference node set, determine the partition node arranged in the middle position in each sub-queue as a child node of the child node, and the child node stores the value of the field corresponding to the determined partition node;
[0071] Return to the step of adding the child node to the reference node set until a sub-tree is reached.
[0072] As can be known from the above description, on the basis of dividing all the sorted records into a plurality of record sets according to the index field by dichotomy and concurrently generating corresponding index sub-trees for each record set, when the index sub-trees are merged into an index tree, in the direction from the root node to the leaf node, each level of child node is iteratively generated in turn by dichotomy until the leaf node, thereby completing the merging of the entire index tree, and the operation is simple and convenient.
[0073] Further, the index tree is a B+ tree.
[0074] As can be known from the above description, by constructing a B+ tree as the index tree, the non-leaf nodes in the index tree store index values, i.e., key values, the leaf nodes store index values and corresponding data values, i.e., records, and the leaf nodes are associated by using a linked list, thereby being able to reduce the range of data query and improve the query efficiency.
[0075] The above index tree creation method and terminal can be applied to a scenario in which an index tree needs to be constructed, in particular, a B+ tree, and the following specific embodiments are described:
[0076] Embodiment One
[0077] Please refer to Figure 1 A method for creating an index tree, comprising:
[0078] Receiving an index tree creation request, the index tree creation request including fields of a library table to be created;
[0079] In a specific implementation, when receiving an operation of adding an index for a field of a certain table, a subsequent creation operation can be triggered by a special asynchronous thread;
[0080] Sort all records in the table based on the field, and divide all sorted records into multiple record sets according to the field;
[0081] When the index creation operation is triggered, the asynchronous thread performs a full table scan, and sorts the full table according to the index field, for example, in ascending order from small to large;
[0082] If the field is a numerical value, it is sorted in ascending order from small to large, and if the field is a character type, each character corresponds to a unicode code, and the records are sorted in ascending order according to the unicode code of each character;
[0083] Among them, the binary method can be used to divide all sorted records into multiple record sets according to the field;
[0084] For example, for a create index request with an index field of user ID, the user ID in the table ranges from 001 to 100, and when the binary method is used for division, it can be divided into four ranges of 001-025, 025-050, 051-075, and 076-100, forming four corresponding record sets;
[0085] Start a number of concurrent threads matching the number of record sets, and each thread generates a corresponding sub-tree according to the record set it matches;
[0086] Taking the above division into four record sets as an example, four concurrent threads are started, and each thread generates a corresponding sub-tree according to the corresponding record set, and the four processes are executed concurrently, wherein each sub-tree is generated in the same way as the existing index tree;
[0087] Merge all generated sub-trees into an index tree;
[0088] When the above four sub-trees are generated, there is a waiting thread that organizes the four sub-trees into a complete index tree structure;
[0089] Optionally, the index tree is a B+ tree.
[0090] Embodiment Two
[0091] This embodiment defines a way to merge all generated sub-trees into an index tree, specifically:
[0092] Determine the division nodes corresponding to the multiple record sets;
[0093] Sort all the generated sub-trees according to their corresponding fields to form a sub-tree queue;
[0094] Take corresponding sub-trees from the sub-tree queue in order in groups of two sub-trees, for each group of sub-trees, determine their corresponding split nodes as the target split nodes corresponding to each group of sub-trees, determine the target split nodes as the parent nodes of each group of sub-trees, and the parent nodes store the values of the fields corresponding to the target split nodes;
[0095] After determining the parent nodes of all sub-trees, sort the currently determined parent nodes according to their corresponding fields to form a parent node queue;
[0096] Take corresponding parent nodes from the parent node queue in order in groups of two parent nodes, for each group of parent nodes, determine their corresponding split nodes as the target split nodes corresponding to each group of parent nodes, determine the target split nodes as the upper-level parent nodes of each group of parent nodes, and the upper-level parent nodes store the values of the fields corresponding to the target split nodes;
[0097] Return to the step of sorting the currently determined parent nodes according to their corresponding fields until the root node is reached;
[0098] Suppose there is an account table with 100w account incentives, and it is now necessary to index according to the user ID in it;
[0099] Suppose the binary search method is used, and three split nodes are obtained, which are user ID=50w, user ID=25w, and user ID=75w, then four sub-trees are constructed, and the sub-tree queue obtained by sorting according to user ID from small to large is: the sub-tree with user ID range [1, 25w], the sub-tree with user ID range (25w, 50w], the sub-tree with user ID range (50w, 75w], and the sub-tree with user ID range (75w, 100w].
[0100] Take corresponding sub-trees from the sub-tree queue in order in groups of two sub-trees, for example, the first time, the sub-tree with user ID range [1, 25w] and the sub-tree with user ID range (25w, 50w] are taken out; the second time, the sub-tree with user ID range (50w, 75w] and the sub-tree with user ID range (75w, 100w] are taken out;
[0101] The split node of the first group of sub-trees is user ID=25w, thus, the parent node of the first group of sub-trees is the user ID data corresponding to user ID=25w, wherein the sub-tree with user ID ranging from 1 to 25w is on the left side of the parent node, and the sub-tree with user ID ranging from 25w to 50w is on the right side of the parent node;
[0102] The split node of the second group of sub-trees is user ID=75w, thus, the parent node of the second group of sub-trees is the user ID data corresponding to user ID=75w, wherein the sub-tree with user ID ranging from 50w to 75w is on the left side of the parent node, and the sub-tree with user ID ranging from 75w to 100w is on the right side of the parent node;
[0103] Then, the user ID data corresponding to user ID=25w and the user ID data corresponding to user ID=75w are sorted to form a parent node queue;
[0104] Then, the parent nodes are taken out in sequence in groups of two, in this embodiment, there is only one group of parent nodes in the parent node queue, which are the user ID data corresponding to user ID=25w and the user ID data corresponding to user ID=75w;
[0105] It is determined that the split node in the group of parent nodes is user ID=50w, thus, their parent node is the user ID data corresponding to user ID=50w, since the root node has been reached at this time, the complete index tree is constructed, and the constructed index tree is shown in Figure 3 In the figure, the leaf nodes store not only the index field but also the record corresponding to the index field (not shown in the figure).
[0106] Embodiment Three
[0107] This embodiment defines another way of how to combine all the generated sub-trees into an index tree, specifically:
[0108] Determine the split nodes corresponding to the plurality of record sets;
[0109] Sort the split nodes according to their corresponding fields to form a split node queue;
[0110] Determine the split node in the middle position of the split node queue as the root node, and the root node stores the value of the field corresponding to the determined split node;
[0111] The root node is added to a reference node set, and a queue composed of the fields is divided into a corresponding number of sub-queues according to the reference node set, and a dividing node arranged in a middle position in each sub-queue is determined as a child node of the root node, and the child node stores a value of the field corresponding to the determined dividing node;
[0112] The child node is added to a reference node set, and the field queue is divided into a corresponding number of sub-queues according to the reference node set, and a dividing node arranged in a middle position in each sub-queue is determined as a child node of the child node, and the child node stores a value of the field corresponding to the determined dividing node;
[0113] For a non-leaf node, a dividing node arranged in a middle position in an interval composed of two child nodes is exactly a parent node of the two child nodes;
[0114] The step of adding the child node to the reference node set is returned to be executed until a sub-tree is reached.
[0115] Suppose that there is an account table, and there are 100w account incentives in the account table, and it is required to establish an index according to a user ID in the account table;
[0116] Suppose that a binary search is used, and three dividing nodes are obtained, which are user ID=50w, user ID=25w, and user ID=75w, and then four sub-trees are constructed, and a sub-tree queue obtained by sorting the sub-trees in ascending order of user ID is: a sub-tree with a user ID range of [1, 25w], a sub-tree with a user ID range of (25w, 50w], a sub-tree with a user ID range of (50w, 75w], and a sub-tree with a user ID range of (75w, 100w].
[0117] The dividing nodes are sorted according to the fields corresponding to the dividing nodes to form a dividing node queue: user ID=25w, user ID=50w, and user ID=75w;
[0118] A dividing node user ID=50w arranged in a middle position in the dividing node queue is taken as a root node, and the root node stores user ID data corresponding to user ID=50w;
[0119] The root node is added to a reference node set, and a field queue [1, 100w] composed of user IDs is divided into two sub-queues [1, 50w] and (50w, 100w] according to user ID=50w;
[0120] The middle position corresponding to the division node 25w and 75w of the two sub-queues is determined as the child node of the root node, that is, 25w is the left child node of the root node, and 75w is the right child node of the root node;
[0121] At this time, the sub-tree has been reached, so the iteration is terminated, and the sub-tree with the user ID range [1, 25w] is directly taken as the left side of the left child node, and the sub-tree with the user ID range (25w, 50w] is directly taken as the right side of the left child node;
[0122] The sub-tree with the user ID range (50w, 75w] is taken as the left side of the right child node, and the sub-tree with the user ID range (75w, 100w] is taken as the right side of the right child node, and thus the complete index tree is constructed, and the constructed index tree is as shown in Figure 3 The leaf node stores the index field and the record corresponding to the index field (not shown in the figure).
[0123] Embodiment Four
[0124] Please refer to Figure 2 An index tree creation terminal, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor implements each step of the index tree creation method of any one of the above-mentioned embodiments when executing the computer program.
[0125] In summary, the index tree creation method and terminal provided by the present application can sort the library table field content that needs to be added to the index, then divide the overall data of the library table into multiple data ranges according to the sorting result, then create sub-trees for data in different data ranges through a corresponding number of concurrent processes, and finally assemble the final index tree according to multiple sub-trees. When assembling the final index tree, it can be iterated from the root node to the leaf node direction, or from the leaf node direction to the root node direction, to form the final index tree. This method is convenient and flexible, can greatly reduce the time consumption of creating the entire index tree, and greatly improves the creation efficiency of the index tree.
[0126] The above-mentioned embodiments are only examples of the present application, and do not limit the patent scope of the present application. Any equivalent transformation or direct or indirect application in related technical fields based on the content of the specification and drawings of the present application is also included in the patent protection scope of the present application.
Claims
1. A method for creating an index tree, characterized in that, include: Receive an index tree creation request, the index tree creation request including the fields of the database table for which the index tree is to be created; Sort all records in the database table based on the field, and divide all sorted records into multiple record sets according to the field; Start concurrent threads matching the number of records in the set, and each thread generates a corresponding subtree based on its matching record set; Merge all generated subtrees into an index tree; The step of dividing all sorted records into multiple record sets based on the field includes: The sorted records are divided into multiple record sets using a binary search method based on the aforementioned field. The step of merging all generated subtrees into an index tree includes: Determine the partitioning nodes corresponding to the multiple record sets; The partitioning nodes are sorted according to their corresponding fields to form a partitioning node queue; The partition node in the middle position of the partition node queue is determined as the root node, and the root node stores the value of the field corresponding to the determined partition node. The root node is added to the reference node set. Based on the reference node set, the field queue consisting of the fields is divided into a corresponding number of sub-queues. The dividing node in the middle position of each sub-queue is determined as the child node of the root node. The child node stores the value of the field corresponding to the determined dividing node. The child node is added to the reference node set, and the field queue is divided into a corresponding number of sub-queues according to the reference node set. The dividing node in the middle position of each sub-queue is determined as the child node of the child node. The child node stores the value of the field corresponding to the determined dividing node. Return to the step of adding the child node to the reference node set until the subtree is reached.
2. The method for creating an index tree according to claim 1, characterized in that, The step of merging all generated subtrees into an index tree includes: Determine the partitioning nodes corresponding to the multiple record sets; All generated subtrees are sorted according to their corresponding fields to form a subtree queue; Two subtrees are taken out in sequence from the subtree queue. For each group of subtrees, the corresponding partitioning node is determined as the target partitioning node for each group of subtrees. The target partitioning node is determined as the parent node of each group of subtrees. The parent node stores the value of the field corresponding to the target partitioning node. After determining the parent nodes of all subtrees, sort the currently determined parent nodes according to their corresponding fields to form a parent node queue. Two parent nodes are taken out sequentially from the parent node queue. For each group of parent nodes, the corresponding partitioning node is determined as the target partitioning node for each group of parent nodes. The target partitioning node is determined as the parent node above the parent node of each group of parent nodes. The parent node stores the value of the field corresponding to the target partitioning node. Return to the previous step and sort the currently determined parent nodes according to their corresponding fields until the root node is reached.
3. A method for creating an index tree according to any one of claims 1 to 2, characterized in that, The index tree is a B+ tree.
4. A terminal for creating an index tree, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it performs the following steps: Receive an index tree creation request, the index tree creation request including the fields of the database table for which the index tree is to be created; Sort all records in the database table based on the field, and divide all sorted records into multiple record sets according to the field; Start concurrent threads matching the number of records in the set, and each thread generates a corresponding subtree based on its matching record set; Merge all generated subtrees into an index tree; The step of dividing all sorted records into multiple record sets based on the field includes: The sorted records are divided into multiple record sets using a binary search method based on the aforementioned field. The step of merging all generated subtrees into an index tree includes: Determine the partitioning nodes corresponding to the multiple record sets; The partitioning nodes are sorted according to their corresponding fields to form a partitioning node queue; The partition node in the middle position of the partition node queue is determined as the root node, and the root node stores the value of the field corresponding to the determined partition node. The root node is added to the reference node set. Based on the reference node set, the field queue consisting of the fields is divided into a corresponding number of sub-queues. The dividing node in the middle position of each sub-queue is determined as the child node of the root node. The child node stores the value of the field corresponding to the determined dividing node. The child node is added to the reference node set, and the field queue is divided into a corresponding number of sub-queues according to the reference node set. The dividing node in the middle position of each sub-queue is determined as the child node of the child node. The child node stores the value of the field corresponding to the determined dividing node. Return to the step of adding the child node to the reference node set until the subtree is reached.
5. The index tree creation terminal according to claim 4, characterized in that, The step of merging all generated subtrees into an index tree includes: Determine the partitioning nodes corresponding to the multiple record sets; All generated subtrees are sorted according to their corresponding fields to form a subtree queue; Two subtrees are taken out in sequence from the subtree queue. For each group of subtrees, the corresponding partitioning node is determined as the target partitioning node for each group of subtrees. The target partitioning node is determined as the parent node of each group of subtrees. The parent node stores the value of the field corresponding to the target partitioning node. After determining the parent nodes of all subtrees, sort the currently determined parent nodes according to their corresponding fields to form a parent node queue. Two parent nodes are taken out sequentially from the parent node queue. For each group of parent nodes, the corresponding partitioning node is determined as the target partitioning node for each group of parent nodes. The target partitioning node is determined as the parent node above the parent node of each group of parent nodes. The parent node stores the value of the field corresponding to the target partitioning node. Return to the previous step and sort the currently determined parent nodes according to their corresponding fields until the root node is reached.
6. A terminal for creating an index tree according to any one of claims 4 to 5, characterized in that, The index tree is a B+ tree.
Citation Information
Patent Citations
Database index creation method, related device, equipment and storage medium
CN115114293A
Computer data storage management system and methods of indexing a dataspace and searching a computer memory
US5701467A