Deep multi-hop query method, device, equipment and medium based on graph data optimization
By dividing graph data into multiple subgraphs and assigning weights to the connecting edges, the distribution of nodes and edges is optimized, which solves the performance bottleneck of distributed graph databases in deep multi-hop queries, improves the efficiency of large graph traversal and computing performance, and reduces storage and computing costs.
Patent Information
- Application Number
- CN202311423027.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-30
- Publication Date
- 2025-09-23
- Estimated Expiration
- 2043-10-30
AI Technical Summary
Existing distributed graph databases have performance bottlenecks in deep multi-hop queries, resulting in redundant and high-cost storage resources. In addition, query paths lack regularity, making it difficult to efficiently handle multi-hop traversals of large-scale, complex graph data.
The graph data is divided into multiple subgraphs. Based on the query request, the target nodes are traversed and the weights of the connecting edges are assigned. The distribution of nodes and edges is optimized by weights, and a subgraph with loose external connections and tight internal coupling is constructed to improve traversal and computation efficiency.
By optimizing the subgraph structure, the efficiency and performance of large graph traversal are improved, storage and computing costs are reduced, and the analysis needs of complex data resources are met.
Smart Images

Figure CN117216333B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a deep multi-hop query method, device, equipment and medium based on graph data optimization. Background Art
[0002] Graph data describes real-world entities and the connections between them. Its concise and intuitive descriptions of inter-entity relationships, coupled with simple storage, enable efficient responses to entity-related queries. Currently, it has found widespread application in online transaction processing (OLTP). For example, enterprise resource management and personnel relationship queries place a significant demand on efficient graph database querying. However, with the rapid development of the economy and society, the scale of various resources is rapidly increasing, and the degree and nature of resource connections are becoming increasingly complex and diverse. Consequently, deep, multi-hop queries pose significant challenges to the traversal mechanisms and performance of graph databases. To meet the demand for improved query response efficiency in large data volumes, existing graph databases, such as Neo4j, have gradually introduced distributed graph databases. These improvements utilize parallel computing to improve graph traversal analysis and enhance the performance of large-scale graph traversal algorithms. However, improving graph traversal performance using distributed graph databases still faces bottlenecks, such as the significant redundancy of storage resources.
[0003] To avoid data inconsistencies caused by data partitioning, most databases perform extensive redundant backups of data resources during distributed operations to enhance reliability. Furthermore, distributed graph databases are more expensive. With the increasing variety of data types and the rapid growth of physical assets, the number of storage and computing nodes has increased significantly, and their economic feasibility will inevitably become a bottleneck restricting this approach. Currently, most related information query requirements are highly random, meaning that each single query randomly selects a query target from the entire existing graph, with no pattern to follow. Furthermore, the query path is deep and multi-hop, meaning that the query process requires deep mining, and the query path passes through multiple nodes, rarely obtaining query results within 1-3 hops. Therefore, there is an urgent need to optimize the deep multi-hop traversal methods of distributed graph databases to improve the query and computing performance of large graphs and meet the needs of analyzing increasingly rich and complex data resources. Summary of the Invention
[0004] In view of this, the present invention provides a deep multi-hop query method, apparatus, device and medium based on graph data optimization to solve at least one of the technical problems existing in the above-mentioned prior art.
[0005] In the first aspect, the present invention provides a deep multi-hop query method based on graph data optimization, the method comprising: obtaining graph data to be queried; dividing the graph data to be queried into multiple subgraphs according to the connection relationship between nodes in the graph data to be queried; traversing the multiple subgraphs based on the target node corresponding to the query request, assigning weights to the connecting edges between the nodes according to the traversed nodes, and obtaining the weight values of the connecting edges; updating the node changes in each subgraph according to the weight values of the connecting edges in each subgraph, and obtaining the optimized graph data to be queried.
[0006] The deep multi-hop query method based on graph data optimization provided by the present invention divides the graph data to be queried into multiple subgraphs from the perspective of graph partitioning. Leveraging the deep multi-hop regularity of the current graph data traversal query, iteratively optimizes the nodes and edges in the subgraphs. Weights are defined and assigned based on the connecting edges of the traversed nodes, i.e., access paths. The distribution of nodes and edges in each subgraph is optimized based on the weights of the access paths. Ultimately, multiple subgraphs with loose external connections and tight internal coupling are constructed, improving graph data traversal and computational efficiency. This method provides a parallel computing and performance optimization solution for large graph traversal.
[0007] In an optional embodiment, traversal is performed in multiple subgraphs based on the target node corresponding to the query request, and weights are assigned to the connecting edges between the nodes according to the traversed nodes to obtain the weight values of the connecting edges, including: obtaining the query request, parsing the query request, and obtaining the target node; traversing in multiple subgraphs with any node as the starting point, comparing the traversed node with the target node until the traversed node matches the target node or all nodes do not match the target node, and stopping the traversal; assigning weights to the connecting edges of the traversed nodes to obtain the weight values of the connecting edges.
[0008] In this embodiment, when querying the target node, it is performed simultaneously in each subgraph, which improves the query efficiency; at the same time, weights are assigned to the nodes in the traversal process, providing a data basis for subsequent optimization and update of the query graph data.
[0009] In an optional embodiment, the node changes in each subgraph are updated according to the weight values of the connecting edges in each subgraph to obtain optimized graph data to be queried, including: obtaining the connecting edges with the smallest weight in each subgraph and the connecting edges across subgraphs; updating the node changes in each subgraph according to the weights of the connecting edges corresponding to the nodes with the smallest weight in each subgraph and other nodes to obtain optimized graph data to be queried; and / or, updating the node changes in each subgraph according to the relationship between the weights of the connecting edges corresponding to the nodes with other nodes across subgraphs and the weights of the connecting edges across subgraphs to obtain optimized graph data to be queried.
[0010] In this embodiment, node changes are updated using the weights of the smallest-weighted edges in each subgraph and the weights of cross-subgraph edges. This allows the weight ratio to be gradually adjusted to introduce larger-weighted nodes from each subgraph, while smaller-weighted nodes are transferred to other subgraphs, thus forming multiple tightly coupled and strongly connected subgraphs. This improves the efficiency of deep, multi-hop traversals of large graphs.
[0011] In an optional embodiment, the method further includes: using the optimized multiple subgraphs in the to-be-queried graph data as the multiple subgraphs to be queried in the next query request.
[0012] In this embodiment, using the multiple subgraphs in the transformed graph data to be queried as the multiple subgraphs to be queried in the next query request can improve the query traversal efficiency.
[0013] In an optional embodiment, the node changes in each subgraph are updated according to the weight values of the connecting edges in each subgraph to obtain optimized graph data to be queried, including: obtaining the number of query requests received; judging whether the number has reached a preset number; when the preset number is reached, the node changes in each subgraph are updated according to the weight values of the connecting edges in each subgraph to obtain optimized graph data to be queried.
[0014] In this embodiment, whether to perform a change update is determined according to the number of query requests, which provides a basis for the change update.
[0015] In an optional embodiment, the graph data to be queried is divided into multiple subgraphs according to the connection relationship between the nodes in the graph data to be queried, including: selecting any node in the graph data to be queried as the starting point, performing a deep traversal query based on the connection relationship of the nodes, and writing the queried nodes to the first subgraph; judging whether the capacity of the first subgraph reaches a preset threshold; when the preset threshold is reached, performing a deep traversal query with the node connected to the last node written in the first subgraph as the starting point, and writing the queried nodes to the second subgraph until the capacity of the second subgraph reaches the preset threshold; repeating the generation method of the second subgraph to obtain multiple subgraphs.
[0016] In this embodiment, nodes are selected and traversed according to the connection relationship between nodes using a deep traversal query method. The traversed nodes are stored in each subgraph according to a preset threshold capacity, thereby achieving division into multiple subgraphs.
[0017] In an optional implementation, the preset threshold is determined based on the capacity of the graph data to be queried and the number of subgraphs.
[0018] In this embodiment, the preset threshold is determined by the capacity of the graph data to be queried and the number of subgraphs, thereby achieving determination of the capacity of each subgraph.
[0019] In the second aspect, the present invention provides a deep multi-hop query device based on graph data optimization, the device including: a data acquisition module for acquiring graph data to be queried; a partitioning module for partitioning the graph data to be queried into multiple subgraphs according to the connection relationship between nodes in the graph data to be queried; a traversal and weight assignment module for traversing multiple subgraphs based on the target node corresponding to the query request, assigning weights to the connecting edges between the nodes according to the traversed nodes, and obtaining the weight values of the connecting edges; an update optimization module for updating the node changes in each subgraph according to the weight values of the connecting edges in each subgraph, and obtaining the optimized graph data to be queried.
[0020] In an optional embodiment, the traversal and weight assignment module is specifically used to: obtain a query request, parse the query request, and obtain a target node; traverse from any node as a starting point in multiple subgraphs, compare the traversed node with the target node, and stop traversing until the traversed node matches the target node or all nodes do not match the target node; assign weights to the connecting edges of the traversed nodes to obtain weight values of the connecting edges.
[0021] In an optional embodiment, the update optimization module is specifically used to: obtain the connecting edges with the smallest weight in each subgraph and the connecting edges across subgraphs; update the node changes in each subgraph according to the weights of the connecting edges corresponding to the nodes with the smallest weight in each subgraph and the connecting edges of other nodes, to obtain optimized graph data to be queried; and / or, update the node changes in each subgraph according to the relationship between the weights of the connecting edges corresponding to the nodes with other nodes across subgraphs and the weights of the connecting edges across subgraphs, to obtain optimized graph data to be queried.
[0022] In an optional embodiment, the apparatus further includes: an updating module configured to use the optimized multiple subgraphs in the to-be-queried graph data as the multiple subgraphs to be queried in the next query request.
[0023] In an optional embodiment, the update optimization module is also used to: obtain the number of query requests received; determine whether the number has reached a preset number; when the preset number is reached, update the node changes in each subgraph according to the weight values of the connecting edges in each subgraph to obtain optimized graph data to be queried.
[0024] In an optional embodiment, the partitioning module is specifically used to: select any node in the graph data to be queried as a starting point, perform a deep traversal query based on the connection relationship of the nodes, and write the queried nodes into the first subgraph; determine whether the capacity of the first subgraph reaches a preset threshold; when the preset threshold is reached, perform a deep traversal query starting from the node connected to the last node written in the first subgraph, and write the queried nodes into the second subgraph until the capacity of the second subgraph reaches the preset threshold; repeat the generation method of the second subgraph to obtain multiple subgraphs.
[0025] In an optional implementation, the preset threshold is determined based on the capacity of the graph data to be queried and the number of subgraphs.
[0026] In a third aspect, the present invention provides a computer device comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the computer instructions to execute the deep multi-hop query method based on graph data optimization of the above-mentioned first aspect or any corresponding embodiment thereof.
[0027] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the deep multi-hop query method based on graph data optimization of the above-mentioned first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the specific embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0029] Figure 1 1 is a flowchart of a deep multi-hop query method based on graph data optimization according to an embodiment of the present invention;
[0030] Figure 2 is a flowchart of another deep multi-hop query method based on graph data optimization according to an embodiment of the present invention;
[0031] Figure 3 is a schematic diagram of partitioning query graph data in a capacity-equalizing manner according to an embodiment of the present invention;
[0032] Figure 4 2. Schematic diagram of graph data query request parsing and distribution according to an embodiment of the present invention;
[0033] Figure 5 1 is a schematic diagram of updating the weights of connecting edges between nodes traversed through deep multi-hop traversal according to an embodiment of the present invention;
[0034] Figure 6 is a schematic diagram of graph data of a first subgraph after weighting according to an embodiment of the present invention;
[0035] Figure 7 is a schematic diagram of node connections of a first subgraph and a second subgraph according to an embodiment of the present invention;
[0036] Figure 8 is a schematic diagram of node connections of the first subgraph and the second subgraph after update according to an embodiment of the present invention;
[0037] Figure 9 is a structural block diagram of a deep multi-hop query device based on graph data optimization according to an embodiment of the present invention;
[0038] Figure 10 Schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0039] To make the purpose, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative efforts shall fall within the scope of protection of the present invention.
[0040] According to an embodiment of the present invention, an embodiment of a deep multi-hop query method based on graph data optimization is provided. It should be noted that the steps shown in the flowchart of 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 can be executed in an order different from that shown here.
[0041] This embodiment provides a deep multi-hop query method based on graph data optimization, which can be used in electronic devices such as computers, mobile phones, tablets, etc. Figure 1 is a flowchart of a deep multi-hop query method based on graph data optimization according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:
[0042] Step S101: Obtain the graph data to be queried. The graph data to be queried is the graph data object that needs to be traversed, that is, the query needs to be performed within the graph data to obtain the query object or target. For example, if a specific business data needs to be queried, the graph data to be queried is the graph data that stores all business data.
[0043] Step S102: Divide the graph data to be queried into multiple subgraphs according to the connection relationship between the nodes in the graph data to be queried. Specifically, if the graph data to be queried is represented as Graph, the multiple subgraphs can be represented as [Sub_graph1, Sub_graph2, ..., Sub_graph N], that is, dividing the graph data to be queried into N subgraphs. Each subgraph, as a part of the graph data to be queried, includes multiple nodes connected to each other, and multiple nodes in multiple subgraphs do not overlap with each other.
[0044] Step S103, based on the target node corresponding to the query request, traverse multiple subgraphs, assign weights to the connecting edges between the nodes according to the traversed nodes, and obtain the weight values of the connecting edges. Specifically, when querying the target node corresponding to the query request, that is, the query object or target, the query can be performed simultaneously in multiple subgraphs to increase the query speed. During the query process, the traversed nodes and the target nodes are compared to determine whether the target node is queried. In addition, in order to implement the update of the subgraph or the query of the query graph data, the connecting edges of the traversed nodes can be weighted to obtain the weight values of the connecting edges. Among them, the weight assignment can be determined according to the number of traversals.
[0045] In step S104, nodes in each subgraph are modified and updated based on the weights of the edges connecting them, thereby obtaining optimized graph data to be queried. Specifically, by comparing the weights of the edges, nodes corresponding to the corresponding edges are modified and updated, such as by transferring nodes from one subgraph to another. This optimizes the graph data to be queried, so that the optimized graph data is constructed into multiple subgraphs with loose external connections and tight internal coupling.
[0046] The deep multi-hop query method based on graph data optimization provided by the present invention divides the graph data to be queried into multiple subgraphs from the perspective of graph partitioning. Leveraging the deep multi-hop regularity of the current graph data traversal query, iteratively optimizes the nodes and edges in the subgraphs. Weights are defined and assigned based on the connecting edges of the traversed nodes, i.e., access paths. The distribution of nodes and edges in each subgraph is optimized based on the weights of the access paths. Ultimately, multiple subgraphs with loose external connections and tight internal coupling are constructed, improving graph data traversal and computational efficiency. This method provides a parallel computing and performance optimization solution for large graph traversal.
[0047] This embodiment provides a deep multi-hop query method based on graph data optimization. The process includes the following steps:
[0048] Step S201: Obtain the graph data to be queried and the query request. Figure 1 Step S101 of the illustrated embodiment will not be described in detail here.
[0049] Step S202 : dividing the graph data to be queried into multiple subgraphs according to the connection relationships between the nodes in the graph data to be queried.
[0050] Specifically, the above step S202 includes:
[0051] Step S2021: Select any node in the graph data to be queried as the starting point, perform a deep traversal query based on the node connections, and write the queried nodes into the first subgraph. Specifically, select any node in the graph data to be queried, store the node in the first subgraph Sub_graph1, and then use the node as the starting point for traversal. Perform a deep traversal query, query downward one by one based on the connection relationships between nodes, and write the queried nodes one by one into the first subgraph. The deep traversal query can use any current deep traversal method, which is not limited by this application.
[0052] Step S2022, determines whether the capacity of the first subgraph reaches a preset threshold; wherein the preset threshold is determined based on the capacity of the graph data to be queried and the number of subgraphs. For example, the capacity of the graph data to be queried Storage_graph can be divided by the number of subgraphs N to obtain the preset threshold Storage_graph / N. In other embodiments, the preset threshold can also be determined in other ways, such as according to actual needs. The determination method of the present invention can be used to divide the graph data to be queried into multiple subgraphs in an equal manner according to the storage capacity, further ensuring query efficiency.
[0053] Specifically, during the process of writing nodes one by one, the capacity of the first subgraph is monitored in real time. If the capacity of the first subgraph exceeds a preset threshold after writing a certain node, indicating that the capacity of the first subgraph has met the requirement, the last node written is removed, and the nodes written before the removed node constitute the first subgraph.
[0054] Step S2023: When the preset threshold is reached, a deep traversal query is performed starting from the node connected to the last node written in the first subgraph, and the queried nodes are written to the second subgraph until the capacity of the second subgraph reaches the preset threshold. Specifically, after the first subgraph is formed, the last node taken out of the first subgraph, that is, the node connected to the last node written in the first subgraph, is used as the starting point, and the deep traversal query is continued. The query is performed downward one by one according to the connection relationship between the nodes, and the queried nodes are written one by one into the second subgraph until the capacity of the second subgraph reaches the preset threshold.
[0055] Step S2024, repeat the generation method of the second subgraph to obtain multiple subgraphs. Specifically, after the second subgraph is formed, the third subgraph, the fourth subgraph, and so on, the Nth subgraph can be formed in the same manner as the second subgraph. Thus, multiple subgraphs [Sub_graph1, Sub_graph2, ..., Sub_graph N ].
[0056] Step S203: traverse multiple subgraphs based on the target node corresponding to the query request, assign weights to the connecting edges between the nodes according to the traversed nodes, and obtain the weight values of the connecting edges; see Figure 1 Step S103 of the illustrated embodiment will not be described in detail here.
[0057] Step S204: Update the node changes in each subgraph according to the weight values of the connecting edges in each subgraph to obtain the optimized graph data to be queried. Figure 1 Step S104 of the illustrated embodiment will not be described in detail here.
[0058] This embodiment provides a deep multi-hop query method based on graph data optimization, which includes the following steps:
[0059] Step S301: Obtain the graph data to be queried and the query request; see Figure 1 Step S101 of the illustrated embodiment will not be described in detail here.
[0060] Step S302: Divide the graph data to be queried into multiple subgraphs according to the connection relationship between the nodes in the graph data to be queried. Figure 1 Step S102 of the illustrated embodiment will not be described in detail here.
[0061] Step S303 , traversing multiple subgraphs based on the target node corresponding to the query request, assigning weights to the connecting edges between the nodes according to the traversed nodes, and obtaining weight values of the connecting edges.
[0062] Specifically, the above step S303 includes:
[0063] Step S3031: Obtain a query request, parse the query request, and obtain a target node. Specifically, the query request may be an object or target entered by the user, such as business data. The query request may include multiple data items. For example, if the query request includes a request target and a request ID in a pre-defined format, the request target at the corresponding location may be extracted to obtain the target node.
[0064] Step S3032, traverse from any node as the starting point in multiple subgraphs, compare the traversed nodes with the target node, until the traversed nodes match the target node or all nodes do not match the target node, then stop traversing; specifically, after parsing to obtain the target node, the target node can be sent to each subgraph to facilitate subgraph comparison. After the subgraph receives the target node, any node can be selected in the subgraph as the starting point to start traversing, that is, traverse each subgraph according to the connection relationship, and each time a node is traversed, it is compared with the target node to determine whether the two match. Until a matching node is traversed. The traversed matching node is used as the query result. There is also a situation where no matching node is found after traversing all nodes in the subgraph, and the query failure result is returned.
[0065] Step S3033, assign weights to the connection edges of the traversed nodes to obtain the weight values of the connection edges. Specifically, during the traversal process, the connection to the traversed nodes is assigned weights. For example, if the starting point of the traversal in a subgraph is node1, and the node traversed that has a connection relationship with node1 is node2, then the connection edge between node1 and node2 is added with the access weight attribute node count_edge1. The type of this attribute field is numeric, with an initial value of 0. After traversal, count_edge1 is added. 1_2 =count_edge 1_2 +1, compare the node node2 with the target node node k If it matches, the query result is returned. If it does not match, continue to search for node2's adjacent brother node node4, and also match node2 with node k The connection edges between them increase the access weight attribute node count_edge 2_4 The value of count_edge is increased by 1, and count_edge is traversed. 2_4 =count_edge 2_4 +1, then compare the node node4 with the target node node k Until the target node is found. k until.
[0066] Step S304: Update the node changes in each subgraph according to the weight values of the connecting edges in each subgraph to obtain the optimized graph data to be queried. Figure 1 Step S104 of the illustrated embodiment will not be described in detail here.
[0067] This embodiment provides a deep multi-hop query method based on graph data optimization, which includes the following steps:
[0068] Step S401: Obtain the graph data to be queried and the query request; see Figure 1 Step S101 of the illustrated embodiment will not be described in detail here.
[0069] Step S402: Divide the graph data to be queried into multiple subgraphs according to the connection relationship between the nodes in the graph data to be queried. Figure 1 Step S102 of the illustrated embodiment will not be described in detail here.
[0070] Step S403: traverse multiple subgraphs based on the target node corresponding to the query request, assign weights to the edges between the nodes according to the traversed nodes, and obtain the weight values of the edges. Figure 1 Step S103 of the illustrated embodiment will not be described in detail here.
[0071] Step S404: Update the node changes in each subgraph according to the weight values of the connecting edges in each subgraph to obtain optimized graph data to be queried.
[0072] Specifically, the above step S304 includes:
[0073] Step S4041, obtaining the number of received query requests.
[0074] Step S4042, determine whether the number of times reaches the preset number of times.
[0075] Specifically, the node change update can be performed once every preset time, for example, it can be determined by the number of query requests received, and an update can be performed after the number of received requests reaches a preset number. The preset number can be determined according to actual needs.
[0076] Step S4041, when the preset number of times is reached, the connecting edges with the smallest weight in each subgraph and the connecting edges across subgraphs are obtained; specifically, after assigning weights to the connecting edges, the weight values of the connecting edges between any two nodes in each subgraph can be traversed to form a weight value sorting table, and the connecting edges with the smallest weight in each subgraph and the connecting edges across subgraphs are obtained through the sorting table. Among them, when the weight of the connecting edge is the smallest, it may be 0 (indicating that it has not been traversed, and the weight value is the initial value) or it may be other values. In addition, when multiple subgraphs are formed, there is a connection relationship between the last node written in each subgraph and the first node written in the next subgraph, then the connecting edge between these two nodes constitutes a connecting edge across the subgraph.
[0077] Step S4042, update the node changes in each subgraph according to the weights of the connecting edges corresponding to the node with the smallest weight in each subgraph and other nodes, and obtain the optimized graph data to be queried; specifically, after determining the connecting edge with the smallest weight in each subgraph, the connecting edge with the smallest weight in all subgraphs and the leaf node corresponding to the connecting edge can be taken out and saved in the cache queue. Then, obtain the weight value of the connecting edge between each node in the cache queue and any node in the graph data to be queried, determine the maximum value among the weight values, and then determine in which subgraph the node with the connecting edge with the largest weight value is located, and then update the node changes in the cache queue to the corresponding subgraph. For example, if the node nodex in the cache queue has the largest weight value of the connecting edge with the node nodey in the third subgraph, then move the node nodex from the original subgraph to the third subgraph.
[0078] Step S4043, and / or, updates the node changes in each subgraph based on the relationship between the weights of the nodes corresponding to the cross-subgraph edge and the weights of the cross-subgraph edge, to obtain optimized graph data to be queried. Specifically, after determining the cross-subgraph edge, the weight value of the edge and the pair of leaf nodes corresponding to the edge are saved. Then, the weight value of the edge between any one of the pair of leaf nodes and the other node in the corresponding subgraph is obtained and compared with the weight value of the cross-subgraph edge. If the former is less than the latter, the node in the pair of leaf nodes in the corresponding subgraph is moved to the other subgraph; if not less than the latter, the node is not moved. For example, if the pair of leaf nodes corresponding to the cross-subgraph edge between the first and second subgraphs is determined to be nodem and noden, and their edge weight is 18, while the weight value of the edge between noden and other nodes in the second subgraph is 17, and 17 is less than 18, noden is moved from the second subgraph to the first subgraph. At this time, the edges between noden and other nodes in the second subgraph constitute the cross-subgraph edge.
[0079] In an optional embodiment, the method further includes: using the optimized subgraphs in the to-be-queried graph data as the subgraphs to be queried in the next query request. Specifically, after optimizing the to-be-queried graph data, the next time a query request is received, the optimized graph data can be used as the graph data query object for querying, thereby improving query efficiency.
[0080] As a specific application example of the embodiment of the present invention, Figure 2 As shown in the figure, the deep multi-hop query method based on graph data optimization can be implemented using the following process:
[0081] Step 1: Read the entire graph data object Graph to be queried and traversed, i.e., the graph data to be queried, obtain its storage space size or capacity size: Storage_graph, and determine the starting traversal node of the graph data object Graph, i.e., the root vertex: node0.
[0082] Step 2: Assume that the graph data object Graph is to be divided into N subgraphs, and each subgraph is defined as: [Sub_graph1, Sub_graph2, ..., Sub_graph N ].
[0083] Step 3: Start traversing from node node0. First, write node node0 into the first subgraph Sub_graph1. Use a deep traversal query method to find the nodes connected to it one by one and write them into the first subgraph Sub_graph1 one by one. At the same time, set a capacity detection program to monitor the capacity of the first subgraph Sub_graph1.
[0084] Step 4: If the capacity of the first subgraph Sub_graph1 exceeds Storage_graph / N for the first time after a node is written, roll back one node, that is, take out the last written node from the first subgraph Sub_graph1. end1 At this point, the graph data of the first subgraph Sub_graph1 is written, and the fallback node node end1 Record it as the new traversal start node: node0, and go to step 5. If the capacity of the first subgraph Sub_graph1 is less than Storage_graph / N, continue traversing and write the traversed nodes into the first subgraph Sub_graph1.
[0085] Step 5: Start traversing the new starting node node0, go to steps 3 and 4, and write the remaining graph data into the remaining subgraphs [Sub_graph2, Sub_graph3, ..., Sub_graph N ], such as Figure 3 As shown, the entire graph is divided into multiple subgraphs in an equal manner according to the storage capacity.
[0086] Step 6: Get the traversal query request for the graph data to be queried, i.e., the access request, and resolve the target node of the query. Figure 4 As shown, assuming the target node to be queried is: node k , then any node in each subgraph is selected as the starting traversal node for traversal, and the starting traversal node is set to: node1.
[0087] Step 7: Figure 5As shown, starting from node node1, query a certain adjacent brother node node2 of node1, and at the same time increase the access weight attribute node count_edge1 of the connection edge between nodes node1 and node2. The type of this attribute field is numeric, the initial value is 0, and after traversal, count_edge 1_2 =count_edge 1_2 +1, compare the node node2 with the target node node k If it matches, the query result is returned, and the process ends, and the process goes to step 10. If it does not match, the process goes to step 8.
[0088] Step 8: Continue to search for node2's adjacent sibling node node4, and also connect node2 with node k The connection edges between them increase the access weight attribute node count_edge 2_4 The value of count_edge is increased by 1, and count_edge is traversed. 2_4 =count_edge 2_4 +1, then compare the node node4 with the target node node k If there is no match, continue traversing according to the processing method in step 7 until the target node is found. k until
[0089] Step 9: If the target node is found k , then the query is successful. If the query is not found, then the query is not found.
[0090] Step 10: After the weight assignment is completed, traverse and query the edge weight values in each subgraph, such as Figure 6 As shown, this is the edge weight assignment in the first subgraph Sub_graph1. Figure 7 This is the edge weight assignment in the first subgraph Sub_graph1 and the second subgraph Sub_graph2.
[0091] Step 11: Sort the weight values of all edges (including connecting edges across subgraphs) in the first subgraph Sub_graph1 and the second subgraph Sub_graph2, as shown in Table 1 and Table 2.
[0092] Table 1
[0093]
[0094]
[0095] Table 2
[0096] Storage node number Edge Name Edge weight Sorting 2 <![CDATA[edge 1_4 ]]> 63 1 2 <![CDATA[edge 1_2 ]]> 55 2 2 <![CDATA[edge 1_... ]]> 39 3 2 <![CDATA[edge 1_5 ]]> 24 4 2 <![CDATA[edge 3_4 ]]> 23 5 2 <![CDATA[edge 5_6 ]]> 13 6 2 <![CDATA[edge 6_9 ]]> 9 7 2 <![CDATA[edge 4_7 ]]> 2 8 2 <![CDATA[edge 6_8 ]]> 1 9 2 ... ... ...
[0097] Step 12: After sorting by weight, take out the edge with the lowest ranking and the node corresponding to the edge and store them in the cache queue. For example, in the first subgraph Sub_graph1, edge 19_17 The value is 2, which is the smallest, and the edge 19_17 and node 17 are taken out and stored in the cache queue. In the second subgraph Sub_graph2, edge 6_8 The value is 0, which is the smallest, and the edge 6_8 It is taken out from node 8 and stored in the cache queue.
[0098] Step 13: After extracting the edges and nodes corresponding to the lowest weight values from all subgraphs, extract each node from the cache queue one by one, determine the connection between each extracted node and all other nodes in the query graph, obtain the weight values of the edges connecting each extracted node to the query graph, determine the maximum value among these weights, and then determine which subgraph contains the node with the largest weight corresponding to the edge. The node changes in the cache queue are then updated to the corresponding subgraph. For example, if node nodex in the cache queue has the largest weight value for the edge connecting it to node nodey in the third subgraph, nodex is moved from its original subgraph to the third subgraph.
[0099] Step 14: For connecting edges across nodes, for example, if one of the edges in the second subgraph Sub_graph2 connects node 1 to node 11 in the first subgraph Sub_graph1, determine whether the weight value of the connecting edge between node 11 and other nodes in the first subgraph Sub_graph1 is less than the weight value of the edge.
[0100] Step 15: If it is less than, node 11 is transferred to the second subgraph Sub_graph2 (performed when the traversed states of the first subgraph and the second subgraph are both idle), and the connection edge between node 11 and the first subgraph Sub_graph1 becomes a cross-node connection edge. If it is greater than, it remains unchanged.
[0101] Step 16: Update the vertices and edges in all subgraphs according to the above changes, such as Figure 8 As shown, this is the situation after the graphs in the first subgraph Sub_graph1 and the second subgraph Sub_graph2 are updated.
[0102] Step 17: Continue to update the edge weights in each subgraph based on new graph data query requests. After receiving m new graph data query requests, re-optimize the distribution of nodes and edges in each subgraph. (m is a positive integer and the value of m can be customized according to actual needs)
[0103] Step 18: End.
[0104] The deep multi-hop query method based on graph data optimization provided in this embodiment, based on the deep multi-hop and regional dense coupling characteristics of graph traversal, first divides the large graph into multiple subgraphs according to the storage equal division method, and then assigns association weights to the edges between nodes according to the deep, multi-hop traversal query characteristics. Then, according to the weight ratio, the associated nodes with larger weight values are gradually introduced into each subgraph, and the nodes with smaller weight values are transferred to other subgraphs. The nodes and edges in each subgraph are continuously iterated and updated according to the query request, and the division results of each subgraph are optimized. This method converts large-scale graphs into multiple densely coupled and strongly connected subgraphs, and continuously optimizes the subgraph division results, thereby improving the efficiency of deep, multi-hop traversal for large graphs.
[0105] This embodiment also provides a deep multi-hop query device based on graph data optimization, which is used to implement the above-mentioned embodiments and preferred implementations. Details that have already been described will not be repeated here. As used below, the term "module" can refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation using hardware, or a combination of software and hardware, is also possible and contemplated.
[0106] This embodiment provides a deep multi-hop query device based on graph data optimization, such as Figure 9 Shown, including:
[0107] Data acquisition module 901, used to obtain the graph data to be queried;
[0108] A partitioning module 902 is configured to partition the graph data to be queried into a plurality of subgraphs according to the connection relationships between the nodes in the graph data to be queried;
[0109] The traversal and weight assignment module 903 is used to traverse the multiple subgraphs based on the target node corresponding to the query request, assign weights to the connecting edges between the nodes according to the traversed nodes, and obtain the weight values of the connecting edges;
[0110] The update optimization module 904 is used to update the node changes in each subgraph according to the weight values of the connecting edges in each subgraph to obtain optimized graph data to be queried.
[0111] In an optional embodiment, the traversal and weight assignment module is specifically used to: obtain a query request, parse the query request, and obtain a target node; traverse from any node as a starting point in multiple subgraphs, compare the traversed node with the target node, and stop traversing until the traversed node matches the target node or all nodes do not match the target node; assign weights to the connecting edges of the traversed nodes to obtain weight values of the connecting edges.
[0112] In an optional embodiment, the update optimization module is specifically used to: obtain the connecting edges with the smallest weight in each subgraph and the connecting edges across subgraphs; update the node changes in each subgraph according to the weights of the connecting edges corresponding to the nodes with the smallest weight in each subgraph and the connecting edges of other nodes, to obtain optimized graph data to be queried; and / or, update the node changes in each subgraph according to the relationship between the weights of the connecting edges corresponding to the nodes with other nodes across subgraphs and the weights of the connecting edges across subgraphs, to obtain optimized graph data to be queried.
[0113] In an optional embodiment, the apparatus further includes: an updating module configured to use the optimized multiple subgraphs in the to-be-queried graph data as the multiple subgraphs to be queried in the next query request.
[0114] In an optional embodiment, the update optimization module is also used to: obtain the number of query requests received; determine whether the number has reached a preset number; when the preset number is reached, update the node changes in each subgraph according to the weight values of the connecting edges in each subgraph to obtain optimized graph data to be queried.
[0115] In an optional embodiment, the partitioning module is specifically used to: select any node in the graph data to be queried as a starting point, perform a deep traversal query based on the connection relationship of the nodes, and write the queried nodes into the first subgraph; determine whether the capacity of the first subgraph reaches a preset threshold; when the preset threshold is reached, perform a deep traversal query starting from the node connected to the last node written in the first subgraph, and write the queried nodes into the second subgraph until the capacity of the second subgraph reaches the preset threshold; repeat the generation method of the second subgraph to obtain multiple subgraphs.
[0116] In an optional implementation, the preset threshold is determined based on the capacity of the graph data to be queried and the number of subgraphs.
[0117] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.
[0118] The embodiment of the present invention also provides a computer device having the above Figure 9 The deep multi-hop query device based on graph data optimization is shown.
[0119] See also Figure 10 , Figure 10 is a structural diagram of a computer device provided by an optional embodiment of the present invention, such as Figure 10As shown, the computer device includes: one or more processors 10, memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components utilize different buses to communicate with each other and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in the memory or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Equally, multiple computer devices can be connected, and each device provides part of the necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 9 A processor 10 is taken as an example.
[0120] The processor 10 may be a central processing unit, a network processor, or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit, a programmable logic device, or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic, or any combination thereof.
[0121] The memory 20 stores instructions that can be executed by at least one processor 10, so as to enable at least one processor 10 to execute the method shown in the above embodiment.
[0122] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created based on the use of a computer device for displaying a small program landing page, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely located relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.
[0123] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid-state drive; the memory 20 may also include a combination of the above types of memory.
[0124] The computer device further includes a communication interface 30 for the computer device to communicate with other devices or a communication network.
[0125] The embodiment of the present invention also provides a computer-readable storage medium. The above-mentioned method according to the embodiment of the present invention can be implemented in hardware, firmware, or implemented as a computer code that can be recorded in a storage medium, or implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and downloaded through a network and will be stored in a local storage medium, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state drive, etc.; further, the storage medium can also include a combination of the above-mentioned types of memory. It can be understood that a computer, a processor, a microprocessor controller or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor or hardware, the method shown in the above embodiment is implemented.
[0126] Although the embodiments of the present invention have been described with reference to the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention. Such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A deep multi-hop query method based on graph data optimization, characterized in that: The method comprises: Obtaining the graph data to be queried, where the graph data to be queried is the object of deep multi-hop query; Divide the graph data to be queried into multiple subgraphs according to the connection relationship between the nodes in the graph data to be queried; Based on the target node corresponding to the query request, multiple subgraphs are traversed, and the weight values of the connecting edges between the nodes are assigned according to the traversed nodes to obtain the weight values of the connecting edges; Update the node changes in each subgraph according to the weight values of the connecting edges in each subgraph to obtain the optimized graph data to be queried; Among them, the node changes in each subgraph are updated according to the weight values of the connecting edges in each subgraph to obtain the optimized graph data to be queried, including: Get the number of query requests received; Determining whether the number of times reaches a preset number of times; When the preset number of times is reached, the node changes in each subgraph are updated according to the weight values of the connecting edges in each subgraph to obtain the optimized graph data to be queried; The graph data to be queried is divided into multiple subgraphs according to the connection relationship between the nodes in the graph data to be queried, including: Select any node in the graph data to be queried as the starting point, perform a deep traversal query based on the connection relationship of the nodes, and write the queried nodes into the first subgraph; Determining whether the capacity of the first subgraph reaches a preset threshold; When the preset threshold is reached, a deep traversal query is performed starting from the node connected to the last node written in the first subgraph, and the queried nodes are written to the second subgraph until the capacity of the second subgraph reaches the preset threshold; Repeat the generation method of the second subgraph to obtain multiple subgraphs.
2. The method according to claim 1, characterized in that Based on the target node corresponding to the query request, multiple subgraphs are traversed, and the connection edges between the nodes are weighted according to the traversed nodes to obtain the weight values of the connection edges, including: Get the query request, parse the query request, and get the target node; Traverse from any node in multiple subgraphs, compare the traversed node with the target node, and stop traversing until the traversed node matches the target node or all nodes do not match the target node. Assign weights to the connecting edges of the traversed nodes to obtain the weight values of the connecting edges.
3. The method according to claim 1, characterized in that Update the node changes in each subgraph according to the weight values of the connecting edges in each subgraph to obtain the optimized graph data to be queried, including: Get the minimum weight connection edges in each subgraph and the connection edges across subgraphs; Update the node changes in each subgraph based on the weights of the connecting edges between the node with the smallest weight in each subgraph and other nodes, and obtain the optimized graph data to be queried; And / or, the node changes in each subgraph are updated according to the relationship between the weights of the connecting edges corresponding to the nodes and other nodes of the cross-subgraph connecting edges and the weights of the connecting edges across the subgraphs to obtain optimized graph data to be queried.
4. The method according to claim 3, characterized in that The method further comprises: The multiple subgraphs in the optimized graph data to be queried are used as the multiple subgraphs to be queried in the next query request.
5. The method according to claim 1, wherein The preset threshold is determined based on the capacity of the graph data to be queried and the number of subgraphs.
6. A deep multi-hop query device based on graph data optimization, characterized in that: The device comprises: Data acquisition module, used to obtain the graph data to be queried; A partitioning module is used to partition the graph data to be queried into multiple subgraphs according to the connection relationship between the nodes in the graph data to be queried; The traversal and weight assignment module is used to traverse multiple subgraphs based on the target node corresponding to the query request, assign weights to the connecting edges between the nodes according to the traversed nodes, and obtain the weight values of the connecting edges; The update optimization module is used to update the node changes in each subgraph according to the weight values of the connecting edges in each subgraph to obtain the optimized graph data to be queried; Among them, the node changes in each subgraph are updated according to the weight values of the connecting edges in each subgraph to obtain the optimized graph data to be queried, including: Get the number of query requests received; Determining whether the number of times reaches a preset number of times; When the preset number of times is reached, the node changes in each subgraph are updated according to the weight values of the connecting edges in each subgraph to obtain the optimized graph data to be queried; The graph data to be queried is divided into multiple subgraphs according to the connection relationship between the nodes in the graph data to be queried, including: Select any node in the graph data to be queried as the starting point, perform a deep traversal query based on the connection relationship of the nodes, and write the queried nodes into the first subgraph; Determining whether the capacity of the first subgraph reaches a preset threshold; When the preset threshold is reached, a deep traversal query is performed starting from the node connected to the last node written in the first subgraph, and the queried nodes are written to the second subgraph until the capacity of the second subgraph reaches the preset threshold; Repeat the generation method of the second subgraph to obtain multiple subgraphs.
7. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the deep multi-hop query method based on graph data optimization according to any one of claims 1 to 5 by executing the computer instructions.
8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the deep multi-hop query method based on graph data optimization according to any one of claims 1 to 5.
Citation Information
Patent Citations
Method, system and device for optimizing multi-hop query in graph database
CN116108238A