A subgraph query method and device
By merging the common parts of the query subgraphs in the graph database into a query tree structure with the branch parts as branches, the problem of low subgraph matching efficiency in the existing technology is solved, and more efficient subgraph query is achieved.
Patent Information
- Application Number
- CN202411779293.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-04
- Publication Date
- 2026-02-13
- Estimated Expiration
- 2044-12-04
AI Technical Summary
Existing technologies are inefficient when performing subgraph matching in graph databases, and it is difficult to efficiently handle batch queries of multiple query subgraphs.
By merging the common parts between several query subgraphs into the trunk of the query tree, and using the remaining parts as branches for subgraph queries, duplicate matching is reduced and query efficiency is improved.
By reducing repeated matching of the same parts in multiple query subgraphs, the efficiency of subgraph matching in graph databases is improved, especially in batch subgraph queries, which significantly improves query speed.
Smart Images

Figure CN119782586B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] One or more embodiments of the present specification relate to the technical field of graph database processing, and in particular to a subgraph query method and device. BACKGROUND
[0002] In the field of computers, a database is a system used to store, manage, and retrieve data. A relational database is a common type of database that is typically used to store structured data. When a user submits a query, the database matches the query with the data in the database, and when a match is found, the database reads the data and returns it to the user.
[0003] Non-relational databases, on the other hand, can be used to store unstructured data. For example, a graph database stores and queries data in a graph structure, with data stored in the form of nodes and edges, where nodes represent data entities and edges represent relationships between entities. The data stored in a graph database is also referred to as a data graph. When a user provides a query subgraph, it is possible to match the given query subgraph in the data graph and obtain all isomorphic graphs of the query subgraph. The data graph contains private data of the user, and when matching the data graph, it is necessary to ensure that the private data is not disclosed.
[0004] Currently, there is a desire for improved solutions that can more efficiently perform subgraph matching on data graphs stored in a graph database. SUMMARY
[0005] One or more embodiments of the present specification describe a subgraph query method and device to more efficiently perform subgraph matching on data graphs stored in a graph database. The specific technical solutions are as follows.
[0006] In a first aspect, an embodiment provides a subgraph query method, comprising:
[0007] obtaining a plurality of query subgraphs to be queried; the plurality of query subgraphs include nodes and edges, and attribute information of the nodes and edges;
[0008] performing a preliminary query in a data graph stored in a graph database based on the same part between the plurality of query subgraphs, to obtain a first query result of the same part; the same part is included in the plurality of query subgraphs and is a subgraph corresponding to the same edges possessed by the plurality of query subgraphs;
[0009] performing subgraph queries in the data graph based on the remaining parts of the plurality of query subgraphs respectively on the basis of the first query result, to obtain query results of each query subgraph.
[0010] In an implementation, the same part between the several query sub-graphs is obtained based on a manner that the several query sub-graphs are merged into a query tree; a trunk part of the query tree is the same part between the several query sub-graphs.
[0011] In an implementation, the remaining part of any one query sub-graph is a branch part of the query tree.
[0012] In an implementation, any first query sub-graph contains several edges and their matching orders, the same part contains edges having corresponding same matching orders in different query sub-graphs; the step of merging the several query sub-graphs into a query tree comprises: taking edges in the first query sub-graph as tree nodes in the query tree, and merging the first query sub-graph into the query tree according to the matching orders, so that the several edges in the same part are merged into the trunk part of the query tree in turn.
[0013] In an implementation, in the first query sub-graph, the edges in the same part have matching orders prior to matching orders of other edges; the operation of merging the first query sub-graph into the query tree comprises:
[0014] merging the first query sub-graph into the query tree according to the matching orders of the several edges in the first query sub-graph and an order from a root node to a leaf node in the query tree.
[0015] In an implementation, when the first query sub-graph is the first one, the step of merging the first query sub-graph into the query tree comprises: taking an edge in a current matching order in the first query sub-graph as a parent node in the query tree and taking an edge in a next matching order as a child node of the parent node according to the matching orders.
[0016] In an implementation, when the first query sub-graph is not the first one, the step of merging the first query sub-graph into the query tree comprises:
[0017] determining a first edge from the first query sub-graph according to the matching orders and determining a first tree node from the query tree according to an order from a parent node to a child node, and iteratively merging in the following manner:
[0018] judging whether the first edge and an edge in a child node of the first tree node can be merged;
[0019] if yes, updating the first edge and the first tree node;
[0020] if no, taking the first edge and other edges in the first query sub-graph as respective levels of child nodes of the first tree node in turn.
[0021] In an implementation, the step of determining whether the first edge can be merged with a child node of the first tree node comprises: determining that the first edge can be merged with a child node of the first tree node when the first edge matches an edge of the child node.
[0022] In an implementation, the tree nodes in the query tree have corresponding edge data, and the edge data comprises: an identifier of the tree node, a child node of the tree node, and an identifier used to indicate whether the edge of the tree node is the last edge in a certain query subgraph.
[0023] When performing the step of taking a first edge in a certain query subgraph as a tree node in the query tree, the step comprises: determining edge data of the tree node based on edge data of the first edge.
[0024] In an implementation, the edge data of the tree node further comprises: a node identifier corresponding to the edge and an edge identifier; the edge identifier is used as the identifier of the tree node; the step of determining the edge data of the tree node based on the edge data of the first edge comprises: when the node identifier of the first edge is recorded in a mapping relationship library, determining the node identifier of the tree node based on a node identifier in a tree node corresponding to the node identifier in the mapping relationship library; the mapping relationship library is used to record a mapping relationship between a node identifier in a query subgraph and a node identifier in a query tree.
[0025] In an implementation, the preliminary query comprises: performing subgraph query in a data graph stored in the graph database based on a main part of the query tree; the step of performing subgraph query in the data graph based on the remaining part of each of the query subgraphs respectively comprises: performing subgraph query based on a branch part of the query tree respectively on the basis of the first query result.
[0026] In an implementation, the step of performing subgraph query in the data graph based on the main part of the query tree comprises:
[0027] When an edge of a first tree node is a to-be-queried edge, performing subgraph query in the data graph on the to-be-queried edge based on a subgraph obtained by querying the data graph based on an edge of a parent node of the first tree node.
[0028] In an implementation, the step of performing subgraph query in the data graph based on the branch part of the query tree comprises: when the first tree node is the last tree node in a corresponding path of the first query subgraph in the query tree, determining a query result corresponding to the first query subgraph based on a subgraph query result of the first tree node in the data graph.
[0029] In a second aspect, embodiments provide a subgraph query device, the device comprising:
[0030] a subgraph obtaining module configured to obtain a plurality of query subgraphs to be queried; the plurality of query subgraphs comprising nodes and edges, and attribute information of the nodes and edges;
[0031] a preliminary query module configured to, based on a same part between the plurality of query subgraphs, perform preliminary query in a data graph stored in a graph database to obtain a first query result of the same part; the same part being contained in the plurality of query subgraphs and being a subgraph corresponding to the same edges possessed by the plurality of query subgraphs;
[0032] a residual query module configured to, based on a residual part of each of the plurality of query subgraphs, perform subgraph query in the data graph on the basis of the first query result to obtain a query result of each query subgraph.
[0033] In a third aspect, embodiments provide a computer readable storage medium having stored thereon a computer program, which, when executed in a computer, causes the computer to perform the method of any one of the first aspect.
[0034] In a fourth aspect, embodiments provide a computing device comprising a memory and a processor, the memory having stored thereon executable code that, when executed by the processor, implements the method of any one of the first aspect.
[0035] In the method and device provided by the embodiments of the present disclosure, the same part between the plurality of query subgraphs is preliminarily queried in the data graph stored in the graph database to obtain the first query result, and on this basis, the residual part of each query subgraph is further queried, which reduces the repeated matching of the same part in the plurality of query subgraphs, and thus the subgraph matching of the data graph stored in the graph database can be more efficiently performed. BRIEF DESCRIPTION OF DRAWINGS
[0036] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following will briefly introduce the drawings needed to be used in the embodiment description. Obviously, the drawings in the following description are only some of the embodiments of the present disclosure, and for those skilled in the art, other drawings can also be obtained from these drawings without any creative effort.
[0037] Figure 1 An embodiment scenario disclosed in the present disclosure is shown in the following figure;
[0038] Figure 2 A flowchart of a subgraph query method provided by the embodiments is shown in the following figure;
[0039] Figure 3 A flowchart of a process for constructing a query tree provided for an embodiment;
[0040] Figure 4 A schematic diagram of a class of edge data of a tree node provided for an embodiment;
[0041] Figure 5 A schematic block diagram of a subgraph query device provided for an embodiment. DETAILED DESCRIPTION
[0042] The scheme provided in the present specification will be described below with reference to the accompanying drawings.
[0043] A large amount of data graphs are stored in a graph database. The data graph is a graph structure data constructed by a large amount of business data. The data graph contains a large amount of nodes and edges between nodes, and attribute information of nodes and edges. Among them, the node represents a data entity, and the edge represents the relationship between entities. The node attribute information and the edge attribute information contain different meanings according to specific scenarios. For example, in a transaction scenario, the node represents a user, the edge represents a transaction between users, the attribute information of the node refers to user attribute information, and specifically can include user account, user attribute, and user historical behavior information, etc.; the attribute information of the edge refers to transaction attribute information, and specifically includes transaction number, transaction amount, transaction time, transaction mode, and transaction account, etc. In the field of commodity pushing, the node represents a user and a commodity, and the edge represents the behavior relationship (such as including clicking, searching, or viewing behavior relationship) between the user and the commodity. The attribute information of the user node refers to user attribute information, and the attribute information of the commodity node refers to commodity attribute information, and specifically includes commodity information, and the attribute information of the edge includes behavior-related information, etc. In addition to this, the data in the data graph can also be data in other business fields. It should be noted that the information related to the user, including user attribute and transaction attribute, is all private data, which needs to be protected in the data processing process. Moreover, the above-mentioned private data related to the user is obtained after authorization by the user.
[0044] The query subgraph (query) is a small graph structure data relative to the data graph. The query subgraph contains nodes and edges, and specifically can contain multiple nodes and multiple edges, and at least contains two nodes and an edge between the two nodes. The query subgraph is a specific pattern graph with a specified structure determined according to some known method. For example, it can be a specific pattern graph with a transaction risk structure, etc. It contains some specific nodes and edges, which constitute the graph pattern to be matched.
[0045] Subgraph query refers to finding all subgraphs isomorphic to a query subgraph in a data graph. The purpose of subgraph query is to find all subgraphs isomorphic to a given small graph in a given large graph. The query subgraph is a small graph used for querying in subgraph matching. In the field of transaction risk prediction, the subgraphs matched in the data graph by using the query subgraph are transactions containing risks, and risk prediction can be performed by using these subgraphs, so as to determine business risks more quickly and exclude business risks.
[0046] The found subgraph and the query subgraph belong to isomorphic graphs. There is a one-to-one mapping between the node sets of the two isomorphic graphs, and the edges between the corresponding vertices also maintain one-to-one correspondence. In the two isomorphic graphs, the corresponding nodes have the same node attribute information, and the corresponding edges have the same node attribute information.
[0047] Figure 1 An embodiment scenario disclosed in the present specification is shown. It includes a risk control platform, a computing device, and a graph database. The risk control platform is configured to send a query subgraph to the computing device. The computing device is configured to perform subgraph query in the graph database based on the query subgraph, and send the obtained query result to the risk control platform. The risk control platform is configured to perform risk prediction based on the query result. The graph database is configured to store data in a data graph. Figure 1 In the embodiment, the query subgraph, the data graph, and the query result are also shown. The colors of the nodes and edges represent the corresponding node attributes and edge attributes, and the numbers in the circles are node numbers. The node numbers of the user subgraph and the query subgraph may be different. For example, the edge 1→2 in the query subgraph and the edge 2→1 in the user subgraph are corresponding, but the node numbers are not the same. Figure 1 The scenario shown in the embodiment is only one scenario, and the embodiment can also be applied to various implementation scenarios in actual application.
[0048] In the actual application scenario of subgraph query, there is usually more than one query subgraph, and therefore batch subgraph query is needed. Batch subgraph query refers to performing subgraph query on multiple query subgraphs in a data graph.
[0049] In order to improve the efficiency of the batch subgraph query process, the embodiment of the present specification provides a subgraph query method. The following describes the embodiment in combination with Figure 2 The embodiment is described.
[0050] Figure 2 A flowchart of a subgraph query method provided by the embodiment is shown. The data graph includes a large number of nodes and edges between the nodes, and the edges can have a direction or no direction. The method can be executed by a computing device. In Figure 1 In the scenario shown in the embodiment, the method of the embodiment can be executed by Figure 1The method is executed by a computing device in the system. The method embodiment comprises the following steps.
[0051] In step S210, a plurality of query sub-graphs Q to be queried are obtained. The plurality of query sub-graphs Q comprises one or more query sub-graphs. Each query sub-graph Q comprises at least two nodes and the connection edges between the nodes, and the attribute information of the nodes and the attribute information of the edges.
[0052] In step S220, based on the same part between the plurality of query sub-graphs Q, a preliminary query is performed in the data graph G stored in the graph database, to obtain a first query result of the same part.
[0053] The same part comprises a plurality of query sub-graphs and is a sub-graph corresponding to the same edges possessed by the plurality of query sub-graphs. The plurality of query sub-graphs can have one or more same edges. Any same edge comprises the same edge attribute information and the same attribute information of the two nodes connected by the edge.
[0054] In one example, the plurality of query sub-graphs Q comprises a first query sub-graph Q1 and a third query sub-graph Q3, and the two query sub-graphs Q have a same part and a different part. The edge 1→2 in the first query sub-graph Q1 and the edge 1→4 in the third query sub-graph Q3 are same edges, and the edge 2→3 in the first query sub-graph Q1 and the edge 4→3 in the third query sub-graph Q3 are same edges. Therefore, the same part is a part composed of a black dot, a blue line, a white dot, a black line and a blue dot in sequence. The remaining part is the different part of the two query sub-graphs, which is a part composed of a black dot, a yellow line and a blue dot in the first query sub-graph Q1, and a part composed of a black dot, a black line, a white dot, a blue line and a blue dot in the third query sub-graph Q3. In order to make the description more concise and clear, Figure 2 In the figure, the node attributes and the edge attributes are represented by the colors of the circles and lines.
[0055] The first query result is only intermediate data of the sub-graph query process, and is not the final query result obtained.
[0056] In the execution of the step, the edges included in the plurality of query sub-graphs Q can be compared to determine the same part between the plurality of query sub-graphs Q, and the same part between the plurality of query sub-graphs Q can be merged into one or more graphs, and the number of the merged graphs is less than the number of the plurality of query sub-graphs Q. That is, the same part can be understood as a graph comprising nodes and edges therebetween. Generally, the same part can be a continuous part in the plurality of query sub-graphs Q.
[0057] When the preliminary query is performed in the data graph G based on the same part, the same part can be regarded as a query sub-graph, and the same part can be queried in the data graph G by using the existing manner, and the specific process is not described herein.
[0058] Step S230, based on the first query result, subgraph queries are performed in the data graph G based on the remaining part of each query subgraph, to obtain the query result of each query subgraph Q. For each query subgraph Q, the query result includes one or more subgraphs. In the transaction risk control field, the query result is used to perform transaction risk prediction.
[0059] After obtaining the first query result of the same part, since the same part is associated with the remaining part of each query subgraph Q, subgraph queries can be continued on the remaining part based on the first query result corresponding to the same part, so that the complete subgraph query result corresponding to each query subgraph Q can be obtained. For example, subgraph queries can be continued on the remaining part of any first query subgraph Q1 within the data graph range contained in the first query result, to obtain the query result corresponding to the first query subgraph Q1. The remaining part of each query subgraph Q is also a query subgraph, and the query on the query subgraph can be performed in the existing manner.
[0060] In the graph database query method provided in this embodiment, since the same part is preliminarily queried in the data graph G, and the remaining part of each query subgraph is continuously queried based on the obtained first query result, repeated subgraph matching on the same part is not required, the calculation amount during query is reduced, and therefore the efficiency during batch subgraph query can be improved.
[0061] In order to improve the query efficiency, in another embodiment of the present specification, the same part of the query subgraph Q is obtained before the step S210 and the step S220. Figure 2 Between the steps S210 and S220 in the embodiment, the step of obtaining the same part of the query subgraph Q can also be included. In specific implementation, the step of obtaining the same part of the query subgraph Q can be implemented by the following step 1, and the steps S220 and S230 can be implemented by the step 2.
[0062] Step 1, the query subgraphs Q are merged into a query tree T.
[0063] The main part of the query tree T is the same part between the query subgraphs Q1, the remaining part of any query subgraph Q is the branch part of the query tree T, and the plurality of paths contained in the query tree T correspond to the plurality of query subgraphs Q. The query tree T contains a plurality of tree nodes, and the plurality of tree nodes form a plurality of paths from the root node to the leaf node.
[0064] Step 2, subgraph queries are performed in the data graph G based on the query tree T in the order from the main part to the branch part of the query tree T, to obtain the query result corresponding to each query subgraph Q. The step 2 can specifically include the following steps 2_1 and 2_2.
[0065] Step 2_1, preliminary query. The preliminary query includes: performing a subgraph query in the data graph G stored in the graph database based on the main part of the query tree T, to obtain a first query result.
[0066] Step 2_2, remaining query. The remaining query includes: based on the first query result, performing a subgraph query based on the branch part of the query tree T, respectively.
[0067] In this embodiment, the plurality of query subgraphs Q are merged into the query tree T, which can make as many same parts as possible between the plurality of query subgraphs Q be merged, and thus can avoid repeated queries as much as possible, thereby improving the query efficiency.
[0068] In step 1, since there is a connection relationship between the nodes and edges in the query subgraph, there is also a connection relationship between the tree nodes in the query tree T. Based on this similar characteristic, the plurality of query subgraphs Q can be merged into the query tree T, so that the main part of the query tree T contains the same part, and the plurality of paths contained in the query tree T correspond to the plurality of query subgraphs Q, respectively. Based on this idea, the plurality of query subgraphs Q can be merged into the query tree T in a variety of implementation manners. The execution process of step 1 will be described in combination with a specific implementation manner.
[0069] In one implementation manner, for any first query subgraph Q1 in the plurality of query subgraphs Q, the first query subgraph Q1 contains a plurality of edges and their matching orders, and the edges contained in the same part have the same matching order in different query subgraphs Q. In this case, step 1 can be executed in the following manner:
[0070] The edges contained in the first query subgraph Q1 are taken as the tree nodes in the query tree T, and the first query subgraph Q1 is merged into the query tree T according to the matching order of the edges in the first query subgraph Q1, so that the plurality of edges of the same part are sequentially merged into the main part of the query tree T, and the different part (i.e. the remaining part) of the first query subgraph Q1 relative to the other query subgraphs Q is merged into the branch part of the query tree T. The edges in the query subgraph Q are taken as the tree nodes in the query tree T, and each tree node is an edge in the query subgraph Q. The edge data in the query subgraph Q can be directly used to determine the data of the tree node, and this correspondence can reduce the complexity of constructing the tree node data.
[0071] Here and in the subsequent part, the operation performed on any first query subgraph Q1 is taken as an example for description. The same or similar operation is performed on the other query subgraphs Q1.
[0072] An edge is the smallest matching unit in the subgraph matching process. In the process of subgraph query, an edge and its two connected nodes constitute a basic unit in matching. The matching order refers to the query order of a certain edge when the query subgraph is queried in the data graph G. For example, in the first query subgraph Q1, the edge 1→2 is a matching unit in the query. The edge 2→3 and the edge 1→3 are different matching units. Each edge in the query subgraph Q1 and its matching order can be expressed as follows: Figure 2
[0073] edges[0] : {node 1, node 2, black, white, blue}
[0074] edges[1] : {node 2, node 3, white, blue, black}
[0075] edges[2] : {node 1, node 3, black, blue, yellow}
[0076] For example, edges[0] is the identification of the edge, where 0 represents the matching order of the edge, and the content in the braces is the source node, the target node, the source node color, the target node color and the edge color of the edge in turn.
[0077] Each edge in the third query subgraph Q3 and its matching order can be expressed as follows:
[0078] edges[0] : {node 1, node 4, black, white, blue}
[0079] edges[1] : {node 4, node 3, white, blue, black}
[0080] edges[2] : {node 3, node 2, blue, white, blue}
[0081] edges[3] : {node 2, node 1, white, black, black}
[0082] It can be seen that the same part between the first query subgraph Q1 and the third query subgraph Q3 is the edge edges[0] and edges[1]. The edges contained in the above same part have the corresponding same matching order in several query subgraphs Q. It can be understood that the matching order of the above same part in the first query subgraph Q1 is the same as the matching order of the same part in the third query subgraph Q3. That is, the matching orders of the edges edges[0] and edges[1] in the two query subgraphs are 0 and 1.
[0083] The query tree is a tree structure data. When constructing the tree structure data, it can be in a top-down (starting from the root node) and bottom-up (starting from the leaf node) manner. When merging the edges in the first query subgraph Ql into the query tree T according to the matching order of the first query subgraph Ql, the query tree T can be constructed in a top-down or bottom-up manner.
[0084] In an implementation, the edges can not be used as the tree nodes, but the nodes in the first query subgraph Ql can be used as the tree nodes in the query tree T, the edges in the first query subgraph Ql can be used as the edges between the tree nodes in the query tree T, or both the nodes and edges in the first query subgraph Ql can be used as the tree nodes in the query tree T.
[0085] The specific construction process of the query tree T is described below. In the implementation where the edges are used as the tree nodes in the query tree T and the query tree T is constructed according to the matching order of the edges contained in the first query subgraph Ql, the first query subgraph Ql can be merged into the query tree T by setting the mutual correspondence between the matching order of the edges contained in the same part and the construction order of the query tree T.
[0086] For example, the matching order of the edges contained in the same part can be arranged after the matching order of the other edges, in which case, when the first query subgraph Ql is merged into the query tree T, the following operation can be performed: the first query subgraph Ql is merged into the query tree T according to the matching order of the edges in the first query subgraph Ql and the order from the leaf node to the root node of the query tree T.
[0087] Alternatively, the first query subgraph Ql can be set as follows: the matching order of the edges contained in the same part is prior to the matching order of the other edges. In this case, when the first query subgraph Ql is merged into the query tree T, the following operation can be performed:
[0088] The first query subgraph Ql is merged into the query tree T according to the matching order of the edges in the first query subgraph Ql and the order from the root node to the leaf node of the query tree T.
[0089] This matching merging manner can make the edges of the same part more conveniently merged into the main part of the query tree T in sequence. The following is an example in the latter manner, combined with Figure 3 The construction process of the query tree T is described in detail.
[0090] Figure 3 A flowchart for constructing the query tree is provided for the embodiment. In the flowchart, the process of merging the multiple query subgraphs Ql-Q3 into the query tree T in sequence is listed from left to right.
[0091] When the first query subgraph Q1 is the first query subgraph to be merged into the query tree T, there is only a root node in the query tree T, and there is no child node yet. The root node can be set as a null node, and is a tree node without edges.
[0092] In this case, the following steps can be performed:
[0093] According to the matching order, the edge in the first query subgraph Q1 in the current matching order is taken as a parent node in the query tree T, and the edge in the next matching order is taken as a child node of the parent node.
[0094] In Figure 3 , the edge in the current matching order can be any one of edges[0], edges[1] and edges[2]. For example, the first edge edges[0] can be taken as a parent node in the query tree T, the next edge edges[1] can be taken as a child node of the parent node, and the edge edges[2] can be taken as a next level child node of the child node. In this way, the multiple edges in the first query subgraph Q1 are added to the query tree T in turn. When the last level leaf node is reached, the leaf node is pointed to the first query subgraph Q1, i.e. query→1, to indicate that the path from the root node to the leaf node corresponds to the first query subgraph Q1.
[0095] When the second query subgraph Q2 is not the first query subgraph to be merged into the query tree T, there are multiple tree nodes in the query tree T, and the tree nodes contain edges. In this case, the second query subgraph Q2 can be merged into the query tree T according to the following implementation.
[0096] According to the matching order, a first edge is determined from the second query subgraph Q2, and a first tree node is determined from the query tree T in the order from a parent node to a child node. Iterative merging is performed according to the following steps 1_1-1_3.
[0097] Step 1_1, it is judged whether the first edge and the edges in the child nodes of the first tree node can be merged. If yes, step 1_2 is performed; if no, step 1_3 is performed.
[0098] Step 1_2, the first edge and the first tree node are updated.
[0099] Step 1_3, the first edge and the other edges in the second query subgraph Q2 are taken as the child nodes of the first tree node in turn.
[0100] In this implementation, the root node is pre-set as an empty node, a tree node without edges. Therefore, initially, the root node is used as the first tree node, and the first edge is merged with the edges of the child nodes of the first tree node for judgment. The above matching order is the matching order of several edges in the second query subgraph Q2. Initially, the edge in the first matching order, that is, the first edge, is used as the first edge.
[0101] When determining whether a merge is possible, we can check if the edge attributes of the first edge match those of any child node of the first tree node. In other words, if the first edge is identical to any edge of any child node of the first tree node, it is considered a match; if the first edge is not identical to any edge of any child node of the first tree node, it is considered a mismatch. If they match, the result of step 1_1 is "yes". If they do not match, the result of step 1_1 is "no".
[0102] Specifically, step 1_1 involves a loop. It checks if the first edge can be merged with an edge belonging to one of the child nodes of the first tree node. If not, it checks if the first edge can be merged with any other child node of the first tree node, and so on, until all child nodes of the first tree node are checked. If none of these merges are possible, the result of step 1_1 is determined to be "no". If at least one child node of the first tree node can be merged with the first edge, the loop stops, and the result of step 1_1 is determined to be "yes".
[0103] When determining whether the first edge matches any child node (e.g., the first child node) contained in the first tree node, we can compare whether the first edge and the edges in the first child node are the same. That is, whether the node attribute information and edge attribute information corresponding to the edge are the same. If they are all the same, then the two are determined to match. In matching, the edge usually refers to the first and last nodes and the edges between the first and last nodes.
[0104] When updating the first edge and the first tree node in step 1_2, the edge of the next matching order in the second query subgraph Q2 can be updated to the first edge, and the child nodes of the first tree node that can be merged (such as the first child node) can be updated to the first tree node.
[0105] In step 1_3, the first edge is taken as the child node of the first tree node, and the next edge of the first edge is taken as the child node of that child node, until all the remaining edges in the second query subgraph Q2 are added to the query tree T.
[0106] After step 1_2 or step 1_3, return to step 1_1 to iteratively perform judgment and merging.
[0107] by Figure 3For example, the first edge is edges[0] in the graph Q2, and the first tree node in the query tree T is the root node root, which has only one child node. The edge edges[0] is matched with the edges in the child node of the root node, and it is found that the source node color, the target node color and the edge color all correspond to the same, i.e., the node attribute information and the edge attribute information correspond to the same, so it is determined that the two can be merged. Since there is only one edge in the second query graph Q2, the child node of the root node can be directed to the second query subgraph Q2, i.e., query→2 is set, which is used to represent that the path from the root node to the child node corresponds to the second query subgraph Q2.
[0108] Similarly, for the third query subgraph Q2, it contains edges[0], edges[1], edges[2] and edges[3]. The numbers in the square brackets [] represent the matching order. The first edge edges[0] is matched with the edges of the child node of the root node (i.e., the second tree node from the top of the query tree T). The result of the judgment is that the two can be merged, and then the second edge edges[1] is matched with the edges of the next level child node (i.e., the third tree node from the top of the query tree T). The result of the judgment is that the two can be merged, and then the third edge edges[2] is matched with the edges of the next level child node (i.e., the fourth tree node from the top of the query tree T, see the query tree T on the right side of Q3). The result of the judgment is that the two cannot be merged, and at this time the third edge edges[2] can be added to the query tree T as a new child node (i.e., a child node parallel to the fourth tree node), and the fourth edge edges[3] is continued to be added to the next level child node of the child node. The last level leaf node is directed to the third query subgraph Q3, i.e., query→3 is set, which is used to represent that the path from the root node to the leaf node corresponds to the third query subgraph Q3.
[0109] When creating the tree nodes of the query tree T, whether the query subgraph is the first or not, the edges in the query subgraph need to be added or merged into the query tree T as the tree nodes of the query tree T, which is essentially creating the edge data of the tree nodes.
[0110] For example, when a first edge in a query subgraph is executed as a tree node in the query tree T, the edge data of the tree node can be determined based on the edge data of the first edge. The first edge is any edge that needs to be added to the query tree.
[0111] The edge data of the tree node can include the identification of the tree node and the child nodes of the tree node, and an identification indicating whether the edge of the tree node is the last edge in a query subgraph. The identification can be indicated by a query parameter. When an edge is the last edge in a query subgraph, the query parameter points to the query subgraph. In addition, the edge data of the tree node can also include the node identification and the edge identification in the edge, and the edge attribute information and the node attribute information, etc. The edge identification can be used as the identification of the tree node.
[0112] Generally, in order to make the numbering inside the query tree T consistent, the nodes and edges in the query tree T can be renumbered, i.e. the node identification and the edge identification are re-determined.
[0113] The edge data of the tree node can be recorded by the class of the tree node. Figure 4 An example of the class of the edge data of the tree node is provided. The edge data includes the following data of the edge: integer variable (int) source node identification (source_id) and target node identification (target_id), string variable (string) source node attribute (source_property), target node attribute (target_property) and edge attribute (edge_property), integer variable edge identification (edge_id), and the child nodes of the tree node (Edge* [] childs), and the query parameter (Query* query). The edge_id is also used to identify which tree node in the query tree T the edge corresponds to.
[0114] As mentioned above, the node identification and the edge identification in the query tree T can be re-determined. In order to more accurately determine the node identification in the query tree during the creation of the query tree T, a mapping relationship table (id_mapping) can be maintained during the merging of a query subgraph into the query tree T, in which the mapping relationship is used to record the mapping relationship between the node identification in the query subgraph and the node identification in the query tree T.
[0115] When the edge data based on the first edge is executed to determine the edge data of a tree node, the following steps can be performed:
[0116] When the node identification of the first edge is not recorded in the mapping relationship, the node identification of the tree node is directly generated, and the corresponding relationship between the node identification in the query subgraph and the node identification in the query tree T is recorded;
[0117] When the node identifier of the first edge is recorded in the mapping relationship, the node identifier of the tree node corresponding to the node identifier in the mapping relationship is determined as the node identifier of the tree node. For example, the node identifier in the tree node corresponding to the node identifier in the mapping relationship can be determined as the node identifier of the tree node, thereby avoiding repeated generation of a new node identifier.
[0118] The process of merging the query graph will be described in detail below through an example and in combination with the class in the foregoing embodiment. Figure 4
[0119] An empty Edge class is created as the root node of the query tree, with the attribute “edge_id” set to 0 and the rest empty.
[0120] An integer variable max_vertex_id is defined to assist in the generation of the tree node identifier (ID) in the query tree T, and is initialized to 1.
[0121] An integer variable max_edge_id is defined to assist in the generation of the edge ID in the query tree T, and is initialized to 1, because 0 has been occupied by the root node.
[0122] The following preprocessing is performed for any query subgraph:
[0123] A temporary pointer parent pointing to the root node in the query tree T is defined, representing the current parent node (i.e., the first tree node mentioned above);
[0124] An empty temporary mapping relationship table id_mapping is created to save the mapping relationship between the node ID (key) in the query subgraph and the node ID (value) in the edge of the tree node in the query tree, both of which are integer variables int and are stored in the form of key-value pairs.
[0125] After the above preprocessing is performed, the following steps 1_4-1_10 are performed to merge the query subgraph into the query tree T.
[0126] Step 1_4, according to the matching order, each edge in the query subgraph is traversed, and the current edge is taken as q_edge (i.e., the first edge mentioned above).
[0127] Step 1_5, each child node of the pointer parent is traversed, and the current child node is referred to as edge t_edge.
[0128] Step 1_6, it is determined whether the edge q_edge and the edge t_edge can be merged.
[0129] The specific determination process can include:
[0130] If the source property of q edge is different from the source property of t edge, return no; otherwise, return yes.
[0131] If the target property of q edge is different from the target property of t edge, return no; otherwise, return yes.
[0132] If the edge property of q edge is different from the edge property of t edge, return no; otherwise, return yes.
[0133] If the source id of q edge does not exist in the keys of id mapping, return yes. If the source id of q edge exists in the keys of id mapping, and if the value of id mapping [q edge. source id] is different from the source id of t edge in the class, return no; if the same, return yes.
[0134] If the target id of q edge does not exist in the keys of id mapping, return yes. If the target id of q edge exists in the keys of id mapping, and if the value of id mapping [q edge. target id] is different from the target id of t edge in the class, return no; if the same, return yes.
[0135] In the judgment, if the result of any one of the above multiple judgment options is no, it means that it cannot be merged. If all the judgment options are yes, it means that it can be merged.
[0136] Step 1_7, if it can be merged, save the mapping relationship of node ID in the mapping relationship table id mapping, change the pointer parent to point to this edge t edge, and return to step 1_4 to continue the next edge q edge.
[0137] In saving the mapping relationship of node ID, it can be saved in the form of the following key-value pair:
[0138] id_mapping [q edge. source id] = t edge. source id;
[0139] id_mapping [q edge. target id] = t edge. target id.
[0140] Step 1_8, if not, go back to step 1_5, continue to take the next child node of the pointer parent as the edge t_edge.
[0141] Step 1_9, if the pointer parent has no child node that can be merged with the edge q_edge, or the pointer parent has no child node at all, then perform the following steps 1_9_1~1_9_6.
[0142] Step 1_9_1, directly add the current edge q_edge to the pointer parent->childs[], as the new child node of the parent node.
[0143] Step 1_9_2, set the edge_id in the class of the new tree node to the value of max_edge_id, and add 1 to the value of max_edge_id.
[0144] Step 1_9_3, for the new tree node, when putting the edge from the query subgraph into the query tree T, the node ID of the edge needs to be changed to the node ID corresponding to the new tree node in the query tree T, which can be modified in the following way:
[0145] If the source_id of the edge q_edge exists in the key of id_mapping, modify the source_id in the class of the new tree node to the value corresponding to id_mapping[q_edge.source_id].
[0146] If the source_id of the edge q_edge does not exist in the key of id_mapping, set the source_id in the class of the new tree node to the value of max_vertex_id, and save the corresponding relationship in id_mapping, and add 1 to the value of max_vertex_id.
[0147] If the target_id of the edge q_edge exists in the key of id_mapping, modify the target_id in the class of the new tree node to the value corresponding to id_mapping[q_edge.target_id].
[0148] If the target_id of the edge q_edge does not exist in the key of id_mapping, set the target_id in the class of the new tree node to the value of max_vertex_id, and save the corresponding relationship in id_mapping, and add 1 to the value of max_vertex_id.
[0149] Step 1_9_4, the attribute information in the class of the edge q edge is taken as the corresponding attribute information in the class of the newly added tree node, including [source property], [target property] and [edge property] in the class, etc.
[0150] Step 1_9_5, the pointer parent is changed to point to the newly added tree node in the current query tree.
[0151] Step 1_9_6, return to step 1_4, and take the edge of the next matching order in the query subgraph as q edge.
[0152] Step 1_10, if the edge q edge is the last edge of the query subgraph, set the query in the class of the corresponding tree node to point to the query subgraph.
[0153] The above describes the process of merging the query subgraph into the query tree T through a specific example. After merging several query subgraphs Q into the query tree T, the query tree T obtained can refer to the rightmost graph in Figure 3 , wherein the edge ID of each tree node is marked beside the tree node, i.e., from edge[0] to edge[5]. Through Figure 3 It can be seen from the embodiment that in the process of merging several query subgraphs Q into the query tree, the edges of the same part can be set in advance to have the same matching order in front in several query subgraphs Q, so that the same part can be more conveniently merged into the main part of the query tree T.
[0154] After merging several query subgraphs Q into the query tree T, the process of subgraph matching also changes accordingly, and the next edge is no longer taken from edges[] in the several query subgraphs Q, but is taken from the current tree node of the query tree T.
[0155] The specific implementation of step 2 will be described below. In step 2_1 described above, when the main part of the query tree T is based on the data graph G stored in the graph database, the subgraph query can be performed according to the following steps:
[0156] When the edge of the first tree node is the to-be-queried edge of the main part, the subgraph matched based on the edge of the parent node of the first tree node in the data graph G is used to perform the subgraph query on the to-be-queried edge in the data graph G. For example, the edge of the first tree node is matched within the subgraph range matched based on the edge of the parent node of the first tree node in the data graph G, so as to gradually narrow the query range.
[0157] Furthermore, in step 2_2, when performing subgraph queries based on the branches of query tree T according to the first query result, subgraph queries can be performed on the branches of query tree T within the range included in the first query result. When the edge of the first tree node is the edge to be queried in the branch, the subgraph obtained by querying the data graph based on the edge of the parent node of the first tree node is used to perform subgraph queries on the edge to be queried in the data graph G.
[0158] When the first tree node is the last tree node in the corresponding path of the first query subgraph Q1 in the query tree T, the query result corresponding to the first query subgraph Q1 is determined based on the subgraph query result of the query subgraph in the data graph G. For example, the subgraph query result of the last tree node in the data graph G can be directly used as the query result corresponding to the first query subgraph Q1.
[0159] Here, the first tree node is any tree node in the query tree T. When the root node does not contain any edges, the first tree node can be one or more of all tree nodes except the root node.
[0160] by Figure 3 Let's take the query tree T obtained from the rightmost side as an example. For Figure 3 The rightmost query tree T is used to perform subgraph queries on the edges of tree nodes in the data graph G, following the order from the trunk to the branches. For example, performing a subgraph query on tree node edge[1] in the data graph G yields matching result 1. Since the query in edge[1] points to the second query subgraph Q2, the matching result 1 is the query result corresponding to the second query subgraph Q2 in the data graph G.
[0161] Next, based on the matching result 1, a subgraph query is performed on the tree node edge[2] in the data graph G to obtain matching result 2. Based on matching result 2, a subgraph query is performed on the tree node edge[3] in the data graph G to obtain matching result 3. Since the query in edge[3] points to the first query subgraph Q1, the matching result 3 is the query result corresponding to the first query subgraph Q1 in the data graph G.
[0162] Next, based on matching result 2, a subgraph query is performed on tree node edge[4] in data graph G to obtain matching result 4. Based on matching result 4, a subgraph query is performed on tree node edge[5] in data graph G to obtain matching result 5. Since the query in edge[5] points to the third query subgraph Q3, the matching result 5 is the query result corresponding to the third query subgraph Q3 in data graph G.
[0163] As can be seen from the above example, the subgraph query results of the tree nodes edge[1] and edge[2] are reused in the subgraph query process, the embodiment avoids repeated matching of the edge in the data graph G, reduces resource waste, saves the matching time of the user subgraph, and thus can more efficiently obtain the query result. In the transaction risk control field, efficient subgraph query can improve the efficiency of risk prediction.
[0164] In this specification, the "first" in the words such as the first query subgraph, the first tree node, and the first edge, and the corresponding "second" (if any) in the text, are only for the convenience of distinguishing and describing, and do not have any limiting meaning.
[0165] In this specification, the computing device and the risk control platform can be implemented by any device, device, platform, device cluster, etc. with computing and processing capability.
[0166] The above describes specific embodiments of the present specification, and other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that in the embodiments, and the desired results can still be achieved. In addition, the processes depicted in the accompanying drawings do not necessarily have to be implemented in the specific order or continuous order shown to achieve the desired results. In some embodiments, multi-task processing and parallel processing are possible, or can be advantageous.
[0167] Figure 5 A schematic block diagram of a subgraph query device according to an embodiment is shown. The device embodiment corresponds to the method embodiment shown. Figure 2 The device 500 comprises:
[0168] The subgraph obtaining module 510 is configured to obtain a plurality of query subgraphs to be queried; the plurality of query subgraphs comprise nodes and edges, and attribute information of the nodes and edges;
[0169] The preliminary query module 520 is configured to perform preliminary query in a data graph stored in a graph database based on the same part between the plurality of query subgraphs, to obtain a first query result of the same part; the same part is contained in the plurality of query subgraphs, and is a subgraph corresponding to the same edge possessed by the plurality of query subgraphs;
[0170] The remaining query module 530 is configured to perform subgraph query in the data graph based on the remaining part of each query subgraph on the basis of the first query result, to obtain the query result of each query subgraph.
[0171] In an implementation, the apparatus 500 further comprises a query tree merging module 540 configured to obtain the same part between the query subgraphs based on merging the query subgraphs into a query tree, a trunk part of the query tree being the same part between the query subgraphs.
[0172] In an implementation, the remaining part of any query subgraph is a branch part of the query tree.
[0173] In an implementation, any first query subgraph contains edges and their matching orders, the same part contains edges having corresponding same matching orders in different query subgraphs; the query tree merging module 540 is specifically configured to merge the first query subgraph into the query tree as tree nodes in the query tree according to the matching orders, so that the edges contained in the same part are merged into the trunk part of the query tree in turn.
[0174] In an implementation, in the first query subgraph, the edges contained in the same part have matching orders earlier than matching orders of other edges. The query tree merging module 540, when merging the first query subgraph into the query tree, comprises:
[0175] merging the first query subgraph into the query tree according to the matching orders of the edges in the first query subgraph and an order from a root node to a leaf node in the query tree.
[0176] In an implementation, the query tree merging module 540, when merging the first query subgraph into the query tree, comprises:
[0177] when the first query subgraph is the first one, merging an edge of a current matching order in the first query subgraph as a parent node in the query tree and an edge of a next matching order as a child node of the parent node according to the matching orders.
[0178] In an implementation, the query tree merging module 540, when merging the first query subgraph into the query tree, comprises:
[0179] when the first query subgraph is not the first one, determining a first edge from the first query subgraph according to the matching orders and determining a first tree node from the query tree according to an order from a parent node to a child node, and iteratively merging according to:
[0180] judging whether the first edge and an edge in a child node of the first tree node can be merged;
[0181] if yes, updating the first edge and the first tree node;
[0182] If not, the first edge and other edges in the first query subgraph are sequentially taken as child nodes of each level of the first tree node.
[0183] In an embodiment, when judging whether the first edge can be merged with a child node of the first tree node, the query tree merging module 540 includes:
[0184] When the first edge matches an edge of any child node contained in the first tree node, it is determined that the first edge can be merged with the child node.
[0185] In an embodiment, a tree node in the query tree has corresponding edge data, which includes an identifier of the tree node and child nodes of the tree node, and an identifier indicating whether an edge of the tree node is the last edge in a certain query subgraph. When performing the operation of taking a first edge in a certain query subgraph as a tree node in the query tree, the query tree merging module 540 includes determining edge data of the tree node based on edge data of the first edge.
[0186] In an embodiment, the edge data of the tree node further includes node identifiers corresponding to the edge and edge identifiers; the edge identifiers are used as the identifier of the tree node. When determining the edge data of the tree node based on the edge data of the first edge, the query tree merging module 540 includes:
[0187] When the node identifier of the first edge is recorded in the mapping relationship library, the node identifier of the tree node is determined based on the node identifier in the tree node corresponding to the node identifier in the mapping relationship library; the mapping relationship library is used to record the mapping relationship between the node identifier in a query subgraph and the node identifier in a query tree.
[0188] In an embodiment, the preliminary query module 520 is specifically configured to perform subgraph queries based on the data graph stored in the graph database by the main part of the query tree; and the remaining query module 530 is specifically configured to perform subgraph queries based on the branch part of the query tree respectively on the basis of the first query result.
[0189] In an embodiment, when performing the subgraph query based on the data graph stored in the graph database by the main part of the query tree, the preliminary query module 520 includes: when the edge of the first tree node is a to-be-queried edge, performing the subgraph query on the to-be-queried edge in the data graph based on the subgraph obtained by querying the data graph based on the edge of the parent node of the first tree node.
[0190] In an implementation, the remaining query module 530, when performing subgraph query in the query graph based on the branch part of the query tree, comprises: when the first tree node is the last tree node in the corresponding path of the first query subgraph in the query tree, determining the query result corresponding to the first query subgraph based on the subgraph query result of the first tree node in the data graph.
[0191] The device embodiments correspond to the method embodiments, and specific descriptions can be referred to the descriptions of the method embodiments, which will not be repeated here. The device embodiments are based on the corresponding method embodiments and have the same technical effects as the corresponding method embodiments. Specific descriptions can be referred to the corresponding method embodiments.
[0192] The embodiments of the present specification also provide a computer readable storage medium, which stores a computer program, and when the computer program is executed in a computer, the computer program causes the computer to execute the method according to any one of the embodiments. Figures 1 to 4 The method according to any one of the embodiments.
[0193] The embodiments of the present specification also provide a computing device, which comprises a memory and a processor, the memory stores executable code, and when the processor executes the executable code, the method according to any one of the embodiments is implemented. Figures 1 to 4 The method according to any one of the embodiments.
[0194] Each of the embodiments in the present specification is described in a progressive manner, and the same or similar parts of each embodiment can be referred to each other. Each embodiment mainly describes the differences from other embodiments. In particular, the storage medium and the computing device embodiments are described more simply because they are basically similar to the method embodiments. The relevant parts can be referred to the part of the description of the method embodiments.
[0195] Those skilled in the art should realize that, in one or more examples described above, the functions described in the embodiments of the present application can be implemented by hardware, software, firmware or any combination thereof. When implemented by software, the functions can be stored in a computer readable medium or transmitted as one or more instructions or codes on a computer readable medium.
[0196] The above specific embodiments further explain the purposes, technical solutions and advantages of the embodiments of the present application. It should be understood that the above description is only a specific embodiment of the present application, and is not used to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made on the basis of the technical solutions of the present application should be included in the protection scope of the present application.
Claims
1. A method for subgraph query, comprising: obtaining a plurality of query subgraphs to be queried; the plurality of query subgraphs comprising nodes and edges, and attribute information of the nodes and edges; merging the plurality of query subgraphs into a query tree; wherein a trunk part of the query tree is a same part between the plurality of query subgraphs, and a remaining part of any one query subgraph is a branch part of the query tree; edges in the plurality of query subgraphs are taken as tree nodes in the query tree, and a plurality of tree nodes form a plurality of paths from a root node to leaf nodes, the plurality of paths respectively corresponding to the plurality of query subgraphs; performing subgraph query based on the trunk part in a data graph stored in a graph database to obtain a first query result of the same part; the same part being contained in the plurality of query subgraphs and being a subgraph corresponding to same edges possessed by the plurality of query subgraphs; based on the first query result, performing subgraph query based on the branch part respectively to obtain a query result of each query subgraph. 2.The method according to claim 1, wherein any first query subgraph contains a plurality of edges and a matching order thereof, and edges contained in the same part have a corresponding same matching order in different query subgraphs; and the step of merging the plurality of query subgraphs into a query tree comprises: taking edges in the first query subgraph as tree nodes in the query tree, and merging the first query subgraph into the query tree according to the matching order, so that the plurality of edges contained in the same part are sequentially merged into the trunk part of the query tree. 3.The method according to claim 2, wherein in the first query subgraph, the matching order of the edges contained in the same part is prior to the matching order of other edges; and the step of merging the first query subgraph into the query tree comprises: merging the first query subgraph into the query tree according to the matching order of the plurality of edges in the first query subgraph and an order from the root node to the leaf node in the query tree. 4.The method according to claim 3, wherein when the first query subgraph is the first one, the step of merging the first query subgraph into the query tree comprises: according to the matching order, taking an edge of a current matching order in the first query subgraph as a parent node in the query tree, and taking an edge of a next matching order as a child node of the parent node. 5.The method according to claim 4, wherein when the first query subgraph is not the first one, the step of merging the first query subgraph into the query tree comprises: determining a first edge from the first query subgraph according to the matching order, determining a first tree node from the query tree according to an order from a parent node to a child node, and iteratively merging in the following manner: judging whether the first edge and an edge in the child nodes of the first tree node can be merged; if yes, updating the first edge and the first tree node; if no, taking the first edge and other edges in the first query subgraph as respective child nodes of the first tree node in turn.
6. The method of claim 5, wherein the determining whether the first edge can be merged with a child node of the first tree node comprises: determining that the first edge can be merged with a child node of the first tree node when the first edge matches an edge of the child node.
7. The method of claim 2, wherein the tree nodes in the query tree have corresponding edge data, and the edge data comprises an identification of the tree node and a child node of the tree node, and an identification indicating whether the edge of the tree node is the last edge in a query subgraph; When performing the step of taking a first edge in a certain query subgraph as a tree node in the query tree, comprising: determining the edge data of the tree node based on the edge data of the first edge.
8. The method of claim 7, the edge data of the tree node further comprising: the node identification and the edge identification corresponding to the edge; the edge identification is used as the identification of the tree node; the determining the edge data of the tree node based on the edge data of the first edge comprises: when the node identification of the first edge is recorded in the mapping relationship library, determining the node identification of the tree node based on the node identification in the tree node corresponding to the node identification in the mapping relationship library; the mapping relationship library is used to record the mapping relationship between the node identification in the query subgraph and the node identification in the query tree.
9. The method of claim 1, wherein the performing subgraph query based on the data graph in which the main part of the query tree is stored in the graph database comprises: when the edge of the first tree node is a to-be-queried edge, performing subgraph query on the to-be-queried edge in the data graph based on the subgraph obtained by querying the edge of the parent node of the first tree node in the data graph.
10. The method of claim 9, wherein the performing subgraph query based on the branch part of the query tree comprises: when the first tree node is the last tree node in the corresponding path of the first query subgraph in the query tree, determining the query result corresponding to the first query subgraph based on the subgraph query result of the first tree node in the data graph.
11. A subgraph query device, comprising: a subgraph obtaining module configured to obtain a plurality of query subgraphs to be queried; the plurality of query subgraphs comprising nodes and edges, and attribute information of the nodes and edges; a query tree merging module configured to merge the plurality of query subgraphs into a query tree; wherein the main part of the query tree is a same part between the plurality of query subgraphs, and a remaining part of any one query subgraph is a branch part of the query tree; edges in the plurality of query subgraphs are used as tree nodes in the query tree, and a plurality of tree nodes form a plurality of paths from a root node to a leaf node, and the plurality of paths correspond to the plurality of query subgraphs, respectively; a preliminary query module configured to perform subgraph query in a data graph in which the main part is stored in a graph database, to obtain a first query result of the same part; the same part is included in the plurality of query subgraphs, and is a subgraph corresponding to the same edges possessed by the plurality of query subgraphs; a remaining query module configured to perform subgraph query based on the branch part on the basis of the first query result, to obtain a query result of each query subgraph.
12. A computer readable storage medium having stored thereon a computer program, which, when executed in a computer, causes the computer to perform the method of any one of claims 1-10.
13. A computing device comprising a memory and a processor, the memory having stored therein executable code, which, when executed by the processor, carries out the method of any one of claims 1-10.
Citation Information
Patent Citations
Data query method and device
CN112749189A
Method, device and equipment for data search
CN115408427A