Neighbor information query method, device and electronic equipment of graph database

CN118551087BActive Publication Date: 2026-10-27中国邮政储蓄银行股份有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410740124.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-07
Publication Date
2026-10-27
Estimated Expiration
2044-06-07

AI Technical Summary

Technical Problem

[0004]本申请的主要目的在于提供一种图数据库的邻居信息查询方法、装置、存储介质、处理器和电子设备,以至少解决现有技术查询某个节点的邻居节点需要遍历全图的节点,从而导致效率低下的问题

Benefits of technology

[0034]应用本申请的技术方案,将所有节点的所有的邻居节点的ID存储至key-value数据库,当存在查询某个节点的邻居节点的需求时,直接从key-value数据库找到这一节点的邻居节点的ID,相比现有技术不需要遍历全部的节点,从而减少了查找节点所需的时间,进而解决了现有技术查询某个节点的邻居节点需要遍历全图的节点,从而导致效率低下的问题。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118551087B_ABST
    Figure CN118551087B_ABST
Patent Text Reader

Abstract

The application provides a neighbor information query method and device of a graph database and electronic equipment, the method comprising: determining the ID of all nodes and the degree neighbor information set of all nodes according to a relational data table, and storing the ID of all nodes and the degree neighbor information set of all nodes to a key-value database; in the case of receiving query request information, finding the H-degree neighbor information set of a first target node from the key-value database. Compared with the prior art, the method does not need to traverse all nodes, thereby reducing the time required to find nodes, and thereby solving the problem that the prior art needs to traverse all nodes to query the neighbor nodes of a certain node, thereby causing low efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and more specifically, to a method, apparatus, storage medium, processor, and electronic device for querying neighbor information in a graph database. Background Technology

[0002] In recent years, as one of the representatives of NoSQL databases, graph databases and graph technologies have been widely used in information systems and services based on relational analysis and computation due to their significant advantages in relational storage, querying, and graph derivation algorithms. Graph databases and graph technologies are based on the concepts of nodes and edges, construct graphs based on the relationships between nodes and edges, and execute relational queries and a series of derivation algorithms.

[0003] Due to the relatively complex data structure of graph data and the high computational requirements of graph queries, the speed of neighbor queries in graph databases has always been a focal point and challenge in the field. Currently, with the increasing demands for real-time data from various business needs, improving the performance of neighbor queries in graph databases has become a consensus among graph database vendors and a key challenge in technological iteration. Currently, taking a graph with billions of nodes and edges as an example, most graph database products can achieve second-level or even millisecond-level response times for neighbor queries within 3 degrees. However, as the neighbor degree increases, performance often drops significantly, especially for high-degree neighbor queries exceeding 20 degrees. Since the query may have traversed all nodes in the graph, performance is often severely impacted, and there have even been cases where queries fail to return results due to query overruns. Summary of the Invention

[0004] The main objective of this application is to provide a method, apparatus, storage medium, processor, and electronic device for querying neighbor information in a graph database, so as to at least solve the problem that the prior art requires traversing all nodes in the graph to query the neighbor nodes of a certain node, resulting in low efficiency.

[0005] To achieve the above objectives, according to one aspect of this application, a method for querying neighbor information in a graph database is provided. The graph database includes multiple nodes, and the method includes:

[0006] Based on the relational data table, determine the IDs of all nodes and the multi-degree neighbor information set of all nodes, and store the IDs of all nodes and the multi-degree neighbor information set of all nodes in a key-value database. The relational data table includes the connection relationships between all nodes in the graph database and the IDs of all nodes. The multi-degree neighbor information set includes the IDs of all N-degree neighbor nodes of the node. The N-degree neighbor node is one of a plurality of nodes, and there are N-1 nodes between the node and the N-degree neighbor node, 1≤N≤M, where M is a positive integer.

[0007] Upon receiving a query request, the system searches for the H-degree neighbor information set of the first target node in the key-value database. The query request indicates a request to query the H-degree neighbor information set of the first target node. The query request includes the ID of the first target node, which is any one of the plurality of nodes, where 1 ≤ H ≤ M.

[0008] Optionally, the key-value database includes multiple key-value data tables. Based on the relational data tables, the IDs of all the nodes and the multi-degree neighbor information sets of all the nodes are determined, and the IDs of all the nodes and the multi-degree neighbor information sets of all the nodes are stored in the key-value database, including:

[0009] The first processing step is to determine the IDs of all the nodes and the set of first-degree neighbors of all the nodes according to the relational data table, and store at least the IDs of all the nodes and the set of first-degree neighbors of all the nodes in the first key-value data table.

[0010] The acquisition step involves obtaining the set of G-1 degree neighbor information for all nodes from the (G-1)th key-value data table, where 2 ≤ G ≤ M;

[0011] The second processing step is to determine the G-degree neighbor information set of all the nodes based on the 1-degree neighbor information set of all the nodes and the G-1-degree neighbor information set of all the nodes, and to store at least the IDs of all the nodes and the G-degree neighbor information set of all the nodes into the G-th key-value data table.

[0012] Update steps: Increment G by 1;

[0013] Repeat the steps, including the second processing step and the update step, multiple times until G equals M.

[0014] Optionally, the process of determining the G-degree neighbor information set of all the nodes based on the 1-degree neighbor information set of all the nodes and the G-1-degree neighbor information set of all the nodes includes:

[0015] From the G-1 degree neighbor information set of the second target node, obtain multiple first target IDs, where the second target node is any one of the multiple nodes, and the first target ID is the ID of the node included in the G-1 degree neighbor information set of the second target node, and the first target ID corresponds one-to-one with the ID of the node included in the G-1 degree neighbor information set of the second target node;

[0016] Based on the first target ID and the set of first-degree neighbor information of all the nodes, a target neighbor information set is determined, wherein the target neighbor information set includes the set of first-degree neighbor information of all the nodes to which the first target ID belongs;

[0017] Based on the G-1 degree neighbor information set of the second target node and the target neighbor information set, at least one second target ID is determined, wherein the second target ID is an ID that exists simultaneously in the G-1 degree neighbor information set and the target neighbor information set of the second target node;

[0018] Delete all the second target IDs in the target neighbor information set to obtain the G-degree neighbor information set of the second target node.

[0019] Optionally, based on the relational data table, determine the IDs of all the nodes and the set of first-degree neighbors of all the nodes, including:

[0020] Based on the relational data table, obtain the IDs of all the nodes and the edge information of all the nodes. The edge information of the nodes includes the ID of the node and the other node connected by the edge to the node.

[0021] Store the IDs of all the nodes and the edge information of all the nodes in the (M+1)th key-value data table;

[0022] From the (M+1)th key-value data table, obtain the IDs of all nodes and the edge information of all nodes, and classify the edge information of the nodes according to the IDs of all nodes to obtain multiple edge information sets. Each edge information set corresponds one-to-one with a node, and each edge information set includes the edge information corresponding to the corresponding node.

[0023] Based on all the edge information sets, determine the 1-degree neighbor information sets of all the nodes.

[0024] Optionally, the key-value database includes multiple key-value tables. The H-th key-value table stores the IDs of all the nodes and the set of H-degree neighbors of all the nodes. Upon receiving a query request, the table searches the key-value database for the set of H-degree neighbors of the first target node, including:

[0025] Based on the ID of the first target node, the H-degree neighbor information set of the first target node is retrieved from the H-th key-value data table.

[0026] Optionally, in the process of storing at least all the IDs of the nodes and the set of G-degree neighbors of all the nodes into the G-th key-value data table, the method includes:

[0027] The ID of the third target node, the set of G-degree neighbors of the third target node, and the number of G-degree neighbors of the third target node are stored in the G-th key-value data table, wherein the third target node is any one of the multiple nodes, and the number of G-degree neighbors of the third target node is the number of IDs contained in the set of G-degree neighbors of the third target node.

[0028] According to another aspect of this application, a neighbor information query device for a graph database is provided. The graph database includes multiple nodes, and the device includes:

[0029] The determining unit is configured to determine the IDs of all nodes and the multi-degree neighbor information set of all nodes based on a relational data table, and store the IDs of all nodes and the multi-degree neighbor information set of all nodes in a key-value database. The relational data table includes the connection relationships between all nodes in the graph database and the IDs of all nodes. The multi-degree neighbor information set includes the IDs of all N-degree neighbor nodes of the node. The N-degree neighbor node is one of a plurality of nodes, and there are N-1 nodes between the node and the N-degree neighbor node, 1≤N≤M, where M is a positive integer.

[0030] The lookup unit is used to look up the H-degree neighbor information set of the first target node from the key-value database when a query request information is received. The query request information indicates a request to query the H-degree neighbor information set of the first target node. The query request information includes the ID of the first target node. The first target node is any one of the plurality of nodes, where 1≤H≤M.

[0031] According to another aspect of this application, a computer-readable storage medium is provided, the computer-readable storage medium including a stored program, wherein, when the program is executed, it controls the device where the computer-readable storage medium is located to perform any of the aforementioned graph database neighbor information query methods.

[0032] According to another aspect of this application, a processor is provided for running a program, wherein the program, when running, executes any of the described methods for querying neighbor information in a graph database.

[0033] According to another aspect of this application, an electronic device is provided, comprising: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs including methods for performing any of the described graph database neighbor information query methods.

[0034] By applying the technical solution of this application, the IDs of all neighboring nodes of all nodes are stored in a key-value database. When there is a need to query the neighboring nodes of a certain node, the IDs of the neighboring nodes of this node are directly found from the key-value database. Compared with the existing technology, it is not necessary to traverse all nodes, thereby reducing the time required to search for nodes. This solves the problem that the existing technology requires traversing all nodes in the graph to query the neighboring nodes of a certain node, which leads to low efficiency. Attached Figure Description

[0035] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:

[0036] Figure 1 A flowchart illustrating a method for querying neighbor information in a graph database according to an embodiment of this application is shown.

[0037] Figure 2 A flowchart illustrating another method for querying neighbor information in a graph database according to an embodiment of this application is shown.

[0038] Figure 3 A structural block diagram of a neighbor information query device for a graph database according to an embodiment of this application is shown. Detailed Implementation

[0039] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.

[0040] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.

[0041] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0042] For ease of description, the following explains some of the nouns or terms used in the embodiments of this application:

[0043] Graph Neighbor Query: Graph databases store and query data using a graph data structure. Their primary function and characteristic lies in their ability to retrieve data relationships, i.e., graph data query functionality. Common graph query functions include k-degree neighbor query, path query, and subgraph query. Among these, the most commonly used is the k-degree neighbor query. This refers to locating all points with k-degree neighbor relationships to the starting point after the graph is constructed, given any node as the starting point. This is achieved by querying points directly connected to the starting point (denoted as 1-degree neighbors), points directly connected to the starting point's first-degree neighbors (denoted as 2-degree neighbors), and a series of points that are neighbors of the starting point and its neighbors (queries are repeated k times). As a fundamental function of graph databases, k-degree neighbor query can not only be directly applied to locating relationships but also forms the basis for many graph algorithms (such as PageRank, shortest path, clustering, etc.). In practice, however, the computational performance of high-order neighbor queries often becomes a bottleneck for graph databases due to the significant computational resource consumption.

[0044] Shortest Path: Due to the inherent characteristics of graph databases, graph queries (especially high-order graph queries) may have multiple connecting paths between the starting node and the target node, leading to confusion in the determination of k-degree neighbors. Currently, in practice, this problem is often solved by explicitly identifying the shortest path. Specifically, among all paths between the starting and target nodes, the path with the fewest nodes is selected as the shortest path. The shortest path itself is both a determination method and a graph algorithm, which is of great significance for k-degree neighbor queries (especially high-order queries). It can effectively avoid confusion in k-degree neighbor determination and prevent the influence of circular relationships between some nodes on neighbor determination.

[0045] MapReduce Algorithm: MapReduce is a software architecture proposed by Google for parallel computation of large-scale datasets. Its core is the divide-and-conquer idea, in which the Mapper is responsible for breaking down complex tasks into several "simple tasks" for parallel processing, and the Reducer is responsible for globally summarizing the results of the map phase. For MapReduce, each subtask is highly parallelized within MapReduce, and the high parallelism of subtasks greatly improves the performance of processing massive amounts of data.

[0046] 1. Mapper: The Mapper is the first step in the MapReduce algorithm. It is responsible for dividing the input data into several small data segments and processing each data segment. The Mapper maps each data segment into a set of key-value pairs, and then sends these key-value pairs to the next step.

[0047] 2. Shuffle-1: Shuffle-1 is the second step of the MapReduce algorithm. It is responsible for sorting the key-value pairs generated by the Mapper according to the value of the key, and distributing key-value pairs with the same key value to the same Reducer for processing.

[0048] 3. Reducer: The Reducer is the last step in the MapReduce algorithm. It is responsible for merging and calculating the key-value pairs passed from the Shuffle-1 step and generating the final output.

[0049] Key-value databases, represented by Redis and BerkeleyDB, use keys to add, query, or delete data. Their biggest advantage is that they support fast queries and are suitable for application scenarios where data changes rapidly.

[0050] As introduced in the background section, due to the relatively complex data structure of graph data and the high computational requirements of graph queries, the speed of neighbor queries in graph databases has always been a focal point and challenge in the field of graph databases. Currently, with the increasing demands for real-time data from various business needs, improving the performance of neighbor queries in graph databases has become a consensus among graph database vendors and a key challenge in technological iteration. Currently, taking a graph with billions of nodes and edges as an example, most graph database products can achieve second-level or even millisecond-level response times for neighbor queries within 3 degrees. However, as the neighbor degree increases, performance often drops significantly, especially for high-degree neighbor queries exceeding 20 degrees. Since the query may have traversed all nodes in the graph, performance is often severely affected, and there have even been cases where queries fail to return results due to query overruns. To address the problem of inefficiency caused by the need to traverse the entire graph to query the neighbor nodes of a specific node in existing technologies, embodiments of this application provide a method, apparatus, storage medium, processor, and electronic device for querying neighbor information in a graph database.

[0051] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.

[0052] This embodiment provides a method for querying neighbor information in a graph database. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Also, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.

[0053] Figure 1 This is a flowchart of a method for querying neighbor information in a graph database according to an embodiment of this application. Figure 1As shown, the method includes the following steps:

[0054] Step S101: Based on the relational data table, determine the IDs of all the above-mentioned nodes and the multi-degree neighbor information set of all the above-mentioned nodes, and store the IDs of all the above-mentioned nodes and the multi-degree neighbor information set of all the above-mentioned nodes in the key-value database. The relational data table includes the connection relationships between all the nodes in the graph database and the IDs of all the nodes. The multi-degree neighbor information set includes the IDs of all the N-degree neighbor nodes of the above-mentioned node. The multi-degree neighbor node is one of the above-mentioned nodes, and there are N-1 nodes between the above-mentioned node and the multi-degree neighbor node, 1≤N≤M, where M is a positive integer.

[0055] Specifically, by storing the IDs of all the aforementioned nodes and the set of multi-degree neighbor information of all the aforementioned nodes in a key-value database, it becomes easier to find the set of H-degree neighbor information of the first target node from the key-value database later.

[0056] The aforementioned key-value database includes multiple key-value data tables. Step S101 involves determining the IDs of all the aforementioned nodes and the set of multi-degree neighbor information for all the aforementioned nodes based on the relational data tables, and storing the IDs of all the aforementioned nodes and the set of multi-degree neighbor information for all the aforementioned nodes in the key-value database. This includes:

[0057] The first processing step is to determine the IDs of all the nodes and the set of first-degree neighbors of all the nodes according to the relational data table, and store at least the IDs of all the nodes and the set of first-degree neighbors of all the nodes in the first key-value data table.

[0058] Specifically, by storing each degree neighbor separately in a key-value data table, the information of each degree neighbor of the node can be distinguished, making it easier to find the information of each degree neighbor later.

[0059] In one embodiment of this application, determining the IDs of all the aforementioned nodes and the set of first-degree neighbor information for all the aforementioned nodes based on the above-mentioned relational data table includes:

[0060] Based on the relational data table above, obtain the IDs of all the nodes and the edge information of all the nodes. The edge information of the nodes includes the ID of the node and the other node connected by the edge to the node.

[0061] Specifically, edge information is used to characterize the ID of a node and another node connected to the edge containing the aforementioned node, thereby characterizing the connection relationship between nodes;

[0062] Store the IDs of all the above nodes and the edge information of all the above nodes into the (M+1)th key-value data table.

[0063] From the (M+1)th key-value data table, obtain the IDs of all the nodes and the edge information of all the nodes. Then, classify the edge information of the nodes according to the IDs of all the nodes to obtain multiple edge information sets. Each edge information set corresponds to a node and includes the edge information corresponding to the node.

[0064] Based on all the above edge information sets, determine the above 1-degree neighbor information sets for all the above nodes.

[0065] The acquisition step involves retrieving the set of G-1 degree neighbor information for all the nodes mentioned above from the G-1th key-value data table, where 2 ≤ G ≤ M.

[0066] Specifically, by obtaining the G-1 degree neighbor information set of all the above-mentioned nodes from the G-1th key-value data table based on the IDs of all the above-mentioned nodes, the required G-1 degree neighbor information set can be quickly found, thereby knowing the G-1 degree neighbor information set of the node.

[0067] The second processing step is to determine the G-degree neighbor information set of all the above-mentioned nodes based on the 1-degree neighbor information set of all the above-mentioned nodes and the G-1-degree neighbor information set of all the above-mentioned nodes, and store at least the IDs of all the above-mentioned nodes and the G-degree neighbor information set of all the above-mentioned nodes in the G-th key-value data table.

[0068] Specifically, by determining the G-degree neighbor information set of all the above-mentioned nodes based on the 1-degree neighbor information set of all the above-mentioned nodes and the G-1-degree neighbor information set of all the above-mentioned nodes, it is convenient to store the IDs of all the above-mentioned nodes and the G-degree neighbor information set of all the above-mentioned nodes into the G-th key-value data table, preventing the omission of nodes with neighbor relationships that are not stored in the corresponding key-value data table.

[0069] In one embodiment of this application, the method for storing at least all the IDs of the aforementioned nodes and the set of G-degree neighbors of all the aforementioned nodes into the G-th key-value data table includes:

[0070] The ID of the third target node, the set of G-degree neighbors of the third target node, and the number of G-degree neighbors of the third target node are stored in the G-th key-value data table. The third target node is any one of the multiple nodes, and the number of G-degree neighbors of the third target node is the number of IDs contained in the set of G-degree neighbors of the third target node.

[0071] Specifically, by storing the ID of the third target node, the set of G-degree neighbors of the third target node, and the number of G-degree neighbors of the third target node in the Gth key-value data table, a mapping relationship is constructed in the key-value data table for the ID of the third target node, the set of G-degree neighbors of the third target node, and the number of G-degree neighbors of the third target node. Since there is a number of neighbors, the situation of missing neighbor nodes is avoided in the future.

[0072] Update steps: Increment G by 1;

[0073] Repeat the steps, including the second processing step and the update step, multiple times until G equals M.

[0074] In addition, the process of determining the G-degree neighbor information set of all the aforementioned nodes, based on the 1-degree neighbor information set of all the aforementioned nodes and the G-1-degree neighbor information set of all the aforementioned nodes, includes:

[0075] From the G-1 degree neighbor information set of the second target node, obtain multiple first target IDs. The second target node is any one of the multiple nodes. The first target ID is the ID of the node included in the G-1 degree neighbor information set of the second target node. The first target ID corresponds one-to-one with the ID of the node included in the G-1 degree neighbor information set of the second target node.

[0076] Based on the first target ID and the first-degree neighbor information set of all the nodes mentioned above, a target neighbor information set is determined. The target neighbor information set includes the first-degree neighbor information set of all the nodes to which the first target ID belongs.

[0077] Based on the G-1 degree neighbor information set and the target neighbor information set of the second target node, at least one second target ID is determined. The second target ID is an ID that exists simultaneously in the G-1 degree neighbor information set and the target neighbor information set of the second target node.

[0078] Delete all the aforementioned second target IDs from the aforementioned target neighbor information set to obtain the aforementioned G-degree neighbor information set of the aforementioned second target node.

[0079] Step S102: Upon receiving the query request information, search for the H-degree neighbor information set of the first target node from the key-value database. The query request information indicates a request to query the H-degree neighbor information set of the first target node. The query request information includes the ID of the first target node. The first target node is any one of the multiple nodes, where 1≤H≤M.

[0080] In the above steps, the IDs of all neighboring nodes of all nodes are stored in a key-value database. When there is a need to query the neighboring nodes of a certain node, the IDs of the neighboring nodes of that node are directly found from the key-value database. Compared with the existing technology, it is not necessary to traverse all nodes, thereby reducing the time required to search for nodes. This solves the problem that the existing technology requires traversing all nodes in the graph to query the neighboring nodes of a certain node, which leads to low efficiency.

[0081] In one embodiment of this application, the key-value database includes multiple key-value data tables. The Hth key-value data table stores the IDs of all the nodes and the H-degree neighbor information set of all the nodes. Upon receiving a query request, the table searches the key-value database for the H-degree neighbor information set of the first target node, including:

[0082] Based on the ID of the first target node, search for the set of H-degree neighbors of the first target node from the H-th key-value data table.

[0083] Specifically, by using the ID of the first target node, the corresponding neighbor information set of the first target node is retrieved from the corresponding key-value data table, thereby saving time compared to the prior art by not having to traverse all nodes.

[0084] The specific implementation method of this application is as follows:

[0085] Calculation step 1: Calculate and record the first-degree neighbors of all nodes and their number.

[0086] Step 1.1, Mapper-1: Take any edge of the relation table as input, use the start ID and end ID of the edge as keys, and the edge (represented as a tuple (start ID, end ID)) as the value, and output key-value data. This step traverses the original relation table by edge, splits it into key-value pairs and forms a set, which is denoted as KV_M1.

[0087] Step 1.2, Shuffle-1: For all key-value data in KV_M1, reorder all key-value pairs in KV_M1 according to the order of the same node ID and different node ID, still denoted as KV_M1.

[0088] Step 1.3, Reducer-1: Taking all key-value pairs with the same key in KV_M1 (let's call any one ID_i) as input, the output is a key-value structure, where ID_i remains the key. The value contains two parts: all first-degree neighbors of ID_i stored as a set, denoted as set_i_1, and the length of set_i_1 (i.e., the number of first-degree neighbors of ID_i). It can be seen that storing all first-degree neighbors of ID_i as a set guarantees that there are no duplicate neighbors.

[0089] Traverse KV_M1 and denote the result set generated by the above calculation as KV_R1.

[0090] Step 1.4: Store all the first-degree neighbor results (i.e., KV_R1) of all nodes in the key-value database, with the key denoted as N1.

[0091] Calculation step 2: Calculate and record the second-degree neighbors of all nodes.

[0092] The calculation of second-degree neighbors is equivalent to calculating the first-degree neighbors of all nodes' first-degree neighbors. Therefore, the calculation will continue to use the result set KV_R1 output in step 1.3 as input to start a new MapReduce-based computation job and calculate second-degree neighbors. The steps are as follows:

[0093] Step 2.1, Mapper-2: Take the key (i.e., node ID, arbitrarily abbreviated as ID_i) and the first element of the value (i.e., the set of all first-degree neighbors of the node, abbreviated as set_i_1) in KV_R1 as input.

[0094] The output is a key-value structure, still using ID_i as the key. The value is divided into two parts: The first part iterates through all elements in set_i_1 (let's call any one j), indexes j in KV_R1, and obtains the first-degree neighbors of each node, denoted as set_i_j_1. After iterating through set_i_1, all the obtained set_i_j_1 are written into a set (denoted as set_i_2). A mutual exclusion operation is performed between set_i_2 and set_i_1, i.e., set_i_2 - (set_i_2 ∩ set_i_1), still denoted as set_i_2. The second part records the length of set_i_2, i.e., the number of all second-degree neighbors of ID_i.

[0095] Traverse KV_R1 and denote the result set generated by the above calculation as KV_R2.

[0096] Step 2.2: Store the results of all first-degree neighbors of all nodes (i.e., KV_R2) in a key-value database, with the key denoted as N2.

[0097] Calculation step 3 and subsequent steps: Calculate and record all neighbors of all nodes.

[0098] Following the same procedure as step 2, calculate and record the information of all nodes' neighbors of degree 3 and above (the set and number of neighboring nodes), and store them in a key-value database, thereby recording all the neighbor information of all nodes.

[0099] The query for neighbor information of all nodes in the graph can be achieved in one step:

[0100] Query Step 1: Based on the neighbor degree and node information to be queried, the corresponding value is retrieved from the key-value database.

[0101] To enable those skilled in the art to better understand the technical solution of this application, the implementation process of the graph database neighbor information query method of this application will be described in detail below with reference to specific embodiments.

[0102] This embodiment relates to a specific method for querying neighbor information in a graph database. The graph database includes multiple nodes, and the key-value database includes multiple key-value data tables, such as... Figure 2 As shown, it includes the following steps:

[0103] Step S1: Based on the relational data table, determine the IDs of all nodes and the multi-degree neighbor information set of all nodes. The relational data table includes the connection relationships between all nodes in the graph database and the IDs of all nodes. The multi-degree neighbor information set includes the IDs of all N-degree neighbor nodes of a node. An N-degree neighbor node is one of multiple nodes, and there are N-1 nodes between a node and its N-degree neighbor node, where 1 ≤ N ≤ M and M is a positive integer.

[0104] Step S2: Based on the relational data table, determine the IDs of all nodes and the set of first-degree neighbors of all nodes, and store at least the IDs of all nodes and the set of first-degree neighbors of all nodes in the first key-value data table.

[0105] Step S3: Based on the IDs of all nodes, retrieve the set of G-1 degree neighbor information for all nodes from the G-1th key-value data table, where 2≤G≤M;

[0106] Step S4: Based on the set of 1-degree neighbors of all nodes and the set of G-1-degree neighbors of all nodes, determine the set of G-degree neighbors of all nodes, and store at least the IDs of all nodes and the set of G-degree neighbors of all nodes in the G-th key-value data table.

[0107] Step S5: Increment G by 1;

[0108] Step S6: Repeat steps S4 and S5 multiple times until G equals M, then proceed to step S7.

[0109] Step S7: Upon receiving the query request information, based on the ID of the first target node, search for the H-degree neighbor information set of the first target node from the H-th key-value data table, and store the IDs of all nodes and the multi-degree neighbor information set of all nodes in the key-value database. The relational data table includes the connection relationships between all nodes in the graph database and the IDs of all nodes. The N-degree neighbor information set includes the IDs of all N-degree neighbor nodes of the node. An N-degree neighbor node is one of multiple nodes, and there are N-1 nodes between the node and the N-degree neighbor node, 1≤N≤M, where M is a positive integer.

[0110] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.

[0111] This application also provides a neighbor information query device for a graph database. It should be noted that the neighbor information query device for a graph database in this application can be used to execute the neighbor information query method for a graph database provided in this application. This device is used to implement the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.

[0112] The following describes the neighbor information query device for a graph database provided in the embodiments of this application. The graph database includes multiple nodes.

[0113] Figure 3 This is a schematic diagram of a neighbor information query device for a graph database according to an embodiment of this application. Figure 3 As shown, the device includes:

[0114] The determining unit 31 is used to determine the IDs of all the above-mentioned nodes and the multi-degree neighbor information set of all the above-mentioned nodes according to the relational data table, and store the IDs of all the above-mentioned nodes and the multi-degree neighbor information set of all the above-mentioned nodes in the key-value database. The relational data table includes the connection relationship between all nodes in the graph database and the IDs of all nodes. The multi-degree neighbor information set includes the IDs of all N-degree neighbor nodes of the above-mentioned node. The multi-degree neighbor node is one of the above-mentioned nodes, and there are N-1 above-mentioned nodes between the above-mentioned node and the multi-degree neighbor node, 1≤N≤M, where M is a positive integer.

[0115] The lookup unit 32 is used to look up the H-degree neighbor information set of the first target node from the key-value database when a query request information is received. The query request information indicates a request to query the H-degree neighbor information set of the first target node. The query request information includes the ID of the first target node. The first target node is any one of the multiple nodes, where 1≤H≤M.

[0116] In the above device, the IDs of all neighboring nodes of all nodes are stored in a key-value database. When there is a need to query the neighboring nodes of a certain node, the IDs of the neighboring nodes of that node are directly found from the key-value database. Compared with the existing technology, it is not necessary to traverse all nodes, thereby reducing the time required to search for nodes. This solves the problem that the existing technology requires traversing all nodes in the graph to query the neighboring nodes of a certain node, which leads to low efficiency.

[0117] In one embodiment of this application, the key-value database includes multiple key-value data tables, and the determining unit includes a first processing module, an acquisition module, a second processing module, a third processing module, and a fourth processing module.

[0118] The first processing module is used to execute the first processing step, which is to determine the IDs of all the nodes and the set of first-degree neighbors of all the nodes according to the relational data table, and to store at least the IDs of all the nodes and the set of first-degree neighbors of all the nodes into the first key-value data table.

[0119] The acquisition module is used to perform the acquisition steps. Based on the IDs of all the above nodes, it retrieves the G-1 degree neighbor information set of all the above nodes from the G-1th key-value data table, where 2≤G≤M.

[0120] The second processing module is used to execute the second processing step, which determines the G-degree neighbor information set of all the above-mentioned nodes based on the above-mentioned 1-degree neighbor information set of all the above-mentioned nodes and the G-1-degree neighbor information set of all the above-mentioned nodes, and stores at least the IDs of all the above-mentioned nodes and the above-mentioned G-degree neighbor information set of all the above-mentioned nodes into the G-th key-value data table.

[0121] The third processing module is used to perform the update step, incrementing G by 1;

[0122] The fourth processing module is used to perform the repetitive steps, repeating the second processing step and the update step mentioned above multiple times until G equals M.

[0123] In one embodiment of this application, the second processing module includes a first acquisition submodule, a first determination submodule, a second determination submodule, and a first processing submodule. During the process of determining the G-degree neighbor information set of all the aforementioned nodes based on the aforementioned 1-degree neighbor information set and the G-1 degree neighbor information set of all the aforementioned nodes,

[0124] The first acquisition submodule is used to acquire multiple first target IDs from the G-1 degree neighbor information set of the second target node. The second target node is any one of the multiple nodes. The first target ID is the ID of the node included in the G-1 degree neighbor information set of the second target node. The first target ID corresponds one-to-one with the ID of the node included in the G-1 degree neighbor information set of the second target node.

[0125] The first determining submodule is used to determine a target neighbor information set based on the first target ID and the first-degree neighbor information set of all the nodes mentioned above. The target neighbor information set includes the first-degree neighbor information set of all the nodes to which the first target ID belongs.

[0126] The second determining submodule is used to determine at least one second target ID based on the G-1 degree neighbor information set and the target neighbor information set of the second target node. The second target ID is an ID that exists in both the G-1 degree neighbor information set and the target neighbor information set of the second target node.

[0127] The first processing submodule is used to delete all the aforementioned second target IDs from the aforementioned target neighbor information set, thereby obtaining the aforementioned G-degree neighbor information set of the aforementioned second target node.

[0128] In one embodiment of this application, the first processing module includes a second acquisition submodule, a second processing submodule, a third processing submodule, and a third determination submodule;

[0129] The second acquisition submodule is used to acquire the IDs of all the nodes and the edge information of all the nodes according to the relational data table. The edge information of the nodes includes the ID of the node and another node connected to the edge of the node.

[0130] The second processing submodule is used to store the IDs of all the above-mentioned nodes and the edge information of all the above-mentioned nodes into the (M+1)th key-value data table.

[0131] The third processing submodule is used to obtain the IDs of all the nodes and the edge information of all the nodes from the M+1th key-value data table, and classify the edge information of the nodes according to the IDs of all the nodes to obtain multiple edge information sets. Each edge information set corresponds to a node and includes the edge information corresponding to the node.

[0132] The third determining submodule is used to determine the set of 1-degree neighbor information for all the above-mentioned nodes based on all the above-mentioned edge information sets.

[0133] In one embodiment of this application, the key-value database includes multiple key-value data tables. The Hth key-value data table is used to store the IDs of all the nodes and the H-degree neighbor information set of all the nodes. The search unit includes a search module. When a query request is received, the search module is used to search for the H-degree neighbor information set of the first target node from the Hth key-value data table based on the ID of the first target node.

[0134] In one embodiment of this application, the second processing module includes a fourth processing submodule. During the process of storing at least all the IDs of the aforementioned nodes and the G-degree neighbor information sets of all the aforementioned nodes into the G-th key-value data table, the fourth processing submodule is used to store the ID of the third target node, the G-degree neighbor information set of the aforementioned third target node, and the number of the aforementioned G-degree neighbors of the aforementioned third target node into the G-th key-value data table. The aforementioned third target node is any one of the plurality of aforementioned nodes, and the number of the aforementioned G-degree neighbors of the aforementioned third target node is the number of IDs contained in the aforementioned G-degree neighbor information set of the aforementioned third target node.

[0135] The neighbor information query device for the aforementioned graph database includes a processor and a memory. The determining unit and the searching unit, among others, are stored as program units in the memory. The processor executes these program units stored in the memory to achieve the corresponding functions. All of the above modules reside in the same processor; alternatively, the modules may be located in different processors in any combination.

[0136] The processor contains a kernel, which retrieves the corresponding program unit from memory. One or more kernels can be configured, and by adjusting kernel parameters, the inefficiency of current technologies that require traversing the entire graph to find a node's neighbors can be addressed.

[0137] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0138] This invention provides a computer-readable storage medium including a stored program, wherein, when the program is executed, it controls the device where the computer-readable storage medium is located to execute the neighbor information query method of the graph database.

[0139] This invention provides a processor for running a program, wherein the program executes a neighbor information query method for a graph database.

[0140] This invention provides a device including a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs at least the following steps: Based on a relational data table, it determines the IDs of all nodes and the multi-degree neighbor information set of all nodes, and stores the IDs of all nodes and the multi-degree neighbor information set of all nodes in a key-value database. The relational data table includes the connection relationships between all nodes in the graph database and the IDs of all nodes. The multi-degree neighbor information set includes the IDs of all N-degree neighbor nodes of the node, where each N-degree neighbor node is one of multiple nodes, and there are N-1 nodes between the node and its N-degree neighbor node, where 1 ≤ N ≤ M, and M is a positive integer. Upon receiving a query request, it searches the key-value database for the H-degree neighbor information set of a first target node. The query request indicates a request to query the H-degree neighbor information set of the first target node, and includes the ID of the first target node, which is any one of multiple nodes, where 1 ≤ H ≤ M. The device described herein can be a server, PC, PAD, mobile phone, etc.

[0141] Optionally, the aforementioned key-value database includes multiple key-value data tables. Based on the relational data tables, the IDs of all the aforementioned nodes and the multi-degree neighbor information sets of all the aforementioned nodes are determined, and the IDs of all the aforementioned nodes and the multi-degree neighbor information sets of all the aforementioned nodes are stored in the key-value database, including:

[0142] The first processing step is to determine the IDs of all the nodes and the set of first-degree neighbors of all the nodes according to the relational data table, and store at least the IDs of all the nodes and the set of first-degree neighbors of all the nodes in the first key-value data table.

[0143] The acquisition step involves retrieving the set of G-1 degree neighbor information for all the nodes mentioned above from the G-1th key-value data table, where 2 ≤ G ≤ M.

[0144] The second processing step is to determine the G-degree neighbor information set of all the above-mentioned nodes based on the 1-degree neighbor information set of all the above-mentioned nodes and the G-1-degree neighbor information set of all the above-mentioned nodes, and store at least the IDs of all the above-mentioned nodes and the G-degree neighbor information set of all the above-mentioned nodes in the G-th key-value data table.

[0145] Update steps: Increment G by 1;

[0146] Repeat the steps, including the second processing step and the update step, multiple times until G equals M.

[0147] Optionally, the process of determining the G-degree neighbor information set of all the aforementioned nodes based on the aforementioned 1-degree neighbor information set and the G-1-degree neighbor information set of all the aforementioned nodes includes:

[0148] From the G-1 degree neighbor information set of the second target node, obtain multiple first target IDs. The second target node is any one of the multiple nodes. The first target ID is the ID of the node included in the G-1 degree neighbor information set of the second target node. The first target ID corresponds one-to-one with the ID of the node included in the G-1 degree neighbor information set of the second target node.

[0149] Based on the first target ID and the first-degree neighbor information set of all the nodes mentioned above, a target neighbor information set is determined. The target neighbor information set includes the first-degree neighbor information set of all the nodes to which the first target ID belongs.

[0150] Based on the G-1 degree neighbor information set and the target neighbor information set of the second target node, at least one second target ID is determined. The second target ID is an ID that exists simultaneously in the G-1 degree neighbor information set and the target neighbor information set of the second target node.

[0151] Delete all the aforementioned second target IDs from the aforementioned target neighbor information set to obtain the aforementioned G-degree neighbor information set of the aforementioned second target node.

[0152] Optionally, based on the aforementioned relational data table, determine the IDs of all the aforementioned nodes and the set of information about all the first-degree neighbors of the aforementioned nodes, including:

[0153] Based on the relational data table above, obtain the IDs of all the nodes and the edge information of all the nodes. The edge information of the nodes includes the ID of the node and the other node connected by the edge to the node.

[0154] Store the IDs of all the above nodes and the edge information of all the above nodes into the (M+1)th key-value data table.

[0155] From the (M+1)th key-value data table, obtain the IDs of all the nodes and the edge information of all the nodes. Then, classify the edge information of the nodes according to the IDs of all the nodes to obtain multiple edge information sets. Each edge information set corresponds to a node and includes the edge information corresponding to the node.

[0156] Based on all the above edge information sets, determine the above 1-degree neighbor information sets for all the above nodes.

[0157] Optionally, the aforementioned key-value database includes multiple key-value tables. The H-th key-value table stores the IDs of all the aforementioned nodes and the set of H-degree neighbor information for all the aforementioned nodes. Upon receiving a query request, the table retrieves the set of H-degree neighbor information for the first target node from the aforementioned key-value database, including:

[0158] Based on the ID of the first target node, search for the set of H-degree neighbors of the first target node from the H-th key-value data table.

[0159] Optionally, in the process of storing at least all the IDs of the aforementioned nodes and the set of G-degree neighbors of all the aforementioned nodes into the G-th key-value data table, the above method includes:

[0160] The ID of the third target node, the set of G-degree neighbors of the third target node, and the number of G-degree neighbors of the third target node are stored in the G-th key-value data table. The third target node is any one of the multiple nodes, and the number of G-degree neighbors of the third target node is the number of IDs contained in the set of G-degree neighbors of the third target node.

[0161] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program having at least the following method steps: determining the IDs of all the aforementioned nodes and the multi-degree neighbor information sets of all the aforementioned nodes according to a relational data table, and storing the IDs of all the aforementioned nodes and the multi-degree neighbor information sets of all the aforementioned nodes in a key-value database, wherein the relational data table includes the connection relationships between all nodes in the aforementioned graph database and the IDs of all nodes, the N-degree neighbor information set includes the IDs of all N-degree neighbor nodes of the aforementioned node, the aforementioned N-degree neighbor node is one of a plurality of aforementioned nodes, and there are N-1 aforementioned nodes between the aforementioned node and the aforementioned N-degree neighbor node, 1≤N≤M, where M is a positive integer; upon receiving a query request information, searching for the H-degree neighbor information set of a first target node from the aforementioned key-value database, the aforementioned query request information indicating a request to query the aforementioned H-degree neighbor information set of the aforementioned first target node, the aforementioned query request information including the ID of the aforementioned first target node, the aforementioned first target node being any one of a plurality of aforementioned nodes, 1≤H≤M.

[0162] Optionally, the aforementioned key-value database includes multiple key-value data tables. Based on the relational data tables, the IDs of all the aforementioned nodes and the multi-degree neighbor information sets of all the aforementioned nodes are determined, and the IDs of all the aforementioned nodes and the multi-degree neighbor information sets of all the aforementioned nodes are stored in the key-value database, including:

[0163] The first processing step is to determine the IDs of all the nodes and the set of first-degree neighbors of all the nodes according to the relational data table, and store at least the IDs of all the nodes and the set of first-degree neighbors of all the nodes in the first key-value data table.

[0164] The acquisition step is to obtain the set of G-1 degree neighbor information of all the above nodes from the G-1th key-value data table, based on the IDs of all the above nodes, where 2≤G≤M;

[0165] The second processing step is to determine the G-degree neighbor information set of all the above-mentioned nodes based on the 1-degree neighbor information set of all the above-mentioned nodes and the G-1-degree neighbor information set of all the above-mentioned nodes, and store at least the IDs of all the above-mentioned nodes and the G-degree neighbor information set of all the above-mentioned nodes in the G-th key-value data table.

[0166] Update steps: Increment G by 1;

[0167] Repeat the above steps, including the second processing step and the update step, multiple times until G equals M.

[0168] Optionally, the process of determining the G-degree neighbor information set of all the aforementioned nodes based on the aforementioned 1-degree neighbor information set and the G-1-degree neighbor information set of all the aforementioned nodes includes:

[0169] From the G-1 degree neighbor information set of the second target node, obtain multiple first target IDs. The second target node is any one of the multiple nodes. The first target ID is the ID of the node included in the G-1 degree neighbor information set of the second target node. The first target ID corresponds one-to-one with the ID of the node included in the G-1 degree neighbor information set of the second target node.

[0170] Based on the first target ID and the first-degree neighbor information set of all the nodes mentioned above, a target neighbor information set is determined. The target neighbor information set includes the first-degree neighbor information set of all the nodes to which the first target ID belongs.

[0171] Based on the G-1 degree neighbor information set and the target neighbor information set of the second target node, at least one second target ID is determined. The second target ID is an ID that exists simultaneously in the G-1 degree neighbor information set and the target neighbor information set of the second target node.

[0172] Delete all the aforementioned second target IDs from the aforementioned target neighbor information set to obtain the aforementioned G-degree neighbor information set of the aforementioned second target node.

[0173] Optionally, based on the aforementioned relational data table, determine the IDs of all the aforementioned nodes and the set of information about all the first-degree neighbors of the aforementioned nodes, including:

[0174] Based on the relational data table above, obtain the IDs of all the nodes and the edge information of all the nodes. The edge information of the nodes includes the ID of the node and the other node connected by the edge to the node.

[0175] Store the IDs of all the above nodes and the edge information of all the above nodes into the (M+1)th key-value data table.

[0176] From the (M+1)th key-value data table, obtain the IDs of all the nodes and the edge information of all the nodes. Then, classify the edge information of the nodes according to the IDs of all the nodes to obtain multiple edge information sets. Each edge information set corresponds to a node and includes the edge information corresponding to the node.

[0177] Based on all the above edge information sets, determine the above 1-degree neighbor information sets for all the above nodes.

[0178] Optionally, the aforementioned key-value database includes multiple key-value tables. The H-th key-value table stores the IDs of all the aforementioned nodes and the set of H-degree neighbor information for all the aforementioned nodes. Upon receiving a query request, the table retrieves the set of H-degree neighbor information for the first target node from the aforementioned key-value database, including:

[0179] Based on the ID of the first target node, search for the set of H-degree neighbors of the first target node from the H-th key-value data table.

[0180] Optionally, in the process of storing at least all the IDs of the aforementioned nodes and the set of G-degree neighbors of all the aforementioned nodes into the G-th key-value data table, the above method includes:

[0181] The ID of the third target node, the set of G-degree neighbors of the third target node, and the number of G-degree neighbors of the third target node are stored in the G-th key-value data table. The third target node is any one of the multiple nodes, and the number of G-degree neighbors of the third target node is the number of IDs contained in the set of G-degree neighbors of the third target node.

[0182] This application also provides an electronic device comprising: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs include methods for executing any of the aforementioned methods for querying neighbor information in a graph database. By storing the IDs of all neighbor nodes of all nodes in a key-value database, when there is a need to query the neighbor nodes of a certain node, the IDs of the neighbor nodes of that node are directly found from the key-value database. Compared with existing technologies, it is not necessary to traverse all nodes, thereby reducing the time required to search for nodes, and thus solving the problem of low efficiency caused by the need to traverse all nodes in the entire graph to query the neighbor nodes of a certain node.

[0183] It is obvious to those skilled in the art that the modules or steps of the present invention described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. They can be implemented using computer-executable program code, and thus can be stored in a storage device for execution by a computing device. In some cases, the steps shown or described can be performed in a different order than those described herein, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.

[0184] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0185] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0186] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0187] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0188] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0189] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0190] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.

[0191] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0192] As can be seen from the above description, the embodiments of this application achieve the following technical effects:

[0193] 1) The neighbor information query method of the graph database in this application stores the IDs of all neighbor nodes of all nodes in a key-value database. When there is a need to query the neighbor nodes of a certain node, the IDs of the neighbor nodes of this node are directly found from the key-value database. Compared with the prior art, it is not necessary to traverse all nodes, thereby reducing the time required to search for nodes. This solves the problem that the prior art requires traversing all nodes in the graph to query the neighbor nodes of a certain node, which leads to low efficiency.

[0194] 2) The neighbor information query device for graph database of this application stores the IDs of all neighbor nodes of all nodes in a key-value database. When there is a need to query the neighbor nodes of a certain node, the IDs of the neighbor nodes of this node are directly found from the key-value database. Compared with the prior art, it is not necessary to traverse all nodes, thereby reducing the time required to search for nodes. This solves the problem that the prior art requires traversing all nodes in the graph to query the neighbor nodes of a certain node, resulting in low efficiency.

[0195] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A method for querying neighbor information in a graph database, characterized in that, The graph database includes multiple nodes, and the method includes: Based on the relational data table, determine the IDs of all nodes and the multi-degree neighbor information set of all nodes, and store the IDs of all nodes and the multi-degree neighbor information set of all nodes in a key-value database. The relational data table includes the connection relationships between all nodes in the graph database and the IDs of all nodes. The multi-degree neighbor information set includes the IDs of all N-degree neighbor nodes of the node. The N-degree neighbor node is one of a plurality of nodes, and there are N-1 nodes between the node and the N-degree neighbor node, 1≤N≤M, where M is a positive integer. Upon receiving a query request, the system searches the key-value database for the H-degree neighbor information set of the first target node. The query request indicates a request to query the H-degree neighbor information set of the first target node. The query request includes the ID of the first target node, which is any one of the multiple nodes, where 1 ≤ H ≤ M. The key-value database includes multiple key-value data tables. Based on the relational data tables, the IDs of all nodes and the multi-degree neighbor information sets of all nodes are determined, and the IDs of all nodes and the multi-degree neighbor information sets of all nodes are stored in the key-value database. This includes: a first processing step, determining the IDs of all nodes and the 1-degree neighbor information sets of all nodes based on the relational data tables, and storing at least the IDs of all nodes and the 1-degree neighbor information sets of all nodes in the first key-value data table; and an acquisition step. The first processing step involves retrieving the G-1 degree neighbor information set of all nodes from the (G-1)th key-value data table, where 2 ≤ G ≤ M. The second processing step involves determining the G-degree neighbor information set of all nodes based on the 1-degree neighbor information set and the G-1 degree neighbor information set, storing at least the IDs of all nodes and the G-degree neighbor information set of all nodes in the Gth key-value data table. The next step involves incrementing G by 1. The second processing step and the update step are repeated multiple times until G equals M. The key-value database includes multiple key-value data tables. The Hth key-value data table is used to store the IDs of all the nodes and the H-degree neighbor information set of all the nodes. When a query request is received, the H-degree neighbor information set of the first target node is searched from the key-value database, including: searching the H-degree neighbor information set of the first target node from the Hth key-value data table according to the ID of the first target node.

2. The method according to claim 1, characterized in that, The process of determining the G-degree neighbor information set of all nodes based on the 1-degree neighbor information set of all nodes and the G-1-degree neighbor information set of all nodes includes: From the G-1 degree neighbor information set of the second target node, obtain multiple first target IDs, where the second target node is any one of the multiple nodes, and the first target ID is the ID of the node included in the G-1 degree neighbor information set of the second target node, and the first target ID corresponds one-to-one with the ID of the node included in the G-1 degree neighbor information set of the second target node; Based on the first target ID and the set of first-degree neighbor information of all the nodes, a target neighbor information set is determined, wherein the target neighbor information set includes the set of first-degree neighbor information of all the nodes to which the first target ID belongs; Based on the G-1 degree neighbor information set of the second target node and the target neighbor information set, at least one second target ID is determined, wherein the second target ID is an ID that exists simultaneously in the G-1 degree neighbor information set and the target neighbor information set of the second target node; Delete all the second target IDs in the target neighbor information set to obtain the G-degree neighbor information set of the second target node.

3. The method according to claim 1, characterized in that, Based on the relational data table, determine the IDs of all nodes and the set of first-degree neighbors for all nodes, including: Based on the relational data table, obtain the IDs of all the nodes and the edge information of all the nodes. The edge information of the nodes includes the ID of the node and the other node connected by the edge to the node. Store the IDs of all the nodes and the edge information of all the nodes in the (M+1)th key-value data table; From the (M+1)th key-value data table, obtain the IDs of all nodes and the edge information of all nodes, and classify the edge information of the nodes according to the IDs of all nodes to obtain multiple edge information sets. Each edge information set corresponds one-to-one with a node, and each edge information set includes the edge information corresponding to the corresponding node. Based on all the edge information sets, determine the 1-degree neighbor information sets of all the nodes.

4. The method according to claim 1, characterized in that, In the process of storing at least all the IDs of the nodes and the set of G-degree neighbors of all the nodes into the G-th key-value data table, the method includes: The ID of the third target node, the G-degree neighbor information set of the third target node, and the number of G-degree neighbors of the third target node are stored in the G-th key-value data table, wherein the third target node is any one of the multiple nodes, and the number of G-degree neighbors of the third target node is the number of IDs contained in the G-degree neighbor information set of the third target node.

5. A neighbor information query device for a graph database, characterized in that, The graph database includes multiple nodes, and the device includes: The determining unit is configured to determine the IDs of all nodes and the multi-degree neighbor information set of all nodes based on a relational data table, and store the IDs of all nodes and the multi-degree neighbor information set of all nodes in a key-value database. The relational data table includes the connection relationships between all nodes in the graph database and the IDs of all nodes. The multi-degree neighbor information set includes the IDs of all N-degree neighbor nodes of the node. The N-degree neighbor node is one of a plurality of nodes, and there are N-1 nodes between the node and the N-degree neighbor node, 1≤N≤M, where M is a positive integer. The lookup unit is used to look up the H-degree neighbor information set of the first target node from the key-value database when a query request information is received. The query request information indicates a request to query the H-degree neighbor information set of the first target node. The query request information includes the ID of the first target node. The first target node is any one of the plurality of nodes, 1≤H≤M. The key-value database includes multiple key-value data tables. The determining unit includes a first processing module, an acquisition module, a second processing module, a third processing module, and a fourth processing module. The first processing module is used to execute a first processing step, which determines the IDs of all nodes and the set of first-degree neighbors of all nodes based on the relational data tables, and stores at least the IDs of all nodes and the set of first-degree neighbors of all nodes in the first key-value data table. The acquisition module is used to execute an acquisition step, which retrieves the key-value data from the (G-1)th key-value table based on the IDs of all nodes. In the data table, obtain the G-1 degree neighbor information set of all the nodes, where 2≤G≤M; the second processing module is used to execute the second processing step, which determines the G degree neighbor information set of all the nodes based on the 1 degree neighbor information set and the G-1 degree neighbor information set of all the nodes, and stores at least the IDs of all the nodes and the G degree neighbor information set of all the nodes in the Gth key-value data table; the third processing module is used to execute the update step, which increments G by 1; the fourth processing module is used to execute the repetition step, which repeats the second processing step and the update step multiple times until G equals M. The key-value database includes multiple key-value data tables. The Hth key-value data table is used to store the IDs of all the nodes and the H-degree neighbor information set of all the nodes. The search unit includes a search module. When a query request is received, the search module is used to search for the H-degree neighbor information set of the first target node from the Hth key-value data table based on the ID of the first target node.

6. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein, when the program is executed, it controls the device on which the computer-readable storage medium is located to perform the neighbor information query method for a graph database according to any one of claims 1 to 4.

7. A processor, characterized in that, The processor is used to run a program, wherein the program executes the neighbor information query method for the graph database according to any one of claims 1 to 4.

8. An electronic device, characterized in that, include: One or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs including a method for performing a neighbor information query method for a graph database according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Neighbor node retrieval method and device

    CN111984828A

  • Graph database query method and device, electronic equipment and storage medium

    CN116186335A