A storage method and device of a graph database
By using a bottom-up storage method that combines B-trees and LSM trees, the memory utilization of graph databases is optimized, the problems of low write efficiency and low query efficiency are solved, and high-performance storage that balances write and query efficiency is achieved.
Patent Information
- Application Number
- CN202311510904.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-13
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2043-11-13
AI Technical Summary
Existing graph databases struggle to balance write and query efficiency when dealing with massive amounts of data, and the failure to promptly remove invalid data further impacts query performance.
The original B-tree is constructed from the bottom up and combined with the LSM tree structure. Memory utilization is optimized through various merge trigger conditions, and index entries are created in the target LSM tree to query user data. Adjacency information is stored in the native graph.
It improves the write and query efficiency of graph databases, optimizes memory utilization, and resolves the impact of invalid data on query performance.
Smart Images

Figure CN117688211B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of graph database technology, and in particular to a method and apparatus for storing graph databases. Background Technology
[0002] Graph databases are a type of NoSQL database that primarily uses graph theory to store information about relationships between entities. There are three basic concepts in a graph database: vertices, which generally indicate an entity; edges, which represent relationships between entities, usually directed edges; and attributes, which describe certain information about a vertex or edge. The core concept of a graph database is to represent and store data using vertices, edges, and attributes, supporting graph query operations such as adding, deleting, modifying, and retrieving data, and providing database management functions. Because graph databases can intuitively visualize relationships, they can quickly respond to complex relational queries, making them a superior method for storing, querying, and analyzing highly interconnected data.
[0003] In graph database storage, a common approach is to convert graph adjacency information into key-value pairs, with the underlying layer being key-value storage. Another approach is native graph storage, which stores adjacency information separately. Since it eliminates the need for key-value encapsulation, it offers better query performance. However, existing graph databases, when writing or querying (reading) data based on native graphs, are limited by memory, making it difficult to balance write and query efficiency. This results in some functionalities failing to meet practical needs when dealing with extremely large datasets, such as processing and importing massive amounts of data at once. In actual use, users continuously add, delete, and modify data. When a large amount of new data is inserted, old, expired, and invalid data is not immediately cleared, resulting in a lot of deleted data remaining in the storage space. Queries then need to traverse both valid and invalid data, and the presence of invalid data negatively impacts query efficiency.
[0004] Therefore, overcoming the shortcomings of the existing technology is an urgent problem to be solved in this technical field. Summary of the Invention
[0005] The technical problem to be solved by the present invention is to provide a method and apparatus for storing graph databases. By optimizing the memory utilization of graph database storage and promptly cleaning up invalid data, the performance of graph databases can be improved while taking into account both write efficiency and query efficiency.
[0006] The present invention adopts the following technical solution:
[0007] In a first aspect, the present invention provides a method for storing a graph database, comprising:
[0008] Based on user data, construct at least one original B-tree from the bottom up;
[0009] The original B-tree is used as the data of the corresponding nodes in the initial LSM tree to obtain the initial LSM tree;
[0010] Obtain the merging trigger condition of the initial LSM tree, determine the original B-tree to be merged according to the merging trigger condition, merge the original B-tree to be merged into at least one merged B-tree, and obtain the target LSM tree containing at least one merged B-tree.
[0011] The native graph is used to store the adjacency information between the tags to which the user data belongs. Based on the adjacency information, an index entry is created in the target LSM tree so that the adjacency information can be obtained through the index entry and the corresponding user data can be queried based on the adjacency information.
[0012] Furthermore, the step of constructing at least one original B-tree from the bottom up based on user data includes:
[0013] Initialize at least one primitive B-tree;
[0014] After initializing at least one primitive B-tree, the insertion process of the primitive B-tree is executed, and the process is iterated until all the user data is inserted into the primitive B-tree.
[0015] Each time a raw B-tree is obtained, each raw B-tree is stored on disk as a B-tree file.
[0016] Furthermore, the insertion process includes:
[0017] Perform merge sorting on at least one user data entry to obtain a merged result set;
[0018] According to the order of the result data in the merged result set, the result data is inserted into the rightmost leaf node of the original B-tree in sequence;
[0019] When the number of result data in the page storing the current rightmost leaf node reaches a preset number of keywords, the intermediate item (i, j) of the B-tree is determined based on the i-th result data inserted into the current rightmost leaf node when the preset number of keywords is reached and the page number j of the page.
[0020] Create a new node as the parent node of the current rightmost leaf node. After the parent node is created, insert the B-tree middle item (i, j) into the parent node.
[0021] Adjust the original B-tree according to its basic properties;
[0022] Following the order of the result data in the merged result set, continue to insert the corresponding result data into the current rightmost leaf node in sequence until the result data in the page storing the current rightmost leaf node reaches the preset number of keywords;
[0023] The above process is iterated until all the result data is inserted into the original B-tree.
[0024] Further, the step of continuing to insert the corresponding result data into the current rightmost leaf node in the order of the result data in the merged result set, until the result data in the page storing the current rightmost leaf node reaches the preset number of keywords, includes:
[0025] Create the right sibling node of the current rightmost leaf node, update the current rightmost leaf node to the right sibling node, and insert the (i+1)th result data into the current rightmost leaf node;
[0026] Based on the (i+1)th result data and the page number k of the page storing the current rightmost leaf node, determine the B-tree intermediate item (i+1, k) and insert the B-tree intermediate item (i+1, k) into the parent node.
[0027] The original B-tree is adjusted according to the aforementioned basic properties;
[0028] Starting from the (i+2)th result data, the corresponding result data is sequentially inserted into the current rightmost leaf node until the number of result data in the page storing the current rightmost leaf node reaches the preset number of keywords.
[0029] Further, obtaining the merge triggering condition of the initial LSM tree and determining the original B-tree to be merged based on the merge triggering condition includes:
[0030] When the number of B-tree files in the m-th layer of the initial LSM tree reaches the first preset threshold corresponding to the m-th layer, multiple original B-trees in the m-th layer that have an intersection with the next layer of the initial LSM tree are identified, and the original B-trees are identified as the original B-trees to be merged.
[0031] And / or, when the number of B-tree files reaches the second preset threshold corresponding to the m-th layer, all original B-trees in the m-th layer are determined as the original B-trees to be merged;
[0032] And / or, the spatial size of each level of the initial LSM tree is obtained according to the preset file size function size(), and the spatial scaling index of the initial LSM tree is obtained based on the spatial size: size(R1) + size(R2) + ... + size(R) n-1 ) / size(R n ); where Rm This represents the B-tree file at the m-th level of the initial LSM tree; when the spatial magnification index reaches a preset magnification threshold, the original B-tree corresponding to the deletion mark in the 0-th level is determined, and the original B-tree is determined as the original B-tree to be merged;
[0033] And / or, when a label, native graph, edge of native graph, vertex of native graph and index item are deleted, a scan of the initial LSM tree is triggered to check whether there is a native B-tree corresponding to the deletion label; if there is, the native B-tree is determined as the native B-tree to be merged;
[0034] And / or, at preset intervals, all original B-trees in the initial LSM tree are identified as the original B-trees to be merged.
[0035] Further, the step of merging the original B-trees to be merged into at least one merged B-tree to obtain a target LSM tree containing at least one merged B-tree includes:
[0036] The original B-tree to be merged is merged with the original B-trees in the next layer that have intersections to form at least one merged B-tree in the next layer;
[0037] And / or, merge the original B-trees to be merged at the same level into a merged B-tree at the corresponding next level;
[0038] And / or, merge the original B-trees to be merged into at least one merged B-tree at the same level;
[0039] The target LSM tree is obtained based on at least one merged B-tree.
[0040] Furthermore, at least one merge task is created, which is used to merge the original B-trees to be merged into at least one merged B-tree; the merge task includes at least one subtask, which is used to merge the original B-trees to be merged into one merged B-tree; at least one subtask of the merge task is executed sequentially using the same thread;
[0041] The process of merging the original B-trees to be merged into at least one merged B-tree includes:
[0042] When all the original B-trees to be merged in the merging task are not at the same level as all the original B-trees to be merged in another merging task, it is determined that there is no hierarchical overlap between the merging task and the other merging task.
[0043] When the data volume of the B-tree file corresponding to the original B-tree to be merged in a merge task is greater than a preset data value, and all the original B-trees to be merged in the multiple subtasks of the merge task are located at the same level of the initial LSM tree, the data range of memory or disk involved in the multiple subtasks is determined, and multiple subtasks with consecutive data ranges are taken as the corresponding multiple first subtasks, and the merge task is split into multiple first subtasks.
[0044] The merging task and the other merging task are executed by two parallel first threads respectively. Each first thread generates the result file of the merging task or the other merging task based on the corresponding original B-tree to be merged. The corresponding first subtask is executed by multiple parallel second threads respectively. Each second thread generates a result file of the merging task based on the corresponding original B-tree to be merged.
[0045] The result file is used as the corresponding B-tree file for the merged B-tree to obtain the merged B-tree.
[0046] Further, before merging the original B-trees to be merged into at least one merged B-tree, the original B-trees to be merged are prefetched from memory or disk, wherein:
[0047] Access the page of the original B-tree to be merged, extract the page corresponding to the leftmost node of the leaf layer in the original B-tree to be merged as the page to be accessed, and determine whether the page to be accessed is already in the cache pool in memory;
[0048] If so, the page to be accessed is retrieved directly from the cache pool;
[0049] If not, the page to be accessed is read from the disk into the cache pool, and then retrieved from the cache pool.
[0050] Treat the page to be accessed as an already accessed page, treat the page corresponding to the right sibling node of the leaf layer as the new page to be accessed, and release the already accessed page.
[0051] The above process is iterated until all the original B-trees to be merged are retrieved from the cache pool.
[0052] Furthermore, the native graph includes vertices and edges, and the adjacency information includes a mapping from the vertex ID of the vertex to the edge ID of the edge; there is at least one vertex under the label, the vertex includes at least one attribute, and the index item includes the attribute and the vertex ID of the corresponding vertex;
[0053] The storage method for the graph database also includes:
[0054] Get all vertices under the label to be deleted;
[0055] Based on the vertex ID to be deleted, obtain the edge ID to be deleted.
[0056] Delete the vertex and edge to be deleted;
[0057] The storage method of the graph database further includes: obtaining the corresponding query edge ID based on the query vertex ID in the received query index item and the query adjacency information of the original graph;
[0058] Based on the queried edge ID and the queried adjacency information, the result vertex ID is obtained;
[0059] Based on the result vertex ID, the corresponding result index in the target LSM tree is obtained, and the corresponding user data is obtained based on the attribute corresponding to the result index.
[0060] Secondly, the present invention also provides a graph database storage device for implementing the graph database storage method described in the first aspect, the device comprising:
[0061] At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor for performing the graph database storage method described in the first aspect.
[0062] Thirdly, the present invention also provides a non-volatile computer storage medium storing computer-executable instructions that are executed by one or more processors to perform the graph database storage method described in the first aspect.
[0063] Unlike existing technologies, the present invention has at least the following beneficial effects:
[0064] This invention constructs at least one original B-tree from the bottom up based on user data, solving the problem of low write efficiency in B-tree structures. It combines B-tree and LSM tree structures by using the original B-tree as the data for the corresponding nodes of the initial LSM tree. By designing multiple merge trigger conditions for the initial LSM tree, it implements various types of merge tasks according to specific needs, optimizing the LSM tree's handling of invalid data. It uses a native graph to store adjacency information between tags to which user data belongs, and creates index entries in the target LSM tree to facilitate obtaining the adjacency information through these index entries. Based on this adjacency information, the corresponding user data can be queried, and the native graph provides adjacency query capabilities, greatly improving the query efficiency of the LSM tree and solving the problem of low query efficiency caused by a large amount of invalid data in the LSM tree. This invention achieves a balance between write and query efficiency by optimizing memory utilization. Attached Figure Description
[0065] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments of the present invention will be briefly described below. Obviously, the drawings described below are merely some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without any creative effort.
[0066] Figure 1 This is a schematic diagram of a B-tree storage structure in the prior art provided by an embodiment of the present invention;
[0067] Figure 2 This is a schematic diagram of the storage structure of an LSM tree in the prior art provided by an embodiment of the present invention;
[0068] Figure 3 This is a schematic diagram of the storage structure of an LSM tree in another prior art provided by an embodiment of the present invention;
[0069] Figure 4 This is a schematic diagram of the overall process of a graph database storage method provided in an embodiment of the present invention;
[0070] Figure 5 This is a schematic diagram of the specific process of step 10 in an embodiment of the present invention;
[0071] Figure 6 This is a schematic diagram of the specific process of step 102 in an embodiment of the present invention;
[0072] Figure 7 This is a schematic diagram of a bottom-up B-tree insertion process provided in an embodiment of the present invention;
[0073] Figure 8 This is a schematic diagram of the specific process of step 1026 in an embodiment of the present invention;
[0074] Figure 9 This is a schematic diagram of another bottom-up B-tree insertion process provided in an embodiment of the present invention;
[0075] Figure 10 This is a schematic diagram of a specific process for triggering the merger in step 30 of an embodiment of the present invention;
[0076] Figure 11 This is a schematic diagram of a specific process for merging in step 30 of an embodiment of the present invention;
[0077] Figure 12 This is a schematic diagram of two merging strategies provided in the embodiments of the present invention;
[0078] Figure 13This is a schematic diagram of the storage structure of an SST file in the prior art provided by an embodiment of the present invention;
[0079] Figure 14 This is a schematic diagram of a specific process for triggering the merger in step 30 of an embodiment of the present invention;
[0080] Figure 15 This is a schematic diagram showing the hierarchical position of a B-tree file involved in a merging task in the initial LSM tree, as provided in an embodiment of the present invention.
[0081] Figure 16 This is a schematic diagram showing the hierarchical position of a B-tree file in the initial LSM tree involved in another merging task provided by an embodiment of the present invention;
[0082] Figure 17 This is a schematic diagram of a specific process for triggering the merger in step 30 of an embodiment of the present invention;
[0083] Figure 18 This is a schematic diagram of a specific process for step 40 in an embodiment of the present invention;
[0084] Figure 19 This is another specific flowchart of step 40 in an embodiment of the present invention;
[0085] Figure 20 This is a schematic diagram of the architecture of a graph database storage device provided in an embodiment of the present invention. Detailed Implementation
[0086] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0087] In the description of this invention, the terms "inner", "outer", "longitudinal", "lateral", "upper", "lower", "top", "bottom", etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are only for the convenience of describing this invention and do not require that this invention must be constructed and operated in a specific orientation. Therefore, they should not be construed as limiting this invention.
[0088] In this invention, the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Therefore, a feature defined with "first," "second," etc., may explicitly or implicitly include one or more of that feature. In the description of this application, unless otherwise stated, "a plurality of" means two or more.
[0089] In this application, unless otherwise expressly specified and limited, the term "connection" shall be interpreted broadly. For example, "connection" may be a fixed connection, a detachable connection, or an integral part; it may be a direct connection or an indirect connection through an intermediate medium.
[0090] Furthermore, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0091] Example 1:
[0092] In graph database storage, existing technologies convert graph adjacency information into key-value pairs, with key-value storage used at the underlying level.
[0093] When using B-trees for key-value storage (specifically, B-trees, B+ trees, etc.), this storage method organizes the data collection using a multi-way tree structure. The nodes of the multi-way tree store pages (also called file pages or data pages), and modifications are performed in-place, with a search complexity of O(log_n). Specifically, a B-tree is a balanced multi-way search tree. A node in a B-tree can store more than two elements, and a node can have more than two child nodes. The balance factor of each node is 1. Figure 1 As shown, in a specific running file system, a B-tree is stored in the form of root node pages, non-leaf node pages, and leaf node pages. Figure 1 The text does not show all non-leaf node pages except the root node; "..." represents a set of multiple non-leaf node pages.
[0094] like Figure 2 As shown, when using LSM (Log Structured Merge Tree) for key-value storage, this storage method organizes the data collection in a hierarchical manner, including three important components: the memory table (MemTable), the immutable memory table (Immutable MemTable), and the sorted string table (SST) file. Modification is done by appending, and the write complexity is O(1). Queries require searching from the new data to the old data, and the search complexity depends on the number of layers. Figure 2 The text does not show all SST files for layers 1 and 2; "..." indicates a collection of multiple SST files.
[0095] In an LSM tree, a memory table is a data structure located in memory, specifically at level 0 of the LSM tree. It stores recently updated data, organized in order of the keys in the key-value pairs. Because data is temporarily stored in memory, which is not reliable storage and will be lost if power is lost, write-ahead logging (WAL) is typically used to ensure data reliability. When the memory table reaches a certain size, it is converted into an immutable memory table. When the file in memory reaches a certain size, the immutable memory table is exported as an SST file; the immutable memory table is an intermediate state in the conversion process. Write operations are handled by the new memory table, and data update operations are not blocked during the transfer process.
[0096] SST files are ordered collections of key-value pairs, representing the LSM tree's data structure on disk. An SST file contains a meta segment and a data segment. The meta segment is indexed, and the data segment stores the data. The meta-index of the meta segment is a single-level directory structure. As the data volume increases, the size of a single SST file is generally fixed, necessitating the creation of multiple SST files. Queries require accessing more SST files, leading to decreased query performance in the graph database and higher memory consumption for the index. Specifically, queries need to load directory blocks from the SST files for data location. With large datasets, each level of the LSM tree contains more SST files, requiring traversal of the meta segment for each SST file, resulting in increased memory usage. Figure 3 As shown, if a specific key needs to be queried within a single level of an LSM tree, a binary search is required within the meta index, which is an array of meta segments and index segments from all SST files at that level, to locate the SST file. Then, the corresponding data is retrieved from the relevant SST file. In other words, the meta index at the same level and the actual data form a two-level index structure. Therefore, using an LSM tree for key-value storage incurs memory overhead similar to a two-level index.
[0097] LSM trees store all data insertion, deletion, and modification operations in memory. When the amount of data affected by these operations reaches a certain threshold, it is then written sequentially to disk in batches. LSM tree data updates are log-based, meaning each data update directly adds an update record. This continuously flushes the immutable memory table to persistent storage (disk) without modifying the keys in the previous SST file, ensuring sequential writing. Therefore, when the memory table reaches a certain size and is flushed to persistent storage as an SST file, records with the same key may exist in different SST files; only the latest record is accurate. For ease of description, the term "memory table" below includes both the memory table itself and the immutable memory table.
[0098] The problems with using LSM trees as a storage structure are twofold: First, it leads to redundant storage. For a given key, all records except the latest one are redundant and invalid data, yet they still occupy storage space, impacting query efficiency. Therefore, compaction is needed, which involves merging multiple SST files to remove redundant and invalid data. Second, reading data from an LSM tree requires searching in reverse order from the latest data until a record for a given key is found. In the worst case, all SST files need to be searched, resulting in low query efficiency. After inserting a large amount of data into the LSM tree, old data gradually accumulates, increasing the number of files in that layer, requiring file traversal for queries. The older the data, the more numerous it becomes, and since LSM tree implementations split files to a fixed size, the number of SST files in older layers is even greater.
[0099] like Figure 4 As shown, Embodiment 1 of the present invention provides a method for storing a graph database, including:
[0100] Step 10: Based on the user data, construct at least one original B-tree from the bottom up.
[0101] In this context, user data refers to the data to be stored input by the user according to their usage needs when using the graph database of this embodiment of the invention; the original B-tree is a B-tree that has not been merged. Bottom-up construction refers to splitting the nodes of the original B-tree sequentially from bottom to top during the construction process. If the user data stored in the leaf node reaches the preset number of keywords, the leaf node is first reconstructed by splitting, and then the process is carried out step by step upwards until the root node. The specific process is described below.
[0102] This embodiment of the invention uses an LSM tree as the storage structure. Since the 0th level of the LSM tree is stored in memory as a memory table, and for the memory table, it is not specified whether its organization of user data is a B-tree, while the levels other than the 0th level are stored on the disk as B-tree files, this step is the process of writing user data to disk when the memory space occupied by the memory table reaches a certain size, that is, converting the memory table storing user data into a B-tree file and storing it on the disk.
[0103] In the graph database based on the storage method of this invention, during queries, the search proceeds directly from the root node to the leaf node in the B-tree. Each level is compared to determine the next level node to search for, so the number of pages in the B-tree file that need to be loaded is equal to the height of the B-tree level. This invention utilizes a multi-level index of the B-tree to solve the problem of high memory overhead during queries in LSM trees, which are similar to two-level indexes. This invention introduces a B-tree structure to replace the SST for storage, enabling high read and write performance with limited memory in scenarios with large amounts of data. In specific implementations, the SST file replaced by the B-tree file is generally used in higher levels of the storage layer, i.e., layers with less frequently accessed or used data and often used for long-term storage.
[0104] Step 20: Use the original B-tree as the data of the corresponding nodes of the initial LSM tree to obtain the initial LSM tree.
[0105] The initial LSM tree is an unmerged LSM tree; the corresponding nodes are nodes in the initial LSM tree at levels other than level 0.
[0106] The storage method of this invention splits the storage layer architecture of the graph database into an index module and a native graph module. The index module uses a hierarchical structure, namely an LSM tree. Through merging, the background asynchronously completes the resource reclamation of the memory resources occupied by each layer of the LSM tree. In each layer of the LSM tree except for layer 0, the data of each node is stored using one or more B-tree structures, that is, the file blocks of the LSM tree are organized using B-trees.
[0107] Step 30: Obtain the merge triggering condition of the initial LSM tree, determine the original B-tree to be merged according to the merge triggering condition, merge the original B-tree to be merged into at least one merged B-tree, and obtain the target LSM tree containing at least one merged B-tree.
[0108] The merge trigger condition is the condition that triggers the initial LSM tree merge; the merged B-tree is the original B-tree after merging; the target LSM tree is the initial LSM tree after merging; and the original B-tree to be merged is a set of multiple original B-trees that need to be merged.
[0109] It is important to note that since not every merge will combine all the original B-trees in the initial LSM tree into a merged B-tree, the target LSM tree may contain both original B-trees and merged B-trees, or it may contain only merged B-trees. The target LSM tree also continues to be merged according to the merge trigger conditions. The merging of the target LSM tree is the same as the merging of the initial LSM tree. The operations in step 30 can directly replace the initial LSM tree with the target LSM tree, which will not be elaborated here.
[0110] Furthermore, since the LSM tree stores user data in memory as a memory table at level 0, and stores user data on disk as a B-tree file at levels other than level 0, the merging of LSM trees only requires an ordered iteration method for the merged objects, without restricting the specific data organization of the merged objects. That is, both memory tables and B-tree files can be merged. When the memory space occupied by the memory tables at level 0 still reaches a certain size after continuous merging, it is necessary to export the memory tables as B-tree files and store them on disk, i.e., the levels other than level 0 of the LSM tree. The process of merging memory tables and exporting them as B-tree files refers to existing technologies and will not be elaborated here.
[0111] For the sake of brevity in explaining the solution, and to avoid repeating the explanation that merging at level 0 involves merging memory tables every time an LSM tree is merged, the following description will use a B-tree as a representative to illustrate the merging of LSM trees, and will not repeat the explanation of merging memory tables at level 0 of the LSM tree. However, it should be understood that level 0 only contains memory tables. For level 0, the set of multiple memory tables that need to be merged is determined according to the merge triggering conditions, and the merged objects are all memory tables.
[0112] The optimization of the merging process in this invention embodiment lies in the following: During the generation phase of the merging task, multiple merging triggering conditions are designed based on the characteristics of B-trees and LSM trees to achieve various types of merging tasks. During the execution phase of the merging task, multiple merging tasks are executed in parallel, and a single merging task is split when its workload is large; prefetching technology is used to optimize disk access; B-trees are constructed from the bottom up, and the generated B-trees are delayed in being flushed to disk. That is, when writing user data into the LSM tree (generating the B-tree), the user data is stored in a memory table and written to a cache, and the user data is not immediately stored in a B-tree file and written to disk. A background thread periodically writes the user data in the cache to disk. This invention embodiment reduces the resource consumption of merging, reduces the time consumption, optimizes memory utilization, and improves the indexing performance of the graph database.
[0113] Step 40: Use the native graph to store the adjacency information between the tags to which the user data belongs. Based on the adjacency information, create an index entry in the target LSM tree so that the adjacency information can be obtained through the index entry, and the corresponding user data can be queried based on the adjacency information.
[0114] The index entries are data that maps the adjacency information of the native graph in the native graph module to the target LSM tree of the index module. The native graph represents the relationships between index entries, and the adjacency information is data in the native graph representing the adjacency relationships between index entries in the target LSM tree.
[0115] It should be noted that, in actual use, the graph database based on the storage method of this invention performs the operation in step 40 using the initial LSM tree before the corresponding merge triggering condition is triggered.
[0116] The native graph module in this embodiment of the invention uses a graph structure, namely a native graph. The native graph module stores the relationships between index items of user data in the index module. By using the native graph to store adjacency information separately, query performance is improved. The index module stores index items, and by designing fields in the index items that point to the native graph, the mapping from the native graph module to the index module is realized.
[0117] Database business scenarios are divided into Online Analytical Processing (OLAP) and Online Transaction Processing (OLTP). In OLAP, data is processed offline in batches, with operation time requirements ranging from minutes to hours, and a large amount of data involved in a single operation. In OLTP, data is processed online, with operation time requirements ranging from milliseconds to seconds, and a smaller amount of data involved in a single operation. For example, an OLTP system might handle all transaction business, requiring data to be returned instantly, with operation time measured in seconds to microseconds. Alternatively, data might be imported into an OLAP system each night for analysis based on data from specific times; this type of analysis often does not require immediate returns, and the generation of analysis results is measured in minutes to hours.
[0118] The CRUD (Create, Read, Update, Delete) functions used in business scenarios are all based on reading and writing user data. The graph database storage method of this invention is suitable for analytical business scenarios that favor OLAP (Online Analytical Processing). In such scenarios, directly using a B-tree results in poor throughput when writing data to the B-tree. Existing B-trees write data from the root node to the leaf node, i.e., "top-down"; when the amount of data in the page corresponding to a node exceeds the storable value, node splitting is triggered. In OLTP systems, the number of data records written at one time is small, so the memory consumption caused by this split is relatively small and acceptable; however, in OLAP systems, batches of data are often imported at once, leading to numerous splits and significant memory consumption.
[0119] The graph database storage method of this invention improves memory utilization during queries by using a B-tree structure to organize and store user data in the underlying storage layer, and achieves better query performance by utilizing the B-tree. Based on the LSM tree merging mechanism, various types of merging tasks are designed to improve write performance while taking into account query efficiency.
[0120] Writing user data to a B-tree incurs significant memory overhead, resulting in poor write performance and making it unsuitable for scenarios with high write efficiency requirements. Similarly, LSM trees often contain a large amount of invalid data, leading to poor query performance and making them unsuitable for scenarios with high query efficiency requirements. Therefore, existing technologies do not consider and cannot combine B-tree and LSM tree structures. However, many big data scenarios currently require a general-purpose, high-performance storage architecture that balances write and query efficiency. This invention provides a bottom-up B-tree construction method that optimizes the B-tree generation algorithm and overcomes the write performance bottleneck of existing B-tree technologies. By combining native graphs to assist LSM tree queries and using native graphs to store the adjacency information of LSM trees, it avoids traversing the LSM tree during queries, which may contain a high probability of invalid data, thus solving the problem of poor LSM tree query performance. In optional embodiments, those skilled in the art can further optimize the write performance of B-trees and the query performance of LSM trees without creative effort, based on existing technologies. This invention, by combining B-tree and LSM tree structures, achieves a high-performance storage architecture suitable for general scenarios.
[0121] This invention constructs at least one original B-tree from the bottom up based on user data, solving the problem of low write efficiency in B-tree structures. It combines B-tree and LSM tree structures by using the original B-tree as the data for the corresponding nodes of the initial LSM tree. By designing multiple merge trigger conditions for the initial LSM tree, it implements various types of merge tasks according to specific needs, optimizing the LSM tree's handling of invalid data. It uses a native graph to store adjacency information between tags to which user data belongs, and creates index entries in the target LSM tree to facilitate obtaining the adjacency information through these index entries. Based on this adjacency information, the corresponding user data can be queried, and the native graph provides adjacency query capabilities, greatly improving the query efficiency of the LSM tree and solving the problem of low query efficiency caused by a large amount of invalid data in the LSM tree. This invention achieves a balance between write and query efficiency by optimizing memory utilization.
[0122] To better illustrate the graph database storage method of the present invention, step 10 of the graph database storage method of the present invention will be further described below. Specifically, as follows... Figure 5 As shown, step 10 includes:
[0123] Step 101: Initialize at least one primitive B-tree.
[0124] Initializing a primitive B-tree involves creating an empty B-tree with only one empty node.
[0125] Step 102: After initializing at least one original B-tree, perform the insertion process of the original B-tree, iterating sequentially until all the user data is inserted into the original B-tree.
[0126] The insertion process involves inserting user data into the original B-tree, as detailed below. It's important to note that the insertion process is also performed after the original B-tree is merged into a merged B-tree. The insertion process for the merged B-tree is the same as that for the original B-tree. The operations in step 102 can directly replace the original B-tree with the merged B-tree, and will not be elaborated upon here.
[0127] Step 103: Each time a raw B-tree is obtained, each raw B-tree is stored on the disk as a B-tree file.
[0128] In this embodiment of the invention, when updating the LSM tree or inserting a piece of data into the LSM tree, a log entry is directly added and stored in a memory table in memory. When the memory table in memory reaches a certain size, it is converted into an immutable memory table and stored in memory. When the memory space occupied by the memory table and the immutable memory table reaches a preset value, the immutable memory table is flushed to disk and persistently stored as a B-tree file. The preset value is selected by those skilled in the art based on the specific use case.
[0129] The insertion process of the original B-tree in step 102 of this embodiment of the invention will be further explained below. Specifically, as follows: Figure 6 As shown, the insertion process includes:
[0130] Step 1021: Perform merge sorting on at least one user data entry to obtain a merge result set.
[0131] Merge sort is a sorting operation based on the merge sort algorithm; the merge result set is a collection of all user data before sorting, organized in size order, and each sorted user data in the merge result set is the result data.
[0132] According to the properties of B-trees, the data in each node of a B-tree must be ordered. In order to improve writing efficiency, this embodiment of the invention selects the merge sort algorithm to organize the order of user data. Those skilled in the art can choose the sorting algorithm according to the specific use case, and no limitation is made here.
[0133] The insertion process is illustrated below with an example: The user data consists of 1 to 101 numbers in a random order. In step 1021, the random numbers 1 to 101 are merged and sorted to obtain a merged result set consisting of 1 to 101 numbers in ascending order.
[0134] Step 1022: Insert the result data into the rightmost leaf node of the original B-tree in the order of the result data in the merged result set.
[0135] In this tree structure, nodes without child nodes are leaf nodes; the rightmost leaf node is the rightmost leaf node among the leaf nodes of the original B-tree in the current state.
[0136] This invention utilizes the property that data in the nodes of a B-tree must be arranged in ascending order. By sorting the user data in advance, the number of node splits in the original B-tree during the insertion process is greatly reduced, thus lowering memory consumption.
[0137] For example, when the merged result set is divided into numbers 1 to 101 in ascending order, and inserted into the initialized original B-tree in ascending order, 1 is first inserted into the empty node of the original B-tree, that is, 1 is used as the data of the only node in the empty B-tree; at this time, since only this node exists in the initialized original B-tree, this node is the current rightmost leaf node; continue to insert 2 to 101 into this node in order.
[0138] Step 1023: When the number of result data in the page storing the current rightmost leaf node reaches the preset number of keywords, determine the B-tree intermediate item (i, j) based on the i-th result data inserted into the current rightmost leaf node when the preset number of keywords is reached and the page number j of the page.
[0139] The preset number of keywords is selected by those skilled in the art based on the specific use case; the index is created each time a page is full, and its value is determined based on the largest result data in the full page and the page number of that page. Furthermore, the intermediate items of the B-tree are the data in the non-leaf nodes of the original B-tree.
[0140] like Figure 7 As shown, a node in the original B-tree (i.e., the page used to store that node) may store data for multiple B-tree intermediate items; B-tree intermediate items Figure 7 The original B-tree will be displayed in pages, for example, in Figure 7 In the page shown, which contains data "(100, 1), (101, 3)", the B-tree intermediate item (100, 1) indicates that data <= 100 is in the subpage with page number 1, and the B-tree intermediate item (101, 3) indicates that data <= 101 is in the subpage with page number 3.
[0141] This invention stores the result data in a single node of the original B-tree, ensuring that the data size in that node is equal to the natural page size of the file system in the specific use case, thus optimizing disk access. The corresponding intermediate B-tree item is used as an index to the result data in the leaf node. During a query, the search proceeds directly from the root node to the leaf node, reducing the memory overhead required for the query and improving query efficiency.
[0142] like Figure 7 As shown, the preset number of keys is 100. The page number of the empty node (B-tree state 1) of the initialized original B-tree is 1. When inserting the result data from 1 to 99 into the empty node, the preset number of keys is not reached. When inserting 100 into the node (B-tree state 2), the preset number of keys 100 is reached. Based on the inserted result data 100 and the page number 1, the intermediate item of the B-tree is determined to be (100, 1). The intermediate item of the B-tree is inserted into the parent page of the page with page number 1 (B-tree state 3). At this time, the page with page number 1 is the child page of the page containing the data (100, 1).
[0143] Step 1024: Create a new node as the parent node of the current rightmost leaf node. After the parent node is created, insert the B-tree intermediate item (i, j) into the parent node.
[0144] It should be noted that in the bottom-up construction method of this invention, there is no data transfer between child nodes and parent nodes as in the B-tree insertion process of the prior art. Instead, the intermediate B-tree item is directly inserted into the newly created parent node as an index item for user data.
[0145] like Figure 7 As shown, when a new node is created, the rightmost leaf node is a child node of the parent node; the B-tree intermediate item (100,1) determined in step 1023 is inserted into the data of the parent node.
[0146] Step 1025: Adjust the original B-tree according to the basic properties of the B-tree.
[0147] During adjustment, the balance of each node in the original B-tree is maintained from bottom to top to ensure the query efficiency, write efficiency, and availability of the original B-tree. For example, all leaf nodes are located at the same level. The basic properties of B-trees are well known to those skilled in the art and will not be elaborated here; the specific implementation method of adjustment refers to the insertion process of B-trees in the prior art and is not limited here.
[0148] Step 1026: Following the order of the result data in the merged result set, continue to insert the corresponding result data into the current rightmost leaf node in sequence until the result data in the page storing the current rightmost leaf node reaches the preset number of keywords.
[0149] Step 1027: Iterate the above process until all the result data is inserted into the original B-tree.
[0150] The following provides a further explanation of step 1026 in an embodiment of the present invention. Specifically, as follows: Figure 8 As shown, step 1026 includes:
[0151] Step 10261: Create the right sibling node of the current rightmost leaf node, update the current rightmost leaf node to the right sibling node, and insert the (i+1)th result data into the current rightmost leaf node.
[0152] In this context, child nodes of the same parent node are sibling nodes, and the right sibling node is the sibling node located to the right of a certain node in the tree.
[0153] like Figure 9 As shown, in this embodiment of the invention, when inserting result data into the original B-tree, insertion only occurs from the rightmost bottom end of the original B-tree, meaning only the right sibling node of the current rightmost leaf node is created. Figure 9 and Figure 7 The original B-tree states are the same. Figure 9 The original B-tree is displayed in the form of a tree structure (data structure). Figure 7 The pages and pointers (arrows) in the text represent the actual storage form of this tree structure.
[0154] For example, when inserting the merged result set (numbers from 1 to 101) into the original B-tree, such as... Figure 9 As shown in the first tree structure from top to bottom, after inserting the result data from 1 to 100, the result data from 1 to 100 has been inserted into the page with page number 1. Since the page is full, the middle item (100,1) of the B-tree has been inserted into the parent node of the node storing the page with page number 1 in the previous steps; that is, the data in the rightmost leaf node at this time is the result data from 1 to 100, and the data in its parent node is the B-tree index item (100,1).
[0155] When inserting the result data of 101, since the inserted result data is arranged in ascending order, which conforms to the properties of a B-tree, the right sibling node of the current rightmost leaf node is directly created to store the result data 101 to be inserted. The situation after insertion is as follows. Figure 9 The second tree structure is shown in the middle.
[0156] It should be noted that since the rightmost leaf node is the rightmost leaf node in the original B-tree under the current state, when implementing the graph database storage method in this embodiment, as long as the right sibling node of the rightmost leaf node is inserted into its parent node, the right sibling node will definitely be the rightmost leaf node after the insertion. Since the process of inserting result data into the original B-tree is an iterative process, for ease of description, the rightmost leaf node is treated as a variable. In each iteration, after inserting result data, the rightmost leaf node is updated to the node containing the inserted result data.
[0157] Step 10262: Based on the (i+1)th result data and the page number k of the page storing the current rightmost leaf node, determine the B-tree intermediate item (i+1, k) and insert the B-tree intermediate item (i+1, k) into the parent node.
[0158] In order for the parent node to be able to index the current rightmost leaf node, the corresponding B-tree intermediate item is added to the parent node.
[0159] Here, the middle item (i+1, k) in the B-tree represents page i. When the page is full, for the new page i+1, a new index is created based on the currently inserted result data k (since the result data is sorted in ascending order, the currently inserted result data must be the largest in the page) and page number i+1. Since the process of inserting result data is a loop iteration process, i+1 and k are variables.
[0160] like Figure 7 In the middle, and like Figure 9 As shown in the third tree structure, since the current rightmost leaf node is page number 3, the largest result data in this page is 101. Therefore, the corresponding B-tree middle item (101,3) is determined and inserted into its parent node, indicating that data less than or equal to 101 is in page number 3.
[0161] Step 10263: Adjust the original B-tree according to the basic properties.
[0162] Step 10263 is the same as step 1025 above, both of which are to adjust the original B-tree to ensure the properties of the B-tree.
[0163] Step 10264: Starting from the (i+2)th result data, insert the corresponding result data into the current rightmost leaf node in sequence until the result data in the page storing the current rightmost leaf node reaches the preset number of keywords.
[0164] In one optional embodiment, instead of inserting the corresponding B-tree index entry each time a result data is inserted, after all result data has been inserted, the rightmost node of each level is traversed from the leaf node upwards, and the corresponding B-tree index entry is inserted to improve the writing efficiency of writing result data into the original B-tree and further solve the problem of low B-tree writing efficiency.
[0165] Existing B-tree insertion techniques are top-down, requiring a binary search to locate child nodes (corresponding pages in the file system) at each level during insertion. However, the merged result set is ordered. This invention provides a bottom-up B-tree construction algorithm that inserts directly from the leaf node towards the root node, eliminating the binary search process and greatly improving the writing efficiency of the B-tree.
[0166] To better illustrate the graph database storage method of the present invention, step 30 of the graph database storage method of the present invention will be further described below. This step involves merging data into the LSM tree maintenance process. Since append writes are much faster than random writes, the operation of writing user data into the LSM tree is converted into append writes as much as possible. However, continuous writing will accumulate a large amount of invalid data (old data and outdated data). To improve query efficiency, the LSM tree reclaims invalid data through merging, merging the continuously accumulating files (memory tables or B-tree files) to a higher level of the LSM tree and removing invalid data. The merging process is a multi-way merge and invalid data cleanup process, which is achieved by continuously inserting filtered valid data into the B-tree (i.e., merging the B-tree). Specifically, as... Figure 10 As shown, step 30, obtaining the merge triggering condition of the initial LSM tree and determining the original B-tree to be merged based on the merge triggering condition, includes:
[0167] Step 301a: When the number of B-tree files in the m-th layer of the initial LSM tree reaches the first preset threshold corresponding to the m-th layer, determine multiple original B-trees in the m-th layer that have an intersection with the next layer of the initial LSM tree, and determine the original B-trees as the original B-trees to be merged.
[0168] The first preset threshold is selected by those skilled in the art based on the specific usage scenario.
[0169] When new user data is written to the original B-tree, a new B-tree file is generated. If the number of B-tree files exceeds the limit, a merge is triggered. When the LSM tree chooses a level compaction strategy for storage, it selects multiple original B-trees in the layer that intersect with the original B-tree of the next layer to trigger the merge. Since the non-leaf nodes of the LSM tree are equivalent to the indexes of the leaf nodes, and only the leaf nodes are equivalent to the data layers storing data, there must exist multiple original B-trees in the m-th layer that intersect with the next layer of the initial LSM tree.
[0170] Step 302a: and / or, when the number of B-tree files reaches the second preset threshold corresponding to the m-th layer, all original B-trees in the m-th layer are determined as the original B-trees to be merged.
[0171] The second preset threshold is selected by those skilled in the art based on the specific usage scenario.
[0172] When the number of B-tree files of the initial LSM tree on the disk reaches the second preset threshold corresponding to the m-th level of the initial LSM tree, all the original B-trees in the m-th level are identified as the original B-trees to be merged, so as to facilitate subsequent merging to complete the reclamation of memory resources and improve the query efficiency of the LSM tree.
[0173] Step 303a: and / or, obtain the spatial size of each level of the initial LSM tree according to the preset file size function size(), and obtain the spatial magnification index of the initial LSM tree size(R1) + size(R2) + ... + size(R) based on the spatial size. n-1 ) / size(R n ); where R m This represents the B-tree file at the m-th level of the initial LSM tree; when the spatial magnification index reaches a preset magnification threshold, the original B-tree corresponding to the deletion mark in the 0-th level is determined, and the original B-tree is determined as the original B-tree to be merged.
[0174] The preset file size function and preset amplification threshold are selected by those skilled in the art based on the specific application scenario; the specific implementation of the preset file size function is based on existing technologies and is not limited here. The deletion marker is a marker carried by the deleted invalid data; since the deletion operation of an LSM tree does not directly delete data from the LSM tree, but writes the deletion marker to level 0, it is necessary to merge data based on the deletion marker to reclaim memory resources; the complexity of writing the deletion marker is log(n) of the LSM tree height, which is very low, ensuring high deletion efficiency and improving the performance of the LSM tree.
[0175] Size amplification in an LSM tree refers to the ratio of currently valid data to the actual space occupied. As users continuously add, delete, and modify user data stored in the LSM tree, the LSM tree grows continuously, with a large amount of new data being inserted while old, expired, and invalid data is not immediately cleared. This results in a large amount of deleted data remaining in the storage space, and this amplification phenomenon significantly reduces query efficiency. This embodiment of the invention triggers merging when the size amplification index reaches a preset amplification threshold, clearing invalid data to mitigate the amplification phenomenon.
[0176] Step 304a: and / or, when a label, native graph, edge of native graph, vertex of native graph and index item are deleted, a scan of the initial LSM tree is triggered to check whether there is a native B-tree corresponding to the deletion label; if there is, the native B-tree is determined as the native B-tree to be merged.
[0177] When a user deletes a label, relationship (i.e., the edges and vertices of the original graph), the original graph itself, or an index, data deletion occurs in a cascading manner. At this point, there is a possibility that user data becomes invalid. To promptly reclaim invalid data and ensure the real-time performance of the LSM tree, a scan is triggered in this situation to check if a merge is necessary.
[0178] Step 305a: and / or, at each preset cleaning interval, determine all original B-trees in the initial LSM tree as the original B-trees to be merged.
[0179] The preset sorting time can be selected by those skilled in the art based on the specific usage scenario.
[0180] This invention allows for manually invoked merge commands from upper layers to improve system performance in certain application scenarios. For example, after importing a large amount of user data, multiple levels of the LSM tree contain numerous B-tree files. Since B-trees offer higher query efficiency, manually creating a merge task merges all data from all levels of the LSM tree to the bottom layer, resulting in only one large B-tree handling all queries within the LSM tree. This significantly improves query efficiency compared to a multi-level LSM tree. Except under high system load, this operation can be used periodically to perform cleanup, improving write and query efficiency. However, under high system load, the background task of this operation can negatively impact system efficiency.
[0181] It should be noted that after the original B-trees are merged into merged B-trees, a merging process is also performed. The merging process of the merged B-trees is the same as that of the original B-trees. The operations in step 30 can directly replace the original B-trees with the merged B-trees, which will not be elaborated here.
[0182] The following is a further description of step 30 in the embodiment of the present invention. Specifically, as follows: Figure 11 As shown, step 30, which involves merging the original B-trees to be merged into at least one merged B-tree to obtain a target LSM tree containing at least one merged B-tree, includes:
[0183] Step 301b: Merge the original B-tree to be merged with the original B-trees that intersect in the next layer to form at least one merged B-tree in the next layer.
[0184] like Figure 12 As shown, when an LSM tree uses a horizontal merging strategy for storage, it stores user data separately according to different levels. Each level of the LSM tree contains at least one B-tree file. The B-tree files are sorted according to the order of the keys in the key-value pairs storing user data, and multiple mergings can be performed. The number of B-tree files generated by horizontal merging is proportional to the number of levels in the LSM tree; the more levels, the more disk space is required, and the lower the query efficiency.
[0185] Step 302b: and / or, merge the original B-trees to be merged at the same level into a merged B-tree at the corresponding next level.
[0186] like Figure 12 As shown, when an LSM tree uses the Size-Tiered Compaction (STC) strategy for storage, it groups B-tree files of the same size into a single tier. Once the number of B-tree files in each tier reaches a certain threshold, two or more B-tree files are merged into a new B-tree file. This process avoids merging mismatched B-tree files too frequently in the future, further improving the write efficiency of the LSM tree and reducing storage costs. However, because it can only merge B-tree files of similar sizes, it cannot effectively utilize contiguous physical space.
[0187] This invention also employs a combined version of the two merging strategies described above: Leveled Size-Tiered Compaction (LSTC). LSTC combines the advantages of both horizontal and STC merging strategies, adding a merging strategy for B-tree files of similar sizes during horizontal merging. Based on the depth of the LSRC's LSM tree, each level of the LSM tree contains B-tree files of consecutive sizes, with higher levels resulting in smaller B-tree file sizes. The LSRC's LSM tree dynamically adjusts the number of levels and the size of the B-tree files according to specific usage scenarios. This further improves write and query efficiency.
[0188] Step 303b: and / or, merge the original B-trees to be merged into at least one merged B-tree at the same level.
[0189] This invention supports a single B-tree carrying a large amount of data. The embodiments of this invention use a B-tree structure as the file unit for storage and provide an All Compaction strategy. During the merging process, files from all layers are merged into a single layer. In a full merging, all user data in the LSM tree is pushed to the same layer; analogously, this transforms the LSM tree into a large B-tree, thus avoiding the need to traverse multiple layers from newest to oldest during queries.
[0190] like Figure 13 As shown, in existing SST files, the index block has only one level. This design aims to make the structure as flat as possible, so that during a query, only the corresponding data block needs to be located in the index block, and then the search can be performed in the data block. If SST files are used as the underlying storage, a large amount of data can only be indexed in a single-level index block, and index loading will consume a lot of memory; in scenarios with large amounts of data, the index will occupy a large amount of memory. The embodiments of this invention use B-trees as the underlying storage, and the multi-level index structure of B-trees solves this problem. In specific implementation, whether to replace all SSTs in the LSM tree with B-trees is a choice made by those skilled in the art; in optional embodiments, considering the convenience of the implementation route, B-trees are used to replace all SSTs in the LSM tree; in some cases, by reducing the amount of data in the system load through sharding, or by configuring a single machine with memory matching the order of magnitude of the usage scenario (generally terabytes, abbreviated as TB), some user data in the LSM tree can still use SST files for underlying storage.
[0191] Step 304b: Obtain the target LSM tree based on at least one merged B-tree.
[0192] The target LSM tree may include at least one original B-tree and at least one merged B-tree, depending on the original B-tree to be merged determined by the merge operation.
[0193] The following is a further description of step 30 in the embodiment of the present invention. Specifically, as follows: Figure 14 As shown, in step 30, at least one merge task is created, which is used to merge the original B-trees to be merged into at least one merged B-tree; the merge task includes at least one subtask, which is used to merge the original B-trees to be merged into one merged B-tree; at least one subtask of the merge task is executed sequentially using the same thread.
[0194] The process of merging the original B-trees to be merged into at least one merged B-tree includes:
[0195] Step 301c: When all the original B-trees to be merged in the merging task are not located at the same level as all the original B-trees to be merged in another merging task, it is determined that there is no level overlap between the merging task and the other merging task.
[0196] like Figure 15 As shown, all the original B-trees to be merged in merge task 1 are not located at the same level as all the original B-trees to be merged in merge task 2, so merge task 1 and merge task 2 can be executed in parallel.
[0197] Step 302c: When the data volume of the B-tree file corresponding to the original B-tree to be merged in a merge task is greater than a preset data value, and all the original B-trees to be merged in the multiple sub-tasks of the merge task are located at the same level of the initial LSM tree, determine the data range of memory or disk involved in the multiple sub-tasks, take multiple sub-tasks with consecutive data ranges as the corresponding multiple first sub-tasks, and split the merge task into multiple first sub-tasks.
[0198] The preset data value is the maximum amount of data that can be merged in a merging task, which can be selected by those skilled in the art based on the specific use case.
[0199] In this embodiment of the invention, for merging tasks involving continuous data intervals, subtasks with continuous data intervals are merged to obtain multiple corresponding first subtasks; subtasks with non-contiguous data intervals remain in their original state and are not merged. For example, ... Figure 16 As shown, B-tree file 1 and B-tree file 2 involve continuous data ranges, so they are merged; as Figure 16 Any B-tree file named "..." shown above and any B-tree file named "..." shown below are not located at the same level as the initial LSM tree, so the data ranges involved are not contiguous and are not merged. Once all subtasks involving contiguous data ranges are merged into the first subtask, the current merge task includes the first subtask and subtasks with discontinuous data ranges.
[0200] like Figure 16As shown, the merge task includes two subtasks, Subtask 1 and Subtask 2. Subtask 1 is used to merge B-tree files 1 and 2, and Subtask 2 is used to merge B-tree files 3 and 4. All the original B-trees to be merged in Subtask 1 are located at the same level as all the original B-trees to be merged in Subtask 2, so the memory or disk data ranges involved in Subtask 1 and Subtask 2 are continuous. The merge task is split into Subtask 1 and Subtask 2 by determining this data range (if Subtask 1 and Subtask 2 are located at level 0 of the initial LSM tree, then the memory data range they involve is determined; if Subtask 1 and Subtask 2 are not located at level 0 of the initial LSM tree, then the disk data range they involve is determined).
[0201] Step 303c: Use two parallel first threads to execute the merging task and the other merging task respectively. Each first thread generates the result file of the merging task or the other merging task based on the corresponding original B-tree to be merged. Use multiple parallel second threads to execute the corresponding first sub-task respectively. Each second thread generates a result file of the merging task based on the corresponding original B-tree to be merged.
[0202] Two parallel first threads are used to execute merge task 1 and merge task 2 respectively. One first thread generates the result file of merge task 1 based on the original B-trees to be merged in merge task 1; the other first thread generates the result file of merge task 2 based on the original B-trees to be merged in merge task 2. Multiple parallel second threads are used to execute subtask 1 and subtask 2 respectively. One second thread generates the corresponding first result set based on the original B-trees to be merged in subtask 1 and writes it into memory; the other second thread generates the corresponding second result set based on the original B-trees to be merged in subtask 2 and writes it into memory. The first and second result sets are then written together to disk to generate the result files of the corresponding merge tasks (the merge tasks to which subtask 1 and subtask 2 belong).
[0203] Step 304c: Use the result file as the corresponding B-tree file for merging B-trees to obtain the merged B-tree.
[0204] This invention improves the merging efficiency of LSM trees by executing merging tasks in parallel.
[0205] The following is a further description of step 30 in the embodiment of the present invention. Specifically, as follows: Figure 17 As shown, in step 30, before merging the original B-trees to be merged into at least one merged B-tree, the original B-trees to be merged are prefetched from memory or disk, wherein:
[0206] Step 301d: Access the pages of the original B-tree to be merged, extract the page corresponding to the leftmost node of the leaf layer in the original B-tree to be merged as the page to be accessed, and determine whether the page to be accessed is already in the cache pool in memory.
[0207] The leftmost node is the leftmost node at a certain level in the tree. The buffer pool is a storage layer component that maintains a cache area in memory to store pages read from disk, improving the write and query efficiency of the graph database by reducing disk I / O operations.
[0208] In this embodiment of the invention, the leaf node layer of the B-tree is prefetched and traversed from left to right to achieve ascending order iteration of the user data stored in the B-tree.
[0209] Step 302d: If yes, then retrieve the page to be accessed directly from the cache pool.
[0210] Step 303d: If not, read the page to be accessed from the disk into the cache pool, and retrieve the page to be accessed from the cache pool.
[0211] Step 304d: Treat the page to be accessed as an accessed page, treat the page corresponding to the right sibling node of the leaf layer as the new page to be accessed, and release the accessed page.
[0212] Step 305d: Iterate the above process until all the original B-trees to be merged are removed from the cache pool.
[0213] Prefetching is a common optimization technique for improving database query performance. Its basic idea is to utilize idle time to read data pages that may be accessed in the future from the hard drive, reducing subsequent I / O operations and thus improving query efficiency. Strategic prefetching refers to using look-ahead analysis techniques for specific operations to improve data row availability, reduce real-time I / O pressure, and lower response time. Generally, the key to strategic prefetching is to analyze business scenarios and access history to develop strategically optimized prefetching algorithms.
[0214] When an application needs to access a page, it first checks if the page is already in the cache pool. If so, it retrieves the page directly from the cache pool; otherwise, it needs to be read from the disk into the cache pool. Since this embodiment of the invention knows in advance which pages need to be accessed and the order of access during the original B-tree merging, prefetching when loading pages from disk improves the memory hit rate of the cache pool, reducing memory hit failures and avoiding the time consumed by page faults that require reloading pages from disk. In an optional embodiment, the system call posix_fadvise is used for prefetching, prefetching the right sibling page POSIXFADVWILLNEED each time and releasing the already accessed left sibling page POSIXFADV_DONTNEED.
[0215] In summary, using a B-tree as the underlying storage offers the following advantages when performing only queries (operations consisting solely of query operations):
[0216] The splitting of the B-tree during the writing process reduces writing performance. The bottom-up generation algorithm in this embodiment of the invention solves this problem. Furthermore, the sequential writing characteristic of the LSM tree in the storage layer makes the storage method of this embodiment of the invention have a higher throughput during writing.
[0217] There is no invalid data in the B-tree, meaning that all user data in the entire disk space is valid data; however, there is invalid data in the LSM tree. In this embodiment of the invention, various merging trigger conditions are designed to clean up the invalid data.
[0218] In single-point query scenarios, B-trees only search from the root node to the leaf nodes, resulting in a query time complexity of O(log n). This requires loading each level's pages into memory, using a memory size of btr.level * pageSize, which is the product of the B-tree's level (btr.level) and the page size (pageSize), where pageSize is a constant. LSM tree search efficiency depends on its level and the data distribution within the LSM tree. It requires searching layer by layer from newest to oldest until the data is found, or if not found at all. Query efficiency is unstable; hot data modifications may result in a direct return, while querying cold data requires accessing multiple file levels. During a query, the LSM tree needs to load all the searched SST files into memory. Therefore, B-trees offer better cost-effectiveness for single-point queries.
[0219] In range query scenarios: B-trees are ordered by key, and range queries correspond to consecutive records; it is only necessary to find the left endpoint of the range and traverse them one by one; in this case, the prefetch mechanism has a very high accuracy in inferring the next page to be accessed, thus making B-tree queries more efficient. In contrast, LSM trees require searching at every level, resulting in a higher number of SST files accessed and a higher memory consumption.
[0220] This invention utilizes a B-tree as the underlying storage for the LSM tree and employs a native graph to enhance the query efficiency of the LSM tree. This enables rapid, batch writing of user data with high write efficiency, and also ensures high query efficiency after writing. Compared to graph databases based on key-value pair encapsulation, the native graph module of this invention provides better adjacency query capabilities. Compared to storage models that directly use B-trees as the index structure, the LSM tree structure of this invention provides better write throughput. Compared to storage models that directly use LSM trees as the index structure, this invention uses B-tree file support, which optimizes I / O operations and reduces memory usage under larger data volumes. Since the underlying file of the LSM tree in this invention is read-only, it facilitates code maintenance and solves the concurrency issues associated with local code modifications when directly using B-trees as the storage model.
[0221] Example 2:
[0222] Based on the above embodiment 1, this embodiment of the invention provides an optional embodiment of step 40 in a graph database storage method, wherein the original graph includes vertices and edges, the adjacency information includes a mapping from the vertex ID of the vertex to the edge ID of the edge; there is at least one vertex under the label, the vertex includes at least one attribute, and the index item includes the attribute and the vertex ID of the corresponding vertex.
[0223] Among them, the index item is the information in the user data; the native graph is the adjacency information of the index item, which includes points and edges, but does not include attribute information; the label is a set of vertices of a certain type.
[0224] The native graph module in this embodiment of the invention handles adjacency queries related to graph databases. Operations on the native graph in this embodiment are cascaded. To better illustrate the storage method of this embodiment, an example of deleting tags is provided, as follows: Figure 18 As shown, the storage method of the graph database further includes:
[0225] Step 401a: Obtain all vertices to be deleted under the label to be deleted.
[0226] Step 402a: Obtain the ID of the edge to be deleted based on the ID of the vertex to be deleted.
[0227] Step 403a: Delete the vertex to be deleted and the edge to be deleted.
[0228] To better illustrate the storage method of this invention, an example of querying based on a custom index item is provided, as follows: Figure 19 As shown, the storage method of the graph database further includes:
[0229] Step 401b: Obtain the corresponding query edge ID based on the query vertex ID in the received query index item and the query adjacency information of the original graph.
[0230] Step 402b: Obtain the result vertex ID based on the query edge ID and the query adjacency information.
[0231] Step 403b: Obtain the corresponding result index in the target LSM tree based on the result vertex ID, and obtain the corresponding user data based on the attribute corresponding to the result index.
[0232] The storage method of this invention includes an index module and a native graph module. Based on the synchronization relationship between the index module and the native graph module, three storage modes are supported: index-first, native graph-first, and balanced. Those skilled in the art can choose the storage mode according to the specific application scenario. "First" refers to the order in which the user data stored in the index module and the native graph module is updated; the module storing older versions of user data updates the user data according to the module storing newer versions.
[0233] In optional embodiments, based on the characteristics of transactions (a transaction is an indivisible unit of work; operations within a transaction are either all executed or none are executed), the graph database is required to use a balanced mode, meaning that a transaction commit requires corresponding updates in both the index module and the native graph module. In analytical scenarios where transaction characteristics are not critical, the graph database is required to use a native graph-first or index-first mode to improve the write and query performance of the graph database.
[0234] In native graph-first mode, after a transaction updating user data commits, the user data stored in the native graph module is always the latest version. However, the version of the user data in the index module may not be the latest and could lag behind the native graph module, meaning there are unsynchronized operations from that transaction. In index-first mode, after the transaction commits, the user data stored in the index module is always the latest version, but the version of the user data in the native graph module may not be the latest and could lag behind the index module, meaning there are unsynchronized operations from that transaction. The index-first mode makes the graph database in this embodiment of the invention closer to a Relational Database Management System (RDBMS). In balanced mode, both the index module and the native graph module store the latest version of user data. Lagging modules always need to confirm with the prior modules when performing queries.
[0235] In native graph-first mode, the deletion flag needs to be verified in the native graph module during querying; in index-first mode, this verification is not required in the native graph module.
[0236] In the native graph-first query mode, the native graph module handles all lookups and deletions. Since deletion operations are marked in the native graph module, user data retrieved from the LSM tree during subsequent lookups needs to be verified in the native graph to confirm its existence. A mark in the native graph module indicates that the corresponding user data has been deleted; even if such user data is found in the LSM tree of the index module, it will be determined as invalid and will not be returned. Meanwhile, the native graph module records the number of vertices and edges deleted in the native graph during deletion operations, thereby calculating the number of deleted index entries. This enables maintenance of the proportion of valid data in the LSM tree index entries, providing a basis for merging (triggering merges).
[0237] Examples of queries in the native graph-first mode and the index-first mode are provided below:
[0238] The native graph structure is: (Person)-[KNOWS]-(Person).
[0239] Here, "Person" is the label corresponding to vertices, and "KNOWS" is the relationship between "Person" vertices, i.e., the edge label between vertices.
[0240] The scenario is: delete a vertex based on the Key value in the index entry of a certain vertex input by the user. The operation steps are as follows:
[0241] (1) In the index module, use the Key to look up the corresponding vertices to obtain an array of vertex IDs;
[0242] (2) In the native graph module, mark all vertex IDs as deleted;
[0243] (3) Delete all index entries corresponding to the Key;
[0244] In the native graph-first mode, a deletion operation response can be returned after step (2) is completed, and the operations in step (3) can be performed in the background. In the index-first mode, a deletion operation response must be returned only after step (3) is completed.
[0245] In this embodiment of the invention, considering incremental synchronization (replaying operations in the OLAP system), a large number of deletion operations may be added. By providing a native graph-first storage mode, the operations in step (3) can be postponed, thereby improving the response speed of the graph database in this embodiment of the invention. The storage method of this embodiment of the invention tightly integrates the index and the native graph in terms of functionality. By supporting three query modes, the index and the native graph are decoupled to a certain extent, allowing some user data in the storage to lag behind, thereby reducing the response time of writing and querying. While taking into account both writing efficiency and query efficiency, the overhead and performance of the graph database storage layer are further optimized.
[0246] Example 3:
[0247] Based on Embodiment 2 above, this embodiment of the invention provides a specific example of querying when using the graph database storage method in Embodiment 2 of the invention, so as to better understand the storage method of the invention. The storage mode is a balanced mode, as detailed below:
[0248] The original graph structure is: (Student) - [Friend] - (Student); (Student) -> [Registered Residence] -> (Province).
[0249] In the "(Student)-[Friend]-(Student)" section, "Student" is the label corresponding to the vertex. The student will be described as a vertex below, and the primary key in this label is the student's student ID. "Student" represents the vertex, and "Friend" represents the relationship between vertices (the labels of edges in the original graph). In the "(Student)->[Registered Residence]->(Province)" section, "Province" is the label corresponding to the endpoint (the endpoint is a directed vertex), and the primary key in this label is the name of the province. "Student" represents the starting point (the starting point is a directed vertex), the endpoint is the province, and "Registered Residence" represents the relationship between the starting and ending points.
[0250] The indexing module is responsible for mapping the index items entered by the user to the vertex IDs of the native graph module, and then mapping the vertex IDs back to the attribute data of the vertex / edge.
[0251] The index module stores the following attribute data:
[0252] The index `Index:<Vertex ID, Attribute Data>` is used to store all attribute data of a vertex; in this embodiment, it includes the index `INDEX_1_STUDENT` to store the attribute data of a student and the index `INDEX_1_PROVINCE` to store the attribute data of a province.
[0253] The index Index_2:<user-input vertex key, vertex ID> stores the mapping from the user-input vertex key to the vertex ID; in this embodiment, it includes the index INDEX_2_STUDENT and the index INDEX_2_PROVINCE.
[0254] Use index_3:<user-input edge key, start ID + end ID + edge ID> to store the mapping from the user-input edge key to the edges in the original graph;
[0255] In a graph database, the user input vertex key for the query "The friends of students in province X are all from province Y" is X.
[0256] (1) Use province X to obtain the starting point ID of X in the index INDEX_2_STUDENT; that is, find the starting point ID of the vertex of the student of province X in the LSM tree;
[0257] (2) Search in the original graph according to the specified path “(X)<-[Household Registration]<-(Student)->[Friend]->-(Student)->[Household Registration]->(Y)” to obtain an array of endpoint IDs for all Y; that is, using the starting point IDs obtained in step (1), search in the specified path of the original graph through the structure of “(Student)-[Friend]-(Student)” and “(Student)->[Household Registration]->(Province)” to obtain an array of endpoint IDs for the province vertices of the friends (students) of the students in province X;
[0258] (3) Map the endpoint ID of each Y endpoint ID array back to the name of the province according to INDEX_1_PROVINCE; that is, in the LSM tree, find the names of the provinces corresponding to the students of province X based on the endpoint ID of the provinces of their friends.
[0259] Example 4:
[0260] like Figure 20 The diagram shown is an architectural schematic of a graph database storage device according to an embodiment of the present invention. The graph database storage device of this embodiment includes one or more processors 21 and a memory 22. Figure 20 Take a processor 21 as an example.
[0261] Processor 21 and memory 22 can be connected via a bus or other means. Figure 20 Taking the example of a connection between China and Israel via a bus.
[0262] The memory 22, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs and non-volatile computer-executable programs, such as the graph database storage method in Embodiment 1. The processor 21 executes the graph database storage method by running the non-volatile software programs and instructions stored in the memory 22.
[0263] Memory 22 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state storage device. In some embodiments, memory 22 may optionally include memory remotely located relative to processor 21, which can be connected to processor 21 via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0264] The program instructions / modules are stored in the memory 22. When executed by one or more processors 21, they perform the graph database storage method described in Embodiment 1 above, for example, by executing the above-described method. Figures 4-6 , Figure 8 , Figures 9-11 , Figure 14 and Figures 17-19 The steps shown.
[0265] It is worth noting that the information interaction and execution process between the modules and units in the above-mentioned device and system are based on the same concept as the processing method embodiment of the present invention. For details, please refer to the description in the method embodiment of the present invention, and will not be repeated here.
[0266] Those skilled in the art will understand that all or part of the steps in the various methods of the embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, which may include: read-only memory (ROM), random access memory (RAM), magnetic disk or optical disk, etc.
[0267] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for storing a graph database, characterized in that, include: Based on user data, at least one primitive B-tree is constructed from the bottom up; wherein, the process includes: initializing at least one primitive B-tree; after initializing at least one primitive B-tree, performing the insertion process of the primitive B-tree, iterating sequentially until all user data is inserted into the primitive B-tree; each time a primitive B-tree is obtained, each primitive B-tree is stored on the disk as a B-tree file; The original B-tree is used as the data of the corresponding nodes in the initial LSM tree to obtain the initial LSM tree; Obtain the merging trigger condition of the initial LSM tree, determine the original B-tree to be merged according to the merging trigger condition, merge the original B-tree to be merged into at least one merged B-tree, and obtain the target LSM tree containing at least one merged B-tree. The native graph is used to store the adjacency information between the tags to which the user data belongs. Based on the adjacency information, an index entry is created in the target LSM tree so that the adjacency information can be obtained through the index entry and the corresponding user data can be queried based on the adjacency information. The native graph includes vertices and edges, and the adjacency information includes a mapping from the vertex ID of the vertex to the edge ID of the edge; at least one vertex exists under each label, the vertex includes at least one attribute, and the index item includes the attribute and the corresponding vertex ID; the storage method of the graph database further includes: obtaining the corresponding query edge ID based on the query vertex ID in the received query index item and the query adjacency information of the native graph; obtaining the result vertex ID based on the query edge ID and the query adjacency information; obtaining the corresponding result index in the target LSM tree based on the result vertex ID; and obtaining the corresponding user data based on the attribute corresponding to the result index.
2. The method for storing a graph database according to claim 1, characterized in that, The insertion process includes: Perform merge sorting on at least one user data entry to obtain a merged result set; According to the order of the result data in the merged result set, the result data is inserted into the rightmost leaf node of the original B-tree in sequence; When the number of result data in the page storing the current rightmost leaf node reaches a preset number of keywords, the intermediate item (i, j) of the B-tree is determined based on the i-th result data inserted into the current rightmost leaf node when the preset number of keywords is reached, and the page number j of the page. Create a new node as the parent node of the current rightmost leaf node. After the parent node is created, insert the middle item (i, j) of the B-tree into the parent node. Adjust the original B-tree according to its basic properties; Following the order of the result data in the merged result set, continue to insert the corresponding result data into the current rightmost leaf node in sequence until the result data in the page storing the current rightmost leaf node reaches the preset number of keywords; The above process is iterated until all the result data is inserted into the original B-tree.
3. The method for storing a graph database according to claim 2, characterized in that, The step of sequentially inserting corresponding result data into the rightmost leaf node according to the order of the result data in the merged result set, until the result data in the page storing the rightmost leaf node reaches the preset number of keywords, includes: Create the right sibling node of the current rightmost leaf node, update the current rightmost leaf node to the right sibling node, and insert the (i+1)th result data into the current rightmost leaf node; Based on the (i+1)th result data and the page number k of the page storing the current rightmost leaf node, determine the B-tree intermediate item (i+1, k) and insert the B-tree intermediate item (i+1, k) into the parent node; The original B-tree is adjusted according to the aforementioned basic properties; Starting from the (i+2)th result data, the corresponding result data is sequentially inserted into the current rightmost leaf node until the number of result data in the page storing the current rightmost leaf node reaches the preset number of keywords.
4. The method for storing a graph database according to claim 1, characterized in that, The step of obtaining the merge triggering condition of the initial LSM tree and determining the original B-tree to be merged based on the merge triggering condition includes: When the number of B-tree files in the m-th layer of the initial LSM tree reaches the first preset threshold corresponding to the m-th layer, multiple original B-trees in the m-th layer that have an intersection with the next layer of the initial LSM tree are identified, and the original B-trees are identified as the original B-trees to be merged. And / or, when the number of B-tree files reaches the second preset threshold corresponding to the m-th layer, all original B-trees in the m-th layer are determined as the original B-trees to be merged; And / or, the spatial size of each level of the initial LSM tree is obtained according to the preset file size function size(), and the spatial scaling index of the initial LSM tree is obtained according to the spatial size. ;in, This represents the B-tree file at the m-th level of the initial LSM tree; when the spatial magnification index reaches a preset magnification threshold, the original B-tree corresponding to the deletion mark in the 0-th level is determined, and the original B-tree is determined as the original B-tree to be merged; And / or, when a label, native graph, edge of native graph, vertex of native graph and index item are deleted, a scan of the initial LSM tree is triggered to check whether there is a native B-tree corresponding to the deletion label; if there is, the native B-tree is determined as the native B-tree to be merged; And / or, at preset intervals, all original B-trees in the initial LSM tree are identified as the original B-trees to be merged.
5. The method for storing a graph database according to claim 4, characterized in that, The step of merging the original B-trees to be merged into at least one merged B-tree to obtain a target LSM tree containing at least one merged B-tree includes: The original B-tree to be merged is merged with the original B-trees in the next layer that have intersections to form at least one merged B-tree in the next layer; And / or, merge the original B-trees to be merged at the same level into a merged B-tree at the corresponding next level; And / or, merge the original B-trees to be merged into at least one merged B-tree at the same level; The target LSM tree is obtained based on at least one merged B-tree.
6. The method for storing a graph database according to claim 4, characterized in that, Create at least one merge task, which is used to merge the original B-trees to be merged into at least one merged B-tree; the merge task includes at least one subtask, which is used to merge the original B-trees to be merged into one merged B-tree; At least one subtask of the merging task is executed sequentially using the same thread; The process of merging the original B-trees to be merged into at least one merged B-tree includes: When all the original B-trees to be merged in the merging task are not at the same level as all the original B-trees to be merged in another merging task, it is determined that there is no hierarchical overlap between the merging task and the other merging task. When the data volume of the B-tree file corresponding to the original B-tree to be merged in a merge task is greater than a preset data value, and all the original B-trees to be merged in the multiple subtasks of the merge task are located at the same level of the initial LSM tree, the data range of memory or disk involved in the multiple subtasks is determined, and multiple subtasks with consecutive data ranges are taken as the corresponding multiple first subtasks, and the merge task is split into multiple first subtasks. The merging task and the other merging task are executed by two parallel first threads respectively. Each first thread generates the result file of the merging task or the other merging task based on the corresponding original B-tree to be merged. The corresponding first subtask is executed by multiple parallel second threads respectively. Each second thread generates a result file of the merging task based on the corresponding original B-tree to be merged. The result file is used as the corresponding B-tree file for merging B-trees to obtain the merged B-tree.
7. The method for storing a graph database according to claim 4, characterized in that, Before merging the original B-trees to be merged into at least one merged B-tree, the original B-trees to be merged are prefetched from memory or disk, wherein: Access the page of the original B-tree to be merged, extract the page corresponding to the leftmost node of the leaf layer in the original B-tree to be merged as the page to be accessed, and determine whether the page to be accessed is already in the cache pool in memory; If so, the page to be accessed is retrieved directly from the cache pool; If not, the page to be accessed is read from the disk into the cache pool, and then retrieved from the cache pool. Treat the page to be accessed as an already accessed page, treat the page corresponding to the right sibling node of the leaf layer as the new page to be accessed, and release the already accessed page. The above process is iterated until all the original B-trees to be merged are retrieved from the cache pool.
8. The method for storing a graph database according to claim 1, characterized in that, The storage method for the graph database also includes: Get all vertices under the label to be deleted; Based on the vertex ID to be deleted, obtain the edge ID to be deleted. Delete the vertex and edge to be deleted.
9. A storage device for a graph database, characterized in that, The system includes at least one processor and a memory, which are connected via a data bus. The memory stores instructions that can be executed by the at least one processor, which, when executed by the processor, are used to implement the graph database storage method according to any one of claims 1-8.
Citation Information
Patent Citations
Data query request processing method and device, equipment and storage medium
CN114969165A
Implementation method, system and equipment of distributed native graph and storage medium
CN115795107A
