Data page read-ahead
Patent Information
- Application Number
- PCT/IB2024/062966
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-12-21
- Filing Date
- 2024-12-20
- Publication Date
- 2025-07-17
AI Technical Summary
When cloud databases use B+ tree index structure, they cannot read data pages in batches through the existing read-out mechanism, resulting in poor search performance.
By finding the target node and its sibling nodes on a tree-shaped index structure such as B+ tree or B tree, batch read the data pages of these nodes from disk into memory.
This greatly reduces I/O waiting time for accessing database systems or file systems and improves search performance.
Smart Images

Figure IB2024062966_17072025_PF_FP_ABST
Abstract
Description
Data Page Prefetching - Technical Field
[0001] This application relates to the field of computer technologies, and in particular, to data page prefetching. Background Art
[0002] The development of cloud technologies has promoted the development of cloud databases. Cloud databases use the technology of separating computing and storage, and make full use of the elastic expansion capabilities of cloud storage and cloud computing resources to achieve the on-demand allocation of storage space and computing resources. Currently, many cloud databases adopt a read-ahead mechanism to prefetch data pages on the disk into the memory to reduce the number of disk I / Os, accelerate the search efficiency, and improve the search performance. Common read-ahead mechanisms include, for example, the Linear read-ahead mechanism, the Random read-ahead mechanism, etc. These read-ahead mechanisms can prefetch a batch of data pages with consecutive physical addresses from the disk into the memory, so that subsequent searches can quickly access these data pages in the memory. However, if a cloud database uses a B+Tree index to accelerate searches, since the physical addresses of the data pages corresponding to logically adjacent nodes in the B+Tree are not consecutive but random, the above read-ahead mechanisms cannot be used, and only one data page can be prefetched at a time, and data pages cannot be prefetched in batches. The search performance of cloud databases needs to be improved. Summary of the Invention
[0003] Multiple aspects of this application provide a data page prefetching method, an electronic device, and a storage medium, so as to provide a new data page prefetching method for various tree index structures such as B+Tree or B-Tree.
[0004] An embodiment of this application provides a data page prefetching method, including: in response to a prefetch request including a keyword range, searching for a tree index structure on the disk according to the smallest keyword in the keyword range to determine the target parent node of the target node, where the data page of the target node includes the data corresponding to the smallest keyword in the keyword range; determining, from the children nodes of the target parent node, the target sibling node on the right side of the target node, where the smallest keyword included in the target sibling node is less than the largest keyword in the keyword range; and prefetching the data pages of the target node and its target sibling node on the right side from the disk into the memory.
[0005] An embodiment of this application further provides an electronic device, including: a memory and a processor; the memory is used for storing a computer program; the processor is coupled to the memory and is used for executing the computer program to perform the steps in the data page prefetching method.
[0006] An embodiment of the present application further provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the processor can implement the steps in the data page prefetching method.
[0007] In the embodiment of the present application, the target node and its sibling nodes are found through the parent node on various tree index structures such as B+ trees or B trees, and multiple data pages of the target node and its sibling nodes are prefetched from the disk to the memory in batches. Thus, a new prefetching mechanism for the tree index structure is provided, which greatly reduces the I / O waiting time of the I / O requests for accessing the database system or the file system and can improve the search performance of the database system or the file system. BRIEF DESCRIPTION OF THE DRAWINGS
[0008] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation to the present application. In the drawings:
[0009] FIG. 1 is an architecture diagram of a cloud database adopting a write-once-read-many architecture provided by an embodiment of the present application;
[0010] FIG. 2 is a flowchart of a data page prefetching method provided by an embodiment of the present application;
[0011] FIG. 3 is an exemplary diagram of a traditional prefetching process for a B+ tree;
[0012] FIG. 4 is an exemplary diagram of a new prefetching process for a B+ tree;
[0013] FIG. 5 is a flowchart of another data page prefetching method provided by an embodiment of the present application;
[0014] FIG. 6 is an exemplary diagram of a traditional prefetching process for a B+ tree;
[0015] FIG. 7 is an exemplary diagram of a new prefetching process for a B+ tree;
[0016] FIG. 8 is a flowchart of another data page prefetching method provided by an embodiment of the present application;
[0017] FIG. 9 is a flowchart of another data page prefetching method provided by an embodiment of the present application;
[0018] FIG. 10 is a schematic structural diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0019] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments of this application and the corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in this application without creative efforts belong to the scope of protection of this application.
[0020] In the embodiments of this application, "at least one" means one or more, and "a plurality" means two or more. "And / or" describes the access relationship of associated objects and indicates that three relationships may exist. For example, A and / or B may represent: A exists alone, A and B exist simultaneously, and B exists alone. Among them, A and B may be singular or plural. In the text description of this application, the character generally indicates that the associated objects before and after are in an "or" relationship. In addition, in the embodiments of this application, "first", "second", "third", etc. are only used to distinguish the content of different objects and have no other special meanings.
[0021] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Moreover, the collection, use, and processing of relevant data need to comply with the relevant laws, regulations, and standards of relevant countries and regions, and corresponding operation entrances are provided for users to choose to authorize or reject.
[0022] The development of cloud technology has promoted the development of cloud databases. Through the technology of separating computing from storage, cloud databases make full use of the elastic expansion capabilities of cloud storage and cloud computing resources to achieve the on-demand allocation of P storage space and computing resources. Currently, many cloud databases adopt a read-ahead mechanism to pre-read data pages in the disk into memory to reduce the number of disk I / Os, accelerate the search efficiency, and improve the search performance. Commonly used read-ahead mechanisms include, for example, the Linear read-ahead mechanism, the Random read-ahead mechanism, etc. These read-ahead mechanisms can pre-read a batch of data pages with consecutive physical addresses from the disk into memory so that subsequent searches can quickly access these data pages in memory. However, if a cloud database uses a B+Tree index to accelerate searches, since the physical addresses of data pages corresponding to logically adjacent nodes in the B+Tree are not consecutive but random, the above read-ahead mechanisms cannot be used, and only one data page can be pre-read at a time, unable to pre-read data pages in batches, and the search performance of the cloud database needs to be improved.
[0023] Therefore, the embodiments of the present application provide a data page pre-reading method, an electronic device, and a storage medium. In the embodiments of the present application, the target node and its sibling nodes are found through the parent node on various tree index structures such as B+Tree or B-Tree, and multiple data pages of the target node and its sibling nodes are pre-read from the disk into memory in batches. Thus, a new read-ahead mechanism for tree index structures is provided, greatly reducing the I / O waiting time of I / O requests for accessing the database system or file system, and capable of improving the search performance of the database system or file system.
[0024] FIG. 1 is an architecture diagram of a cloud database adopting a write-once-read-many architecture provided by an embodiment of the present application. Referring to FIG. 1, the cloud database adopting the write-once-read-many architecture includes: a client, a read-write node (also referred to as an RW node), multiple read-only nodes (also referred to as RO nodes), and a storage node.
[0025] Among them, the read-write node is a database computing node that can perform read operations and write operations, can read and write data in the disk of the storage node, and supports operations such as adding, deleting, changing, or searching. The read-only node can only perform searches The operating database computing nodes can only read data from the disks of the storage nodes and cannot write data to the disks of the storage nodes. In practical applications, the client can send write requests or read requests to the RW nodes to write data to the RW nodes and read data from the RW nodes. The client can only send read requests to the R0 nodes and cannot send write requests to the R0 nodes. The data pages in the disks of the storage nodes are pre-read into the memory of the read-write nodes or read-only nodes, so that the client can quickly access these data pages in the memory subsequently, accelerating the search efficiency and improving the search performance.
[0026] The technical solutions provided by the embodiments of the present application are described in detail below with reference to the accompanying drawings.
[0027] In practical applications, for various systems such as database systems and file systems that organize data using B+ trees on disks, the data page pre-reading method provided by the embodiments of the present application can be used for pre-reading. The B+ tree includes non-leaf nodes and leaf nodes from top to bottom. The non-leaf nodes include ^ • nodes and internal nodes. The non-leaf nodes do not store data but only store keys (keys). All data (also referred to as row records) is stored in the data pages of the leaf nodes. The keys in the non-leaf nodes and leaf nodes are arranged in ascending order. For an m-order B+ tree, where m is a positive integer, the number of keys in the root node is [1, m-1], the number of keys in the internal nodes is [m / 2-1, m-1], the data pages of all leaf nodes include all keys (keys), and each leaf node has a pointer to the adjacent leaf node. For more introductions about B+ trees, reference can be made to the related technologies.
[0028] The interval pre-reading for the B+ tree is introduced below with reference to Figure 2. Interval pre-reading refers to pre-reading the data of the keys that fall within the key range. Figure 2 is a flowchart of a data page pre-reading method provided by an embodiment of the present application. Referring to Figure 2, the method may include the following steps 201 to step 203.
[0029] 201> In response to a pre-reading request including a key range, search the B+ tree in the disk according to the minimum key in the key range to determine the target parent node of the target leaf node. The data page of the target leaf node includes the data corresponding to the minimum key in the key range.
[0030] In this embodiment, the pre-read request is used to request to pre-read the data page from the disk to the memory, so that the client can quickly access the data page in the memory later. In practical applications, the pre-read request can be triggered flexibly. For example, when the client initiates a read request for data of a certain keyword to a read-write node or a read-only node, a pre-read request for keywords within a certain range behind the certain keyword can be triggered. For another example, the pre-read request is triggered at a fixed time. For another example, when the trigger condition set on demand is met, the pre-read request is triggered, but it is not limited to this.
[0031] In this embodiment, the triggered pre-read request may include a keyword range. This pre-read request is used to request that the data of keywords falling within the keyword range be pre-read from the disk to the memory. The keyword range refers to a range defined by a minimum keyword and a maximum keyword. For example, the keyword range is [49, 135), 49 is the minimum keyword, and 135 is the maximum keyword. Keywords.
[0032] In this embodiment, in response to the triggered pre-read request, the B+ tree in the disk is searched according to the minimum keyword in the keyword range to determine the target parent node of the target leaf node. The data page of the target leaf node includes the data corresponding to the minimum keyword in the keyword range. The target parent node refers to the parent node of the target leaf node (a non-leaf node). Specifically, the data page of the leaf node stores the keyword and its corresponding data in association. Starting from the root node of the B+ tree, the minimum keyword in the keyword range is compared with the keywords included in the non-leaf nodes on the B+ tree from top to bottom until the target parent node of the target leaf node is found. It can be understood that each comparison involves searching for a node on the B+ tree, and searching for a node on the B+ tree will perform a disk I / O (input / output) once...
[0033] 202. Determine a target sibling node on the right side of the target leaf node from the child nodes of the target parent node, wherein the minimum keyword included in the target sibling node is smaller than the maximum keyword in the keyword range.
[0034] Specifically, in a B+ tree, leaf nodes with the same parent node are sibling nodes to each other, and each leaf node is linked in ascending order of keywords. For a certain leaf node, the keyword of the sibling node on the left side of this leaf node is less than the keyword of this leaf node, and the keyword of the sibling node on the right side of this leaf node is greater than the keyword of this leaf node. Taking Figure 3 as an example, the keywords included in the P2 page corresponding to the first leaf node are: 19, 48; the keywords included in the P3 page corresponding to the second leaf node are: 49, 57; the keywords included in the P4 page corresponding to the third leaf node are: 59, 66. The first leaf node is the sibling node on the left side of the second leaf node, the third leaf node is the sibling node on the right side of the second leaf node, the keyword of the first leaf node is less than the keyword of the second leaf node, and the keyword of the third leaf node is greater than the keyword of the second leaf node.
[0035] Based on the above, based on the size of the keywords included in the leaf node, the target sibling node on the right side of the target leaf node can be determined from the child nodes of the target parent node. The smallest keyword included in the target sibling node is less than the largest keyword in the keyword range, that is, the target sibling node is the target sibling node whose smallest keyword among the sibling nodes on the right side of the target leaf node is less than the largest keyword in the keyword range.
[0036] 203. Read the data pages of the target leaf node and its target sibling node on the right side from the disk into the memory.
[0037] Figure 3 is an exemplary diagram of a traditional prefetching process for a B+ tree. Figure 3 shows a partial B+ tree, and the partial B+ tree includes a root node (ROOT), 1 internal node, and 5 leaf nodes from top to bottom. The keywords included in the P0 page corresponding to the root node are: 19, 200; the keywords included in the P1 page corresponding to the internal node are: 19, 49, 59, 67, 90; the keywords included in the P2 page corresponding to the first leaf node are: 19, 48; the keywords included in the P3 page corresponding to the second leaf node are: 49, 57; the keywords included in the P4 page corresponding to the third leaf node are: 59, 66; the keywords included in the P5 page corresponding to the fourth leaf node are: 67, 88; the keywords included in the P6 page corresponding to the fifth leaf node are: 90, 130.
[0038] «It is necessary to prefetch the data in the interval [49, 90), and the specific prefetching process is as follows.
[0039] SK responds to the prefetch request for the data in the range [49, 90), accesses the B+ tree in the disk, reads the P0 page corresponding to the root node of the B+ tree from the disk into the memory, compares the minimum keyword 49 in the range [49, 90) with the keywords included in the P0 page in the memory, and determines the P1 page corresponding to the internal node to be accessed according to the comparison result. That is, the P1 page is located through the P0 page.
[0040] S2s accesses the B+ tree in the disk to prefetch the P1 page from the disk into the memory, compares the minimum keyword 49 in the range [49, 90) with the keywords included in the P1 page, and determines the P3 page corresponding to the leaf node to be accessed according to the comparison result.
[0041] S3. Accesses the B+ tree in the disk to read the P3 page from the disk into the memory. In this way, in the subsequent access stage, the data corresponding to the keywords from 49 to 58 is searched in the P3 page.
[0042] S4. Reads the P4 page on the B+ tree in the disk into the memory according to the next pointer of the P3 page. In this way, in the subsequent access stage, the data corresponding to the keywords from 59 to 66 is searched in the P4 page.
[0043] S5. Reads the P5 page on the B+ tree in the disk into the memory according to the next pointer of the P4 page. In this way, in the subsequent access stage, the data corresponding to the keywords from 67 to 89 is searched in the P5 page. Thus, the prefetch for the range [49, 90) is completed.
[0044] As can be seen from the example in Figure 3, in the traditional prefetch method for the B+ tree, only after the previous data page is prefetched from the disk into the memory, the next leaf node is searched based on the next pointer of the leaf node corresponding to the previous data page, and the data page of the next leaf node is prefetched from the disk into the memory. At most one data page can be prefetched at a time, and the prefetch efficiency of the data page is relatively low.
[0045] Figure 4 is an exemplary diagram of a new prefetch process for the B+ tree. The partial B+ tree shown in Figure 4 is the same as the partial B+ tree shown in Figure 3 and will not be elaborated here.
[0046] Assume that it is necessary to prefetch the data in the range [49, 90). The specific prefetch process is as follows.
[0047] The SK response pre-reads the request for data in the range [49, 90), accesses the B+ tree in the disk, reads the P0 page corresponding to the root node of the B+ tree from the disk into the memory, compares the minimum keyword 49 in the range [49, 90) with the keywords included in the P0 page in the memory, and determines the P1 page corresponding to the internal node to be accessed according to the comparison result. That is, it locates the P1 page through the P0 page.
[0048] S2. Access the B+ tree in the disk to read the Pl page from the disk into the memory, compare the minimum keyword 49 in the range [49, 90) with the keywords included in the P1 page, and determine the P3 page, P4 page, and P5 page corresponding to the leaf nodes to be accessed according to the comparison result.
[0049] S3. Access the B+ tree in the disk to pre-read the P3 page, P4 page, and P5 page from the disk into the memory. In this way, in the subsequent access stage, search for the data corresponding to the keywords 49 to 58 in the P3 page.
[0050] S4. In the subsequent access stage, find the P4 page in the memory according to the next pointer of the P3 page, and search for the data corresponding to the keywords 59 to 66 in the P4 page. Since the P4 page has been pre-read into the memory, there is no need to initiate a disk I / O to access the disk, reducing the I / O waiting time.
[0051] S5. In the subsequent access stage, find the P5 page in the memory according to the next pointer of the P4 page, and search for the data corresponding to the keywords 67 to 89 in the P5 page. Since the P5 page has been pre-read into the memory, there is no need to initiate a disk I / O to access the disk, reducing the I / O waiting time. Thus, the pre-reading of the range [49, 90) is completed.
[0052] As can be seen from the example in Figure 4, the new pre-reading method for the B+ tree finds the target leaf node and its sibling nodes through the parent node on the B+ tree, and batch pre-reads multiple data pages of the target leaf node and its sibling nodes from the disk into the memory, greatly reducing the I / O waiting time and greatly improving the pre-reading efficiency of the data pages.
[0053] In this embodiment, the data pages of the target leaf node and its right target sibling node in the disk can be prefetched into the memory at one time. Further optionally, the data pages of the target leaf node and its right target sibling node in the disk can be prefetched into the memory in batches, which can avoid the problem of excessive memory pressure in a short time and ensure the stability of the memory.
[0054] In practical applications, when prefetched into the memory in batches, there is no limit to the number of batches and the number of data pages included in each batch. For example, the data pages are prefetched into the memory in 5 batches, and the number of data pages to be prefetched in each batch can be the same or different.
[0055] Further optionally, in order to improve the prefetching effect, the implementation method of prefetching the data pages of the target leaf node and its right target sibling node in the disk into the memory in batches is as follows: detecting the current remaining capacity of the memory; determining the first number of data pages that can be prefetched in the current batch according to the current remaining capacity of the memory; determining the second number of data pages starting from the data page of the first un-prefetched node in the disk as the data pages to be prefetched in the current batch, and prefetching the data pages to be prefetched in the current batch into the memory. The first un-prefetched node is the target leaf node or the target sibling node on the right side of the target leaf node, and the second number is less than or equal to the first number; after waiting for the first preset duration, repeat the step of detecting the current remaining capacity of the memory until all the data pages of the target leaf node and its right target sibling node in the disk are prefetched into the memory.
[0056] In this embodiment, the first number can be flexibly set based on the current remaining capacity of the memory and the size of the data page, and the memory capacity occupied by the first number of data pages does not exceed the current remaining capacity of the memory. For example, the current remaining capacity of the memory is 1 MB (megabyte), the size of a data page is 16 KB (kilobyte), and the first number is at most 64.
[0057] In this embodiment, the data pages of the target leaf node and its right target sibling node in the disk are sequentially prefetched into the memory in batches, and the data page with a smaller keyword is prefetched earlier. Here, the number of data pages prefetched each time is referred to as the second number, and the second number is less than or equal to the first number. The second number prefetched each time can be the same or different. For each prefetch, determine the first un-prefetched node for this prefetch. It can be understood that the first un-prefetched node for the first batch prefetch is the target leaf node; the first un-prefetched node for other batch prefetches is the target sibling node with the smallest keyword that has not been prefetched during the prefetch process of the previous batch.
[0058] In this embodiment, there needs to be an interval of a first preset duration between prefetching of two adjacent batches, and the first preset duration can be flexibly set according to requirements. It can be understood that as time goes by, the current remaining capacity of the memory changes, and setting an interval of the first preset duration between prefetching of two adjacent batches can improve the prefetching effect.
[0059] Further optionally, in order to improve the prefetching effect, before determining the second number of data pages starting from the data page of the first un-prefetched node in the disk as the data pages to be prefetched in the current batch, it is also possible to determine whether the data pages of the most recent third number of batches that have been prefetched into the memory have been accessed; if so, then execute the step of determining the second number of data pages starting from the data page of the first un-prefetched node in the disk as the data pages to be prefetched in the current batch; if not, then wait for a preset second duration and then repeat the step of determining whether the data pages of the most recent third number of batches that have been prefetched into the memory have been accessed. Among them, the third number and the second duration can be flexibly set according to requirements.
[0060] Taking the third number as 5 as an example, if the data pages of the most recent 5 batches that have been prefetched into the memory have been accessed for operations such as searching, modifying, and updating, it indicates that there is a very high probability that the data pages of the current batch will be accessed in a short time. At this time, the prefetching of the data pages of the current batch can be immediately performed. If the data pages of the most recent 5 batches that have been prefetched into the memory have not been accessed for operations such as searching, modifying, and updating, it indicates that there is a very high probability that the data pages of the current batch will not be accessed in a short time. At this time, the prefetching of the data pages of the current batch can be postponed, and after waiting for the preset second duration, it is determined again whether to start the prefetching of the data pages of the current batch.
[0061] The data page prefetching method provided by the embodiments of the present application finds the target leaf node and its sibling nodes through the parent node on the B+ tree, and prefetches multiple data pages of the target leaf node and its sibling nodes from the disk to the memory in batches. Thereby, a new prefetching mechanism for the B+ tree is provided, which greatly reduces the I / O waiting time of the access I / O requests for accessing the database system or the file system, and can improve the search performance of the database system or the file system.
[0062] In practical applications, for interval prefetching of the B+ tree, it may be necessary to find all the leaf nodes through multiple parent nodes on the B+ tree. In order to improve the reliability of data page prefetching, another interval prefetching method for the B+ tree will be introduced below with reference to FIG. 5. FIG. 5 is a flowchart of another data page prefetching method provided by the embodiments of the present application. Referring to FIG. 5, the method may include the following steps 201 to step 205.
[0063] In response to a prefetch request including a keyword range, find the B+ tree in the disk according to the minimum keyword in the keyword range to determine the target parent node of the target leaf node. The data page of the target leaf node includes the data corresponding to the minimum keyword in the keyword range.
[0064] 202. Determine the target sibling node on the right side of the target leaf node from the children of the target parent node. The minimum keyword included in the target sibling node is less than the maximum keyword in the keyword range.
[0065] 203. Prefetch the data pages of the target leaf node and its target sibling node on the right side from the disk into the memory.
[0066] For the implementation manners of steps 201 to 203 in the embodiment shown in FIG. 5, reference may be made to the implementation manners of steps 201 to 203 in the embodiment shown in FIG. 2, which will not be elaborated herein.
[0067] 204. Determine whether the maximum keyword included in the last target sibling node of the target leaf node is less than the maximum keyword in the keyword range; if the judgment result is no, end; if the judgment result is yes, then execute step 205.
[0068] Among them, the last target sibling node of the target leaf node is the target sibling node with the largest keyword among the target sibling nodes of the target leaf node.
[0069] 205. Use the first sibling node on the right side of the target parent node as the new target parent node, and use the first leaf node of the new target parent node as the new target leaf node, and return to execute step 202.
[0070] Figure 6 is an exemplary diagram of the traditional read-ahead process for a B+ tree. The figure shows a partial B+ tree, which from top to bottom includes a root node, two internal nodes, and nine leaf nodes. The keywords included in the P0 page corresponding to the root node are: 19, 98; the keywords included in the P1 page corresponding to the internal node are: 19, 49, 59, 67, 90; the keywords included in the P11 page corresponding to the internal node are: 98, 115, 125, 145; the keywords included in the P2 page corresponding to the leaf node are: 19, 48; the keywords included in the P3 page corresponding to the leaf node are: 49, 57; the keywords included in the P4 page corresponding to the leaf node are: 59, 66; the keywords included in the P5 page corresponding to the leaf node are: 67, 88; the keywords included in the P6 page corresponding to the leaf node are: 90, 93; the keywords included in the P7 page corresponding to the leaf node are: 98, 110; the keywords included in the P8 page corresponding to the leaf node are: 115, 119; the keywords included in the P9 page corresponding to the leaf node are: 125, 130; the keywords included in the P10 page corresponding to the leaf node are: 145, 150.
[0071] It is necessary to perform read-ahead on the data in the interval [49, 135), and the specific read-ahead process is as follows.
[0072] In response to the read-ahead request for the data in the interval [49, 135), the B+ tree in the disk is accessed, the P0 page corresponding to the root node of the B+ tree is read from the disk into the memory, the smallest keyword 49 in the interval [49, 135) is compared with the keywords included in the P0 page in the memory, and according to the comparison result, it is determined that the P1 page corresponding to the internal node needs to be accessed. That is, the P1 page is located through the P0 page.
[0073] S2. Access the B+ tree in the disk to pre-read the P1 page from the disk into the memory, compare the smallest keyword 49 in the interval [49, 135) with the keywords included in the P1 page, and according to the comparison result, determine that the P3 page corresponding to the leaf node needs to be accessed.
[0074] S3. Access the B+ tree in the disk to pre-read the P3 page from the disk into the memory. In this way, in the subsequent access stage, the data corresponding to the keywords from 49 to 58 is searched in the P3 page.
[0075] S4. Prefetch the P4 page on the B+ tree in the disk into the memory according to the next pointer on the P3 page. In this way, during the subsequent access stage, search for the data corresponding to the keywords from 59 to 66 in the P4 page.
[0076] Prefetch the P5 page on the B+ tree in the disk into the memory according to the next pointer on the P4 page. In this way, during the subsequent access stage, search for the data corresponding to the keywords from 67 to 89 in the P5 page.
[0077] Read the P6 page on the B+ tree in the disk into the memory according to the next pointer on the P5 page. In this way, during the subsequent access stage, search for the data corresponding to the keywords from 90 to 97 in the P6 page.
[0078] Read the P7 page on the B+ tree in the disk into the memory according to the next pointer on the P6 page. In this way, during the subsequent access stage, search for the data corresponding to the keywords from 98 to 114 in the P7 page.
[0079] Read the P8 page on the B+ tree in the disk into the memory according to the next pointer on the P7 page. In this way, during the subsequent access stage, search for the data corresponding to the keywords from 115 to 124 in the P8 page.
[0080] Read the P9 page on the B+ tree in the disk into the memory according to the next pointer on the P8 page. In this way, during the subsequent access stage, search for the data corresponding to the keywords from 125 to 135 in the P9 page. Thus, the prefetching of the interval [49, 135) is completed.
[0081] As can be seen from the example in Figure 6, in the traditional prefetching method for B+ trees, only after the previous data page is prefetched from the disk into the memory, the next leaf node is searched based on the next pointer of the leaf node corresponding to the previous data page, and the data page of the next leaf node is prefetched from the disk into the memory. At most, only one data page can be prefetched at a time, and the prefetching efficiency of the data page is relatively low.
[0082] Figure 7 is an exemplary diagram of the new prefetching process for B+ trees. The partial B+ tree shown in Figure 7 is the same as the partial B+ tree shown in Figure 6, and will not be elaborated here.
[0083] «It is necessary to prefetch the data in the interval [49, 135). The specific prefetching process is as follows.
[0084] The SK response pre-reads the request for the data in the interval [49, 135), accesses the B+ tree in the disk, reads the P0 page corresponding to the root node of the B+ tree from the disk into the memory, compares the minimum keyword 49 in the interval [49, 135) with the keywords included in the P0 page in the memory, and determines the P1 page corresponding to the internal node to be accessed according to the comparison result. That is, it locates the P1 page through the P0 page.
[0085] S2. Access the B+ tree in the disk to pre-read the P1 page from the disk into the memory, compare the minimum keyword 49 in the interval [49, 135) with the keywords included in the P1 page, and determine the P3 page, P4 page, P5 page, and P6 page corresponding to the leaf nodes to be accessed according to the comparison result.
[0086] S3. Access the B+ tree in the disk to pre-read the P3 page, P4 page, P5 page, and P6 page from the disk into the memory. In the subsequent access stage, search for the data corresponding to the keywords from 49 to 58 in the P3 page.
[0087] In the subsequent access stage, find the P4 page in the memory according to the next pointer of the P3 page, and search for the data corresponding to the keywords from 59 to 66 in the P4 page.
[0088] In the subsequent access stage, find the P5 page in the memory according to the next pointer of the P4 page, and search for the data corresponding to the keywords from 67 to 89 in the P5 page.
[0089] In the subsequent access stage, find the P6 page in the memory according to the next pointer of the P5 page, and search for the data corresponding to the keywords from 90 to 97 in the P6 page.
[0090] S3. Since the maximum keyword 90 in the P6 page is less than the maximum keyword in the interval [49, 135), pre-read the P11 page on the B+ tree in the disk into the memory according to the next pointer of the P6 page, and determine the P7 page, P8 page, and P9 page corresponding to the leaf nodes to be accessed based on the keywords included in the P11 page.
[0091] S3. Access the B+ tree in the disk to pre-read the P7 page, P8 page, and P9 page from the disk into the memory. In the subsequent access stage, search for the data corresponding to the keywords from 97 to 114 in the P7 page.
[0092] In the subsequent access stage, find the P8 page in memory according to the next pointer of the P7 page, and search for the data corresponding to the keywords from 115 to 114 in the P8 page.
[0093] In the subsequent access stage, find the P9 page in memory according to the next pointer of the P8 page, and search for the data corresponding to the keywords from 125 to 135 in the P9 page. Thus, the prefetching of the interval [49, 135) is completed.
[0094] As can be seen from the example in Figure 7, the new prefetching method for B+ trees finds more involved leaf nodes through multiple parent nodes on the B+ tree, and batches multiple data pages of more involved leaf nodes from disk to memory, greatly reducing the I / O waiting time and greatly improving the prefetching efficiency of data pages.
[0095] The data page prefetching method provided by the embodiments of the present application finds more involved leaf nodes through the parent nodes on the B+ tree, and batches multiple data pages of more involved leaf nodes from disk to memory. Thus, a new prefetching mechanism for B+ trees is provided, greatly improving the prefetching efficiency and reliability of data pages, greatly reducing the I / O waiting time of I / O requests for accessing the database system or file system, and being able to improve the search performance of the database system or file system.
[0096] The interval prefetching for the tree-shaped index structure is introduced below with reference to Figure 8. The tree-shaped index structure is, for example, a B+ tree or a B tree, and there is no limitation thereto. Figure 8 is a flowchart of another data page prefetching method provided by the embodiments of the present application. This method can be applied to a database system or a file system, but is not limited thereto. Referring to Figure 8, this method may include the following steps 801 to step 803.
[0097] 801. In response to a prefetching request including a keyword range, search for the tree-shaped index structure in the disk according to the minimum keyword in the keyword range to determine the target parent node of the target node. The data page of the target node includes the data corresponding to the minimum keyword in the keyword range.
[0098] 802. Determine the target sibling node on the right side of the target node from the child nodes of the target parent node. The minimum keyword included in the target sibling node is less than the maximum keyword in the keyword range.
[0099] 803. Prefetch the data pages of the target node and its target sibling node on the right side from the disk to the memory.
[0100] In this embodiment, if the tree index structure is a B+ tree, the type of the target node is a leaf node; if the tree index structure is a B tree, the type of the target node is a leaf node or a non-leaf node.
[0101] Further optionally, after pre-reading the data pages of the target node and its target sibling node on the right from the disk into the memory, the above method further includes: determining whether the maximum key included in the last target sibling node of the target node is less than the maximum key in the key range; if the determination result is yes, then taking the first sibling node on the right of the target parent node as the new target parent node, and taking the first child node of the new target parent node as the new target node, and repeating the step of determining the target sibling node on the right of the target node from the child nodes of the target parent node until the determination result is no.
[0102] Further optionally, pre-reading the data pages of the target node and its target sibling node on the right from the disk into the memory includes: pre-reading the data pages of the target node and its target sibling node on the right from the disk into the memory in batches.
[0103] Further optionally, pre-reading the data pages of the target node and its target sibling node on the right from the disk into the memory in batches includes: detecting the current remaining capacity of the memory; determining a first quantity of data pages allowed to be pre-read in the current batch according to the current remaining capacity of the memory; determining the second quantity of data pages starting from the data page of the first un-pre-read node in the disk as the data pages to be pre-read in the current batch, and pre-reading the data pages to be pre-read in the current batch into the memory, the first un-pre-read node is the target node or the target sibling node on the right of the target node, and the second quantity is less than or equal to the first quantity; after waiting for a first preset duration, repeating the step of detecting the current remaining capacity of the memory until all the data pages of the target node and its target sibling node on the right in the disk are pre-read into the memory. Before determining the second quantity of data pages starting from the data page of the first un-pre-read node in the disk as the data pages to be pre-read in the current batch, it further includes: determining whether the data pages in the most recent third quantity of batches pre-read into the memory have been accessed; if so, then performing the step of determining the second quantity of data pages starting from the data page of the first un-pre-read node in the disk as the data pages to be pre-read in the current batch; if not, then repeating the step of determining whether the data pages in the most recent third quantity of batches pre-read into the memory have been accessed after waiting for a second preset duration.
[0104]
[0105] It should be noted that the implementation methods of the steps of the data page prefetching method for B-trees are similar to those of the data page prefetching method for B+-trees, and will not be elaborated here.
[0106] The data page prefetching method provided by the embodiments of the present application finds the target node and its sibling nodes through the parent node on the tree-shaped index structure, and prefetches multiple data pages of the target node and its sibling nodes from the disk to the memory in batches. Thereby, a new prefetching mechanism for the tree-shaped index structure is provided, which greatly reduces the I / O waiting time of the access I / O requests for accessing the database system or the file system, and can improve the search performance of the database system or the file system.
[0107] The single-keyword prefetching for the tree-shaped index structure will be introduced below with reference to FIG. 9. The tree-shaped index structure is, for example, a B+-tree or a B-tree, and there is no limitation thereto. FIG. 9 is a flowchart of another data page prefetching method provided by the embodiments of the present application. This method can be applied to a database system or a file system, but is not limited thereto. Referring to FIG. 9, this method may include the following steps 901 to step 903.
[0108] 901. In response to a prefetching request including a keyword, search for the tree-shaped index structure in the disk according to the keyword in the prefetching request to determine the target parent node of the target node. The data page of the target node includes the keyword in the prefetching request.
[0109] In this embodiment, in response to the triggered prefetching request, search for the tree-shaped index structure in the disk according to the keyword in the prefetching request to determine the target parent node of the target node. The data page of the target node includes the keyword in the prefetching request. The target parent node refers to the parent node of the target node (belonging to a non-leaf node). Specifically, the keyword and its corresponding data are associated and saved in the data page of the target node. Starting from the root node of the tree-shaped index structure, compare the keyword in the prefetching request with the keywords included in the nodes on the tree-shaped index structure from top to bottom until the target parent node of the target node is found.
[0110] In this embodiment, if the tree-shaped index structure is a B+-tree, the type of the target node is a leaf node; if the tree-shaped index structure is a B-tree, the type of the target node is a leaf node or a non-leaf node.
[0111] 902. Determine the sibling node on the right side of the target node from the child nodes of the target parent node.
[0112] 903. Prefetch the data pages of the target node and its sibling node on the right side in the disk to the memory.
[0113] In this embodiment, the data pages of the target node and its sibling nodes on the disk can be prefetched into the memory at one time. Further optionally, the data pages of the target node and its sibling nodes on the disk can be prefetched into the memory in batches, which can avoid the problem of excessive memory pressure in a short time and ensure the stability of the memory. It can be understood that prefetching more data pages into the memory can accelerate the query efficiency of the data pages in the memory.
[0114] In practical applications, when prefetched into the memory in batches, there are no restrictions on the number of batches and the number of data pages included in each batch. For example, the data pages are prefetched into the memory in 5 batches, and the number of data pages to be prefetched for each batch can be the same or different.
[0115] For more introduction about the prefetching method of data pages, reference can be made to the relevant content of the foregoing embodiment, which will not be elaborated here.
[0116] The data page prefetching method provided by the embodiment of the present application finds the target node and its sibling nodes through the parent node on the tree index structure, and prefetches multiple data pages of the target node and its sibling nodes from the disk to the memory in batches. Thus, a new prefetching mechanism for the tree index structure is provided, which greatly reduces the I / O waiting time of the access I / O requests for accessing the database system or the file system, and can improve the search performance of the database system or the file system.
[0117] FIG. 10 is a schematic structural diagram of an electronic device provided by the embodiment of the present application. As shown in FIG. 10, the electronic device includes: a memory 11 and a processor 12; the memory 11 is used for storing computer programs and can be configured to store various other data to support operations on the computing platform. Examples of such data include instructions for any application program or method for operating on the computing platform, contact data, phone book data, messages, pictures, videos, etc.
[0118] The memory 11 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0119] The processor 12, coupled to the memory 11, is configured to execute a computer program in the memory 11 for: in response to a prefetch request including a keyword range, looking up a tree index structure in a magnetic disk according to the smallest keyword in the keyword range to determine a target parent node of a target leaf node, where the data page of the target leaf node includes data corresponding to the smallest keyword in the keyword range; determining, from the children of the target parent node, a target sibling node on the right side of the target leaf node, where the smallest keyword included in the target sibling node is less than the largest keyword in the keyword range; and prefetching data pages of the target leaf node and its target sibling node on the right side from the magnetic disk into the memory. After the processor 12 prefetches data pages of the target leaf node and its target sibling node on the right side from the magnetic disk into the memory, it is further configured to: determine whether the largest keyword included in the last target sibling node of the target leaf node is less than the largest keyword in the keyword range; if the determination result is yes, use the first sibling node on the right side of the target parent node as a new target parent node, and use the first child node of the new target parent node as a new target leaf node, and repeat the step of determining the target sibling node on the right side of the target leaf node from the children of the target parent node until the determination result is no. When the processor 12 prefetches data pages of the target leaf node and its target sibling node on the right side in the magnetic disk into the memory, it is configured to: prefetch data pages of the target leaf node and its target sibling node on the right side in the magnetic disk into the memory in batches.
[122] Further optionally, when the processor 12 prefetches the data pages of the target leaf node and its right target sibling node in the disk into the memory in batches, it is used for: detecting the current remaining capacity of the memory; determining the first quantity of data pages allowed to be prefetched in the current batch according to the current remaining capacity of the memory; determining the second quantity of data pages starting from the data page of the first un-prefetched node in the disk as the data pages to be prefetched in the current batch, and prefetching the data pages to be prefetched in the current batch into the memory, the first un-prefetched node being the target leaf node or the target sibling node on the right side of the target leaf node, and the second quantity being less than or equal to the first quantity; after waiting for the first preset duration, repeating the step of detecting the current remaining capacity of the memory until all the data pages of the target leaf node and its right target sibling node in the disk are prefetched into the memory.
[123] Further optionally, before the processor 12 determines the second quantity of data pages starting from the data page of the first un-prefetched node in the disk as the data pages to be prefetched in the current batch, it is also used for: determining whether the data pages of the most recent third quantity of batches prefetched into the memory have been accessed; if so, then performing the step of determining the second quantity of data pages starting from the data page of the first un-prefetched node in the disk as the data pages to be prefetched in the current batch; if not, then waiting for the preset second duration and repeating the step of determining whether the data pages of the most recent third quantity of batches prefetched into the memory have been accessed.
[124] Further optionally, the processor 12 is also used for: in response to a prefetch request including a keyword, searching for a tree-shaped index structure in the disk according to the keyword in the prefetch request to determine the target parent node of the target leaf node, the target leaf node including the keyword in the prefetch request; determining the sibling node on the right side of the target leaf node from the child nodes of the target parent node, and prefetching the data pages of the target leaf node and its right sibling node in the disk into the memory.
[0125] Further optionally, if the tree-shaped index structure is a B+ tree, the type of the target leaf node is a leaf node; if the tree-shaped index structure is a B tree, the type of the target leaf node is a leaf node or a non-leaf node.
[0126] Further optionally, as shown in FIG. 10, the electronic device further includes: other components such as a communication component 13, a display 14, a power supply component 15, an audio component 16, etc. Only some components are schematically shown in FIG. 10, which does not mean that the electronic device only includes the components shown in FIG. 10. In addition, the components within the dashed box in FIG. 10 are optional components, rather than essential components, and can be determined according to the product form of the electronic device. The electronic device in this embodiment can be implemented as a terminal device such as a desktop computer, a laptop computer, a smart phone, or an IOT (Internet of Things) device, or can also be a server device such as a conventional server, a cloud server, or a server array. If the electronic device in this embodiment is implemented as a terminal device such as a desktop computer, a laptop computer, or a smart phone, it may include the components within the dashed box in FIG. 10; if the electronic device in this embodiment is implemented as a server device such as a conventional server, a cloud server, or a server array, it may not include the components within the dashed box in FIG. 10.
[0127] For the detailed implementation process of the processor executing each action, reference can be made to the relevant descriptions in the foregoing method embodiments or device embodiments, and details will not be described herein again.
[0128] Correspondingly, an embodiment of the present application further provides a computer-readable storage medium storing a computer program, and when the computer program is executed, it can implement each step that can be executed by the electronic device in the foregoing method embodiment.
[0129] Correspondingly, an embodiment of the present application further provides a computer program product, including a computer program / instructions, and when the computer program / instructions are executed by a processor, the processor can be caused to implement each step that can be executed by the electronic device in the foregoing method embodiment.
[0130] The above communication component is configured to facilitate communication, in a wired or wireless manner, between the device where the communication component is located and other devices. The device where the communication component is located can access a communication standard-based wireless network, such as a mobile communication network like WiFi (Wireless Fidelity), 2G (2 Generation), 3G (3 Generation), 4G (4 Generation) / LTE (long Term Evolution), 5G (5 Generation), etc., or a combination thereof. In an exemplary embodiment, the communication component receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component further includes a Near Field Communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on Radio Frequency Identification (RFID) technology, The Infrared Data Association (IrDA) technology, Ultra Wide Band (UWB) technology, Bluetooth (Bluetooth, BT) technology and other technologies.
[0131] The above display includes a screen, and the screen can include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a touch panel, the screen can be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors can sense not only the boundaries of touch or swipe actions but also detect the duration and pressure associated with the touch or swipe operation.
[0132] The above power supply component provides power for various components of the device where the power supply component is located. The power supply component can include a power management system, one or more power sources, and other components associated with generating, managing, and distributing power for the device where the power supply component is located.
[0133] The above audio component can be configured to output and / or input an audio signal. For example, the audio component includes a microphone (MIC). When the device where the audio component is located is in an operation mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in a memory or sent via a communication component. In some embodiments, the audio component further includes a speaker for outputting an audio signal.
[0134] It should also be noted that the term "comprising", "including" or any other variant thereof is intended to cover a non-exclusive inclusion, such that a process, method, commodity or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, commodity or device. Without further limitation, an element defined by the statement "comprising an....." does not exclude the presence of additional identical elements in the process, method, commodity or device comprising the said element.
[0135] The above description is only for the embodiments of the present application and is not intended to limit the present application. For those skilled in the art, various changes and modifications can be made to the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included within the scope of the claims of the present application.
Claims
Claims 1. A data page pre-reading method, comprising: In response to a pre-read request including a keyword range, searching a tree index structure in a disk according to a minimum keyword in the keyword range to determine a target parent node of a target node, wherein a data page of the target node includes data corresponding to the minimum keyword in the keyword range; determining a target sibling node on the right side of the target node from child nodes of the target parent node, wherein the minimum keyword included in the target sibling node is smaller than the maximum keyword in the keyword range; Pre-read the data pages of the target node and its right-hand target sibling nodes from the disk into the memory.
2. The method according to claim 1, wherein: After pre-reading the data pages of the target node and its right target sibling node from the disk into the memory, it also includes: judging whether the maximum keyword included in the last target sibling node of the target node is smaller than the maximum keyword in the keyword range; if the judgment result is yes, taking the first sibling node on the right side of the target parent node as the new target parent node, and taking the first child node of the new target parent node as the new target node, and repeatedly executing the step of determining the target sibling node on the right side of the target node from the child nodes of the target parent node until the judgment result is no.
3. The method according to claim 1, wherein: Pre-reading the data pages of the target node and the target sibling node on the right side of the disk into the memory includes: pre-reading the data pages of the target node and the target sibling node on the right side of the disk into the memory in batches.
4. The method according to claim 3, wherein: Pre-reading the data pages of the target node and the target sibling node on the right side of the disk into the memory in batches includes: detecting the current remaining capacity of the memory; determining a first number of data pages allowed to be pre-read in the current batch according to the current remaining capacity of the memory; determining a second number of data pages in the disk starting from the data page of the first node that has not been pre-read as the data pages to be pre-read in the current batch, and pre-reading the data pages to be pre-read in the current batch into the memory, the first node that has not been pre-read is the target node or the target sibling node on the right side of the target node, and the second number is less than or equal to the first number; after waiting for a first preset time, repeatedly executing the step of detecting the current remaining capacity of the memory until all the data pages of the target node and the target sibling node on the right side of the disk are pre-read into the memory.
5. The method according to claim 4, wherein: Before determining the second number of data pages in the disk starting from the first data page of the node that has not been pre-read as the data pages to be pre-read in the current batch, the method further includes: determining whether the latest third number of batches of data pages that have been pre-read in the memory have been accessed; If so, execute the step of determining the second number of data pages in the disk starting from the data page of the first node that has not been pre-read as the data pages to be pre-read in the current batch; if not, wait for a preset second time length and then repeat the step of determining whether the data pages of the third batch that have been pre-read in the memory have been accessed.
6. The method according to claim 1, further comprising: In response to a pre-read request including a keyword, searching a tree index structure in a disk according to the keyword in the pre-read request to determine a target parent node of a target node, wherein a data page of the target node includes the keyword in the pre-read request; The sibling node to the right of the target node is determined from the child nodes of the target parent node, and the data pages of the target node and the sibling node to the right of the target node in the disk are pre-read into the memory.
7. The method according to any one of claims 1 to 6, wherein: If the tree index structure is a B+ tree, the type of the target node is a leaf node; if the tree index structure is a B tree, the type of the target node is a leaf node or a non-leaf node.
8. The method according to any one of claims 1 to 6, wherein: The method is applied to a database system or a file system.
9. An electronic device, comprising: Memory and processor; The memory is used to store computer programs; The processor is coupled to the memory and is configured to execute the computer program for performing the steps of the method according to any one of claims 1 to 8.
10. A computer-readable storage medium storing a computer program, wherein: When the computer program is executed by a processor, the processor is enabled to implement the steps of the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Database historical data automatic archiving system
CN110569232A
High-performance-oriented intelligent cache replacement strategy adaptive to prefetching
CN113297098A
Method and device for improving cross-node access performance of distributed cache and medium
CN115712583A
Methods and systems for an improved database
US11061903B1
System and method for improving index performance through prefetching
US20030126116A1