Graph database query method and apparatus, electronic device, and storage medium

By parsing the query statement and reverse-searching the identification information of neighboring entity points, the problems of large data volume and low efficiency in network transmission during distributed graph database queries are solved, and efficient data acquisition is achieved.

CN116186335BActive Publication Date: 2025-12-23TSINGHUA UNIVERSITY +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310114923.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-07
Publication Date
2025-12-23
Estimated Expiration
2043-02-07

AI Technical Summary

Technical Problem

In existing technologies, distributed graph database queries involve large amounts of data transmitted over the network and have low query efficiency, failing to fully utilize the characteristics of data storage.

Method used

The query request is obtained by parsing the query statement. Based on the query association depth and the direction of the relationship edge, the identification information of the associated neighbor entity points is found in reverse. When the query association depth is greater than a preset threshold, the query request is broadcast to all storage nodes. The target data is obtained by looping the query logic.

Benefits of technology

It reduces the amount of data transmitted over the network and improves query efficiency, especially significantly shortening query time when the association depth is large.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116186335B_ABST
    Figure CN116186335B_ABST
Patent Text Reader

Abstract

The application provides a graph database query method and device, electronic equipment and a storage medium, wherein the method comprises: parsing a query statement obtained to obtain a query request, wherein the query request is composed of a query correlation depth, starting point identification information and a relationship edge direction; in the case that the query correlation depth is greater than a preset threshold, the query request is sent to all storage nodes, the first identification information of the first neighbor entity point associated is reversely found by using the starting point identification information according to the relationship edge direction; the second identification information of the second neighbor entity point associated in the next degree is found by using the first identification information according to the relationship edge direction, and the second identification information is returned; the loop query logic is executed according to the comparison of the query request and the correlation depth corresponding to the second neighbor entity point and the query correlation depth, and target data is obtained. Through the application, the problems of large network transmission data and low query efficiency in the related art are solved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer, and in particular to a graph database query method and device, electronic equipment and storage medium. BACKGROUND

[0002] In today's era, with the rapid development of the Internet, social networks and e-commerce, a large amount of graph data has been accumulated. Graph databases have undergone continuous technological innovation due to their natural inclusiveness of highly correlated data. However, how to efficiently query the graph database has brought challenges to distributed graph databases.

[0003] Currently, distributed graph databases usually use breadth-first search or depth-first search methods to query data. The characteristics of these systems are that when querying multiple degrees of neighbors, the starting point identifier information of the starting entity point is used to determine the storage node where the data is located; the storage node obtains the identifier information of the associated neighbor entity point according to the starting point identifier information and then transmits the data to the query node; the query node iteratively constructs a query request according to the returned data until the query ends. However, this query method does not fully utilize the characteristics of data storage in distributed graph databases, and each degree of associated neighbor of the entity point needs to be transmitted to the query node through the network, so that the theoretical best query performance is not achieved.

[0004] Therefore, the existing technology has the problems of large amount of network transmission data and low query efficiency. SUMMARY

[0005] The present application provides a graph database query method, device, electronic equipment and storage medium to at least solve the problem of large amount of network transmission data and low query efficiency in related technologies.

[0006] According to an aspect of an embodiment of the present application, a graph database query method is provided, which comprises:

[0007] The obtained query statement is parsed to obtain a query request, wherein the query request is composed of a query association depth, a starting point identifier information and a relationship edge direction;

[0008] In the case where the query association depth is greater than a preset threshold, the query request is sent to all storage nodes, and the first identifier information of the first neighbor entity point associated with the starting point identifier information is found in reverse according to the relationship edge direction;

[0009] According to the relationship edge direction, the second identifier information of the second neighbor entity point associated with the first identifier information is found, and the second identifier information is returned;

[0010] According to the comparison between the query request and the associated depth of the second neighbor entity point and the query associated depth, a loop query logic is executed to obtain target data.

[0011] According to another aspect of the embodiments of the present application, a graph database query device is also provided, which comprises:

[0012] The parsing module is configured to parse the obtained query statement to obtain a query request, wherein the query request comprises a query associated depth, a start point identification information and a relationship edge direction;

[0013] The first sending module is configured to send the query request to all storage nodes if the query associated depth is greater than a preset threshold, and reversely search for first identification information of a first neighbor entity point associated with the start point identification information according to the relationship edge direction;

[0014] The searching module is configured to search for second identification information of a second neighbor entity point associated with the first identification information according to the relationship edge direction, and return the second identification information;

[0015] The data returning module is configured to execute a loop query logic according to the comparison between the query request and the associated depth of the second neighbor entity point and the query associated depth, to obtain target data.

[0016] Optionally, the data returning module comprises:

[0017] The first obtaining unit is configured to obtain the target data according to the second identification information if the associated depth is equal to the query associated depth;

[0018] The second obtaining unit is configured to update the start point identification information in the query request according to the second identification information if the associated depth is less than the query associated depth, and send the updated query request to the storage nodes until the associated depth of the neighbor entity point searched is equal to the query associated depth, and obtain the target data according to the identification information of the neighbor entity point.

[0019] Optionally, the second obtaining unit comprises:

[0020] The obtaining submodule is configured to obtain a corresponding storage node according to the second identification information if the associated depth and the query associated depth differ by the preset threshold, and take the storage node as a target storage node;

[0021] The first obtaining sub-module is configured to update the start point identification information in the query request according to the second identification information, and send the updated query request to the target storage node to obtain target identification information of a target neighbor entity point.

[0022] The second obtaining sub-module is configured to obtain the target data according to the target identification information.

[0023] Optionally, the apparatus further comprises:

[0024] The obtaining module is configured to, in a case where the query correlation depth is less than or equal to the preset threshold, obtain a storage node corresponding to the start point according to the start point identification information, and take the storage node as a target storage node.

[0025] The second sending module is configured to send the query request to the target storage node to obtain the target data.

[0026] Optionally, the second sending module comprises:

[0027] The first obtaining unit is configured to, in a case where the query correlation depth is equal to the preset threshold, send the query request to the target storage node, obtain identification information of a neighbor entity point according to the start point identification information and the relationship edge direction, and obtain the target data according to the identification information.

[0028] The second obtaining unit is configured to, in a case where the query correlation depth is less than the preset threshold, send the query request to the target storage node, and obtain the target data according to the start point identification information.

[0029] Optionally, the relationship edge direction comprises a directed edge and an undirected edge, and the first sending module comprises:

[0030] The first finding unit is configured to, in a case where the relationship edge direction is a directed edge, find the first neighbor entity point having a relationship edge direction opposite to the relationship edge direction between the start point and the first neighbor entity point by using the start point identification information, and obtain the first identification information.

[0031] The second finding unit is configured to, in a case where the relationship edge direction is an undirected edge, find all the first neighbor entity points having the relationship edge between the start point and the first neighbor entity points by using the start point identification information, and obtain the first identification information.

[0032] Optionally, the finding module comprises:

[0033] a third searching unit, configured to, when the relationship edge direction is a directed edge, search, by using the first identification information, the second neighbor entity point having the same relationship edge direction as the relationship edge direction between the first neighbor entity point and the second neighbor entity point, to obtain the second identification information;

[0034] a fourth searching unit, configured to, when the relationship edge direction is an undirected edge, search, by using the first identification information, all the second neighbor entity points having the relationship edge with the first neighbor entity point, to obtain the second identification information.

[0035] According to still another aspect of the embodiments of the present application, an electronic device is provided, which comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory complete communication with each other through the communication bus; the memory is configured to store a computer program; and the processor is configured to execute the method steps in any of the above embodiments by running the computer program stored in the memory.

[0036] According to still another aspect of the embodiments of the present application, a computer readable storage medium is provided, which stores a computer program, wherein the computer program is configured to execute the method steps in any of the above embodiments when running.

[0037] In the embodiments of the present application, the obtained query statement is parsed to obtain a query request, wherein the query request comprises a query association depth, a start point identification information and a relationship edge direction; when the query association depth is greater than a preset threshold, the query request is sent to all storage nodes, the first identification information of the first neighbor entity point associated with the start point is reversely searched by using the start point identification information according to the relationship edge direction; the second identification information of the second neighbor entity point associated with the first neighbor entity point is searched by using the first identification information according to the relationship edge direction, and the second identification information is returned; and the loop query logic is executed according to the comparison between the query request and the association depth corresponding to the second neighbor entity point and the query association depth, to obtain target data. Through the above method, the associated neighbor entity point with an association depth of two degrees relative to the start point can be obtained by one data transmission, the network transmission data amount is effectively reduced, and the query time is reduced and the query efficiency is improved when the association depth is large. The problems of large network transmission data amount and low query efficiency in the related art are solved. BRIEF DESCRIPTION OF DRAWINGS

[0038] The accompanying drawings, which are incorporated herein and form part of the specification, illustrate embodiments consistent with the present application and, together with the description, further serve to explain the principles of the application.

[0039] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or prior art description. Obviously, for those of ordinary skill in the art, other drawings can also be obtained based on these drawings without any creative effort.

[0040] Figure 1 is a flow diagram of an optional graph database query method according to an embodiment of the present application;

[0041] Figure 2 is a query method diagram of an optional association depth exceeding 1 according to an embodiment of the present application;

[0042] Figure 3 is a flow diagram of an optional distributed graph database multi-degree neighbor query method according to an embodiment of the present application;

[0043] Figure 4 is a structure block diagram of an optional distributed graph database multi-degree neighbor query device according to an embodiment of the present application;

[0044] Figure 5 is a structure block diagram of an optional graph database query device according to an embodiment of the present application;

[0045] Figure 6 is a structure block diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0046] In order to make the personnel in the technical field better understand the present application, the following will combine the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without any creative effort should belong to the scope of protection of the present application.

[0047] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-described drawings are used to distinguish similar objects, and do not necessarily have to describe a specific order or sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device including a series of steps or units does not have to be limited to only those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to these processes, methods, products or devices.

[0048] According to an aspect of an embodiment of the present application, a graph database query method is provided, as shown in the figure, the flow of the method can include the following steps: Figure 1

[0049] Step S101, the obtained query statement is parsed to obtain a query request, wherein the query request is composed of a query association depth, a starting point identification information and a relationship edge direction.

[0050] Optionally, the query statement is parsed to obtain the query association depth, the starting point identification information and the relationship edge direction, and the query association depth, the starting point identification information and the relationship edge direction together constitute the query request.

[0051] The query statement is written by a graph database query language. The entity point is a super node associated with a large number of relationship edges. The starting point identification information is the unique identification information of the starting entity point (starting point) of the query request. The specific identification information includes at least one of letters, numbers or combinations of letters and numbers, for example: key1, key2.

[0052] The relationship edge represents the association information between entity points. The type of the relationship edge includes a directed edge and an undirected edge. In the directed edge, the edge from one entity point to other entity points is an outgoing edge, and the edge from other entity points to the entity point is an incoming edge. The directed edge is always pointed from the starting point to the ending point. The present application determines whether the relationship edge is a directed edge or an undirected edge according to the relationship edge direction in the query request. If the relationship edge is a directed edge, only the one-way edge data of all the entity points involved in the query is queried in the query process. If the relationship edge is an undirected edge, the relationship edge type is ignored in the query process, and all the relationship edge data of the entity points is queried. Illustratively, the identification information of the starting entity point is 0, the incoming edge associated with the entity point is 01, and the outgoing edge associated with the entity point is 02. The query associated undirected edge output is 01 and 02.

[0053] ​The association depth is the distance length between the entity point to be queried and the starting point, for example, the 5-degree neighbor node of the starting point entity point identification information 0 is queried.

[0054] In step S102, if the association depth is greater than the preset threshold, the query request is sent to all storage nodes, and the first identification information of the first neighbor entity point associated with the starting point is found in reverse according to the relationship edge direction and the starting point identification information.

[0055] Optionally, the relationship edge data in the distributed graph database is stored in the same storage node as the associated entity point data, and the storage node of the entity point and its associated relationship edge data can be determined according to the partition rule calculation through the unique identification information of the entity point. Different query requests have different distribution strategies.

[0056] If the association depth exceeds the preset threshold, for example, 1 degree, the broadcast strategy is used, and the query request is broadcast to all storage nodes. After the query request is broadcast to all storage nodes, each storage node acquires the first identification information of the neighbor entity point (i.e. the first neighbor entity point) associated with the starting point according to the starting point identification information in the query request and the relationship edge data stored in the current storage node, and according to the relationship edge direction.

[0057] In step S103, the second identification information of the second neighbor entity point associated with the first identification information is found according to the relationship edge direction, and the second identification information is returned.

[0058] Optionally, since the relationship edge data is stored in the same storage node as the associated entity point data, the second identification information of the second neighbor entity point associated with the starting point can be acquired according to the relationship edge direction and the first identification information of the first neighbor entity point. It should be noted that the second neighbor entity point is the neighbor entity point with an association depth of 1 for the first neighbor entity point, and is also the neighbor entity point with an association depth of 2 for the above-mentioned starting point.

[0059] In step S104, the target data is obtained by executing the loop query logic according to the comparison between the query request and the association depth of the second neighbor entity point and the query association depth.

[0060] Optionally, the association depth of the second neighbor entity point relative to the starting point is 2, if the query association depth in the query request is greater than 2, a new query request is iteratively constructed and the above process is repeated, and further neighbor entity points relative to the above-mentioned starting point are searched from the second neighbor entity point, until the association depth is satisfied. If the association depth requirement is satisfied and the relationship edge direction is met, the target data is acquired according to the identification information of the neighbor entity node satisfying the association depth and returned to the user.

[0061] In the embodiment of the present application, the query request is obtained by analyzing the obtained query statement, wherein the query request is composed of a query correlation depth, a starting point identification information and a relationship edge direction; in the case that the query correlation depth is greater than a preset threshold, the query request is sent to all storage nodes, and according to the relationship edge direction, the first identification information of the first neighbor entity point associated is reversely found by using the starting point identification information; according to the relationship edge direction, the second identification information of the second neighbor entity point associated is found by using the first identification information, and the second identification information is returned; according to the comparison between the query request and the correlation depth corresponding to the second neighbor entity point and the query correlation depth, the loop query logic is executed to obtain the target data. Through the above method, the associated neighbor entity point with a correlation depth of two degrees relative to the starting point can be obtained by one data transmission, which effectively reduces the network transmission data amount and reduces the query time and improves the query efficiency when the correlation depth is large. The problems of large network transmission data amount and low query efficiency in the related art are solved.

[0062] As an optional embodiment, according to the comparison between the query request and the correlation depth corresponding to the second neighbor entity point and the query correlation depth, the loop query logic is executed to obtain the target data, comprising:

[0063] In the case that the correlation depth is equal to the query correlation depth, the target data is obtained according to the second identification information;

[0064] In the case that the correlation depth is less than the query correlation depth, the starting point identification information in the query request is updated according to the second identification information, and the updated query request is sent to the storage node until the correlation depth of the neighbor entity point queried is equal to the query correlation depth, and the target data is obtained according to the identification information of the neighbor entity point.

[0065] Optionally, since the associated neighbor entity point with a correlation depth of two degrees relative to the starting point can be obtained by one data transmission, the correlation depth corresponding to the second neighbor entity point is even, for example: 2, 4, 6, etc. If the query correlation depth and the correlation depth corresponding to the second neighbor entity point are both 2, then the second neighbor entity point is the entity point that the user wants to query at this time, and the attribute data val1 (i.e. the target data) corresponding to the second neighbor entity point is queried according to the second identification information corresponding to the second neighbor entity point, and is returned to the query node.

[0066] In the case that the association depth is less than the query association depth, for example, the association depth is 2 and the query association depth is 5, the starting point identification information in the query request needs to be updated according to the second identification information, and the updated query request is sent to all storage nodes, and the query process of S102-S104 is repeated until the association depth of the queried neighbor entity point is equal to the query association depth and meets the relationship edge direction, then the corresponding attribute data val1 (i.e. target data) is queried according to the identification information of the neighbor entity point at this time, and is returned to the query node.

[0067] In the embodiments of the present application, different query rules are executed according to the comparison of the association depth and the query association depth, and in the case that the association depth of the neighbor entity point obtained by one data transmission query is two degrees, the target data is ensured to be obtained.

[0068] As an optional embodiment, in the case that the association depth is less than the query association depth, the starting point identification information in the query request is updated according to the second identification information, the updated query request is sent to the storage node, until the association depth of the queried neighbor entity point is equal to the query association depth, and the target data is obtained according to the identification information of the neighbor entity point, comprising:

[0069] If the association depth and the query association depth differ by a preset threshold, the corresponding storage node is obtained according to the second identification information, and the storage node is taken as a target storage node;

[0070] The starting point identification information in the query request is updated according to the second identification information, and the updated query request is sent to the target storage node, and the target identification information of the target neighbor entity point is obtained;

[0071] The target data is obtained according to the target identification information.

[0072] Optionally, the present application discloses a query rule: in the case that the association depth is odd and the query is at the last degree of association depth, 1 degree needs to be queried separately. If the association depth is 3, the neighbor entity point of the starting point with 2 degrees of association depth is obtained by one transmission, and at this time, the neighbor entity point of the next degree (i.e. 3 degrees) needs to be searched, and then 2 degrees of association depth cannot be searched at one time.

[0073] The relationship edge data in the distributed graph database is stored in the same storage node as the entity point data associated therewith. If the associated depth corresponding to the second neighbor entity point differs from the query associated depth by 1 degree (i.e., the preset threshold), the corresponding storage node is acquired according to the second identification information, and the storage node is taken as the target storage node. Based on the above query rule, the start point identification information in the query request is updated according to the second identification information, and the updated query request is sent to the target storage node. The target storage node is queried according to the query request to obtain a next-degree neighbor entity point (i.e., a target neighbor entity point) in the direction of the relationship edge, and target identification information of the target neighbor entity point is obtained. Finally, the corresponding attribute data val1 (i.e., target data) is queried according to the target identification information, and is returned to the query node.

[0074] In the embodiments of the present application, by setting the query rule that the associated depth is an odd number and the last-degree associated depth, in the case that the associated neighbor entity point with an associated depth of two degrees is obtained through one data transmission query, the target data is ensured to be obtained.

[0075] As an optional embodiment, the method further comprises:

[0076] In the case that the query associated depth is less than or equal to the preset threshold, the storage node corresponding to the start point is acquired according to the start point identification information, and the storage node is taken as the target storage node.

[0077] The query request is sent to the target storage node, and the target data is obtained.

[0078] Optionally, the relationship edge data in the distributed graph database is stored in the same storage node as the entity point data associated therewith. The storage node where the entity point and the relationship edge data associated therewith are located can be determined according to the partition rule through the unique identification information of the entity point. Different query requests have different distribution strategies.

[0079] If the associated depth is 0 degree or 1 degree (i.e., in the case that the query associated depth is less than or equal to the preset threshold), the storage node (i.e., the target storage node) where the data of the entity to be queried is located is acquired through the unique identification information (i.e., the start point identification information) of the entity to be queried. The query request is sent to the target storage node. If the associated depth is 0 degree, the corresponding attribute data val1 (i.e., the target data) is queried in the target storage node according to the start point identification information, and is returned to the query node. If the associated depth is 1 degree, the neighbor identification information of the neighbor entity node with an associated depth of 1 degree from the start point is obtained in the target storage node according to the start point identification information and the direction of the relationship edge, and the neighbor identification information is returned to the query node. The attribute data val1 (i.e., the target data) is acquired in the corresponding storage node according to the neighbor identification information.

[0080] In the embodiment of the present application, the query request is obtained by analyzing the graph database query statement, and the storage node processing the request is determined according to the query request. Then, the storage node determines the data access rule according to the association depth in the request, and further queries the target data according to the access rule.

[0081] As an optional embodiment, the query request is sent to the target storage node to obtain the target data, including:

[0082] In the case where the query association depth is equal to the preset threshold, the query request is sent to the target storage node, the identification information of the neighbor entity point is obtained according to the starting point identification information and the relationship edge direction, and the target data is obtained according to the identification information.

[0083] In the case where the query association depth is less than the preset threshold, the query request is sent to the target storage node, and the target data is obtained according to the starting point identification information.

[0084] Optionally, in the case where the query association depth is equal to the preset threshold, that is, the query association depth is 1, the neighbor entity point existing between the starting point and having a relationship edge direction consistent with the relationship edge direction specified in the query request is queried according to the starting point identification information, the identification information of the neighbor entity point meeting the condition is returned, and the target data is obtained according to the identification information. If the relationship edge direction is specified in the query request, the identification information of the matched neighbor entity point is returned, and if the relationship edge direction is not specified in the query request, the identification information of all associated neighbor entity points is returned.

[0085] For example, the starting point identification information is key1, the query association depth is 1, and the associated relationship edge direction is out edge. The query request is processed according to the following query rule, including: the identification information of all associated neighbor entity points having the relationship edge type of out edge is obtained according to the identification information of the entity point key1, the identification information is transmitted to the query node after the identification information is obtained, and the target data is obtained according to the identification information. It should be noted that the above process in the present example is similar to the steps when the association depth is odd and the query is performed at the last degree of association depth.

[0086] In the case where the query association depth is less than the preset threshold, that is, the query association depth is 0, the attribute data of the starting point is queried according to the starting point identification information, and the attribute data is returned to the query node. For example, the starting point identification information is key1, the corresponding attribute data val1 (i.e. the target data) is found according to key1, and is returned to the query node.

[0087] In the embodiment of the present application, the query rules when the query association depth is 0 or 1 are designed, and then the data query rule is determined according to the association depth in the query request, and the target data is queried.

[0088] As an optional embodiment, the relationship edge direction comprises a directed edge and an undirected edge, according to the relationship edge direction, the first identifier information of the associated first neighbor entity point is reversely looked up by using the start point identifier information, comprising:

[0089] In the case that the relationship edge direction is a directed edge, the first neighbor entity point whose relationship edge direction is opposite to the direction between the start point is looked up by using the start point identifier information, and the first identifier information is obtained;

[0090] In the case that the relationship edge direction is an undirected edge, all first neighbor entity points having relationship edges with the start point are looked up by using the start point identifier information, and the first identifier information is obtained.

[0091] Optionally, after the query request is broadcast to all storage nodes, the first degree neighbor entity point associated with the start point is obtained by using the reverse lookup method according to the start point identifier information in the query request and the relationship edge data stored on the current storage node, since the relationship edge data are stored in the same storage node with the associated entity point data, the identifier information of the associated first degree neighbor entity point is used to obtain the identifier information of the next degree neighbor entity point, so that the two-degree associated entity point data is obtained by one network transmission.

[0092] The application determines whether the relationship edge is a directed edge or an undirected edge according to the relationship edge direction in the query request, the directed edge has a direction, and the undirected edge has no direction. The reverse lookup method comprises: in the case that the relationship edge direction is a directed edge, the first neighbor entity point whose relationship edge direction is opposite to the direction between the start point is looked up by using the start point identifier information, and the first identifier information is obtained; in the case that the relationship edge direction is an undirected edge, all first neighbor entity points having relationship edges with the start point are looked up by using the start point identifier information, and the first identifier information is obtained.

[0093] The application adopts a key-value storage mode, and the value represents the data stored in each storage node. As shown in Figure 2 The entity point identifier information of the query is key1 (i.e. the start point identifier information), the association depth is greater than 1, the associated relationship edge type is an out edge, and the query request is processed according to the reverse query rule, comprising: the identifier information key2 and key3 (i.e. the first identifier information) of the associated entity point (i.e. the first neighbor entity point) having the relationship edge type of an in edge with the entity point is queried according to the identifier information key1 of the entity point.

[0094] In the embodiment of the present application, the first neighbor entity point is queried according to the reverse query rule, and the relationship edge direction between the starting point and the first neighbor entity point is opposite to the relationship edge direction specified in the query request, thereby providing a basis for querying and obtaining two-degree associated entity data through one network transmission.

[0095] As an optional embodiment, the second identification information of the second neighbor entity point associated with the first identification information is found according to the relationship edge direction, comprising:

[0096] In the case of a directed edge, the second neighbor entity point with the same relationship edge direction between the first neighbor entity point and the relationship edge is found using the first identification information, and the second identification information is obtained.

[0097] In the case of an undirected edge, all second neighbor entity points having a relationship edge with the first neighbor entity point are found using the first identification information, and the second identification information is obtained.

[0098] Optionally, the present application determines whether the relationship edge is a directed edge or an undirected edge according to the relationship edge direction in the query request. If the direction is indicated, it is a directed edge, and if the direction is not indicated, it is an undirected edge.

[0099] If the relationship edge direction is not indicated in the query request, all second neighbor entity points having a relationship edge with the first neighbor entity point are found using the first identification information, and the second identification information is obtained. If the relationship edge direction is indicated in the query request, the second neighbor entity point with the required relationship edge direction between the first neighbor entity point and the relationship edge is found using the first identification information.

[0100] As shown in Figure 2 , the identification information key4 and key5 (i.e. the second identification information) of the associated entity point (i.e. the second neighbor entity point) associated with the relationship edge type out edge is queried according to the first identification information key2 and key3, and key4 and key5 are returned to the query node.

[0101] In the embodiment of the present application, the second identification information of the second neighbor entity point is queried and returned based on the reverse query rule according to the first identification information, and two-degree associated entity data is queried and obtained through one network transmission, thereby avoiding the repeated query caused by the repeated associated entity points of multiple starting points in the prior art, and effectively reducing the network transmission data amount.

[0102] As an optional embodiment, Figure 3 is a flowchart of an optional distributed graph database multi-degree neighbor query method according to an embodiment of the present application, which comprises:

[0103] S301, determine the starting point identification information, relationship edge direction and association depth of the query request according to the information provided by the query statement.

[0104] S302, determine the target storage node of the query according to the query request, when the association depth is 0 or 1 degree, determine the storage node, return the data to the user after querying the data; when the association depth exceeds 1, broadcast the query request to all storage nodes.

[0105] S303, after the storage node obtains the broadcast query request, the associated neighbor entity is found reversely according to the starting entity point identification information, and the associated next degree neighbor entity is found forwardly according to the neighbor entity, and the data is returned to the query node.

[0106] S304, according to the data returned by the storage node, iteratively construct the query request until the requirement of the association depth is met, and return the data to the user.

[0107] Optionally, the specific implementation manner of the embodiment of the application is described in other embodiments, which will not be repeated here.

[0108] In the embodiment of the application, the query request is obtained by analyzing the graph database query statement, and the storage node processing the request is determined according to the query request, then the storage node determines the data access rule according to the association depth in the request, and then accesses the data according to the access rule until the requirement of the association depth is met. Compared with the traditional query method in which each degree of associated neighbor query needs to return data to the query node, the repeated query caused by the repeated associated entity points of multiple starting points is effectively reduced, the network transmission amount is effectively reduced, and the query efficiency of the distributed graph database system is improved.

[0109] As an optional embodiment, Figure 4 is a structural block diagram of an optional distributed graph database multi-degree neighbor query device according to the embodiment of the application, the device can execute the above-mentioned distributed graph database multi-degree neighbor query method, and the device comprises a graph database query language analysis module 410, a query request processing module 420 and a data access module 420.

[0110] Optionally, the graph database query language analysis module 410 is used for obtaining the query statement request, analyzing the query statement, obtaining the query request contained therein, determining the starting entity point identification information, the associated relationship edge type and the association depth.

[0111] The query request processing module 420 determines a distribution strategy of the query according to the association depth, and sends a query request constructed by the starting entity point identification information, the relationship edge type and the association depth to the target storage node. The association depth includes at least one of 0 degree, 1 degree and more than 1 degree. The association depth is determined in advance according to the query statement of the user. If the association depth is 0 degree, the corresponding query request processing module 420 includes a query statement response sub-module, which is configured to respond to the received query statement and respond the data returned by the storage node to the user. If the association depth is 1 degree, the corresponding query request processing module 420 includes a target node calculation sub-module, which is configured to determine the target storage node according to the entity point identification information; and a query request transmission sub-module, which is configured to send the query request to the target storage node. If the association depth is more than 1 degree, the corresponding query request processing module 420 includes a query request broadcast sub-module, which is configured to broadcast the query request to all the storage nodes.

[0112] The data access module 430 is configured to determine a query strategy according to the association depth in the query request, obtain corresponding data, and return the obtained data to the query node. The association depth includes at least one of 0 degree, 1 degree and more than 1 degree. The association depth is determined according to the query request. If the association depth is 0 degree, the corresponding data access module 430 includes a data access sub-module, which is configured to respond to the received data query request and transmit the attribute data corresponding to the entity point identification information to the query node. If the association depth is 1 degree, the corresponding data access module 430 includes an identification information access sub-module, which is configured to respond to the received association entity identification information query request, obtain the associated entity point identification information and then transmit the same to the query node. If the association depth is more than 1 degree, the corresponding data access module 430 includes a multi-degree query sub-module, which is configured to respond to the received multi-degree query request, obtain the entity identification information associated with the starting entity point, and then query the associated entity point identification information according to the obtained identification information again.

[0113] In the embodiments of the present application, the query request is obtained by analyzing the graph database query statement, the storage node processing the request is determined according to the query request, then the storage node determines the data access rule according to the association depth in the request, and further accesses the data according to the access rule until the requirement of the association depth is met. Compared with the traditional query method in which the data needs to be returned to the query node for each degree of association neighbor query, the network transmission amount is effectively reduced, and the query efficiency of the distributed graph database system is improved.

[0114] According to another aspect of the embodiments of the present application, a graph database query device for implementing the above-mentioned graph database query method is also provided. Figure 5 The structure block diagram of an optional graph database query device according to the embodiments of the present application is shown in FIG. 2. Figure 5As shown, the apparatus can include:

[0115] The parsing module 501 is configured to parse the obtained query statement to obtain a query request, wherein the query request comprises a query correlation depth, a starting point identification information, and a relationship edge direction.

[0116] The first sending module 502 is configured to, in a case where the query correlation depth is greater than a preset threshold, send the query request to all storage nodes, and according to the relationship edge direction, reversely find first identification information of a first neighbor entity point associated with the starting point identification information.

[0117] The finding module 503 is configured to, according to the relationship edge direction, find second identification information of a second neighbor entity point associated with the first identification information, and return the second identification information.

[0118] The data returning module 504 is configured to, according to a comparison between the query request and the correlation depth of the second neighbor entity point and the query correlation depth, execute a loop query logic to obtain target data.

[0119] It should be noted that the parsing module 501 in this embodiment can be configured to execute the above step S101, the first sending module 502 in this embodiment can be configured to execute the above step S102, the finding module 503 in this embodiment can be configured to execute the above step S103, and the data returning module 504 in this embodiment can be configured to execute the above step S104.

[0120] Through the above modules, one data transmission can obtain an associated neighbor entity point with a correlation depth of two degrees relative to the starting point, effectively reducing the network transmission data volume, and when the correlation depth is large, the query time is reduced and the query efficiency is improved. The problems of large network transmission data volume and low query efficiency in the related art are solved.

[0121] As an optional embodiment, the data returning module comprises:

[0122] The first obtaining unit is configured to, in a case where the correlation depth is equal to the query correlation depth, obtain the target data according to the second identification information.

[0123] The second obtaining unit is configured to, in a case where the correlation depth is less than the query correlation depth, update the starting point identification information in the query request according to the second identification information, send the updated query request to the storage nodes, until the correlation depth of the neighbor entity point obtained by the query is equal to the query correlation depth, and obtain the target data according to the identification information of the neighbor entity point.

[0124] As an optional embodiment, the second obtaining unit comprises:

[0125] The acquisition submodule is configured to acquire the corresponding storage node according to the second identification information if the associated depth differs from the query associated depth by a preset threshold, and take the storage node as a target storage node.

[0126] The first obtaining submodule is configured to update the start point identification information in the query request according to the second identification information, and send the updated query request to the target storage node to obtain target identification information of the target neighbor entity point.

[0127] The second obtaining submodule is configured to obtain the target data according to the target identification information.

[0128] As an optional embodiment, the device further comprises:

[0129] The acquisition module is configured to acquire the storage node corresponding to the start point according to the start point identification information if the query associated depth is less than or equal to a preset threshold, and take the storage node as a target storage node.

[0130] The second sending module is configured to send the query request to the target storage node to obtain the target data.

[0131] As an optional embodiment, the second sending module comprises:

[0132] The first acquisition unit is configured to send the query request to the target storage node if the query associated depth is equal to the preset threshold, acquire the identification information of the neighbor entity point according to the start point identification information and the relationship edge direction, and acquire the target data according to the identification information.

[0133] The second acquisition unit is configured to send the query request to the target storage node if the query associated depth is less than the preset threshold, and acquire the target data according to the start point identification information.

[0134] As an optional embodiment, the relationship edge direction comprises a directed edge and an undirected edge, and the first sending module comprises:

[0135] The first finding unit is configured to find, if the relationship edge direction is a directed edge, a first neighbor entity point having a relationship edge direction opposite to the relationship edge direction between the start point and the first neighbor entity point by using the start point identification information, to obtain first identification information.

[0136] The second finding unit is configured to find, if the relationship edge direction is an undirected edge, all first neighbor entity points having a relationship edge between the start point and the first neighbor entity points by using the start point identification information, to obtain first identification information.

[0137] As an optional embodiment, the finding module comprises:

[0138] The third searching unit is configured to search, in the case that the relationship edge direction is a directed edge, a second neighbor entity point with the same relationship edge direction as the relationship edge between the first neighbor entity point and the second neighbor entity point, using the first identification information, to obtain second identification information.

[0139] The fourth searching unit is configured to search, in the case that the relationship edge direction is an undirected edge, all second neighbor entity points having a relationship edge with the first neighbor entity point, using the first identification information, to obtain second identification information.

[0140] It should be noted that the above modules and the examples and application scenarios realized by the corresponding steps are the same, but are not limited to the content disclosed in the above embodiments.

[0141] According to still another aspect of the embodiments of the present application, an electronic device for implementing the above-mentioned graph database query method is provided, which can be a server, a terminal, or a combination thereof.

[0142] Figure 6 is a structural block diagram of an optional electronic device according to the embodiments of the present application, as shown in Figure 6 includes a processor 601, a communication interface 602, a memory 603, and a communication bus 604, wherein the processor 601, the communication interface 602, and the memory 603 complete mutual communication through the communication bus 604, wherein,

[0143] The memory 603 is configured to store a computer program.

[0144] The processor 601 is configured to execute the computer program stored in the memory 603, and realize the following steps:

[0145] The obtained query statement is parsed to obtain a query request, wherein the query request is composed of a query association depth, a starting point identification information, and a relationship edge direction;

[0146] In the case that the query association depth is greater than a preset threshold, the query request is sent to all storage nodes, and the first identification information of the associated first neighbor entity point is reversely searched using the starting point identification information according to the relationship edge direction;

[0147] The second identification information of the associated second neighbor entity point of the next level is searched using the first identification information according to the relationship edge direction, and the second identification information is returned;

[0148] According to the comparison between the query request and the association depth of the second neighbor entity point and the query association depth, a loop query logic is executed to obtain target data.

[0149] Optionally, in the embodiment, the communication bus described above can be a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For convenience of representation, Figure 6 Only one thick line is used in the figure to represent the bus, but it does not mean that there is only one bus or only one type of bus.

[0150] The communication interface is used for communication between the electronic device and other devices.

[0151] The memory can include a RAM, and can also include a non-volatile memory, for example, at least one disk memory. Optionally, the memory can also be at least one storage device located away from the aforementioned processor.

[0152] As an example, as shown in Figure 6 The memory 603 described above can include, but is not limited to, the parsing module 501, the first sending module 502, the searching module 503, and the data returning module 504 in the graph database query device described above. In addition, other module units in the graph database query device described above can also be included, but not limited to, which will not be described in detail in the present example.

[0153] The processor described above can be a general-purpose processor, which can include, but is not limited to, a CPU (Central Processing Unit), an NP (Network Processor), etc. It can also be a DSP (Digital Signal Processing), an ASIC (Application Specific Integrated Circuit), an FPGA (Field-Programmable Gate Array) or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component.

[0154] Optionally, the specific examples in the embodiment can refer to the examples described in the above-described embodiments, which will not be described in detail in the present embodiment.

[0155] Those skilled in the art can understand, Figure 6The structure shown is only schematic, and the device implementing the above method of querying the graph database can be a terminal device, which can be a smartphone (such as an Android phone, an iOS phone, etc.), a tablet computer, a palm computer, a Mobile Internet Device (MID), a PAD, or the like. Figure 6 This does not limit the structure of the above electronic device. For example, the terminal device can further include more or fewer components (such as a network interface, a display device, etc.) than those shown in the above embodiment, or have a different configuration from that shown in the above embodiment. Figure 6 ​ The structure shown is only schematic, and the device implementing the above method of querying the graph database can be a terminal device, which can be a smartphone (such as an Android phone, an iOS phone, etc.), a tablet computer, a palm computer, a Mobile Internet Device (MID), a PAD, or the like.

[0156] Those of ordinary skill in the art can understand that all or part of the steps of the various methods of the above embodiments can be instructed by a program to terminal device related hardware, and the program can be stored in a computer readable storage medium, which can include a flash disk, a ROM, a RAM, a magnetic disk, an optical disk, or the like.

[0157] According to yet another aspect of the embodiments of the present application, a storage medium is also provided. Optionally, in the present embodiment, the above storage medium can be used to store program code for executing the method of querying the graph database.

[0158] Optionally, in the present embodiment, the above storage medium can be located on at least one of the plurality of network devices in the network shown in the above embodiment.

[0159] Optionally, in the present embodiment, the storage medium is configured to store program code for executing the following steps:

[0160] parsing the obtained query statement to obtain a query request, wherein the query request is composed of a query correlation depth, a starting point identification information, and a relationship edge direction;

[0161] in the case where the query correlation depth is greater than a preset threshold, sending the query request to all storage nodes, and according to the relationship edge direction, reversely searching for first identification information of a first neighbor entity point associated with the starting point identification information;

[0162] according to the relationship edge direction, searching for second identification information of a second neighbor entity point associated with the first identification information, and returning the second identification information;

[0163] according to a comparison between the query request and the correlation depth corresponding to the second neighbor entity point and the query correlation depth, executing a loop query logic to obtain target data.

[0164] Optionally, specific examples in the present embodiment can refer to the examples described in the above embodiments, which will not be described herein again. ​

[0165] Optionally, in the present embodiment, the storage medium can include, but is not limited to, a U disk, a ROM, a RAM, a mobile hard disk, a magnetic disk or an optical disk, and various storage medium capable of storing program codes.

[0166] In the description of the present specification, the description of the terms "the present embodiment", "one embodiment", "some embodiments", "an example", "a specific example", or "some examples" and the like means that the specific features, structures, materials or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present disclosure. In the present specification, the illustrative description of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any appropriate manner in any one or more embodiments or examples. In addition, the different embodiments or examples described in the present specification and the features of the different embodiments or examples can be combined and combined by those skilled in the art without contradiction. In the description of the present disclosure, the meaning of "a plurality of" is at least two, for example, two, three, etc., unless otherwise explicitly specified.

[0167] Obviously, the above embodiments are only examples for clearly illustrating, but not limiting the embodiments. Based on the above description, those skilled in the art can make other different forms of changes or variations. Here, it is not necessary and impossible to enumerate all the embodiments. The obvious changes or variations derived therefrom are still within the protection scope of the present invention.

Claims

1. A graph database query method, characterized in that, The method comprises: The obtained query statement is parsed to obtain a query request, wherein the query request is composed of a query correlation depth, a starting point identification information, and a relationship edge direction; In a case where the query correlation depth is greater than a preset threshold, the query request is sent to all storage nodes, and a first identification information of a first neighbor entity point associated with the starting point identification information is reversely searched according to the relationship edge direction; The relationship edge direction comprises a directed edge and an undirected edge, and the first identification information of the first neighbor entity point associated with the starting point identification information is reversely searched according to the relationship edge direction, comprising: in a case where the relationship edge direction is a directed edge, the first neighbor entity point having a relationship edge direction opposite to the relationship edge direction between the starting point is searched according to the starting point identification information to obtain the first identification information; and in a case where the relationship edge direction is an undirected edge, all the first neighbor entity points having the relationship edge between the starting point are searched according to the starting point identification information to obtain the first identification information; The second identification information of a second neighbor entity point associated with the first identification information is searched according to the relationship edge direction, and the second identification information is returned; According to the comparison between the query request and the correlation depth corresponding to the second neighbor entity point and the query correlation depth, a loop query logic is executed to obtain target data; In a case where the correlation depth is equal to the query correlation depth, the target data is obtained according to the second identification information; in a case where the correlation depth is less than the query correlation depth, the starting point identification information in the query request is updated according to the second identification information, the updated query request is sent to the storage nodes, until the correlation depth of the queried neighbor entity point is equal to the query correlation depth, and the target data is obtained according to the identification information of the neighbor entity point; In a case where the query correlation depth is less than or equal to the preset threshold, a storage node corresponding to the starting point is obtained according to the starting point identification information, and the storage node is taken as a target storage node; the query request is sent to the target storage node to obtain the target data.

2. The method of claim 1, wherein, In a case where the correlation depth is less than the query correlation depth, the starting point identification information in the query request is updated according to the second identification information, the updated query request is sent to the storage nodes, until the correlation depth of the queried neighbor entity point is equal to the query correlation depth, and the target data is obtained according to the identification information of the neighbor entity point, comprising: If the correlation depth and the query correlation depth differ by the preset threshold, a corresponding storage node is obtained according to the second identification information, and the storage node is taken as a target storage node; updating the start point identification information in the query request according to the second identification information, and sending the updated query request to the target storage node to obtain target identification information of a target neighbor entity point; obtaining the target data according to the target identification information.

3. The method of claim 1, wherein, The sending of the query request to the target storage node to obtain target data comprises: in a case where the query association depth is equal to the preset threshold, sending the query request to the target storage node, obtaining identification information of a neighbor entity point according to the start point identification information and the relationship edge direction, and obtaining the target data according to the identification information; in a case where the query association depth is less than the preset threshold, sending the query request to the target storage node, and obtaining the target data according to the start point identification information.

4. The method of claim 1, wherein, The searching of the second identification information of a second neighbor entity point associated with the first identification information according to the relationship edge direction comprises: in a case where the relationship edge direction is a directed edge, searching the second neighbor entity point having the same relationship edge direction between the first neighbor entity point and the relationship edge according to the first identification information to obtain the second identification information; in a case where the relationship edge direction is an undirected edge, searching all the second neighbor entity points having the relationship edge with the first neighbor entity point according to the first identification information to obtain the second identification information.

5. A graph database query apparatus, characterized by, comprise: a parsing module configured to parse a query sentence obtained to obtain a query request, wherein the query request comprises a query association depth, start point identification information and a relationship edge direction; a first sending module configured to, in a case where the query association depth is greater than a preset threshold, send the query request to all storage nodes, and search first identification information of a first neighbor entity point associated with the start point identification information according to the relationship edge direction; the relationship edge direction comprises a directed edge and an undirected edge, and the first sending module comprises: a first searching unit configured to, in a case where the relationship edge direction is a directed edge, search the first neighbor entity point having an opposite relationship edge direction between the start point and the relationship edge according to the start point identification information to obtain the first identification information; and a second searching unit configured to, in a case where the relationship edge direction is an undirected edge, search all the first neighbor entity points having the relationship edge with the start point according to the start point identification information to obtain the first identification information; a searching module configured to search second identification information of a second neighbor entity point associated with the first identification information according to the relationship edge direction, and return the second identification information; a data returning module configured to execute a loop query logic according to a comparison between an association depth corresponding to the second neighbor entity point and the query association depth to obtain target data. The data returning module comprises: a first obtaining unit, configured to obtain the target data according to the second identification information when the association depth is equal to the query association depth; a second obtaining unit, configured to update the start point identification information in the query request according to the second identification information when the association depth is less than the query association depth, send the updated query request to the storage node until the association depth of the queried neighbor entity point is equal to the query association depth, and obtain the target data according to the identification information of the neighbor entity point. The acquisition module is configured to acquire a storage node corresponding to the start point according to the start point identification information and take the storage node as a target storage node when the query association depth is less than or equal to the preset threshold. The second sending module is configured to send the query request to the target storage node and obtain the target data.

6. An electronic device comprising a processor, a communication interface, a memory and a communication bus, wherein, The processor, the communication interface and the memory complete mutual communication through the communication bus, and the processor is characterized in that, The memory is configured to store a computer program. The processor is configured to execute the method steps in any one of claims 1 to 4 by running the computer program stored on the memory.

7. A computer readable storage medium, characterized in that, The storage medium stores a computer program, and the computer program is executed by the processor to implement the method steps in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Graph query method and system

    CN110209885A

  • Graph pattern matching method based on multi-source-point parallel exploration

    CN112559807A