Data query method for graph database and related equipment
By designing the output results of each query operator in the graph database, including the data structure of the previous query results, and executing the query operators in the sequence, the problems of low efficiency of path traversal and infinite loops in the graph database are solved, and efficient data query is achieved.
Patent Information
- Application Number
- CN202510068760.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-15
- Publication Date
- 2025-04-18
- Estimated Expiration
- 2045-01-15
AI Technical Summary
In graph database, how to design data query methods to ensure that path traversal based on Acyclic pattern is efficient and avoid infinite loops?
By generating an execution plan that includes multiple query operators executed in sequence, the output result of each query operator contains its own query results and the query results of all previous query operators, ensuring that each query operator can check whether its results are repeated with the previous results during execution, and avoid repeated traversal.
It effectively avoids repeated traversal of nodes or edges during data query, ensures that the path traversal efficiency based on Acyclic mode is high, and efficient data query is achieved.
Smart Images

Figure CN119848284A_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of the present specification relate to the field of graph database technology, and in particular, to a data query method and related equipment for a graph database. Background Art
[0002] Graph Database is a database system specially designed for storing and querying graph data. Graph data mainly consists of nodes and edges, where nodes represent entities and edges represent the relationship between entities. Nodes and edges also have several properties, which are usually key-value pairs (KV) attached to nodes or edges to describe the characteristics of nodes or edges.
[0003] In some graph data query scenarios, it is often necessary to use an acyclic mode path traversal method to implement data query. Among them, the acyclic mode refers to a path traversal without loops, that is, the nodes and edges on the path will not appear repeatedly. This mode is very important for ensuring traversal efficiency and preventing infinite loops. In the actual execution process, data query based on the acyclic mode can be implemented by multiple operators executed in sequence. The input data that each operator depends on during execution usually comes from the output of the previous operator. Therefore, how to reasonably design the organizational structure of the data transmitted between operators to meet the query requirements of efficient data query based on the acyclic mode path traversal is an urgent problem to be solved. Summary of the invention
[0004] In view of this, one or more embodiments of the present specification provide a data query method and related equipment for a graph database.
[0005] In a first aspect, this specification provides a data query method for a graph database, the method comprising:
[0006] Generate an execution plan corresponding to a query statement for the graph database; the execution plan includes multiple query operators executed in sequence; wherein the output result of any query operator among the multiple query operators includes the query result of the query operator and the query results of all query operators executed before the query operator;
[0007] Execute the multiple query operators in sequence, and when executing a first query operator among the multiple query operators, determine whether there is a query result that is the same as the query result of the first query operator among all query results included in the output result of the second query operator; wherein the second query operator is an adjacent operator executed before the first query operator;
[0008] If not, the output result of the first query operator is generated based on the query result of the first query operator and all query results included in the output result of the second query operator.
[0009] In a second aspect, this specification provides a data query device for a graph database, the device comprising:
[0010] An execution plan generating unit, configured to generate an execution plan corresponding to a query statement for the graph database; the execution plan includes a plurality of query operators executed in sequence; wherein the output result of any query operator among the plurality of query operators includes the query result of the query operator and the query results of all query operators executed before the query operator;
[0011] a determination unit, configured to execute the plurality of query operators in sequence, and when executing a first query operator among the plurality of query operators, determine whether there is a query result identical to the query result of the first query operator among all query results included in an output result of a second query operator; wherein the second query operator is an adjacent operator executed before the first query operator;
[0012] An output result generating unit is used to, if not, generate an output result of the first query operator based on the query result of the first query operator and all query results included in the output result of the second query operator.
[0013] Accordingly, this specification also provides a computing device, including: a memory and a processor; the memory stores computer programs / instructions that can be executed by the processor; when the processor runs the computer program / instructions, it executes the data query method for the graph database described in the first aspect above.
[0014] Accordingly, the present specification also provides a computer-readable storage medium on which a computer program / instruction is stored. When the computer program / instruction is executed by a processor, the data query method for the graph database as described in the first aspect above is executed.
[0015] Accordingly, the present specification also provides a computer program product, which includes a computer program / instructions. When the computer program / instructions are executed by a processor, the data query method for the graph database as described in the first aspect above is performed.
[0016] In summary, after obtaining the query statement for the graph database, an execution plan corresponding to the query statement can be generated, and the execution plan can include multiple query operators executed in sequence. This specification designs a data structure for the output result of the operator, wherein the output result of each operator includes not only its own query result, but also the query results of all operators executed before it. In this way, when the current query operator is executed in sequence, it can be determined whether there is a query result identical to the query result of the current query operator in all the query results included in the output result of the previous query operator. If not, the output result of the current query operator can be generated based on the query result of the current query operator itself and the query results of all query operators executed before, and so on, until the execution of the last query operator ends. Through the above-mentioned data structure designed for the output result of the operator, and the corresponding operator execution process, it can be effectively guaranteed that the nodes or edges that have been traversed in the data query process will not reappear, thereby meeting the needs of efficient data query based on the path traversal of the Acyclic mode. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 It is a schematic diagram of the architecture of a data query system for a graph database provided by an exemplary embodiment;
[0018] Figure 2 is a schematic diagram of a data structure of an output result provided by an exemplary embodiment;
[0019] Figure 3 It is a flowchart of a data query method for a graph database provided by an exemplary embodiment;
[0020] Figure 4 is a schematic diagram of a data structure of a query result provided by an exemplary embodiment;
[0021] Figure 5 It is a schematic diagram of graph data provided by an exemplary embodiment;
[0022] Figure 6 is a schematic diagram of a physical execution plan provided by an exemplary embodiment;
[0023] Figure 7 is a schematic diagram of an output result of a point query operator provided by an exemplary embodiment;
[0024] Figure 8 is a schematic diagram of an output result of an edge query operator provided by an exemplary embodiment;
[0025] Fig. 9 is a schematic diagram of output results of another point query operator provided by an exemplary embodiment;
[0026] Fig.10 is a schematic diagram of output results of another edge query operator provided by an exemplary embodiment;
[0027] Fig.11 is a schematic diagram of output results of another edge query operator provided by an exemplary embodiment;
[0028] Fig.12 is a schematic diagram of output results of another point query operator provided by an exemplary embodiment;
[0029] Fig.13 This is a schematic diagram of an output result of a Projection operator provided by an exemplary embodiment;
[0030] Fig.14 It is a structural schematic diagram of a data query device for a graph database provided by an exemplary embodiment;
[0031] Fig.15 It is a structural diagram of a computing device provided by an exemplary embodiment. DETAILED DESCRIPTION
[0032] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Instead, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.
[0033] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.
[0034] It should be noted that the “plurality” mentioned in this application refers to two or more than two.
[0035] In addition, the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0036] This specification provides a technical solution and designs a data structure for the output results of an operator, wherein the output results of each operator include, in addition to its own query results, the query results of all operators executed before it, so that the subsequently executed operators can accurately check whether their query results are repeated with the previous query results, thereby ensuring that the nodes or edges that have been traversed will not appear repeatedly.
[0037] In the implementation, first obtain the query statement for the graph database, and then generate an execution plan corresponding to the query statement. The execution plan may include multiple query operators executed in sequence; wherein the output result of any query operator among the multiple query operators includes the query results of all query operators executed before the query operator. Further, the multiple query operators may be executed in sequence, and when the first query operator among the multiple query operators is executed, it is determined whether there is a query result identical to the query result of the first query operator among all the query results included in the output result of the second query operator. Among them, the second query operator is an adjacent operator executed before the first query operator. Further, if it is determined that there is no query result identical to the query result of the first query operator among all the query results included in the output result of the second query operator, the output result of the first query operator may be generated based on the query result of the first query operator and all the query results included in the output result of the second query operator, and so on, until the execution of the last query operator is completed. Finally, the query result of the query statement may be generated based on the output result of the last query operator.
[0038] In the above technical solution, the execution plan corresponding to the query statement may include multiple query operators executed in sequence. This specification designs a data structure for the output result of the operator, wherein the output result of each operator includes not only its own query result, but also the query results of all operators executed before it. In this way, when the current query operator is executed in sequence, it can be determined whether there is a query result identical to the query result of the current query operator in all the query results included in the output result of the previous query operator. If not, the output result of the current query operator can be generated based on the query result of the current query operator itself and the query results of all query operators executed before, and so on, until the execution of the last query operator ends, and then the final query result of the query statement can be obtained based on the output result of the last query operator. Through the data structure designed for the output result of the operator and the corresponding operator execution process, it can be effectively guaranteed that the nodes or edges that have been traversed in the data query process will not reappear, thereby meeting the needs of efficient data query based on the path traversal of the Acyclic mode.
[0039] See also Figure 1 , Figure 1 This is a schematic diagram of the architecture of a data query system for a graph database provided by an exemplary embodiment. One or more embodiments provided in this specification may be Figure 1 The system architecture shown in the figure or a similar system architecture is specifically implemented. Figure 1 As shown, the system architecture may include a computing device 100 and a computing device 200, wherein a communication connection may be established between the computing device 100 and the computing device 200 in any possible manner, and this specification does not specifically limit this.
[0040] like Figure 1 As shown, the computing device 100 may be equipped with a server of the graph database system, and the computing device 200 may be equipped with a client of the graph database system. The user may initiate a data query to the graph database through the client in the computing device 200, and accordingly, the server in the computing device 100 may obtain a query statement for the graph database and execute a corresponding data query to generate a query result corresponding to the query statement and return it to the client, etc. This specification does not specifically limit this.
[0041] In an illustrated embodiment, after obtaining a query statement for a graph database, the computing device 100 may generate an execution plan corresponding to the query statement. The query statement may be a Graph Query Language Row (GQL) statement, specifically a GQL statement for performing data query based on path traversal in an Acyclic mode. The execution plan corresponding to the query statement may include multiple query operators executed in sequence, and the input data that each query operator relies on when executing a data query may come from the output of the previous query operator.
[0042] In an illustrated embodiment, the output result of any query operator among the multiple query operators may include the query result of the query operator and the query results of all query operators executed before the query operator. Figure 2 , Figure 2 FIG. 1 is a schematic diagram of a data structure of an output result provided by an exemplary embodiment. Figure 2 As shown, the output result of each query operator includes not only its own query result, but also the query results of all query operators executed before the query operator. In an embodiment shown, the multiple query results included in the output result can be sorted according to the order in which they are generated (or the order in which the query operators are executed). For example, the leftmost query result can be the query result of the most recent query operator, and the query results on the left and right can be the query results of the first query operator executed. This specification does not make specific limitations on this.
[0043] Further, the computing device 100 may execute multiple query operators in sequence based on the generated execution plan. When executing the first query operator among the multiple query operators, it may be determined whether there is a query result identical to the query result of the first query operator among all query results included in the output result of the second query operator. For details, please refer to the following Figure 3 The description of the corresponding embodiment is not repeated here. The second query operator is an adjacent operator executed before the first query operator.
[0044] Furthermore, if it is determined that there is no query result identical to the query result of the first query operator among all the query results included in the output result of the second query operator, the output result of the first query operator can be generated based on the query result of the first query operator and all the query results included in the output result of the second query operator, and so on, until the execution of the last query operator is completed.
[0045] Finally, based on the output result of the last query operator, the final query result of the query statement can be generated and returned to the user, which is not specifically limited in this specification.
[0046] As described above, this specification has reasonably designed the data structure of the output results of the operators, wherein the output results of each operator include, in addition to its own query results, the query results of all operators executed before it, so that the subsequently executed operators can accurately check whether their query results are repeated with the previous query results, thereby ensuring that the traversed nodes or edges will not appear repeatedly, thereby meeting the requirements of efficient data query based on the path traversal of the Acyclic mode.
[0047] In an illustrated embodiment, the computing device 100 may be a smart wearable device, a smart phone, a tablet computer, a laptop computer, a desktop computer, etc. having the above functions, and this specification does not specifically limit this. In an illustrated embodiment, the computing device 200 may be a desktop computer, a server, or a server cluster composed of multiple servers, etc. having the above functions, and this specification does not specifically limit this.
[0048] It should be noted that Figure 1 The system architecture shown is for illustrative purposes only. In some possible implementations, the data query system for the graph database may include more or fewer devices than those shown in the figure, and this specification does not make any specific limitations on this.
[0049] See also Figure 3 , Figure 3 This is a flowchart of a data query method for a graph database provided by an exemplary embodiment. This method can be applied to Figure 1 The graph database system shown in FIG. 1 can be specifically applied to the computing device 100 in the graph database system. Figure 3 As shown, the method may specifically include the following steps S301 to S303.
[0050] Step S301, generating an execution plan corresponding to the query statement for the graph database; the execution plan includes multiple query operators executed in sequence; wherein the output result of any query operator among the multiple query operators includes the query result of the query operator and the query results of all query operators executed before the query operator.
[0051] In an illustrated embodiment, the graph database system may first obtain a query statement for the graph database, then parse the query statement, and generate an execution plan corresponding to the query statement based on the parsing result. The query statement may be a GQL statement for data query based on the path traversal of the Acyclic mode. The generated execution plan corresponding to the query statement may specifically be a physical execution plan. In an illustrated embodiment, a logical execution plan may be generated based on the parsing result of the query statement, and then a physical execution plan may be further generated based on the logical execution plan. This specification does not specifically limit this.
[0052] It should be noted that the physical execution plan is usually a tree composed of multiple operators, which may include multiple query operators executed in sequence. The input data that each query operator relies on when executing data query can come from the output of the previous query operator.
[0053] In an illustrated embodiment, the output result of any query operator among the multiple query operators may include the query result of the query operator and the query results of all query operators executed before the query operator. The query result of each query operator may include graph data queried from the graph database, including node data or edge data.
[0054] In an illustrated embodiment, the multiple query operators may include a point query operator (VertexGet) for querying node data and an edge query operator (Traverse) for querying edge data. Accordingly, the query result of the point query operator may include the queried node data, such as several attribute values of the node, such as id: A, name: Zhang San, phone: 12345, etc.; the query result of the edge query operator may include the queried edge data, such as the starting point id (src_id) of the edge: A, the end point id (dst_id): B, the edge type (edge_type): transfer, etc., which is not specifically limited in this specification.
[0055] In an illustrated embodiment, in addition to the above-mentioned multiple query operators, the physical execution plan may also include a projection operator executed after the last query operator, such as a Projection operator, which is used for expression calculation, for example, it can be used to return the final query result of the query statement, and this specification does not make specific limitations on this.
[0056] Step S302: execute the multiple query operators in sequence, and when executing the first query operator among the multiple query operators, determine whether there is a query result that is the same as the query result of the first query operator among all the query results included in the output result of the second query operator; wherein the second query operator is an adjacent operator executed before the first query operator.
[0057] Furthermore, after generating a physical execution plan corresponding to the query statement, the graph database system may execute multiple query operators included in the physical query plan in sequence.
[0058] In an illustrated implementation, the execution process of the physical execution plan may include cyclically calling a getNextRow method to obtain output results.
[0059] In an illustrated embodiment, in the process of sequentially executing multiple query operators, when the first query operator among the multiple query operators is executed, the output result of the second query operator can be obtained. Exemplarily, the first query operator can obtain the output result of the second query operator by calling the getNextRow method of the second query operator.
[0060] The second query operator is an adjacent operator executed before the first query operator, and the output result of the second query operator includes the query result of the second query operator and the query results of all query operators executed before the second query operator. It should be noted that the "first" and "second" in this specification are only used to distinguish different objects, and do not directly limit their order or priority.
[0061] Furthermore, after obtaining the output result of the second query operator, based on the query result of the second query operator contained in the output result of the second query operator, further data query can be performed on the graph database to obtain the query result of the first query operator.
[0062] In an illustrated embodiment, if the second query operator is a point query operator and the first query operator is an edge query operator, the first query operator can further query the edge data associated with the node data from the graph database based on the node data included in the query result of the second query operator. In other words, the first query operator further performs path traversal using the node queried by the second query operator as input data to traverse to the edge connected to the node, that is, the edge starting from the node.
[0063] In an illustrated embodiment, if the second query operator is an edge query operator and the first query operator is a point query operator, the first query operator can further query the point data associated with the edge data from the graph database based on the edge data included in the query result of the second query operator. In other words, the first query operator further performs path traversal using the edge queried by the second query operator as input data to traverse to the point connected to the edge, that is, the end point of the edge.
[0064] Further, after obtaining the query result of the first query operator, it may be determined whether there is a query result identical to the query result of the first query operator among all the query results included in the output result of the second query operator.
[0065] It should be noted that this specification does not specifically limit the specific implementation method of determining whether there are identical query results.
[0066] In one illustrated embodiment, in addition to the above-mentioned node data / edge data, the query results of any query operator may also include the operator identifier of the query operator (which can be recorded as Flag) and metadata corresponding to the graph data queried by the query operator (which can be recorded as GraphKey).
[0067] Among them, the operator identifier can be used to indicate that the operator type of the query operator is a point query operator or an edge query operator. Exemplarily, the value of the operator identifier can be 0, 1 or 2. The value of the operator identifier is 0, which can indicate that the query operator is neither a point query operator nor an edge query operator; the value of the operator identifier is 1, which can indicate that the query operator is a point query operator; the value of the operator identifier is 2, which can indicate that the query operator is an edge query operator. Exemplarily, a value of 1 can be used to represent an edge query operator, and a value of 2 can be used to represent a point query operator. This specification does not make specific limitations on this. In the following embodiments, the example of using a value of 1 to represent a point query operator and a value of 2 to represent an edge query operator is used for explanation.
[0068] The metadata corresponding to the graph data can be divided into metadata corresponding to the node data and metadata corresponding to the edge data. In the query results of the point query operator, the metadata corresponding to the node data can include the node type (type) and the node identifier (such as the node id), which can be recorded as<id,vertex_type> , which is not specifically limited in this specification. In the query result of the edge query operator, the metadata corresponding to the edge data may include the edge type, the edge start point identifier and the edge end point identifier, which can be recorded as<src_id,edge_type,dst_id> , this manual does not make any specific limitation on this.
[0069] In one illustrated embodiment, see Figure 4 , Figure 4 FIG. 1 is a schematic diagram of a data structure of a query result provided by an exemplary embodiment. Figure 4 As shown in , the query results of the query operator can be divided into two parts: header and graph data. Figure 4 As shown, the Header may include the above-mentioned operator identifier and metadata, and the Data may include multiple storage units (cells). Each Cell may store graph data in the form of KV. Taking node data as an example, one cell stores key: id, value: A, and another cell stores key: name, value: Zhang San, and so on. This specification does not make any specific limitations on this.
[0070] based on Figure 4 The data structure of the query result shown in the figure, if the first query operator is a point query operator, when determining whether there is a query result identical to the query result of the first query operator among all the query results included in the output result of the second query operator, it may specifically include:
[0071] Traverse all query results included in the output result of the second query operator, and for the target query result of the currently traversed target query operator, determine whether the operator type indicated by the operator identifier included in the target query result is a point query operator. In an illustrated embodiment, if the operator type indicated by the operator identifier included in the target query result is not a point query operator (for example, the value of the operator identifier is 0 or 2), then traverse to the next query result. In an illustrated embodiment, if the operator type indicated by the operator identifier included in the target query result is a point query operator (for example, the value of the operator identifier is 1), then further determine whether the target query result is the same as the query result of the first query operator. Specifically, the metadata corresponding to the node data queried by the target query operator and contained in the target query result can be read first; then, it can be determined whether the node type and node identifier contained in the metadata correspond one-to-one to the node type and node identifier contained in the query result of the first query operator. If so, it is determined that the target query result is the same as the query result of the first query operator, and the traversal is ended; if not, it is determined that the target query result is different from the query result of the first query operator, and then traversal is continued to the next query result, and so on.
[0072] based on Figure 4 The data structure of the query result shown in the figure, if the first query operator is an edge query operator, when determining whether there is a query result identical to the query result of the first query operator among all the query results included in the output result of the second query operator, it may specifically include:
[0073] Traverse all query results included in the output result of the second query operator, and for the target query result of the currently traversed target query operator, determine whether the operator type indicated by the operator identifier included in the target query result is an edge query operator. In an illustrated embodiment, if the operator type indicated by the operator identifier included in the target query result is not an edge query operator (for example, the value of the operator identifier is 0 or 1), then traverse to the next query result. In an illustrated embodiment, if the operator type indicated by the operator identifier included in the target query result is an edge query operator (for example, the value of the operator identifier is 2), then further determine whether the target query result is the same as the query result of the first query operator. Specifically, the metadata corresponding to the edge data queried by the target query operator and contained in the target query result can be read first; then, it can be determined whether the edge type, the starting point identifier and the end point identifier contained in the metadata correspond one-to-one to the edge type, the starting point identifier and the end point identifier contained in the query result of the first query operator. If so, it is determined that the target query result is the same as the query result of the first query operator, and the traversal is ended; if not, it is determined that the target query result is different from the query result of the first query operator, and then traversal is continued to the next query result, and so on.
[0074] In addition, it should be noted that when each query operator executes a data query based on graph path traversal, it may obtain one query result or multiple different query results (that is, it may traverse to one node / edge or multiple nodes / edges). Correspondingly, the output result of each query operator may be one output result or multiple output results corresponding to the multiple query results it has queried. In an illustrated embodiment, each output result of the query operator can be recorded as GQLRow, and each query result contained in the output result can be recorded as ContigousRow, where Row means a row, representing one result.
[0075] Based on this, when the first query operator obtains the output result of the second query operator, it can specifically include: sequentially obtaining each of the multiple output results of the second query operator. Accordingly, the above step S302 and the following step S303 are executed for each output data obtained.
[0076] In an illustrated embodiment, if a query result that is the same as the query result of the first query operator exists among all the query results contained in a certain output result of the second query operator currently obtained, the next output result of the multiple output results of the second query operator can be further obtained, and so on, until the last output result of the second query operator is obtained.
[0077] In an illustrated implementation, if all query results included in each output result of the second query operator include a query result that is the same as the query result of the first query operator, it can be determined that the final query result of the query statement is empty.
[0078] Step S303: If not, generating the output result of the first query operator based on the query result of the first query operator and all query results included in the output result of the second query operator.
[0079] In an illustrated embodiment, if it is determined that there is no query result identical to the query result of the first query operator among all the query results included in the output result of the second query operator, the output result of the first query operator can be generated based on the query result of the first query operator and all the query results included in the output result of the second query operator.
[0080] In an illustrated embodiment, if the second query operator generates multiple output results, then after generating an output result, the first query operator can further obtain the next output result of the multiple output results of the second query operator and perform similar operations, and so on, until the last output result of the second query operator is obtained, the execution of the first query operator ends, and so on, until the last query operator is executed.
[0081] Furthermore, after the execution of the last query operator in the physical execution plan is completed, the output result of the last query operator can be obtained, and based on the output result of the last query operator, the final query result of the query statement is generated. It should be understood that the output result of the last query operator includes the query results of all query operators in the physical execution plan.
[0082] In an illustrated embodiment, when generating the final query result of a query statement based on the output result of the last query operator, it can specifically include: obtaining the query result of the last query operator contained in the output result of the last query operator; then, reading the node data or edge data contained in the query result of the last query operator, and using the node data or edge data as the final query result of the query statement.
[0083] In one illustrated embodiment, the physical execution plan may also include a Projection operator executed after the last query operator. Accordingly, the Projection operator may obtain the output result of the last query operator, extract the node data or edge data contained in the data part, and generate a corresponding output result based on the node data or edge data. Furthermore, the physical execution plan may eventually extract the node data or edge data from the output result of the Projection operator as the query result, and return it to the user, etc., so this specification does not make specific limitations on this.
[0084] The following will illustrate the data query method for the graph database provided in this specification through specific examples.
[0085] In one illustrated embodiment, see Figure 5 , Figure 5 This is a schematic diagram of graph data provided by an exemplary embodiment. Figure 5 As shown, the graph data contains multiple nodes, namely user A, user B and user C. There are two directed edges between user A and user B, and the edge type is transfer. User A→user B means user A transfers to user B, and user B→user A means user B transfers to user A. There is one directed edge between user B and user C, and the edge type is transfer. User B→user C means user B transfers to user C.
[0086] In one illustrated implementation, the user's current data query requirement may be to query which users' accounts the money transferred from user A reaches after two hops, and user A itself must be excluded from the result, that is, the final correct query result should only include user C.
[0087] In an illustrated embodiment, the above data query requirement can be implemented using the path traversal method of the Acyclic mode. Exemplarily, the query statement using the path traversal method of the Acyclic mode in the graph query language to implement the above data query requirement can be as follows:
[0088] MATCH ACYCLIC(a:User where id(a)='A')-[r1:transfer]->(b:User)-[r2:transfer]->(x:User)RETURN x.id;
[0089] The syntax of the above query statement can be divided into two parts: MATCH and RETURN.
[0090] The MATCH part includes: MATCH ACYCLIC(a:User where id(a)='A')-[r1:transfer]->(b:User)-[r2:transfer]->(x:User), where a, b, and x are variables. The MATCH part is used to describe the path to be matched in the graph. Specifically, the starting node of the path is node a, and the id of a is 'A'. Then, starting from node a, it reaches node b through the 1-degree transfer edge, and node b reaches node x through the transfer edge. In this process, all paths that meet the conditions will be matched. The keyword ACYCLIC is used to indicate that there cannot be repeated edges and points in the matched path.
[0091] The RETURN part includes: RETURN x,id, which is used to output the id attribute of node x in each path matched by the MATCH part.
[0092] Further, after obtaining the above query statement, the graph database system can parse the query statement and generate a physical execution plan corresponding to the query statement based on the parsing result. Figure 6 , Figure 6 FIG. 1 is a schematic diagram of a physical execution plan provided by an exemplary embodiment. Figure 6 As shown, the physical execution plan generated based on the above query statement may include multiple operators executed in sequence, for example, including a VertexGet(a) operator, a Traverse(r1) operator, a VertexGet(b) operator, a Traverse(r2) operator, a VertexGet(x) operator, and a Projection(x,id) operator.
[0093] Next, we will combine Figure 6 The physical execution plan shown explains the execution process of each operator.
[0094] 1. Execution process of VertexGet(a) operator
[0095] The VerterxGet(a) operator is a leaf node in the entire physical execution plan. The user specifies the condition for querying the User point table in the statement: Where id(a) = 'A', so the VerterxGet(a) operator can directly query the point data with id equal to 'A' in the User point table, obtain the query result of the VerterxGet(a) operator, and generate the corresponding output result (GQLRow).
[0096] For example, see Figure 7 , Figure 7FIG. 1 is a schematic diagram of the output result of a point query operator provided by an exemplary embodiment. Figure 7 As shown in the figure, the output result of the VerterxGet(a) operator may include the query result (ContigousRow) of the VerterxGet(a) operator. The operator identifier value in the Haeder of the query result of the VerterxGet(a) operator is 1, indicating that the VerterxGet(a) operator is a point query operator. The Haeder also includes metadata corresponding to the queried point data.<A,User> ; The Data of the query result contains the queried point data, which may include Key:id, Value:A, etc.
[0097] 2. Execution process of Traverse(r1) operator
[0098] First, the getNextRow method of the VerterxGet(a) operator is called to obtain the output result of the VerterGet(a) operator, where the VerterxGet(a) operator is a child operator of the Traverse(r1) operator. The obtained output result can be called oneChildResult, which is not specifically limited in this specification.
[0099] Then, extract the id value (i.e. A) in the Data of the query result of the VerterGet(a) operator contained in the output result of the VerterGet(a) operator, and use the variable src_id to represent it. Then, use src_id as the starting point of the edge to query the transfer edge table to obtain the query result of the Traverse(r1) operator. In one illustrated embodiment, the operator identifier in the Haeder of the query result of the Traverse(r1) operator is 2, indicating that the Traverse(r1) operator is an edge query operator. The Haeder also contains metadata corresponding to the queried edge data.<A,transfer,B> ; The Data of the query result contains the queried edge data, which may include Key: dst_id, Value: B, etc.
[0100] Then, traverse each query result contained in the output result of the VerterGet(a) operator. If the operator identifier in the Header of the currently traversed query result is 2, extract the metadata in the Header and determine whether the metadata matches the query result in the Traverse(r1) operator.<A,transfer,B> Are they the same? If not, traverse to the next query result. If so, it indicates that the edge<A,transfer,B> It has been accessed, and the currently obtained output result cannot generate new results. Then the Traverse(r1) operator can then obtain the next output result of the VerterGet(a) operator.
[0101] like Figure 7 As shown in the figure, since the only output result of the VerterGet(a) operator only contains the query result of the VerterGet(a) operator, and the operator identifier value in the Header of the query result of the VerterGet(a) operator is 1, it indicates that the edge<A,transfer,B> If the node has not been visited, the Traverse(r1) operator can generate an output result based on its own query result and the query result of the VerterGet(a) operator.
[0102] For example, see Figure 8 , Figure 8 FIG. 1 is a schematic diagram of an output result of an edge query operator provided by an exemplary embodiment. Figure 8 As shown in the figure, the output result of the Traverse(r1) operator includes the query result of the Traverse(r1) operator and the query result of the VerterGet(a) operator from left to right. For details, please refer to Figure 8 , which will not be elaborated here.
[0103] 3. Execution process of VertexGet(b) operator
[0104] First, the getNextRow method of the Traverse(r1) operator is called to obtain the output result of the Traverse(r1) operator, where the Traverse(r1) operator is a child operator of the VertexGet(b) operator.
[0105] Then, extract the dst_id value (i.e., B) in the Data of the query result of the Traverse(r1) operator contained in the output result of the Traverse(r1) operator, and use the variable vid to represent it. Then, use vid as the id attribute value of the point to query the User point table to obtain the query result of the VertexGet(b) operator. In an illustrated embodiment, the operator identifier in the Haeder of the query result of the VertexGet(b) operator is 1, indicating that the VertexGet(b) operator is a point query operator. Haeder also contains metadata corresponding to the queried point data.<B,User> ; The Data of the query result contains the queried point data, which may include Key:id, Value:B, etc.
[0106] Then, traverse each query result contained in the output result of the Traverse(r1) operator. If the operator identifier in the Header of the currently traversed query result is 1, extract the metadata in the Header and determine whether the metadata matches the query result of the VertexGet(b) operator.<B,User> Are they the same? If not, traverse to the next query result. If so, indicate the point<B,User> It has been accessed, and the currently obtained output result cannot generate new results. Then the VertexGet(b) operator can continue to obtain the next output result of the Traverse(r1) operator.
[0107] like Figure 8 As shown in the figure, in the only output result of the Traverse(r1) operator, only the operator identifier in the Header of the VerterGet(a) operator is 1, and the value recorded in the Header is<A,User> and<B,User> Inconsistency, indicating point<B,User> If it has not been visited, the VertexGet(b) operator can generate an output result based on its own query result, the query result of the Traverse(r1) operator, and the query result of the VerterGet(a) operator.
[0108] For example, see Fig. 9 , Fig. 9 FIG. 1 is a schematic diagram of the output result of another point query operator provided by an exemplary embodiment. Fig. 9 As shown in the figure, the output result of the VertexGet(b) operator includes the query result of the VertexGet(b) operator, the query result of the Traverse(r1) operator, and the query result of the VerterGet(a) operator from left to right. For details, please refer to Fig. 9 , which will not be elaborated here.
[0109] 4. Execution process of Traverse(r2) operator
[0110] First, the getNextRow method of the VertexGet(b) operator is called to obtain the output result of the VertexGet(b) operator, where the VertexGet(b) operator is a child operator of the Traverse(r2) operator.
[0111] Then, extract the id value (i.e. B) in the Data of the query result of the VertexGet(b) operator contained in the output result of the VertexGet(b) operator, represent it using the variable src_id, and then use src_id as the starting point of the edge to query the transfer edge table to obtain the query result of the Traverse(r2) operator.
[0112] like Figure 5 As shown, there is a transfer relationship between user B and both user A and user C, so the Traverse(r2) operator can obtain two query results corresponding to user A and user C. In an embodiment shown, in the query result corresponding to user A, Haeder contains metadata corresponding to a queried edge data.<B,transfer,A> , Data includes edge data Key: dst_id, Value: A, etc. In an illustrated embodiment, in the query result corresponding to user C, Haeder also includes metadata corresponding to another edge data queried.<B,transfer,C> , Data contains edge data Key: dst_id, Value: C, etc.
[0113] Then, similar to the execution process of the Traverse(r1) operator above, the Traverse(r2) operator can traverse each query result contained in the output result of the VerterGet(b) operator.<B,transfer,A> Or side<B,transfer,C> , then the Traverse(r2) operator can generate two output results based on its own two query results, the query result of the VertexGet(b) operator, the query result of the Traverse(r1) operator, and the query result of the VerterGet(a) operator.
[0114] For example, see Fig.10 , Fig.10 FIG. 1 is a schematic diagram of another output result of an edge query operator provided by an exemplary embodiment. Fig.10As shown in the figure, in one output result of the Traverse(r2) operator, from left to right, it contains the edges queried by the Traverse(r2) operator.<B,transfer,A> For details, please refer to the corresponding query results, the query results of the VertexGet(b) operator, the query results of the Traverse(r1) operator, and the query results of the VerterGet(a) operator. Fig.10 , which will not be elaborated here.
[0115] For example, see Fig.11 , Fig.11 FIG. 1 is another schematic diagram of the output result of an edge query operator provided by an exemplary embodiment. Fig.11 As shown in the figure, in another output result of the Traverse(r2) operator, from left to right, it contains the edges queried by the Traverse(r2) operator.<B,transfer,C> For details, please refer to the corresponding query results, the query results of the VertexGet(b) operator, the query results of the Traverse(r1) operator, and the query results of the VerterGet(a) operator. Fig.11 , which will not be elaborated here.
[0116] 5. Execution process of VertexGet(x) operator
[0117] First, call the getNextRow method of the Traverse(r2) operator to obtain Fig.10 An output result of the Traverse(r2) operator is shown, where the Traverse(r2) operator is a child operator of the VertexGet(x) operator.
[0118] Then, extract Fig.10 The output result of the Traverse(r2) operator shown in the figure contains the dst_id value (i.e. A) in the Data of the query result of the Traverse(r2) operator, which is represented by the variable vid. Then, vid is used as the id attribute value of the point to query the User point table to obtain a query result of the VertexGet(x) operator, i.e.<A,User> .
[0119] Then, similar to the execution process of the VertexGet(b) operator above, when traversing Fig.10 The output result of the Traverse(r2) operator shown in the figure contains each query result, because the query result of the VerterGet(a) operator contains the same<A,User> , then the VertexGet(x) operator can then obtain Fig.11Another output result of the Traverse(r2) operator is shown.
[0120] Similarly, the VertexGet(x) operator can be Fig.11 The output result of the Traverse(r2) operator shown in the figure contains the dst_id value (i.e. C) in the Data of the query result of the Traverse(r2) operator. Query the User point table to obtain another query result of the VertexGet(x) operator, i.e.<C,User> .
[0121] Similarly, when traversing Fig.11 When the output result of the Traverse(r2) operator shown in the figure contains each query result, since each query result does not exist<C,User> , then the VertexGet(x) operator can be based on<C,User> The corresponding query results, as well as Fig.11 The query results of the Traverse(r2) operator, the query results of the VertexGet(b) operator, the query results of the Traverse(r1) operator, and the query results of the VerterGet(a) operator shown generate an output result.
[0122] For example, see Fig.12 , Fig.12 FIG. 1 is another schematic diagram of the output result of a point query operator provided by an exemplary embodiment. Fig.12 As shown in the output of the VertexGet(x) operator, from left to right, the VertexGet(x) operator query results are included.<C,User> The corresponding query results, the edges queried by the Traverse(r2) operator<B,transfer,C> For details, please refer to the corresponding query results, the query results of the VertexGet(b) operator, the query results of the Traverse(r1) operator, and the query results of the VerterGet(a) operator. Fig.12 , which will not be elaborated here.
[0123] 6. Execution process of Projection(x,id) operator
[0124] First, call the getNextRow method of the VertexGet(x) operator to obtain the output result of the VertexGet(x) operator, where the VertexGet(x) operator is a child operator of the Projection(x,id) operator.
[0125] Then, the Data part of the query result of the VertexGet(x) operator contained in the output result of the VertexGet(x) operator is extracted, and the corresponding output result is generated based on it.
[0126] For example, see Fig.13 , Fig.13 FIG. 1 is a schematic diagram of the output result of a Projection operator provided by an exemplary embodiment. Fig.13 As shown in the figure, the output result of the Projection operator only contains the query result of the Projection operator. The operator identifier value in the Haeder of the query result is 0, indicating that it is neither a point query operator nor an edge query operator. Correspondingly, the metadata in the Haeder is empty; the Data of the query result contains the point data finally queried, which may specifically include Key:id, Value:C, etc.
[0127] Furthermore, the physical execution plan can eventually be returned from the Projection operator as follows Fig.13 The data of node C is extracted from the output result shown, and the data of node C is returned to the user as the final query result of the query statement.
[0128] In summary, this specification designs a data structure of the output results of an operator, in which the output results of each operator include the query results of all operators executed before it in addition to its own query results, so that the operator executed later can accurately check whether its query results are repeated with the previous query results, thereby ensuring that the traversed nodes or edges will not appear repeatedly. The query results meet the Acyclic semantic requirements and ensure the correctness of the query results.
[0129] Corresponding to the implementation of the above method flow, the embodiment of this specification also provides a data query device for a graph database. Fig.14 , Fig.14 is a schematic diagram of a data query device for a graph database provided by an exemplary embodiment. The device 140 can be applied to Figure 1 The graph database system shown in FIG. 1 can be specifically applied to the computing device 100 in the graph database system. Fig.14 As shown, the device 140 includes:
[0130] An execution plan generating unit 1401 is used to generate an execution plan corresponding to a query statement for the graph database; the execution plan includes multiple query operators executed in sequence; wherein the output result of any query operator among the multiple query operators includes the query result of the query operator and the query results of all query operators executed before the query operator;
[0131] A determining unit 1402 is configured to execute the multiple query operators in sequence, and when executing a first query operator among the multiple query operators, determine whether there is a query result that is the same as the query result of the first query operator among all query results included in the output result of the second query operator; wherein the second query operator is an adjacent operator executed before the first query operator;
[0132] The output result generating unit 1403 is configured to, if not, generate the output result of the first query operator based on the query result of the first query operator and all query results included in the output result of the second query operator.
[0133] In an illustrated implementation manner, the determining unit 1402 is specifically configured to:
[0134] Obtaining the output result of the second query operator;
[0135] Based on the query result of the second query operator included in the output result of the second query operator, further perform data query on the graph database to obtain the query result of the first query operator;
[0136] It is determined whether there is a query result identical to the query result of the first query operator among all the query results included in the output result of the second query operator.
[0137] In an illustrated embodiment, the plurality of query operators include a point query operator for querying node data and an edge query operator for querying edge data.
[0138] In an illustrated embodiment, the query result of any query operator includes the node data or edge data queried by the query operator; the determining unit 1402 is specifically used to:
[0139] Based on the node data included in the query result of the second query operator, the edge data associated with the node data is further queried from the graph database; or, based on the edge data included in the query result of the second query operator, the node data associated with the edge data is further queried from the graph database.
[0140] In an illustrated implementation manner, the query result of any query operator further includes an operator identifier of the query operator, where the operator identifier is used to indicate that the operator type of the query operator is a point query operator or an edge query operator.
[0141] In an illustrated implementation manner, the first query operator is a point query operator, and the determining unit 1402 is specifically configured to:
[0142] Traversing all query results included in the output result of the second query operator, and determining, for the target query result of the currently traversed target query operator, whether the operator type indicated by the operator identifier included in the target query result is a point query operator;
[0143] If so, it is further determined whether the target query result is the same as the query result of the first query operator; if not, traverse to the next query result.
[0144] In an illustrated implementation manner, the first query operator is an edge query operator, and the determining unit 1402 is specifically configured to:
[0145] Traversing all query results included in the output result of the second query operator, and determining, for the target query result of the currently traversed target query operator, whether the operator type indicated by the operator identifier included in the target query result is an edge query operator;
[0146] If so, it is further determined whether the target query result is the same as the query result of the first query operator; if not, traverse to the next query result.
[0147] In an illustrated embodiment, the query result of the point query operator further includes metadata corresponding to the queried node data; wherein the metadata corresponding to the node data includes a node type and a node identifier;
[0148] The determining unit 1402 is specifically configured to:
[0149] Reading metadata contained in the target query result and corresponding to the node data queried by the target query operator;
[0150] Determine whether the node type and node identifier included in the metadata are identical to the node type and node identifier included in the query result of the first query operator in one-to-one correspondence; if so, determine that the target query result is identical to the query result of the first query operator.
[0151] In an illustrated embodiment, the query result of the edge query operator further includes metadata corresponding to the queried edge data; wherein the metadata corresponding to the edge data includes the edge type, the start point identifier and the end point identifier of the edge;
[0152] The determining unit 1402 is specifically configured to:
[0153] Reading metadata contained in the target query result and corresponding to the edge data queried by the target query operator;
[0154] Determine whether the edge type, edge starting point identifier and end point identifier contained in the metadata correspond one-to-one with the edge type, edge starting point identifier and end point identifier contained in the query result of the first query operator. If so, determine that the target query result is the same as the query result of the first query operator.
[0155] In an illustrated embodiment, the apparatus further includes a query result generating unit 1404, configured to:
[0156] Obtaining the query result of the last query operator contained in the output result of the last query operator;
[0157] The node data or edge data included in the query result of the last query operator is read, and the node data or edge data is used as the query result of the query statement.
[0158] In an illustrated embodiment, the apparatus 140 further includes a result determination unit 1405, configured to:
[0159] If there is a query result that is the same as the query result of the first query operator among all the query results included in the output result of the second query operator, it is determined that the query result of the query statement is empty.
[0160] In an illustrated embodiment, the output result of the second query operator includes at least one output result corresponding to at least one query result queried by the second query operator;
[0161] In an illustrated embodiment, the result determination unit 1405 is specifically configured to:
[0162] Obtaining each output result of at least one output result of the second query operator in sequence, and if there is a query result that is the same as the query result of the first query operator among all query results included in the currently obtained output results, further obtaining the next output result of the at least one output result;
[0163] If the query result that is the same as the query result of the first query operator exists in all the query results included in each output result of the second query operator, it is determined that the query result of the query statement is empty.
[0164] In an illustrated embodiment, the query statement is a query statement for performing data query based on path traversal in an Acyclic mode.
[0165] The implementation process of the functions and effects of each unit in the above-mentioned device 140 is specifically described in the above-mentioned embodiment, and will not be repeated here. It should be understood that the above-mentioned device 140 can be implemented by software, or by hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by the processor (CPU) of the device where it is located reading the corresponding computer program instructions into the memory and running them. From the hardware level, in addition to the CPU and memory, the device where the above-mentioned device is located usually also includes other hardware such as chips for wireless signal transmission and reception, and / or other hardware such as boards and cards for realizing network communication functions.
[0166] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the units or modules may be selected according to actual needs to achieve the purpose of the scheme of this specification. Those of ordinary skill in the art may understand and implement it without creative work.
[0167] The devices, units, and modules described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device, a vehicle-mounted computer, or a combination of any of these devices.
[0168] Corresponding to the above method embodiment, the embodiment of this specification also provides a computing device. Fig.15 , Fig.15 It is a structural diagram of a computing device provided by an exemplary embodiment. Fig.15 The computing device shown may be the above Figure 1 The computing device 100 in the graph database system is shown. Fig.15 As shown, the computing device includes a processor 1001 and a memory 1002, and may further include an input device 1004 (such as a keyboard, etc.) and an output device 1005 (such as a display, etc.). The processor 1001, the memory 1002, the input device 1004, and the output device 1005 may be connected via a bus or other means. Fig.15As shown, the memory 1002 includes a computer-readable storage medium 1003, which stores a computer program that can be executed by the processor 1001. The processor 1001 can be a CPU, a microprocessor, or an integrated circuit for controlling the execution of the above method embodiment. When the processor 1001 runs the stored computer program, it can execute the various steps of the data query method for the graph database in the embodiment of this specification, including: generating an execution plan corresponding to the query statement for the graph database; the execution plan includes multiple query operators executed in sequence; wherein the output result of any query operator among the multiple query operators includes the query results of all query operators executed before the query operator; executing the multiple query operators in sequence, and when executing the first query operator among the multiple query operators, determining whether there is a query result identical to the query result of the first query operator among all the query results included in the output result of the second query operator; wherein the second query operator is an adjacent operator executed before the first query operator; if not, then based on the query result of the first query operator and all the query results included in the output result of the second query operator, generate the output result of the first query operator, and so on, until the execution of the last query operator is completed; based on the output result of the last query operator, generate the query result of the query statement, and so on. For a detailed description of the various steps of the above-mentioned data query method for the graph database, please refer to the previous content, which will not be repeated here.
[0169] Corresponding to the above method embodiment, the embodiment of this specification also provides a computer-readable storage medium, which stores a computer program. When these computer programs are executed by the processor, they execute the various steps of the data query method for the graph database in the embodiment of this specification. Please refer to the description of the above embodiment for details, which will not be repeated here.
[0170] The above description is only a preferred embodiment of this specification and is not intended to limit this specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of this specification should be included in the scope of protection of this specification.
[0171] In a typical configuration, a terminal device includes one or more CPUs, input / output interfaces, network interfaces, and memory.
[0172] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0173] Computer readable media include permanent and non-permanent, removable and non-removable media and can store information by any method or technology. The information can be computer readable instructions, data structures, program modules or other data.
[0174] Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.
[0175] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0176] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems or computer program products. Therefore, the embodiments of this specification may take the form of complete hardware embodiments, complete software embodiments or embodiments combining software and hardware. Moreover, the embodiments of this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
Claims
1. A data query method for a graph database, characterized in that: The method comprises: Generate an execution plan corresponding to a query statement for the graph database; the execution plan includes multiple query operators executed in sequence; wherein the output result of any query operator among the multiple query operators includes the query result of the query operator and the query results of all query operators executed before the query operator; Execute the multiple query operators in sequence, and when executing a first query operator among the multiple query operators, determine whether there is a query result that is the same as the query result of the first query operator among all query results included in the output result of the second query operator; wherein the second query operator is an adjacent operator executed before the first query operator; If not, the output result of the first query operator is generated based on the query result of the first query operator and all query results included in the output result of the second query operator.
2. The method according to claim 1, characterized in that The determining whether there is a query result identical to the query result of the first query operator among all the query results included in the output result of the second query operator, comprises: Obtaining the output result of the second query operator; Based on the query result of the second query operator included in the output result of the second query operator, further perform data query on the graph database to obtain the query result of the first query operator; It is determined whether there is a query result identical to the query result of the first query operator among all the query results included in the output result of the second query operator.
3. The method according to claim 2, characterized in that The multiple query operators include a point query operator for querying node data and an edge query operator for querying edge data.
4. The method according to claim 3, characterized in that The query result of any query operator includes the node data or edge data queried by the query operator; further performing data query on the graph database based on the query result of the second query operator includes: Based on the node data included in the query result of the second query operator, the edge data associated with the node data is further queried from the graph database; or, based on the edge data included in the query result of the second query operator, the node data associated with the edge data is further queried from the graph database.
5. The method according to claim 4, characterized in that The query result of any query operator also includes an operator identifier of the query operator, where the operator identifier is used to indicate whether the operator type of the query operator is a point query operator or an edge query operator.
6. The method according to claim 5, characterized in that The first query operator is a point query operator, and determining whether there is a query result identical to the query result of the first query operator among all query results included in the output result of the second query operator includes: Traversing all query results included in the output result of the second query operator, and determining, for the target query result of the currently traversed target query operator, whether the operator type indicated by the operator identifier included in the target query result is a point query operator; If so, it is further determined whether the target query result is the same as the query result of the first query operator; if not, traverse to the next query result.
7. The method according to claim 5, characterized in that The first query operator is an edge query operator, and determining whether there is a query result identical to the query result of the first query operator among all query results included in the output result of the second query operator includes: Traversing all query results included in the output result of the second query operator, and determining, for the target query result of the currently traversed target query operator, whether the operator type indicated by the operator identifier included in the target query result is an edge query operator; If so, it is further determined whether the target query result is the same as the query result of the first query operator; if not, traverse to the next query result.
8. The method according to claim 6, characterized in that The query result of the point query operator also includes metadata corresponding to the queried node data; wherein the metadata corresponding to the node data includes the node type and the node identifier; The determining whether the target query result is the same as the query result of the first query operator includes: Reading metadata contained in the target query result and corresponding to the node data queried by the target query operator; Determine whether the node type and node identifier included in the metadata are identical to the node type and node identifier included in the query result of the first query operator in one-to-one correspondence; if so, determine that the target query result is identical to the query result of the first query operator.
9. The method according to claim 7, characterized in that: The query result of the edge query operator also includes metadata corresponding to the queried edge data; wherein the metadata corresponding to the edge data includes the edge type, the start point identifier and the end point identifier of the edge; The determining whether the target query result is the same as the query result of the first query operator includes: Reading metadata contained in the target query result and corresponding to the edge data queried by the target query operator; Determine whether the edge type, edge starting point identifier and end point identifier contained in the metadata correspond one-to-one with the edge type, edge starting point identifier and end point identifier contained in the query result of the first query operator. If so, determine that the target query result is the same as the query result of the first query operator.
10. The method according to claim 1, characterized in that The method further comprises: If there is a query result that is the same as the query result of the first query operator among all the query results included in the output result of the second query operator, it is determined that the query result of the query statement is empty.
11. The method according to claim 10, characterized in that The output result of the second query operator includes at least one output result corresponding to at least one query result queried by the second query operator; If there is a query result identical to the query result of the first query operator among all the query results included in the output result of the second query operator, determining that the query result of the query statement is empty includes: Obtaining each output result of at least one output result of the second query operator in sequence, and if there is a query result that is the same as the query result of the first query operator among all query results included in the currently obtained output results, further obtaining the next output result of the at least one output result; If the query result that is the same as the query result of the first query operator exists in all the query results included in each output result of the second query operator, it is determined that the query result of the query statement is empty.
12. The method according to claim 4, characterized in that The method further comprises: Obtaining the query result of the last query operator contained in the output result of the last query operator; The node data or edge data included in the query result of the last query operator is read, and the node data or edge data is used as the query result of the query statement.
13. The method according to any one of claims 1 to 12, characterized in that: The query statement is a query statement for performing data query based on path traversal in an Acyclic mode.
14. A data query device for a graph database, characterized in that: The device comprises: An execution plan generating unit, configured to generate an execution plan corresponding to a query statement for the graph database; the execution plan includes a plurality of query operators executed in sequence; wherein the output result of any query operator among the plurality of query operators includes the query result of the query operator and the query results of all query operators executed before the query operator; a determination unit, configured to execute the plurality of query operators in sequence, and when executing a first query operator among the plurality of query operators, determine whether there is a query result identical to the query result of the first query operator among all query results included in an output result of a second query operator; wherein the second query operator is an adjacent operator executed before the first query operator; An output result generating unit is used to, if not, generate an output result of the first query operator based on the query result of the first query operator and all query results included in the output result of the second query operator.
15. A computing device, characterized in that: include: Memory and processor; The memory has stored thereon computer programs / instructions executable by the processor; When the processor runs the computer program / instructions, it performs the method according to any one of claims 1 to 13.
16. A computer-readable storage medium, characterized in that: A computer program / instruction is stored thereon, and when the computer program / instruction is executed by a processor, the method according to any one of claims 1 to 13 is implemented.
17. A computer program product, characterized in that The computer program product comprises a computer program / instruction, and when the computer program / instruction is executed by a processor, the method according to any one of claims 1 to 13 is implemented.
Citation Information
Patent Citations
Data query method and device, storage medium and electronic equipment
CN115391426A
Data processing method and device, readable storage medium and electronic equipment
CN115982416A
Query deduplication method, query deduplication device and computer storage medium
CN118210953A
Data query method, system and device
CN119311747A
Routing SQL statements to elastic compute nodes using workload class
US11379483B1