B + tree merging method and device, equipment, storage medium and program product
By extracting and sorting key-value pairs from the first leaf node of the B+ tree and writing them into the second leaf node of the merged B+ tree based on structural parameters, the problem of increased complexity caused by the excessive size of the B+ tree is solved, achieving efficient data integration and resource saving.
Patent Information
- Application Number
- CN202511571543.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-30
- Publication Date
- 2026-02-03
AI Technical Summary
When the size of a B+ tree becomes too large, the complexity of query and insertion operations increases significantly, leading to longer system response times. Existing technologies frequently adjust the B+ tree structure, consuming computational resources and being inefficient.
By extracting key-value pairs from the first leaf nodes of at least two B+ trees to be merged, sorting them in ascending order of key values, and writing the key-value pairs into the second leaf node of the merged B+ tree based on pre-obtained structural parameters, a parent node of the second leaf node is generated, thus forming the merged B+ tree.
It reduces operational complexity, decreases computational resource consumption, improves data integration processing efficiency, and avoids a large number of node changes and tree depth changes.
Smart Images

Figure CN121455951A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the technical field of computer, and particularly relates to a B+ tree merging method and device, equipment, storage medium and program product. BACKGROUND
[0002] With the rapid development of information technology, the amount of data generated by system operation increases dramatically. As a balanced tree structure, B+ tree becomes an ideal carrier for recording running data due to its excellent query ability, ensuring the efficiency of data access and update. However, in practical application, the performance of B+ tree is closely related to its size, and running data is continuously generated. When the size of B+ tree is too large, not only the complexity of query and insertion operation will be significantly increased, but also the system response time will be increased and the overall performance will be reduced. Therefore, in order to ensure the query and update efficiency of running data, a new B+ tree is often opened to continue to record the newly added running data when the current used B+ tree reaches a certain size.
[0003] However, when it is necessary to persistently store and manage running data, in order to improve the efficiency of data retrieval, statistical analysis and consistency maintenance, it is often necessary to integrate the data scattered in multiple B+ trees into one B+ tree. The main technical means to realize the integration function at present is to insert nodes into one of the B+ trees one by one. However, when the amount of data to be integrated is large, frequent adjustment of the structure of B+ tree will lead to a significant increase in operation complexity, consume a large amount of computing resources, and prolong the processing time. Therefore, how to efficiently integrate the data in multiple B+ trees is a technical problem to be solved at present. SUMMARY
[0004] In order to solve the above technical problems, the present disclosure provides a B+ tree merging method, device, equipment, storage medium and program product.
[0005] The first aspect of the embodiment of the present disclosure provides a B+ tree merging method, which comprises: obtaining at least two B+ trees to be merged; extracting key-value pairs from the first leaf nodes of the at least two B+ trees to be merged, and sorting the key-value pairs in ascending order according to the values of the keys; based on the pre-obtained structure parameters, sequentially writing the key-value pairs into the second leaf nodes of the merged B+ tree, and generating the upper nodes of the second leaf nodes to obtain the merged B+ tree.
[0006] The second aspect of the embodiment of the present disclosure provides a B+ tree merging device, which comprises: an obtaining module, configured to obtain at least two B+ trees to be merged; extracting key-value pairs from the first leaf nodes of the at least two B+ trees to be merged, and sorting the key-value pairs in ascending order according to the values of the keys; generating, based on the pre-acquired structure parameters, the second leaf nodes of the merged B+ tree by sequentially writing the key-value pairs into the second leaf nodes of the merged B+ tree, and generating upper nodes of the second leaf nodes to obtain the merged B+ tree.
[0007] A third aspect of the embodiments of the present disclosure provides a computer device, including a memory and a processor, and a computer program, wherein the memory stores the computer program, and when the computer program is executed by the processor, the B+ tree merging method of the first aspect is implemented.
[0008] A fourth aspect of the embodiments of the present disclosure provides a computer readable storage medium, and the storage medium stores a computer program, and when the computer program is executed by a processor, the B+ tree merging method of the first aspect is implemented.
[0009] A fifth aspect of the embodiments of the present disclosure provides a computer program product, including a computer program, and when the computer program is executed by a processor, the B+ tree merging method of the first aspect is implemented.
[0010] Compared with the prior art, the technical solutions provided by the embodiments of the present disclosure have the following advantages: In the B+ tree merging method, device, equipment, storage medium and program product provided by the embodiments of the present disclosure, by acquiring at least two B+ trees to be merged, extracting key-value pairs from the first leaf nodes of the at least two B+ trees to be merged, and sorting the key-value pairs in ascending order according to the values of the keys, based on the pre-acquired structure parameters, sequentially writing the key-value pairs into the second leaf nodes of the merged B+ tree, and generating upper nodes of the second leaf nodes to obtain the merged B+ tree, when integrating data on multiple B+ trees, the key-value pairs are extracted from the first leaf nodes of the B+ trees to be merged and written into the second leaf nodes of the merged B+ tree, and then the upper nodes of the second leaf nodes are generated to obtain the complete merged B+ tree, instead of inserting nodes in bulk into one B+ tree, thereby avoiding a large number of node changes and changes in tree depth, reducing the complexity of operations, reducing the consumption of computing resources, and improving the processing efficiency of data integration. BRIEF DESCRIPTION OF DRAWINGS
[0011] The accompanying drawings, which are incorporated into and form part of the specification, illustrate embodiments consistent with the present disclosure and, together with the specification, serve to explain the principles of the present disclosure.
[0012] In order to more clearly illustrate the technical solutions in the embodiments of the present disclosure or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or prior art description. Obviously, for those of ordinary skill in the art, other drawings can also be obtained based on these drawings without any creative effort.
[0013] Figure 1 is a flowchart of a B+ tree merging method provided by an embodiment of the present disclosure. Figure 2 is a schematic diagram of a B+ tree merging method provided by an embodiment of the present disclosure. Figure 3 is a structural schematic diagram of a B+ tree merging device provided by an embodiment of the present disclosure. Figure 4 is a structural schematic diagram of a computer device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0014] In order to more clearly illustrate the above-mentioned purposes, features and advantages of the present disclosure, the solutions of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.
[0015] In the following description, many specific details are set forth in order to provide a thorough understanding of the present disclosure, but the present disclosure can also be implemented in other ways different from those described herein; obviously, the embodiments in the description are only some of the embodiments of the present disclosure, not all the embodiments.
[0016] It should be understood that each step recorded in the method embodiments of the present disclosure can be executed in different order and / or in parallel. In addition, the method embodiments can include additional steps and / or omit the execution of the steps shown. The scope of the present disclosure is not limited in this respect.
[0017] Figure 1 is a flowchart of a B+ tree merging method provided by an embodiment of the present disclosure. The method can be executed by a B+ tree merging device, which can be realized in software and / or hardware. The B+ tree merging device can be configured in an electronic device, such as a server or a terminal. The terminal specifically includes a mobile phone, a computer, a tablet computer and the like. As shown in the figure, the B+ tree merging method provided by the embodiment includes the following steps. Figure 1 S101, acquiring at least two B+ trees to be merged. S101, acquiring at least two B+ trees to be merged.
[0018] The B+ tree in the embodiments of the present disclosure is a balanced multi-way lookup tree, which is a variant of the B tree. The leaf nodes are used to store index information and actual data records (or pointers to data records) in the form of key-value pairs. The non-leaf nodes are used to store index information, guiding the search process of the actual data records. The specific rule definition manner of the B+ tree (such as the relationship between the index information in the parent node and the corresponding relationship of the sub-tree, the relationship between the index information in the parent node and the index information in the child node, etc.) is not limited here.
[0019] In the embodiments of the present disclosure, the B+ tree merging device can first acquire at least two B+ trees to be merged when it is necessary to integrate the data in the at least two B+ trees to be merged, so that all the data is stored in one B+ tree.
[0020] In an exemplary embodiment of the present disclosure, the B+ tree merging device can periodically perform merging processing on the B+ trees continuously generated for recording running data, acquire the B+ trees generated in a target time period, and determine the B+ trees as the B+ trees to be merged. The B+ tree merging device can also acquire at least two B+ trees to be merged according to a user instruction.
[0021] S102, extracting key-value pairs from the first leaf nodes of the at least two B+ trees to be merged, and sorting the key-value pairs in ascending order of the values of the keys.
[0022] The first leaf node in the embodiments of the present disclosure can be understood as a leaf node in the B+ tree to be merged.
[0023] In the embodiments of the present disclosure, after acquiring the at least two B+ trees to be merged, the B+ tree merging device can extract all the key-value pairs in each first leaf node in each B+ tree to be merged, and sort all the acquired key-value pairs in ascending order of the values of the keys. Any sorting algorithm can be used, such as bubble sort, selection sort, insertion sort, quick sort, heap sort, and bucket sort, which is not limited here.
[0024] In an exemplary embodiment of the present disclosure, the B+ tree merging device can sort the key-value pairs after extracting the key-value pairs from each first leaf node in each B+ tree to be merged. The key-value pairs can also be sorted during the extraction process, which is not limited here.
[0025] S103, based on the pre-acquired structure parameters, sequentially writing the key-value pairs into the second leaf nodes of the merged B+ tree, and generating the upper nodes of the second leaf nodes, to obtain the merged B+ tree.
[0026] The structural parameter in the embodiments of the present disclosure can be understood as a parameter related to the structural definition of the B+ tree. For example, the structural parameter can include the order of the B+ tree, the space load rate of the node, and the like, which are not limited herein.
[0027] The second leaf node in the embodiments of the present disclosure can be understood as a leaf node in the merged B+ tree.
[0028] In the embodiments of the present disclosure, after obtaining all the key-value pairs to be integrated and sorting the key-value pairs according to the values of the keys, the B+ tree merging device can write the key-value pairs in sequence to the second leaf node of the merged B+ tree according to the pre-obtained structural parameters of the B+ tree. Specifically, it can be determined whether a new second leaf node needs to be created and the next key-value pair is written to the newly created second leaf node based on the structural parameters of the B+ tree, until all the key-value pairs are written to the second leaf node, and the upper nodes of the second leaf node including the root node are generated, thereby obtaining the merged B+ tree.
[0029] In an exemplary embodiment of the present disclosure, the B+ tree merging device can generate the upper nodes after all the second leaf nodes are generated and written, or can generate the upper nodes during the generation and writing of the second leaf nodes, which are not limited herein.
[0030] The embodiments of the present disclosure can obtain at least two B+ trees to be merged, extract key-value pairs from the first leaf nodes of the at least two B+ trees to be merged, sort the key-value pairs in ascending order according to the values of the keys, write the key-value pairs to the second leaf node of the merged B+ tree in sequence based on the pre-obtained structural parameters, and generate the upper nodes of the second leaf node to obtain the merged B+ tree. When integrating data on multiple B+ trees, the key-value pairs are extracted from the first leaf nodes of the B+ trees to be merged and written to the second leaf node of the merged B+ tree, and the upper nodes of the second leaf node are generated to obtain the complete merged B+ tree, which can replace the bulk insertion of nodes into one B+ tree, thereby avoiding a large number of node changes and changes in tree depth, reducing the complexity of the operation, reducing the consumption of computing resources, and improving the processing efficiency of data integration.
[0031] In some embodiments, S101 can comprise: obtaining first leaf node chain tables of the at least two B+ trees to be merged; and S102 can comprise: extracting a current key-value pair with the smallest key value in each first leaf node chain table respectively, storing a target current key-value pair with the smallest key value in each current key-value pair into a second leaf node chain table created in advance, and extracting a next current key-value pair from the first leaf node chain table to which the target current key-value pair belongs, repeating the steps of extracting a current key-value pair and storing a target current key-value pair into the second leaf node chain table until each key-value pair in each first leaf node chain table is traversed.
[0032] Specifically, the leaf nodes of the B+ tree are connected to each other through pointers to form a chain table, through which efficient sequential traversal in the B+ tree can be performed, and the B+ tree merging device obtaining the first leaf nodes in the at least two B+ trees to be merged is essentially required to obtain the key-value pairs in the first leaf nodes of the at least two B+ trees to be merged, and therefore the first leaf node chain tables of the at least two B+ trees to be merged can be directly obtained. When the key-value pairs in the first leaf nodes of each B+ tree to be merged are sorted in ascending order of the key values, each first leaf node chain table can be traversed, and a current key-value pair with the smallest key value in the chain table is extracted from the first leaf node of the first leaf node chain table. Since the key-value pairs in the first leaf node of the first leaf node chain table are arranged in ascending order of the key values, the key-value pairs can be sequentially traversed in the order of the first leaf nodes in the first leaf node chain table and the order of the key-value pairs in the first leaf nodes. The current key-value pair being traversed is the current key-value pair with the smallest key value. After the current key-value pairs with the smallest key value in each first leaf node chain table are extracted, the key values in each current key-value pair are compared, and a target current key-value pair with the smallest key value is stored in a second leaf node chain table created in advance. The next current key-value pair is extracted from the first leaf node chain table to which the target current key-value pair belongs, compared with the key values of the current key-value pairs extracted from other first leaf node chain tables, and stored in the second leaf node chain table as a next target current key-value pair. The steps of extracting a current key-value pair and storing a target current key-value pair into the second leaf node chain table are repeated until each key-value pair in each first leaf node chain table is traversed, which can save the time for querying the next node in the B+ trees to be merged, and further improve the processing efficiency of data integration.
[0033] Figure 2 is a schematic diagram of a B+ tree merging method provided by an embodiment of the present disclosure, as Figure 2As shown, the B+ tree merging device can obtain first leaf node linked lists of the at least two B+ trees to be merged, store the key-value pairs extracted from the first leaf nodes in the first leaf node linked lists in the second leaf node linked list in ascending order of the values of the keys, and then write the key-value pairs in the second leaf node linked list into the second leaf nodes of the merged B+ tree in sequence, generate the upper nodes of the second leaf nodes, and obtain the merged B+ tree.
[0034] Optionally, when storing the target current key-value pair with the smallest value of the key in the second leaf node linked list pre-created, the B+ tree merging device can, in response to multiple target current key-value pairs containing the same value of the key in the target current key-value pair, store, based on the creation times of the at least two B+ trees to be merged pre-obtained, the target current key-value pair of the B+ tree to be merged corresponding to the first leaf node linked list to which the target current key-value pair belongs and having the latest creation time into the second leaf node linked list.
[0035] Specifically, when comparing the values of the keys in the current key-value pairs extracted from the first leaf node linked lists to determine the target current key-value pair to be stored in the second leaf node linked list, if there are multiple target current key-value pairs containing the same value of the key and being the smallest, the B+ tree merging device can, based on the creation times of the at least two B+ trees to be merged pre-obtained, determine the target current key-value pair of the B+ tree to be merged corresponding to the first leaf node linked list and having the latest creation time as the target current key-value pair to be stored in the second leaf node linked list, and determine that the other target current key-value pairs are not to be stored in the second leaf node linked list, but when extracting the next current key-value pair, the operation of extracting the next current key-value pair is performed for each first leaf node linked list to which the target current key-value pair belongs, so that when the key-value pair conflict occurs, the latest key-value pair is used to overwrite the previous key-value pair.
[0036] In some other embodiments, the structure parameters can include a space load rate and / or an order of the B+ tree. When the structure parameters include the space load rate, S103 can include: calculating a ratio of a sum of a space usage of the current second leaf node and a data amount of the current key-value pair to be written and a preset node space size; in response to the ratio being less than or equal to the space load rate, writing the current key-value pair to be written into the current second leaf node; otherwise, writing the current key-value pair to be written into the next second leaf node.
[0037] Specifically, the B+ tree merging device can write the key-value pairs into the second leaf nodes of the merged B+ tree in sequence based on the pre-acquired structure parameters. For each key-value pair, before writing the key-value pair into the current second leaf node, the B+ tree merging device calculates the sum of the space usage of the current second leaf node and the data amount of the current key-value pair to be written, and calculates the ratio of the sum of the space usage and the data amount to the preset node space size. If the ratio is less than or equal to the space load rate, it can be determined that the preset space load rate will not be exceeded after the key-value pair is written, and thus the current key-value pair to be written can be written into the current second leaf node. If the ratio is greater than the space load rate, the current key-value pair to be written is written into the next second leaf node. In this way, the merged B+ tree has space elasticity, and frequent splitting and merging caused by subsequent insertion of new nodes can be avoided.
[0038] When the structure parameters include the order, S103 can include: in response to the number of key-value pairs written in the current second leaf node being less than the order, writing the current key-value pair to be written into the current second leaf node, otherwise writing the current key-value pair to be written into the next second leaf node.
[0039] Specifically, the B+ tree merging device can write the key-value pairs into the second leaf nodes of the merged B+ tree in sequence based on the pre-acquired structure parameters. For each key-value pair, before writing the key-value pair into the current second leaf node, the B+ tree merging device calculates the sum of the space usage of the current second leaf node and the data amount of the current key-value pair to be written, and calculates the ratio of the sum of the space usage and the data amount to the preset node space size. If the ratio is less than or equal to the space load rate, it can be determined that the preset space load rate will not be exceeded after the key-value pair is written, and thus the current key-value pair to be written can be written into the current second leaf node. If the ratio is greater than the space load rate, the current key-value pair to be written is written into the next second leaf node. In this way, the merged B+ tree has space elasticity, and frequent splitting and merging caused by subsequent insertion of new nodes can be avoided.
[0040] When the structure parameters include the space load rate and the order, the B+ tree merging device can determine the space usage of the current second leaf node and the number of key-value pairs written in the current second leaf node. If the ratio of the sum of the space usage and the data amount of the current key-value pair to be written to the preset node space size is less than or equal to the space load rate, and the number of key-value pairs written in the current second leaf node is less than the order, the current key-value pair to be written is written into the current second leaf node. If at least one of the above two conditions is not met, the current key-value pair to be written is written into the next second leaf node.
[0041] In some embodiments, S103 can include: in response to each key-value pair being written into the second leaf node, generating the upper nodes of the second leaf node from bottom to top until the root node of the merged B+ tree is generated.
[0042] Specifically, the B+ tree merging device can generate the upper layer nodes of the second leaf node from bottom to top after each key-value pair has been written into the second leaf node or after each key-value pair except the key-value pair conflict has been written into the second leaf node. Specifically, the B+ tree merging device can first generate the parent node of the second leaf node, and then further generate the parent node of the parent node until the root node of the merged B+ tree is generated.
[0043] Optionally, the B+ tree merging device can also create or update the parent node of the second leaf node after writing the key-value pair into the newly created second leaf node, create or update the parent node of the internal node after writing the index information into the newly created internal node, until each key-value pair has been written into the second leaf node or each key-value pair except the key-value pair conflict has been written into the second leaf node, and the root node is also created and filled.
[0044] Figure 3 is a structural schematic diagram of a B+ tree merging device provided by an embodiment of the present disclosure. As shown in Figure 3 the B+ tree merging device 300 includes an acquisition module 310, an extraction module 320, and a generation module 330. The acquisition module 310 is configured to acquire at least two B+ trees to be merged. The extraction module 320 is configured to extract key-value pairs from the first leaf nodes of the at least two B+ trees to be merged, and sort the key-value pairs in ascending order of the values of the keys. The generation module 330 is configured to write the key-value pairs into the second leaf node of the merged B+ tree in sequence based on the pre-acquired structure parameters, and generate the upper layer nodes of the second leaf node to obtain the merged B+ tree.
[0045] Optionally, the acquisition module 310 is specifically configured to acquire the first leaf node linked list of each of the at least two B+ trees to be merged. The extraction module 320 is specifically configured to extract the current key-value pair with the smallest value of the key in each first leaf node linked list, store the target current key-value pair with the smallest value of the key in each current key-value pair into the pre-created second leaf node linked list, and extract the next current key-value pair from the first leaf node linked list to which the target current key-value pair belongs. The steps of extracting the current key-value pair and storing the target current key-value pair into the second leaf node linked list are repeated until each key-value pair in each first leaf node linked list is traversed.
[0046] Optionally, the extraction module 320 is specifically used to respond to multiple target current key-value pairs containing the same key value, and then, based on the creation time of the at least two B+ trees to be merged obtained in advance, store the target current key-value pair with the latest creation time of the B+ tree to be merged among the multiple target current key-value pairs into the second leaf node linked list.
[0047] Optionally, the structural parameters include space load rate. The generation module 330 includes: a calculation unit, used to calculate the ratio of the sum of the current space usage of the second leaf node and the data volume of the key-value pair to be written to a preset node space size; and a writing unit, used to write the key-value pair to be written to the current second leaf node if the ratio is less than or equal to the space load rate, otherwise write the key-value pair to be written to the next second leaf node.
[0048] Optionally, the structural parameters include the order. Specifically, the generation module 330 is used to write the current key-value pair to be written to the current second leaf node if the number of key-value pairs written in the current second leaf node is less than the order; otherwise, it writes the current key-value pair to be written to the next second leaf node.
[0049] Optionally, the generation module 330 is specifically configured to generate the upper-level nodes of the second leaf nodes from bottom to top in response to each of the key-value pairs having been written to the second leaf node, until the root node of the merged B+ tree is generated.
[0050] The B+ tree merging device provided in this embodiment can execute the method described in any of the above embodiments, and its execution method and beneficial effects are similar, so they will not be described again here.
[0051] Figure 4 This is a schematic diagram of the structure of a computer device provided in an embodiment of this disclosure.
[0052] like Figure 4 As shown, the computer device may include a processor 410 and a memory 420 storing computer program instructions.
[0053] Specifically, the processor 410 may include a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits that can be configured to implement the embodiments of this application.
[0054] The memory 420 can include mass storage for data or instructions. As an example and not by way of limitation, the memory 420 can include a Hard Disk Drive (HDD), a floppy disk drive, a flash memory, a Compact Disc (CD) or other optical disk, a Universal Serial Bus (USB) drive, or a combination of two or more of these. The memory 420 can be removable and / or non-removable (or fixed) as appropriate. The memory 420 can be internal or external as appropriate. In particular embodiments, the memory 420 is non-volatile, solid-state memory. In particular embodiments, the memory 420 includes a Read-Only Memory (ROM). Where appropriate, this ROM can be mask-programmed ROM, programmable ROM (PROM), erasable PROM (EPROM), electrically erasable PROM (EEPROM), electrically alterable ROM (EAROM), or flash memory, or a combination of two or more of these. The transceiver 430 can communicate bi-directionally with one or more devices, either wired or wirelessly. As an example and not by way of limitation, the transceiver 430 can include a modem, a network card (wireless or wired), or a radio frequency transmitter and / or receiver. The transceiver 430 can communicate with the network 460 through a wired or wireless connection. The transceiver 430 can include one or more antennas or antenna arrays, as appropriate. In particular embodiments, the transceiver 430 can be used to exchange data with a base station, a device, another computer, or a server. In particular embodiments, the transceiver 430 can be used to exchange data with a base station, a device, another computer, or a server.
[0055] The processor 410 performs the steps of the B+ tree merge method provided by embodiments of the present disclosure by reading and executing computer program instructions stored in the memory 420.
[0056] In one example, the computer device can also include a transceiver 430 and a bus 440. As shown, the processor 410, the memory 420, and the transceiver 430 are connected through the bus 440 and complete communication among each other. Figure 4
[0057] Bus 440 includes a hardware, software, or both that couples components of computer system 400 to each other. As an example without limitation, bus 440 can include an Accelerated Graphics Port (AGP) or other graphics bus, an Extended Industry Standard Architecture (EISA) bus, a Front Side BUS (FSB), a Hyper Transport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an InfiniBand (IB) interconnect, a Low Pin Count (LPC) bus, a memory bus, a Micro Channel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local (VLB) bus, or some other suitable bus or interconnect, or a combination of two or more of these. Bus 440 can include one or more buses, where appropriate. Although this application describes and illustrates a particular bus, this application contemplates any suitable bus or interconnect.
[0058] The embodiment of the present disclosure further provides a computer readable storage medium, which can store a computer program. When the computer program is executed by a processor, the processor implements the B+ tree merging method provided by the embodiment of the present disclosure.
[0059] The storage medium can include, for example, a memory 420 storing computer program instructions, which can be executed by a processor 410 of the B+ tree merging device to complete the B+ tree merging method provided by the embodiments of the present disclosure. Alternatively, the storage medium can be a non-transitory computer readable storage medium, for example, a ROM, a random access memory (RAM), a compact disc read-only memory (CD-ROM), a magnetic tape, a floppy disk, and an optical data storage device, etc. The computer program can be written in any combination of one or more programming languages to implement the program code for performing the operations of the embodiments of the present disclosure, including an object-oriented programming language, such as Java, C++, etc., and a conventional procedural programming language, such as a "C" language or similar programming languages. The program code can be executed completely on a user computing device, partially on a user device, as an independent software package, partially on a user computing device and partially on a remote computing device, or completely on a remote computing device or server.
[0060] The embodiments of the present disclosure further provide a computer program product, comprising a computer program, which, when executed by a processor, causes the processor to implement the B+ tree merging method provided by the embodiments of the present disclosure.
[0061] It should be noted that, in this document, relational terms such as "first" and "second", and the like, are used solely to distinguish one entity or action from another entity or action, without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises", "comprising", or any other variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but can include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element preceded by "comprises a" does not, without more constraints, foreclose the existence of additional identical elements in the process, method, article, or apparatus that comprises the element.
[0062] The above description is merely one implementation of the present disclosure, and those skilled in the art can understand or implement the present disclosure based on the above description. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to these embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A B+ tree merging method, characterized by, The method comprises: obtaining at least two B+ trees to be merged; extracting key-value pairs from first leaf nodes of the at least two B+ trees to be merged, and sorting the key-value pairs in ascending order of key values; based on the pre-obtained structure parameters, sequentially writing the key-value pairs into second leaf nodes of a merged B+ tree, and generating upper nodes of the second leaf nodes to obtain the merged B+ tree.
2. The method of claim 1, wherein, The obtaining of the at least two B+ trees to be merged comprises: obtaining first leaf node chains of the at least two B+ trees to be merged respectively; The extracting of the key-value pairs from the first leaf nodes of the at least two B+ trees to be merged and the sorting of the key-value pairs in ascending order of key values comprise: extracting a current key-value pair with the smallest key value from each first leaf node chain, storing a target current key-value pair with the smallest key value in each current key-value pair into a pre-created second leaf node chain, and extracting a next current key-value pair from the first leaf node chain to which the target current key-value pair belongs, repeating the steps of extracting a current key-value pair and storing a target current key-value pair into the second leaf node chain until each key-value pair in each first leaf node chain is traversed.
3. The method of claim 2, wherein, The storing of the target current key-value pair with the smallest key value in each current key-value pair into the pre-created second leaf node chain comprises: in response to multiple target current key-value pairs containing the same key value in the target current key-value pair, storing a target current key-value pair with the latest creation time of the B+ tree to be merged to which the multiple target current key-value pairs belong into the second leaf node chain based on the pre-obtained creation time of the at least two B+ trees to be merged.
4. The method of claim 1, wherein, The structure parameters comprise a space load rate, and the sequentially writing of the key-value pairs into the second leaf nodes of the merged B+ tree based on the pre-obtained structure parameters comprises: calculating a ratio of a sum of a space usage of a current second leaf node and a data amount of a current key-value pair to be written and a preset node space size; in response to the ratio being less than or equal to the space load rate, writing the current key-value pair to be written into the current second leaf node, otherwise writing the current key-value pair to be written into a next second leaf node.
5. The method of claim 1, wherein, The structure parameters comprise a degree, and the sequentially writing of the key-value pairs into the second leaf nodes of the merged B+ tree based on the pre-obtained structure parameters comprises: in response to a number of key-value pairs written into a current second leaf node being less than the degree, writing a current key-value pair to be written into the current second leaf node, otherwise writing the current key-value pair to be written into a next second leaf node.
6. The method of claim 1, wherein, The generating of the upper nodes of the second leaf nodes comprises: in response to each key-value pair being written into the second leaf node, generating upper nodes of the second leaf node from bottom to top until a root node of the merged B+ tree is generated.
7. A B+ tree merging apparatus, characterized by comprising: The apparatus comprises: an obtaining module configured to obtain at least two B+ trees to be merged; An extraction module is configured to extract key-value pairs from a first leaf node of the at least two B+ trees to be merged, and sort the key-value pairs in ascending order of the values of the keys. A generation module is configured to sequentially write the key-value pairs into a second leaf node of a merged B+ tree based on pre-acquired structure parameters, and generate an upper node of the second leaf node to obtain the merged B+ tree.
8. A computer device, comprising: Comprise: a memory; a processor; and a computer program; wherein the computer program is stored in the memory and configured to be executed by the processor to implement the B+ tree merging method as claimed in any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The storage medium has a computer program stored therein, and when the computer program is executed by a processor, the B+ tree merging method as claimed in any one of claims 1-6 is implemented.
10. A computer program product comprising a computer program, characterized in that, The computer program is executed by the processor to implement the B+ tree merging method as claimed in any one of claims 1-6.
