A method to accelerate accurate subgraph matching
By performing multi-core decomposition and auxiliary structure construction on query graphs, combined with graph cache optimization, the performance problem of the precise subgraph matching algorithm in large-scale situations is solved, and the accelerated matching process and result compression is achieved. It is suitable for large-scale scenarios and optimized Resource utilization and matching efficiency.
Patent Information
- Application Number
- CN202210301789.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-25
- Publication Date
- 2025-01-07
- Estimated Expiration
- 2042-03-25
AI Technical Summary
In the prior art, the precise subgraph matching algorithm has huge time overhead and memory resource overhead under large scale situations, especially when the query graph is very large, it is difficult to build a general index and the index size is huge, resulting in increased query overhead and optimization. Difficulty increases.
By multi-core decomposition of query graphs, generate auxiliary structures and execution plans, optimize the matching process using graph cache, limit memory usage, dynamically build and compress matching results to reduce resource consumption.
It realizes accelerating and accurate subgraph matching method with simple principles, simple operation, wide application scope and faster processing speed. It can maximize the use of memory resources when resource constraints are limited, reduce the overhead of result saving, and is suitable for large-scale matching scenarios.
Smart Images

Figure CN114741565B_ABST
Abstract
Description
Technical Field
[0001] The present invention mainly relates to the technical field of big data processing, and in particular to a method for accelerating precise subgraph matching. Background Art
[0002] As a data type with very powerful descriptive capabilities, "graph data" has a wide range of applications in many fields, including biological macromolecule analysis, financial fraud detection, social network analysis, knowledge graph query, etc.
[0003] Among them, the subgraph matching algorithm is one of the most commonly used operations in graph data analysis queries. The subgraph matching algorithm can be divided into two types of algorithms: inexact subgraph matching and exact subgraph matching according to different application scenarios. Among them, the exact subgraph matching algorithm is implemented based on the subgraph isomorphism algorithm.
[0004] The subgraph isomorphism problem is a classic NP-complete problem that is very challenging in large-scale situations. The main challenges currently faced are: 1) the search state space is exponential; 2) the number of final matching results may be very large; 3) it is difficult to build a general index, and even if it is built, the size of the index will be very large; these problems will lead to an explosive growth in query overhead and increase the difficulty of algorithm optimization.
[0005] Some practitioners such as Liu Yuanhong, Wang Zhao and others adopted a graph clipping method in their Chinese patent application (application number: CN202011623281.8) "A subgraph matching method, device and storage medium" to first reduce the size of the search space to a certain extent, and then through N rounds of iteration (N is the number of nodes in the query graph), the matching of one node is expanded each time, and finally all matching results are continuously expanded. In addition, some expansions have been made to the precise subgraph matching scenarios, which can adapt to some flexible queries.
[0006] Other practitioners have used the principle of precise subgraph matching in the Chinese patent application (application number: CN202010296929.9) "A continuous subgraph matching method, system and device for pattern graph changes" applied by Guo Deke, Zhang Qianzhen and others to detect possible network attacks in the network, and specifically optimized performance for dynamic changes in the query graph.
[0007] However, judging from the above-mentioned disclosed patent documents and prior art, accurate subgraph matching algorithms have a wide range of application scenarios. In the actual application scenarios of these patent documents, the performance issues of subgraph matching are mentioned, including time overhead and huge memory resource overhead, especially when the query graph is very large. This shows that it is very important to improve the performance of the subgraph matching algorithm. Summary of the invention
[0008] The technical problem to be solved by the present invention is: in view of the technical problems existing in the prior art, the present invention provides a method for accelerating precise sub-graph matching which has simple principle, simple operation, wider application range and faster processing speed.
[0009] In order to solve the above technical problems, the present invention adopts the following technical solutions:
[0010] A method for accelerating accurate subgraph matching, the steps comprising:
[0011] Step S0: Decomposition: Perform multi-core decomposition on the query graph, decompose a large query graph into multiple small subgraphs, each of which is called a core, and finally obtain a compressed graph;
[0012] Step S1: Obtain auxiliary structure A: According to the query graph, first perform pruning on the data graph D, determine the candidate node set of each query graph node, and generate an auxiliary structure A for accelerating the query;
[0013] Step S2: Generate a query execution plan: Generate a query execution plan based on the above results; the query execution plan includes an inter-core matching order and an intra-core matching order;
[0014] Step S3: Initialize GraphCache: Initialize the graph cache according to the memory limit given by the user to ensure that the memory usage does not exceed the given threshold M during the query execution;
[0015] Step S4: Execute the matching process: Based on the query plan and the auxiliary structure A, start the matching process and finally get the result;
[0016] Step S5: Obtaining matching results: When the graph cache is large enough to accommodate all the results, the contents of the graph cache are directly written to the disk as the matching results in compressed form.
[0017] As a further improvement of the method of the present invention: in step S0, the step of decomposing a query graph Q into multiple cores includes:
[0018] Step S01: Prepare three queues s ,Queue d ,Queue c , which are used to store the decomposed cores, the query graph subgraphs to be decomposed, and the bridge nodes between cores, respectively, and are initialized as Queue d ={};
[0019] Step S02: Each time from the Queue dTake out a query graph subgraph Q', traverse each node u∈V(Q'), and try to remove u from Q', including all edges connected to u. If at this time, Q' is decomposed into two unconnected subgraphs Q'1 and Q'2, then add both subgraphs to the queue Queue d At the same time, add u to the queue Queue c Otherwise, put it into the queue as a core s middle;
[0020] Step S03: Repeat step S02 until the queue is full. d Empty, Queue s and Queue c The figure shows the result of multi-core decomposition corresponding to the query graph Q, and the results in the two queues are displayed in the form of a compressed graph.
[0021] As a further improvement of the method of the present invention: in step S1, the process of constructing the auxiliary structure A includes:
[0022] Step S11: For each query graph node u∈V(Q), the candidate node set A u The calculation is done by traversing each data graph node v∈V(D) and checking whether v satisfies the following constraints: 1) The labels of the two nodes are the same, that is, L(u)=L(v); 2) The number of labels of the adjacent nodes of the two nodes must also satisfy |N l (u)|≤|N l (v) |;
[0023] Where L is the set of all labels in the graph, N l (u) is the neighbor set of node u whose adjacent nodes are labeled l. Only when these two constraints are met can node v be added to the candidate node set A(u);
[0024] Step S12: For each edge e(u1,u2) in the query graph, If there is such an edge e(v1,v2)∈E(D) in the data graph, then in the auxiliary structure A, the two nodes in A Add an edge connection to complete the initialization of auxiliary structure A;
[0025] Step S13: Given a sequence of query graph nodes Prune A and take one query graph node at a time in order For any node A in A u (v), and any neighbor u′∈N(u) of u, if there is no such node A in A u′(v′) and A u (v) connected, then A u (v) and its connected edges are deleted from A, indicating that node v cannot be matched with node u and is deleted from the search space in advance;
[0026] Step S14: Repeat step S13 until A no longer changes, or repeat it until a specified threshold is reached, and the construction and cutting of the auxiliary structure A is completed.
[0027] As a further improvement of the method of the present invention: in step S2, the step of generating the query plan includes:
[0028] Generate inter-core matching order The specific process is as follows:
[0029] 3) For each core Q c , whose approximate number of matching results is The first matching kernel is selected as Add it to middle;
[0030] Among them, |A u | is the number of candidate sets of node u in the auxiliary structure, and d is the core Q c The average degree of |V(Q c )| is the core Q c The number of nodes;
[0031] 4) Select Join Among them For all and in the compressed graph The set of nodes adjacent to the core in ;
[0032] For each core Q c The kernel matching order The generated process includes:
[0033] 2) For the selection of the first node, if Q c exist The first match is above, so the first node is selected as If Q c exist If it is not the first match, then the first node is selected as in Q c according to The previous core that matches the sequence, and then adds the first node selected to middle;
[0034] 2) Then select Join Among them For the core Q c All with The set of nodes adjacent to the node.
[0035] As a further improvement of the method of the present invention: in step S4, the matching process and the flow of the graph cache work include:
[0036] Step S41: The entire matching process is divided into intra-core matching and inter-core matching. The intra-core matching is to find the subgraph corresponding to the query graph from the data graph and temporarily store it in the graph cache; the inter-core matching is to use the graph cache. If a hit occurs, the local matching result is directly obtained from the graph cache.
[0037] Step S42: For the sequences matching between cores In matching a core Q c When Q c The kernel matching order
[0038] Step S43: For a kernel Q c , according to the corresponding sequence in the core Perform operations;
[0039] Step S44: Perform insertion and deletion operations on the graph cache.
[0040] As a further improvement of the method of the present invention: the operation on the image cache in step S42 includes:
[0041] (1) For the first matching query graph node First generate a triple query key in is a data graph that can be Matching node, id(Q c ) is the core Q c A preset id is used to send the triple to the graph cache to perform the query operation. The graph cache will return all the data graphs that can be matched with Q. c Matching and and The set of matching subgraphs is denoted as If the result returned is The algorithm directly backtracks and prunes. If the returned result is not empty, it traverses Each time, one of the matching results is added to the global partial matching result, and then the matching order between cores is calculated. Jump to the next core Q′ to be matched c ;
[0042] (2) For the last matching query graph node According to the auxiliary structure A, by traversing all The candidate node set is After matching a node in the candidate node set, continue searching according to the depth-first strategy. During the backtracking process, if the return value of the backtracking is true, the entire Q c The local matching results are added to the graph cache to complete the dynamic construction of the graph cache.
[0043] As a further improvement of the method of the present invention: in step S43, for a core Q c , according to the corresponding sequence in the core The in-core matching process includes the following:
[0044] (1) For the first matching query graph node If its partial matching result in the global context has not yet matched a node, its candidate node set is Each time, one of the nodes is taken to continue matching according to the depth-first strategy. If it has already matched the result in the global partial matching result, the result is used directly and the traversal continues in the depth-first order.
[0045] (2) For other query graph nodes in the sequence The candidate node set is calculated by Calculated;
[0046] in To match the sequence The set of nodes in the neighbors of that precede its match, For A in the auxiliary structure Q u Zhongyu The set of nodes connected to each other means that when u p The set of candidate nodes for u after matching with v.
[0047] As a further improvement of the method of the present invention: in the step S44, the graph cache includes a main body composed of a hash table and a linked list, and a queue Queue of a management block f , to prevent block elimination, the process of inserting and deleting operations includes:
[0048] (1) Initialize M / k empty memory blocks based on the user-specified threshold M and the preset block size k and store them in a queue Queue f , where the size of k should be at least larger than the size of each core in Q;
[0049] (2) When inserting a result, the read / write head calculates whether there is any remaining space to store the result based on the block offset and block size of the read / write head. If there is, it is written directly and the read / write head moves back accordingly. If not, it is added to the queue. f Apply for a new block, continue to store, and link the new block with the end block. f When there are no new blocks in the cluster, the elimination strategy is executed to recycle some blocks for allocating new blocks.
[0050] (3) Execute the elimination strategy, select a linked list without elimination lock according to the elimination strategy, and then directly traverse the entire linked list in sequence to perform the deletion and recycling operation;
[0051] (4) If Queue f When executing the elimination strategy, if it is found that all the remaining linked lists have elimination locks, an error will be reported, indicating that more space needs to be allocated to store more blocks.
[0052] As a further improvement of the method of the present invention: in step S5, the result of the overall image cache is a compressed form of the matching result. When decompressing, the specific process includes:
[0053] Step S51: According to the sequence matching between cores From the first core Starting from the matching results of the first core, the matching results of the first core are obtained by traversing the query key Query the graph cache to get the match All matching results, where u1 is The first matching query graph node in ;
[0054] Step S52: For each core Q in the decompression process C The matching result f c , added to the global partial matching result, i.e. f p =f p ∪f c , and build a query key (u n ,f C (u n ),id(Q′ c )), continue to query the graph cache, query Q c The next kernel Q′ c The matching results.
[0055] Step S53: Repeat step S52 until a complete matching result f is obtained.
[0056] As a further improvement of the method of the present invention: in step S3, a preset block size k is built into the program. When the number of blocks used in the matching process exceeds the total number M / k, a FIFO elimination strategy is adopted to avoid memory usage exceeding a given threshold.
[0057] Compared with the prior art, the advantages of the present invention are:
[0058] 1. A method for accelerating accurate subgraph matching of the present invention has a simple principle and is easy to operate. It does not depend on whether the graph itself is directed or undirected, and can be combined with many existing subgraph matching algorithms. The present invention can provide a good acceleration effect in large-scale situations, and can compress the matching results to reduce the cost of saving the results. Especially in resource-constrained situations, the present invention can maximize the use of existing memory resources to form a cache to accelerate the matching solution.
[0059] 2. A method for accelerating precise subgraph matching of the present invention can accelerate the matching process in large-scale matching scenarios, and can also compress a large number of matching results. Currently, the method of the present invention is mainly experimented in an undirected graph with labeled nodes and unlabeled edges. The method of the present invention is also compatible with various other types of graphs, such as directed graphs and graphs with labeled edges. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] Figure 1 It is a schematic flow diagram of the method of the present invention.
[0061] Figure 2 It is a query graph of the present invention in a specific application example.
[0062] Figure 3 It is a compressed diagram of the present invention in a specific application example.
[0063] Figure 4 It is a schematic diagram of GraphCache (graph cache) in a specific application example of the present invention. DETAILED DESCRIPTION
[0064] The present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0065] like Figure 1-4 As shown, a method for accelerating accurate subgraph matching of the present invention comprises the following steps:
[0066] Step S0: Decomposition: Before executing the query, the query graph is first decomposed into multiple cores, and a large query graph is decomposed into multiple small subgraphs, each of which is called a core, and finally a compressed graph is obtained;
[0067] Step S1: Obtain auxiliary structure A: According to the query graph (note that it is not the core), first perform pruning on the data graph D, determine the candidate node set of each query graph node, and finally generate an auxiliary structure A for accelerating the query;
[0068] Step S2: Generate a query execution plan: Generate a query execution plan based on the results of the above steps S0 and S1, that is, the result of the multi-core decomposition of the query graph and the auxiliary structure A; the query execution plan includes the inter-core matching order and the intra-core matching order;
[0069] Step S3: Initialize the graph cache: Initialize the graph cache according to the memory limit given by the user to ensure that the memory usage does not exceed the given threshold M during the query execution;
[0070] Step S4: Execute the matching process: Based on the query plan obtained in the above preprocessing process and the auxiliary structure A, start the matching process and finally obtain the result;
[0071] Step S5: Obtaining matching results: When the graph cache is large enough to accommodate all the results, the contents of the graph cache can be directly written to the disk as needed, which can be used as the matching result, and is a compressed result.
[0072] In a specific application example, in step S4, the entire matching process is a state search process. In this example, a depth-first strategy is adopted to avoid a large amount of memory consumption. At the same time, during the matching process, the graph cache is dynamically queried to insert and delete data, and the matching is accelerated through the hit process of the graph cache.
[0073] In a specific application example, in step S3, a preset block size k is built into the program. The block method is used to facilitate memory management. When the number of blocks used in the matching process exceeds the total number M / k, the FIFO elimination strategy will be adopted to avoid memory usage exceeding a given threshold.
[0074] In a specific application example, in step S0, the specific steps of decomposing a query graph Q into multiple cores are as follows:
[0075] Step S01: First prepare three queues s ,Queue d ,Queue c , which are used to store the decomposed cores, the query graph subgraphs to be decomposed, and the bridge nodes between cores, respectively, and are initialized as Queue d = {Q};
[0076] Step S02: Each time from the Queue d Take out a query graph subgraph Q′ from the query graph, and then traverse each node u∈V(Q′), try to remove u from Q′, including all edges connected to u. If at this time, Q′ is decomposed into two unconnected subgraphs Q′1 and Q′2, then add both subgraphs to the queue Queue d At the same time, add u to the queue Queue c Otherwise, put it into the queue as a core s middle;
[0077] Step S03: Repeat step S02 until the queue is full. d Is empty, then Queue s and Queue c The result of multi-core decomposition corresponding to the query graph Q is shown in the figure. At this time, the results in the two queues can be displayed in the form of a compressed graph, where the compressed graph is a bipartite graph with two types of nodes. One node comes from the Queue. s For each core in the queue, another node comes from c For each bridge node in, for a bridge node v and a core Q c , if v∈V(Q c ), then an edge is used to connect two "nodes" on the compressed graph, Figure 2 As an example, after multi-core decomposition, the final compressed graph is as follows Figure 3 .
[0078] In a specific application example, in step S1, the specific steps of constructing the auxiliary structure A are as follows:
[0079] Step S11: For each query graph node u∈V(Q), its candidate node set A u The calculation of , needs to traverse each data graph node v∈V(D), check whether v satisfies the following constraints: 1) the labels of the two nodes are the same, that is, L(u)=L(v), 2) the number of labels of the adjacent nodes of the two nodes also needs to satisfy |N l (u)|≤|N l (v)|, where L is the set of all labels in the graph, N l () is the neighbor set of node u whose adjacent nodes have label l. Only when these two constraints are met can node v be added to the candidate node set A(u).
[0080] Step S12: For each edge e(u1,u2) in the query graph, If there is such an edge e(v1,v2)∈E(D) in the data graph, then in the auxiliary structure A, the two nodes in A Add an edge connection, thus completing the initialization of the auxiliary structure A.
[0081] Step S13: Then given a sequence of query graph nodes A is further pruned, taking one query graph node at a time in order For any node A in A u (v), and any neighbor u′∈N(u) of u, if there is no such node A in A u′ (v′) and A u (v) are connected, then A u (v) and its connected edges are deleted from A, which means that node v cannot be matched with node u and is therefore deleted in advance from the search space.
[0082] Step S14: Repeat step S13 until A no longer changes, or repeat it until a specified threshold (generally set to 3 in practice), that is, the construction and cutting of the auxiliary structure A is completed.
[0083] In a specific application example, in step S2, the specific steps of generating the query plan are as follows:
[0084] The first step is to generate the inter-core matching order The specific process is as follows:
[0085] 5) For each core Q c , the approximate number of matching results can be obtained by Therefore, the first matching kernel is selected as Add it to middle;
[0086] Among them, |A u | is the number of candidate sets of node u in the auxiliary structure, and d is the core Q c The average degree of |V(Q c )| is the core Q c The number of nodes;
[0087] 6) Then select Join Among them For all and in the compressed graph The set of nodes adjacent to the nodes (cores) in .
[0088] For each core Q c The kernel matching order The specific idea of its generation is similar:
[0089] 3) For the selection of the first node, if Q c exist is the first match, so the first node is selected as If Q c exist is not the first match, then the first node is selected as in Q c according to The previous core that matches the sequence, and then adds the first node selected to middle.
[0090] 4) Then select Join Among them For the core Q c All with The set of nodes adjacent to the node.
[0091] In a specific application example, in step S4, the specific steps of the matching process and the graph cache work are as follows:
[0092] Step S41: The entire matching process is divided into intra-core matching and inter-core matching. Since in step S2, each core has a sequence of nodes as the search order, the intra-core matching is the same as the traditional matching algorithm. Any matching algorithm can be adopted according to the actual situation to find the subgraph corresponding to the query graph from the data graph and temporarily store it in the graph cache;
[0093] For inter-core matching, the graph cache can be used. If a hit occurs, the local matching result can be directly obtained from the graph cache, avoiding the traditional matching algorithm from searching for repeated local results again.
[0094] Step S42: For the sequences matching between cores In matching a core Q c When Q c The kernel matching order There are two operations on graph caching:
[0095] (1) For the first matching query graph node First generate a triple query key in is a data graph that can be Matching node, id(Q c ) is the core Q c A preset id is used to send the triple to the graph cache to perform the query operation. The graph cache will return all the data graphs that can be matched with Q.c Matching and and The set of matching subgraphs is denoted as If the result returned is The algorithm directly backtracks and prunes. If the returned result is not empty, it traverses Each time, one of the matching results is added to the global partial matching result, and then the matching order between cores is calculated. Jump to the next core Q′ to be matched c , continue to step S32.
[0096] (2) For the last matching query graph node According to the auxiliary structure A, by traversing all The specific calculation method is the same as the process of matching in the core. After matching a node in the candidate node set, the search continues according to the depth-first strategy. In the backtracking process, if the backtracking return value is true, it means that such a match is valid and the final solution can be found, so the entire Q c The local matching results are added to the graph cache to complete the dynamic construction of the graph cache.
[0097] Step S43: For a kernel Q c , according to the corresponding sequence in the core There are the following in-kernel matching processes:
[0098] (1) For the first matching query graph node If its partial matching result in the global context has not yet matched a node, its candidate node set is Each time, one of the nodes is taken to continue matching according to the depth-first strategy. If it has already matched the result in the global partial matching result, the result is used directly and the traversal continues in the depth-first order.
[0099] (2) For other query graph nodes in the sequence The candidate node set is calculated by Calculated;
[0100] in To match the sequence The set of nodes in the neighbors of that precede its match, For A in auxiliary structure A u Zhongyu The set of nodes connected to each other means that when u p After matching with v, the candidate node set of u;
[0101] Step S44: For the graph cache, Figure 4 Its structure is shown in the figure, including the main body composed of hash tables and linked lists, and the queue Queue that manages blocks. f , and the elimination lock that prevents block elimination. The specific steps of insertion and deletion are as follows:
[0102] (1) When initializing, first initialize M / k empty memory blocks according to the user-specified threshold M and the preset block size k, and store them in a queue Queue f , where the size of k should be at least larger than the size of each core in Q, so that the matching results of a core can be temporarily stored. During the entire search process, for the graph cache linked list being built, a read-write head will be maintained to continuously insert results, and an elimination lock will be added to the current linked list to prevent it from being selected and eliminated by the elimination strategy.
[0103] (2) When inserting a result, the read / write head calculates whether there is any remaining space to store the result based on the block offset and block size of the read / write head. If there is, it is written directly and the read / write head moves back accordingly. If not, it is added to the queue. f Apply for a new block, continue to store, and link the new block with the end block. f When there are no new blocks in the cluster, the elimination strategy will be executed to recycle some blocks for allocating new blocks.
[0104] (3) Execute the elimination strategy. First, select a linked list without an elimination lock according to the elimination strategy, and then directly traverse the entire linked list to perform the deletion and recycling operation;
[0105] (4) If Queue f When executing the elimination strategy, if it is found that all the remaining linked lists have elimination locks, an error will be reported, indicating that more space should be allocated to store more blocks.
[0106] In a specific application example, in step S5, the overall result of the graph cache can actually be regarded as a compressed form of the matching result. When decompressing, although a depth-first search strategy is also used for decompression, there is no backtracking process, that is, each search is a meaningful decompression process. The specific decompression process is as follows:
[0107] Step S51: According to the sequence matching between cores From the first core Starting from the matching results of the first core, the matching results of the first core can be obtained by traversing the query key Query the graph cache to get the matching All matching results, where u1 is The first matching query graph node in .
[0108] Step S52: For each core Q in the decompression process C The matching result f c , add it to the global partial matching result, i.e. f p =f p ∪f c , and build a query key (u n ,f C (u n ),id(Q′ c )), continue to query the graph cache, query Q c The next kernel Q′ c The matching results.
[0109] Step S53: Repeat step S52 until a complete matching result f is obtained.
[0110] The above are only preferred embodiments of the present invention, and the protection scope of the present invention is not limited to the above embodiments. All technical solutions under the concept of the present invention belong to the protection scope of the present invention. It should be pointed out that for ordinary technicians in this technical field, some improvements and modifications without departing from the principle of the present invention should be regarded as the protection scope of the present invention.
Claims
1. A method for accelerating accurate subgraph matching, characterized in that the steps include: Step S0: Decomposition: Perform multi-core decomposition on the query graph, decomposing a large query graph into multiple small subgraphs, each of which is called a core, and finally obtaining a compressed graph; Step S1: Get auxiliary structure :Based on the query graph, first Perform pruning to determine the candidate node set for each query graph node and generate an auxiliary structure for accelerating the query ; Step S2: Generate query execution plan: Based on the auxiliary structure Generate an execution plan for the query; the execution plan for the query includes an inter-core matching order and an intra-core matching order; Step S3: Initialize the graph cache: Initialize the graph cache according to the memory limit given by the user to ensure that the memory usage does not exceed the given threshold during the query execution. ; Step S4: Execute the matching process: based on the query plan and auxiliary structure , start the matching process and finally get the result; Step S5: Obtain matching results: When the graph cache is large enough to accommodate all the results, the contents of the graph cache are directly written to the disk as the matching results in compressed form; In step S1, the auxiliary structure The build process includes: Step S11: For each query graph node , candidate node set The calculation is done by traversing each data graph node ,examine Do the following constraints apply: 1) The labels of the two nodes are the same, i.e. ; 2) The number of labels of the adjacent nodes of two nodes must also satisfy in is the set of all labels in the graph, For Node The neighboring node labels are The neighbor set of the node can only be added if these two constraints are met. Add to candidate node set middle; Step S12: For each edge in the query graph ,for , if there is such an edge in the data graph , then in the auxiliary structure In The two nodes in , add an edge connection to complete the auxiliary structure Initialization of Step S13: Given a sequence of query graph nodes ,right Perform pruning, taking one query graph node at a time in order ,for Any node in ,and Any neighbor of , if in There is no such node in and Connected, it will and its connected edges from Delete, indicating that the node It cannot be connected with the node Those that match are pre-deleted from the search space; Step S14: Repeat step S13 until No longer changes, or repeats until a specified threshold, completing the auxiliary structure Construction and cutting; In step S2, the query plan generation step includes: Generate inter-core matching order The specific process is as follows: 1) For each core , the number of matching results is given by , the first matching core selection is , add it to middle; in, Auxiliary structure nodes The number of candidate sets, For the core The average degree of For the core The number of nodes; 2) Select Join Among them For all and in the compressed graph The set of nodes adjacent to the core in ; For each core The kernel matching order ,The generated process includes: 1) For the selection of the first node, if exist The first match is above, so the first node is selected as ;if exist If it is not the first match, then the first node is selected as ; in for according to The previous core that matches the sequence, and then adds the first node selected to middle; 2) Then select Join Among them For the nuclear All with The set of nodes adjacent to the middle node; In step S4, the matching process and the flow of the graph cache work include: Step S41: The entire matching process is divided into intra-core matching and inter-core matching. The intra-core matching is to find the subgraph corresponding to the query graph from the data graph and temporarily store it in the graph cache; the inter-core matching is to use the graph cache. If a hit occurs, the local matching result is directly obtained from the graph cache. Step S42: For the sequences matching between cores , in matching a kernel When, according to The kernel matching order ; Step S43: For a core , according to the corresponding sequence in the core Perform operations; Step S44: performing insertion and deletion operations on the graph cache; In step S3, a preset block size is built into the program , when the number of blocks used in the matching process exceeds the total When , the FIFO elimination strategy is used to prevent memory usage from exceeding a given threshold.
2. The method for accelerating accurate subgraph matching according to claim 1, characterized in that: In step S0, a query graph is used The steps to decompose into multiple cores include: Step S01: Prepare three queues , , , which are used to store the decomposed cores, the query graph subgraphs to be decomposed, and the bridge nodes between cores, respectively, and are initialized as , ; Step S02: Each time from Extract a query graph subgraph from , traverse each node , try to from Removed from the list, including all and Connected edges, if at this time, Decomposed into two disconnected subgraphs , , then add both subgraphs to the queue At the same time, Join the queue Otherwise, put it into the queue as a core middle; Step S03: Repeat step S02 until the queue is empty, and The query graph The corresponding multi-core decomposition results show the results in the two queues in the form of compressed graphs.
3. The method for accelerating accurate subgraph matching according to claim 1, characterized in that: The operations on the image cache in step S42 include: (1) For the first matching query graph node , first generate a triple query key ,in is a data graph that can be Matching nodes, For the core A preset id is used to send the triple to the graph cache to perform the query operation. The graph cache will return all the data graphs that can be matched Matching and and The set of matching subgraphs is denoted as If the result returned is , the algorithm directly backtracks and prunes. If the returned result is not empty, it traverses , each time one of the matching results is added to the global partial matching result, and then the order of matching between cores is , jump to the next core to be matched ; (2) For the last matching query graph node , according to the auxiliary structure , by traversing all The candidate node set is After matching a node in the candidate node set, continue searching according to the depth-first strategy. During the backtracking process, if the return value of the backtracking is true, the entire current node is The local matching results are added to the graph cache to complete the dynamic construction of the graph cache.
4. The method for accelerating accurate subgraph matching according to claim 1, characterized in that: In step S43, for a core , according to the corresponding sequence in the core , including the following in-kernel matching process: (1) For the first matching query graph node ,If its partial matching result in the global context has not yet matched a node, then its candidate node set is ,Each time, take one of the nodes and continue to match it according to the depth-first strategy. If it has matched the result in the global partial matching result, use the result directly and continue to traverse in the depth-first order; (2) For other query graph nodes in the sequence , the candidate node set is calculated by Calculated; in To match the sequence , The set of nodes in the neighbors of that precede its match, For auxiliary structures middle Zhongyu The node is a set of nodes connected to each other, which means that and After matching, The candidate node set.
5. The method for accelerating accurate subgraph matching according to claim 1, characterized in that: In step S44, the graph cache includes a main body composed of a hash table and a linked list, and a queue for managing blocks. , to prevent block elimination, the process of inserting and deleting operations includes: (1) Based on the threshold specified by the user and the preset block size ,initialization Empty memory blocks are stored in a queue ,in The size should be at least The size of each kernel in ; (2) When inserting a result, the read / write head calculates whether there is any remaining space to store the result based on the block offset and block size of the read / write head. If there is, it is written directly and the read / write head moves back accordingly. If not, it moves to the next block. Apply for a new block, continue to store, and link the new block with the last block. When there are no new blocks in the cluster, the elimination strategy is executed to recycle some blocks for allocating new blocks. (3) Execute the elimination strategy. According to the elimination strategy, select a linked list without an elimination lock, and then directly traverse the entire linked list in sequence to perform the deletion and recycling operation; (4) If When executing the elimination strategy, if it is found that all the remaining linked lists have elimination locks, an error will be reported, indicating that more space needs to be allocated to store more blocks.
6. The method for accelerating accurate subgraph matching according to any one of claims 1 to 5, characterized in that: In step S5, the result of the overall graph cache is a compressed form of the matching result. When decompressing, the specific process includes: Step S51: According to the sequence matching between cores , from the first core Starting from the matching results of the first core, the matching results of the first core are obtained by traversing the query key , , query the graph cache and get the matching All matching results, where for The first matching query graph node in ; Step S52: For each core in the decompression process Matching results , added to the global partial matching result, namely , while building a query key , continue to query the graph cache, query The next core The matching results; Step S53: Repeat step S52 until a complete matching result is obtained. .
Citation Information
Patent Citations
Continuous sub-graph matching method and system for mode graph change, and equipment
CN111510454A
Sub-graph matching method, device and equipment and storage medium
CN112667860A