A graph database query method, device and computer-readable storage medium

By identifying and replacing redundant units in graph database queries and optimizing the execution plan, the problem of inefficiency in multi-hop queries is solved, and a more efficient query path is achieved.

CN120596517BActive Publication Date: 2025-10-28杭州悦数科技有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511087926.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-08-05
Publication Date
2025-10-28
Estimated Expiration
2045-08-05

AI Technical Summary

Technical Problem

Existing graph database query methods suffer from low query efficiency during multi-hop queries due to traversing all nodes and numerous join operations, especially when there are join operations unrelated to the output target.

Method used

By identifying redundant units in the initial execution plan and replacing them with target sub-units related to the output target, the execution plan is updated to eliminate redundant operations and reduce scanning and computation.

Benefits of technology

It improves the query efficiency of graph databases, reduces the amount of data scanning and computation, and optimizes the query path.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120596517B_ABST
    Figure CN120596517B_ABST
Patent Text Reader

Abstract

This application relates to a graph data query method, apparatus, and computer-readable storage medium. The graph data query method includes: determining an output target and an initial execution plan based on a query instruction; the initial execution plan including several operation units connected in execution order; a redundant unit identification step: in the initial execution plan, traversing the operation units in execution order, identifying the first operation unit that meets a preset redundancy condition as a redundant unit, and stopping the current traversal; an execution plan update step: in the redundant units, identifying target sub-units related to the output target, modifying the connection between the redundant unit and the upper-level operation unit to a connection between the target sub-unit and the upper-level operation unit, obtaining an intermediate execution plan; performing the redundant unit identification step and the execution plan update step again based on the intermediate execution plan until the preset conditions are met to obtain the target execution plan, and querying the graph database based on the target execution plan.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of graph database technology, and in particular to a graph data query method, apparatus and computer-readable storage medium. Background Art

[0002] Graph databases represent data using nodes and edges representing the relationships between nodes. For highly interconnected data, graph databases achieve fast data retrieval by traversing adjacent nodes and querying along the edges of relationships.

[0003] In existing technologies, graph database query methods include multi-hop queries. Multi-hop queries require traversing all nodes in the graph database, resulting in a large number of join operations. Many of these join operations are irrelevant to the output target, which reduces the query efficiency of the graph database. Therefore, improving the query efficiency of graph databases is a pressing issue. Summary of the Invention

[0004] This application provides a graph database query method, apparatus, and computer-readable storage medium to at least solve the problem of low query efficiency in graph databases in related technologies.

[0005] In a first aspect, embodiments of this application provide a graph database query method, including:

[0006] The output target and initial execution plan are determined based on the query command. The initial execution plan includes several operation units connected in execution order.

[0007] Redundant unit identification step: In the initial execution plan, the operation units are traversed according to the execution order, and the first operation unit that meets the preset redundancy condition is identified as a redundant unit, and the current traversal is stopped;

[0008] Update execution plan steps: In the redundant unit, determine the target sub-unit related to the output target. In the initial execution plan, modify the connection between the redundant unit and the upper-level operation unit to the connection between the target sub-unit and the upper-level operation unit to obtain the intermediate execution plan.

[0009] Based on the intermediate execution plan, the confirmation of redundant units and the update of execution plan are performed again until the preset conditions are met to obtain the target execution plan, and the graph database is queried according to the target execution plan.

[0010] In one embodiment, after determining the target subunit associated with the output target, the method further includes:

[0011] Identify redundant operation subunits that are irrelevant to the output target;

[0012] The redundant operation subunit is replaced by the target subunit, and the internal connection of the redundant unit is modified to be the connection of the two target subunits.

[0013] In one embodiment, modifying the connection between the redundant unit and the upper-layer operation unit to a connection between the target subunit and the upper-layer operation unit includes:

[0014] Based on the connection between the two target sub-units, the internal connection relationship of the redundant unit is determined;

[0015] Based on the internal connection relationship, modify the connection between the redundant unit and the upper-level operation unit to obtain the connection between the target subunit and the upper-level operation unit.

[0016] In one embodiment, the operation unit includes:

[0017] The node scanning subunit is used to determine the target node of the current operation unit according to the query instruction, scan all nodes in the graph database, and output the node identifier of the target node when the target node is scanned.

[0018] The edge scanning subunit is used to determine the target relationship of the target node in the current operation unit according to the query instruction, and scan all edges related to the target node with the target node as the scanning starting point. When a target edge that satisfies the target relationship is scanned, the endpoint identifier and the starting point identifier of the target edge are output.

[0019] In one embodiment, the preset redundancy condition satisfies the following condition:

[0020] The data pointed to by the endpoint identifier of the target edge is the same as the data pointed to by the point identifier of the target node, and the target node is not the output target; and / or

[0021] The data pointed to by the starting point identifier of the target edge is the same as the data pointed to by the point identifier of the target node, and the target node is not the output target.

[0022] In one embodiment, the connection between the target sub-unit and the upper-level operation unit specifically satisfies the following conditions:

[0023] The data referred to by the identifier output by the target subunit is the same as the data referred to by the starting point identifier of the upper-level operation.

[0024] In one embodiment, modifying the connection between the redundant unit and the upper-layer operation unit to a connection between the target subunit and the upper-layer operation unit includes:

[0025] Based on the connection between the redundant unit and the upper-level operation unit, the first identifier output by the redundant unit and the second identifier output by the upper-level operation unit are determined.

[0026] A third identifier is determined for the target subunit, and the first identifier is modified using the third identifier to achieve the connection between the target subunit and the upper-level operation unit.

[0027] Secondly, embodiments of this application provide a graph database query device, characterized in that it includes:

[0028] The module for determining the initial execution plan is used to determine the output target and the initial execution plan based on the query command. The initial execution plan includes several operation units connected in execution order.

[0029] The redundancy unit identification module is used to identify the redundancy unit step: in the initial execution plan, the operation units are traversed according to the execution order, the first operation unit that meets the preset redundancy condition is identified as the redundancy unit, and the current traversal is stopped;

[0030] The execution plan update module is used to update the execution plan steps: in the redundant unit, the target sub-unit related to the output target is determined; in the initial execution plan, the connection between the redundant unit and the upper-level operation unit is modified to the connection between the target sub-unit and the upper-level operation unit to obtain the intermediate execution plan.

[0031] The query module is used to perform the confirmation of redundant units and the update of execution plan steps again based on the intermediate execution plan until the preset conditions are met to obtain the target execution plan, and then query the graph database according to the target execution plan.

[0032] Thirdly, embodiments of this application provide a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the graph database query method as described in the first aspect above.

[0033] Fourthly, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the graph database query method as described in the first aspect above.

[0034] The graph database query method, apparatus, and computer-readable storage medium provided in this application have at least the following technical effects.

[0035] By identifying redundant units in the execution plan and determining the target sub-units related to the output target within the redundant units, and replacing the connections of the redundant units with the connections between the target sub-units and the upper-level operation pages, operations unrelated to the output target in the redundant units are eliminated. Only the operation sub-units related to the output target are retained. By repeatedly executing the steps of identifying redundant units and updating the execution plan, the initial execution plan is updated to obtain the target execution plan. As a result, when querying the graph database by executing the target execution plan, redundant operations are no longer executed, thereby reducing the amount of data scanning and computation in the graph database and improving the query efficiency of the graph database.

[0036] Details of one or more embodiments of this application are set forth in the following drawings and description to make other features, objects and advantages of this application more readily apparent. Attached Figure Description

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

[0038] Figure 1 This is a flowchart illustrating a graph database query method according to an exemplary embodiment;

[0039] Figure 2 This is a schematic diagram illustrating the determination of redundant units according to an exemplary embodiment;

[0040] Figure 3 This is a flowchart illustrating the steps of updating an execution plan in a graph database according to an exemplary embodiment;

[0041] Figure 4 This is a schematic diagram illustrating a target execution plan according to an exemplary embodiment;

[0042] Figure 5 This is a block diagram illustrating a graph database query apparatus according to an exemplary embodiment;

[0043] Figure 6 This is a block diagram of an electronic device according to an exemplary embodiment. Detailed Implementation

[0044] To make the objectives, technical solutions, and advantages of this application clearer, the application is described and illustrated below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application. All other embodiments obtained by those skilled in the art based on the embodiments provided in this application without inventive effort are within the scope of protection of this application.

[0045] Obviously, the accompanying drawings described below are merely some examples or embodiments of this application. Those skilled in the art can apply this application to other similar scenarios based on these drawings without any inventive effort. Furthermore, it is understood that although the efforts made in this development process may be complex and lengthy, for those skilled in the art related to the content disclosed in this application, any changes to design, manufacturing, or production based on the technical content disclosed in this application are merely conventional technical means and should not be construed as insufficient disclosure of the content of this application.

[0046] In this application, the reference to "embodiment" means that a specific feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment that is mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described in this application may be combined with other embodiments without conflict.

[0047] Unless otherwise defined, the technical or scientific terms used in this application shall have the ordinary meaning understood by one of ordinary skill in the art to which this application pertains. The terms “a,” “an,” “an,” “the,” and similar words used in this application do not indicate quantity limitation and may indicate singular or plural. The terms “comprising,” “including,” “having,” and any variations thereof used in this application are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or device that includes a series of steps or modules (units) is not limited to the listed steps or units, but may also include steps or units not listed, or may include other steps or units inherent to these processes, methods, products, or devices. The terms “connected,” “linked,” “coupled,” and similar words used in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. “Multiple” used in this application refers to two or more. “And / or” describes the relationship between related objects, indicating that three relationships may exist; for example, “A and / or B” can represent: A alone, A and B simultaneously, and B alone. The character " / " generally indicates that the preceding and following objects are in an "or" relationship. The terms "first," "second," and "third" used in this application are merely to distinguish similar objects and do not represent a specific ordering of the objects.

[0048] Firstly, embodiments of this application provide a graph database query method. Figure 1 This is a flowchart illustrating a graph database query method according to an exemplary embodiment, such as... Figure 1 As shown, graph database query methods include:

[0049] Step S101: Determine the initial execution plan according to the query instruction. The initial execution plan includes several operation units connected in the execution order. The query instruction includes the output target.

[0050] The process involves obtaining a query command to query the graph database and determining an initial execution plan based on the command. The query command includes nodes and edges. By identifying the output target based on the node and edge requirements in the query command, the graph database automatically generates an initial execution plan. This initial execution plan consists of several operation units connected in execution order. By executing these operation units in sequence, the output target can be found in the graph database.

[0051] In one embodiment, the query instruction is: MATCH(p1:Person)-[e1:KNOWS]->(p2:Person)-[e2:KNOWS]->(p3:Person) RETURN p3. The query instruction means: there exists a path where p1 knows p2 and p2 knows p3, and return p3, where p1, p2, and p3 are nodes, p3 is the output target, and e1 and e2 are the connections between nodes, i.e., edges. In other words, through the query instruction, the query path of the graph database can be: first, match the node labeled "person," i.e., p1. Starting from p1, find node p2 through the KNOWS type relationship, where p2 is someone p1 directly knows. Then, based on node p2, find node p3 through the KNOWS type relationship, where p3 is a friend of p1's friend, and finally return all nodes p3 that meet the above conditions.

[0052] The graph database automatically generates an execution plan based on the query command. It finds node p1 and its KNOWS type relation as the first operation unit, finds node p1 and its KNOWS type link as the second operation unit, connects the first and second operation units and returns the output target as the third operation unit. The execution plan connects the first, second and third operation units in the execution order of the first, second and third operation units, and returns node p3.

[0053] The operation unit is the basic unit for executing the initial execution plan. Each operation unit obtains the required query nodes and edges from the query instruction. Functionally, operation units can be divided into connection-type operations, scan-type operations, and modification-type operations. For scan-type operation units, the operation units include node scanning operations and edge scanning operations. In this application, the operation units in the initial execution plan include:

[0054] The scanning node sub-unit is used to determine the target node of the current operation unit according to the query instruction, scan all nodes in the graph database, and output the point identifier of the target node when the target node is scanned.

[0055] The edge scanning sub-unit is used to determine the target relationship of the target node in the current operation unit according to the query instruction. Taking the target node as the scanning starting point, it scans all edges related to the target node. When a target edge that satisfies the target relationship is scanned, the endpoint identifier and starting point identifier of the target edge are output.

[0056] For example, the query instruction (p1:Person)-[e1:KNOWS] is executed by the first operation unit. The node scanning sub-unit of the first operation unit is NodeScan(p1), which scans all nodes in the graph database, finds all nodes labeled "Person," and assigns these found nodes as p1. The edge scanning sub-unit of the first operation unit is EdgeScan(e1), which searches for all edges of type "KNOWS" around node p1, starting from node p1; these edges are e1. In this case, the data referred to by the starting point identifier of e1 in the first operation unit is the same as the data referred to by the vertex identifier of node p1; that is, both the starting point identifier of e1 and the vertex identifier of node p1 refer to node p1.

[0057] The query command (p2:Person)-[e2:KNOWS] is executed by the second operation unit. The node scanning sub-unit of the second operation unit is NodeScan(p2), which scans all nodes in the graph database, finds all nodes labeled "Person," and assigns these found nodes as p2. The edge scanning sub-unit of the second operation unit is EdgeScan(e2), which searches for all edges of type "KNOWS" around node p2, starting from node p2; these edges are e2. At this point, the data referred to by the starting point identifier of e2 in the first operation unit is the same as the data referred to by the vertex identifier of node p2; that is, both the starting point identifier of e2 and the vertex identifier of node p2 refer to node p2.

[0058] In the query instruction (p1:Person)-[e1:KNOWS]->(p2:Person)-[e2:KNOWS], the third operation unit executes the query. The third operation unit connects the first operation unit and the second operation unit, which means finding all data whose endpoint identifiers of e1 are the same as the data whose point identifiers of node p2 are the same.

[0059] Based on the first, second, and third operation units mentioned above, the query path (p1:Person)-[e1:KNOWS]->(p2:Person)-[e2:KNOWS] in the entire query instruction is completed. In the fourth operation unit, the final node p3 is obtained and returned according to the query path. That is, by scanning the node subunit NodeScan(p3), all nodes p3 with the label Person are found and the node p3 is output.

[0060] The initial execution plan involves scanning the graph database using the edge scanning sub-unit and node scanning sub-unit, as well as connecting operations within the aforementioned operation units. This allows the output target of the query instruction to be found in the graph database.

[0061] Step S102: Confirming Redundant Units: In the initial execution plan, traverse the operation units according to the execution order, identify the first operation unit that meets the preset redundancy conditions as a redundant unit, and stop the current traversal.

[0062] In the initial execution plan, the operation units are traversed sequentially according to the execution order. During the traversal, the first operation unit that meets the preset redundancy condition is designated as a redundant unit, and the current traversal is stopped to update the redundant unit. Optionally, the last operation unit in the initial execution plan is used as the starting unit for traversal, and the operation units are traversed sequentially using a preorder traversal of a binary tree, with the first operation unit that meets the preset redundancy condition designated as a redundant unit.

[0063] It should be noted that the preset redundancy condition satisfies any one of the following conditions:

[0064] The data pointed to by the endpoint identifier of the target edge is the same as the data pointed to by the point identifier of the target node, and the target node is not the output target.

[0065] The data pointed to by the endpoint identifier of the target edge is the same as the data pointed to by the endpoint identifier of the target node. That is, when connecting two operation units according to the execution order, the data pointed to by the endpoint identifier of the target edge of the first operation unit is the same as the data pointed to by the endpoint identifier of the target node of the second operation unit. Furthermore, the node of the current operation unit is not an output target. For example, in the third operation unit, connecting the first and second operation units, the endpoint identifier of the target edge e1 points to p2, and the endpoint identifier of the target node of the second operation unit also points to p2. The target node of the third operation unit is node p3, but node p3 is an output target; therefore, the third operation unit is not a redundant unit. If node p3 is not an output target, then the third operation unit is a redundant unit.

[0066] The data pointed to by the starting point identifier of the target edge is the same as the data pointed to by the point identifier of the target node, and the target node is not the output target.

[0067] The data pointed to by the starting point identifier of the target edge is the same as the data pointed to by the vertex identifier of the target node. That is, in the operation unit, by scanning the edge sub-unit and scanning the node sub-unit, starting from the target node of the scanning node sub-unit, all edges of the target node are queried until all target edges that meet the target relationship are found. In other words, in the operation unit, the vertex identifier of the target node is the starting point of the target edge. And the target node is the output target. For example, the first operation unit scans all nodes in the graph database, finds all nodes labeled "Person", and takes the found nodes as p1. Starting from node p1, it searches for all edges of type "KNOWS" around node p1. Since the data pointed to by the starting point identifier of the target edge is the same as the data pointed to by the vertex identifier of the target node, and node p1 is not the output target, the first operation unit is a redundant unit.

[0068] In one embodiment, Figure 2 This is a schematic diagram illustrating the determination of redundant units according to an exemplary embodiment, such as... Figure 2 As shown, the initial execution plan defines a query path based on the query instruction. This query path includes a first operation unit, a second operation unit, a third operation unit, and a fourth operation unit. The first operation unit scans the starting node and its edges, and obtains information about the second node. The second operation unit, based on the second node information, scans the second node and its edges, and obtains information about the third node. The third operation unit, a connection-type operation, connects the first and second operation units in the execution order to determine the initial query link. The fourth operation unit determines the complete query link based on the third operation unit, returns the output target, and outputs the target. For example, the first operation unit first scans node p1 and its edge e1, obtaining information about node p2 (the second node) based on these parameters. The second operation unit then scans node p2 and its edge e2 to obtain information about the output target p3. The third operation unit connects the first and second operation units to obtain a preliminary query path of p1-e1-p2-e2. Finally, the fourth operation unit determines the complete query path as p1-e1-p2-e2-p3 based on the preliminary query path from the third operation unit and outputs the target p3. The execution plan is traversed according to the execution order, starting from the fourth operation unit and using the first second operation unit that meets the preset redundancy conditions as a redundant unit.

[0069] Continuing with step S102, in the graph database query, the query command can be completed through the query path defined by the execution plan. However, in the execution plan, starting from the starting node, the output target is obtained only after passing through several relations and intermediate nodes. During the query process, it is still necessary to find intermediate nodes unrelated to the output target and connect them. For the output target, scanning intermediate nodes is a redundant operation. Therefore, by pre-setting redundancy conditions, operation units containing redundant operations are filtered out for subsequent updates.

[0070] Step S103, Update Execution Plan: In the redundant unit, identify the target sub-unit related to the output target. In the initial execution plan, modify the connection between the redundant unit and the upper-level operation unit to the connection between the target sub-unit and the upper-level operation unit to obtain the intermediate execution plan.

[0071] In the redundant unit, target sub-units related to the output target and redundant operation sub-units unrelated to the output target are determined based on the output target. The redundant unit is replaced by the target sub-unit. The internal connection relationship of the redundant unit is changed from the original connection between the target sub-unit and the redundant operation sub-unit to a connection between two target sub-units.

[0072] In this context, the target sub-units related to the output target satisfy the condition that the operations performed within the sub-units retrieve the information indispensable to the output target. In the graph database, nodes only contain node information, while edges contain information about the starting and ending nodes. The initial execution plan automatically generates a query path based on the query instruction, obtaining the output target by connecting nodes and edges. For any node that is not an output target, it only serves as an intermediate connection object; therefore, non-output target nodes are irrelevant to the output target. For any edge, it contains information about the starting and ending nodes, possesses query node and connection relationships, and satisfies the information required by the output target; therefore, the edge is related to the output target. Thus, in the operation unit, the edge scanning sub-unit is a sub-unit related to the output target, while the node scanning sub-unit, if the scanned node is not an output target, is a sub-unit unrelated to the output target; if the scanned node is an output target, it is a sub-unit related to the output target.

[0073] In the initial execution plan, starting from the operation unit at the end, the initial execution plan is traversed to query redundant units. Starting from the output target, the operations related to the output target can be obtained more clearly.

[0074] Continuing with step S103, based on the connection between the two target sub-units, determine the internal connection relationship of the redundant unit. The internal connection relationship is that the data pointed to by the starting point identifier of the target edge is the same as the data pointed to by the starting point identifier of the target edge. Based on the internal connection relationship, modify the connection between the redundant unit and the upper-level operation unit to obtain the connection between the target sub-unit and the upper-level operation unit. That is, update the connection relationship between the redundant unit and the upper-level connection unit in the initial execution plan: the data pointed to by the point identifier of the target node of the redundant unit is the same as the data pointed to by the starting point identifier of the target edge of the upper-level connection unit, to the data pointed to by the identifier output by the target sub-unit is the same as the data pointed to by the starting point identifier of the target edge of the upper-level connection unit. Once the connection update between the target sub-unit and the upper-level operation unit is complete, the updated initial execution plan, i.e., the intermediate execution plan, can be obtained.

[0075] In one embodiment, the second operation unit includes a node scanning subunit and an edge scanning subunit. The node scanning subunit scans node p2, and the edge scanning subunit scans all edges of type KNOWS around node p2. According to the conventions of graph databases, when an edge is found, it must have a corresponding start and end node. In the second operation unit, node p2 does not need to be output; therefore, the node scanning subunit is a redundant operation unit. The target edge e2 not only contains the KNOWS type relationship for finding node p3, but also contains information about node p2. Therefore, the edge scanning subunit is the target subunit. Replacing the node scanning subunit with the edge scanning subunit not only preserves the information about node p2 but also eliminates redundant scanning operations. The internal connection update of the second operation unit is the connection between the two edge scanning subunits. Furthermore, the internal connection condition of the second operation unit is updated to be the same as the data pointed to by the point identifier of the target node p2 and the data pointed to by the starting point identifier of the target edge e2. That is, there is only a scanning edge sub-unit in the second operation unit.

[0076] Modifying the connection between operation units specifically manifests as modifying identifiers:

[0077] Based on the connection between the redundant unit and the upper-level operation unit, the first identifier output by the redundant unit and the second identifier output by the upper-level operation unit are determined, wherein the data referred to by the first identifier and the second identifier are the same.

[0078] The third identifier of the target subunit is determined, and the first identifier is modified with the third identifier to realize the connection between the target subunit and the upper-level operation unit.

[0079] For example, the connection between the redundant unit and the upper-level operation unit is expressed as: element_id(p2) = right_node_id(e1). The first identifier output by the redundant unit is the node identifier element_id(p2) of the target node p2, and the second identifier output by the upper-level operation unit is the starting point identifier right_node_id(e1) of the target edge. Both refer to the same data, which is node p2. By replacing the redundant unit with the target sub-unit, the connection between the target sub-unit and the upper-level operation unit is expressed as left_node_id(e2) = right_node_id(e1). The identifier output by the target sub-unit is the starting point identifier of the target edge e2, and the second identifier output by the upper-level operation unit is the starting point identifier right_node_id(e1) of the target edge.

[0080] Continuing with step S103, when the redundant unit contains only target sub-units related to the output target, the connection between the redundant unit and the upper-level operation unit is modified to a connection between the target sub-unit and the upper-level operation unit, thus replacing the redundant unit with the target sub-unit. The target sub-unit is directly connected to the upper-level operation unit, obtaining the intermediate execution plan. This method preserves operations related to the output target, reduces redundant scans, and avoids unnecessary operation units.

[0081] Step S104: Based on the intermediate execution plan, perform the redundancy unit confirmation step and the execution plan update step again until the preset conditions are met to obtain the target execution plan, and query the graph database according to the target execution plan.

[0082] Based on the intermediate execution plan obtained in step S103, the redundant unit confirmation step (S103) and the execution plan update step (S103) are repeated on the intermediate execution plan. Redundant units in the execution plan are continuously eliminated and the execution plan is updated until no redundant units are found in the redundant unit confirmation step (S102). At this point, the current execution plan is the target plan, completing the optimization of the initial execution plan. The graph database queries the graph database based on the target execution plan and returns the output target.

[0083] The target execution plan is obtained by eliminating redundant units and optimizing the execution plan through steps S101 to S104 described above. Experiments were conducted on the sf100, sf300, and sf1000 datasets of the LDBC SNB (Social Network Benchmark). Using the graph database query method of this application, when redundant units are eliminated, the execution plan no longer needs to scan all the data in the dataset to obtain the target data, thus reducing the number of queries required in the execution plan and improving query efficiency.

[0084] In another embodiment, Figure 3 This is a flowchart illustrating the steps of updating an execution plan in a graph database according to an exemplary embodiment, such as... Figure 3 As shown, according to the query command MATCH (p1:Person)-[e1:KNOWS]->(p2:Person)-[e2:KNOWS]->(p3:Person) RETURN p3, the initial execution plan is obtained. `plan` is the execution plan, `details` are the specific steps in the execution plan, `Project` is the output content, `HashJoin` is the operation unit, `Edgescan` is the edge scanning sub-unit, and `Nodescan` is the node scanning sub-unit. The redundant unit, i.e., `Join2`, is determined through step S102. In the redundant unit `Join2`, the edge scanning sub-unit is the target sub-unit related to the output target, and the node scanning sub-unit is the redundant operation sub-unit unrelated to the output target. The node scanning sub-unit is replaced by the edge scanning sub-unit; that is, `ldbc.Person, p2` is replaced by `ldbc.KNOWS, e2{}`. Modify the internal connection relationship of the redundant unit Join2, changing it from left_node_id(e2)=element_id(p2) to left_node_id(e2)=left_node_id(e2).

[0085] Since the internal connection relationship of the redundant unit Join2 has been rewritten, the connection relationship of the upper-level operation unit Join3, which is connected to the redundant unit Join2, is also updated, from element_id(p2)=right_node_id(e1) to left_node_id(e2)=right_node_id(e1). At this time, the redundant unit Join2 has been eliminated, and an intermediate execution plan is obtained.

[0086] Figure 4 This is a schematic diagram illustrating a target execution plan according to an exemplary embodiment, such as... Figure 4 As shown, based on the intermediate execution plan, the redundant unit Join1 is reconfirmed, and the redundant unit Join1 is eliminated by scanning the edge sub-units to obtain the target execution plan.

[0087] In summary, the graph data query method provided in this application eliminates operations unrelated to the output target in redundant units by identifying redundant units in the initial execution plan, replacing them with target sub-units related to the output target, and adjusting the connections of upper-level operation units connected to the redundant units. This reduces the steps of scanning irrelevant data in the execution plan and decreases the amount of scanning. Furthermore, the target execution plan retains only operations related to the output target, simplifying the execution steps and reducing computational load. When the target execution plan is obtained using the above method, the graph data is queried based on the target execution plan, which improves the query efficiency of the graph database.

[0088] Secondly, embodiments of this application provide a graph database query device. Figure 5 This is a block diagram illustrating a graph database query apparatus according to an exemplary embodiment. Figure 5 As shown, the graph database query device includes: a graph database query device, characterized in that it includes:

[0089] The execution plan determination module is used to determine the output target and the initial execution plan based on the query command. The initial execution plan includes several operation units connected in the execution order.

[0090] The redundancy unit identification module is used to identify redundancy units. The steps are as follows: In the initial execution plan, the operation units are traversed in the execution order, the first operation unit that meets the preset redundancy conditions is identified as the redundancy unit, and the current traversal is stopped.

[0091] The execution plan update module is used to update the execution plan steps: In the redundant unit, the target sub-unit related to the output target is identified. In the initial execution plan, the connection between the redundant unit and the upper-level operation unit is modified to the connection between the target sub-unit and the upper-level operation unit to obtain the intermediate execution plan.

[0092] The query module is used to reconfirm redundant unit steps and update execution plan steps based on intermediate execution plans until the target execution plan is obtained under preset conditions, and then query the graph database based on the target execution plan.

[0093] In summary, the graph database query apparatus provided in this application eliminates operations unrelated to the output target in redundant units by identifying redundant units in the execution plan, determining target sub-units related to the output target within the redundant units, and replacing the connections of redundant units with connections between target sub-units and upper-level operation pages. Only operation sub-units related to the output target are retained. By repeatedly executing the steps of identifying redundant units and updating the execution plan, the initial execution plan is updated to obtain the target execution plan. As a result, when querying the graph database by executing the target execution plan, redundant operations are no longer executed, thereby reducing the amount of data scanning and computation in the graph database and improving the query efficiency of the graph database.

[0094] It should be noted that the graph database query device provided in this embodiment is used to implement the above-described embodiments, and details already described will not be repeated. As used above, terms such as "module," "unit," and "subunit" can refer to a combination of software and / or hardware that performs a predetermined function. Although the device described in the above embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.

[0095] Thirdly, embodiments of this application provide an electronic device, Figure 6 This is a block diagram illustrating an electronic device according to an exemplary embodiment. (e.g.) Figure 6 As shown, the electronic device may include a processor 81 and a memory 82 storing computer program instructions.

[0096] Specifically, the processor 81 may include a central processing unit (CPU), an application specific integrated circuit (ASIC), or one or more integrated circuits that can be configured to implement the embodiments of this application.

[0097] The memory 82 may include a mass storage device for data or instructions. For example, and not limitingly, the memory 82 may include a hard disk drive (HDD), a floppy disk drive, a solid-state drive (SSD), flash memory, an optical disk drive, a magneto-optical disk drive, magnetic tape, or a Universal Serial Bus (USB) drive, or a combination of two or more of these. Where appropriate, the memory 82 may include removable or non-removable (or fixed) media. Where appropriate, the memory 82 may be internal or external to a data processing device. In a particular embodiment, the memory 82 is non-volatile memory. In a particular embodiment, the memory 82 includes read-only memory (ROM) and random access memory (RAM). Where appropriate, the ROM may be a mask-programmed ROM, a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), an electrically alterable read-only memory (EAROM), or flash memory, or a combination of two or more of these. Where appropriate, the RAM can be Static Random-Access Memory (SRAM) or Dynamic Random-Access Memory (DRAM). DRAM can be Fast Page Mode Dynamic Random-Access Memory (FPMDRAM), Extended Data Out Dynamic Random-Access Memory (EDODRAM), Synchronous Dynamic Random-Access Memory (SDRAM), etc.

[0098] The memory 82 can be used to store or cache various data files that need to be processed and / or communicated, as well as possible computer program instructions executed by the processor 81.

[0099] The processor 81 implements any of the graph database query methods described in the above embodiments by reading and executing computer program instructions stored in the memory 82.

[0100] In one embodiment, the graph database query device may further include a communication interface 83 and a bus 80. Wherein, as... Figure 6 As shown, the processor 81, memory 82, and communication interface 83 are connected through bus 80 and complete communication with each other.

[0101] The communication interface 83 is used to enable communication between the various modules, devices, units, and / or equipment in the embodiments of this application. The communication interface 83 can also enable data communication with other components such as external devices, image / data acquisition devices, databases, external storage, and image / data processing workstations.

[0102] Bus 80 includes hardware, software, or both, that couples the components of the graph database query device together. Bus 80 includes, but is not limited to, at least one of the following: data bus, address bus, control bus, expansion bus, and local bus. For example, and not as a limitation, bus 80 may include an Accelerated Graphics Port (AGP) or other graphics bus, an Extended Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a Hyper Transport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an InfiniBand interconnect, a Low Pin Count (LPC) bus, a memory bus, a Micro Channel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local Bus (VLB) bus, or other suitable buses, or a combination of two or more of these. Where appropriate, bus 80 may include one or more buses. Although specific buses are described and illustrated in the embodiments of this application, this application considers any suitable bus or interconnection.

[0103] Fourthly, embodiments of this application provide a computer-readable storage medium having a program stored thereon, which, when executed by a processor, implements the graph database query method provided in the first aspect.

[0104] The readable storage medium may be more specifically adopted, including but not limited to: portable disk, hard disk, random access memory, read-only memory, erasable programmable read-only memory, optical storage device, magnetic storage device, or any suitable combination thereof.

[0105] In a possible implementation, the present invention can also be implemented as a program product comprising program code, which, when the program product is run on a terminal device, is used to cause the terminal device to perform the steps of implementing the graph database query method provided in the first aspect.

[0106] The program code for executing the present invention can be written in any combination of one or more programming languages. The program code can be executed entirely on the user device, partially on the user device, as a standalone software package, partially on the user device and partially on a remote device, or entirely on a remote device.

[0107] The technical features of the above-mentioned embodiments can be combined arbitrarily. In order to make the description concise, not all possible combinations of the technical features in the above-mentioned embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0108] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.

Claims

1. A graph database query method, characterized in that, include: The output target and initial execution plan are determined based on the query command. The initial execution plan includes several operation units connected in execution order. Redundant unit identification step: Traverse the operation units according to the execution order, identify the first operation unit that meets the preset redundancy condition as the redundant unit, and stop the current traversal; Update execution plan steps: In the redundant unit, determine the target sub-unit related to the output target, modify the connection between the redundant unit and the upper-level operation unit in the initial execution plan to the connection between the target sub-unit and the upper-level operation unit, and obtain the intermediate execution plan; Based on the intermediate execution plan, the confirmation of redundant units and the update of execution plan are performed again until the preset conditions are met to obtain the target execution plan. The graph database is then queried according to the target execution plan. The operation unit includes: a node scanning subunit, configured to determine the target node of the current operation unit according to the query instruction, scan all nodes in the graph database, and output the node identifier of the target node when the target node is scanned; and an edge scanning subunit, configured to determine the target relationship of the target node in the current operation unit according to the query instruction, scan all edges related to the target node using the target node as the scanning starting point, and output the endpoint identifier and starting point identifier of the target edge when a target edge that satisfies the target relationship is scanned. The connection between the target subunit and the upper-level operation unit specifically satisfies the condition that the data pointed to by the identifier output by the target subunit is the same as the data pointed to by the starting point identifier of the upper-level operation. The step of modifying the connection between the redundant unit and the upper-level operation unit to the connection between the target subunit and the upper-level operation unit includes: determining a first identifier output by the redundant unit and a second identifier output by the upper-level operation unit based on the connection between the redundant unit and the upper-level operation unit, wherein the first identifier and the second identifier refer to the same data; determining a third identifier of the target subunit, and modifying the first identifier with the third identifier to realize the connection between the target subunit and the upper-level operation unit.

2. The graph database query method according to claim 1, characterized in that, After determining the target subunit associated with the output target, the method further includes: Identify redundant operation subunits that are irrelevant to the output target; The redundant operation subunit is replaced by the target subunit, and the internal connection of the redundant unit is modified to be the connection of the two target subunits.

3. The graph database query method according to claim 2, characterized in that, The step of modifying the connection between the redundant unit and the upper-level operation unit to the connection between the target subunit and the upper-level operation unit includes: Based on the connection between the two target sub-units, the internal connection relationship of the redundant unit is determined; Based on the internal connection relationship, modify the connection between the redundant unit and the upper-level operation unit to obtain the connection between the target subunit and the upper-level operation unit.

4. The graph database query method according to claim 1, characterized in that, The preset redundancy condition satisfies the following conditions: The data pointed to by the endpoint identifier of the target edge is the same as the data pointed to by the point identifier of the target node, and the target node is not the output target; and / or The data pointed to by the starting point identifier of the target edge is the same as the data pointed to by the point identifier of the target node, and the target node is not the output target.

5. A graph database query device, characterized in that, include: The module for determining the initial execution plan is used to determine the output target and the initial execution plan based on the query command. The initial execution plan includes several operation units connected in execution order. The redundancy unit identification module is used to identify the redundancy unit step: in the initial execution plan, the operation units are traversed according to the execution order, the first operation unit that meets the preset redundancy condition is identified as the redundancy unit, and the current traversal is stopped; The execution plan update module is used to update the execution plan steps as follows: In the redundant unit, a target sub-unit related to the output target is determined; in the initial execution plan, the connection between the redundant unit and the upper-level operation unit is modified to the connection between the target sub-unit and the upper-level operation unit to obtain an intermediate execution plan; wherein, the operation unit includes: a node scanning sub-unit, used to determine the target node of the current operation unit according to the query instruction, scan all nodes in the graph database, and output the node identifier of the target node when the target node is scanned; and an edge scanning sub-unit, used to determine the target relationship of the target node in the current operation unit according to the query instruction, scan all edges related to the target node with the target node as the scanning starting point, and output the endpoint identifier and starting point identifier of the target edge when a target edge that satisfies the target relationship is scanned. The connection between the target subunit and the upper-level operation unit specifically satisfies the condition that the data pointed to by the identifier output by the target subunit is the same as the data pointed to by the starting point identifier of the upper-level operation. The step of modifying the connection between the redundant unit and the upper-level operation unit to the connection between the target subunit and the upper-level operation unit includes: based on the connection between the redundant unit and the upper-level operation unit, determining a first identifier output by the redundant unit and a second identifier output by the upper-level operation unit, wherein the first identifier and the second identifier refer to the same data; determining a third identifier of the target subunit, and modifying the first identifier with the third identifier to realize the connection between the target subunit and the upper-level operation unit; The query module is used to perform the confirmation of redundant units and the update of execution plan steps again based on the intermediate execution plan until the preset conditions are met to obtain the target execution plan, and then query the graph database according to the target execution plan.

6. An electronic device, characterized in that, It includes a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor, when executing the computer program, implements the graph database query method as described in any one of claims 1 to 4.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the graph database query method as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Data query method and device, electronic equipment and storage medium

    CN115640315A

  • Graph database query method based on runtime filtering

    CN120371870A