A graph database query method, apparatus, device, and storage medium
By parsing graph query statements and performing paired filtering operations, the problems of low query efficiency and poor accuracy in graph databases are solved, and efficient and accurate query results are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-22
- Publication Date
- 2026-03-10
AI Technical Summary
Existing graph databases are inefficient and produce inaccurate results during the query process, especially when edge directions are ignored, which complicates the process.
By parsing the graph query statement, determining the edge index and node information, and performing pairwise combination and filtering operations, the query range is narrowed down to the target node.
It improves the efficiency and accuracy of graph database queries, meets diverse user query needs, and enhances user experience.
Smart Images

Figure CN115905630B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of graph database query technology, and in particular to a graph database query method, apparatus, device and storage medium. Background Technology
[0002] Graph databases are data management systems based on vertices and edges as the basic storage units, designed for efficient storage and retrieval of graph data. Graph databases belong to the category of NoSQL databases. Their data storage, retrieval, and data structure differ significantly from relational databases. Graph data structures directly store the dependencies between nodes, while relational databases and other types of NoSQL databases represent these relationships in a less direct way. Compared to traditional relational databases, graph databases can adapt to various business scenarios with a more flexible combination of vertices and edges, and can analyze complex relational networks using an efficient and concise graph query language.
[0003] However, as business scenarios become increasingly complex, vertices and edges gradually contain more attributes, meaning the information corresponding to vertices and edges becomes richer. This increased information about vertices and edges complicates the processing of business scenarios. During the query process, this reduces processing efficiency and can easily lead to inaccurate query results.
[0004] Therefore, improving the efficiency and accuracy of queries is an urgent problem that needs to be solved. Summary of the Invention
[0005] This application provides a graph database query method to improve query efficiency and accuracy.
[0006] Firstly, a graph database query method is provided, including:
[0007] The graph query statement is parsed to obtain query rules. If the query rules specify an edge starting from the graph database, at least one candidate edge associated with the edge index in the graph query statement is determined from the graph database. If the query rules specify ignoring edge direction, the corresponding pair information for each candidate edge is obtained, and the pair information is combined into pairs to obtain N candidate pair information combinations. The pair information is used to represent entities on the nodes connected by the edge, and N is an integer greater than 0. A filtering operation is performed on the N candidate pair information combinations to obtain M target pair information combinations that meet the requirements, where M is an integer less than or equal to N. Based on the M target pair information combinations, a target node is determined, and starting from the target node, a query is performed in the graph database to obtain the query result of the graph query statement.
[0008] In one possible implementation, after performing a filtering operation on the N candidate pair-point combination information to obtain M target pair-point combination information that meet the requirements, the method further includes:
[0009] In the M target point combination information, the nodes that are target entities are labeled with a first label, and the remaining entities are labeled with a second label; the step of determining the target node based on the M target point combination information includes:
[0010] If the first tag is specified in the query rule, the node where the target entity is located is taken as the target node; or if the second tag is specified in the query rule, the node where the remaining entities are located is taken as the target node; or if neither the first tag nor the second tag is specified in the query rule, the node where each entity is located is taken as the target node.
[0011] In one possible implementation, the filtering operation on the N candidate pair combination information includes:
[0012] Based on the target entity in the graph query statement, compare it with the entities in the N candidate point combination information; filter the candidate point combination information that does not contain the target entity.
[0013] In one possible implementation, obtaining the pair information corresponding to each candidate edge and combining the pair information into pairs includes:
[0014] Based on the first identifier of the first selected edge, determine the first node and the second node connected to the first selected edge; wherein the first selected edge is any one of the candidate edges; combine the first entity on the first node and the second entity on the second node into a pair.
[0015] Secondly, a graph database query device is provided, comprising: a query module, a determination module, and a combination module;
[0016] The query module is configured to parse a graph query statement to obtain query rules; if the query rules contain an edge starting from the graph database, it instructs the determination module to determine at least one candidate edge associated with the edge index in the graph database based on the edge index in the graph query statement; and if the query rules contain an edge direction ignoring parameter, it instructs the combination module to obtain the corresponding pair information for each candidate edge and combine the pair information into pairs to obtain N candidate pair information combinations; and instructs the combination module to perform a filtering operation on the N candidate pair information combinations to obtain M target pair information combinations that meet the requirements; and, based on the M target pair information combinations, it determines the target node and selects the target node from the graph database. Starting from the target node, a query is performed in the graph database to obtain the query result of the graph query statement; the determining module is used to determine at least one candidate edge associated with the edge index in the graph database according to the instruction of the query module and the edge index in the graph query statement; the combining module is used to obtain the corresponding pair information of each candidate edge according to the instruction of the query processing module, and combine the pair information into pairs to obtain N candidate pair combination information; and to perform a filtering operation on the N candidate pair combination information to obtain M target pair combination information that meet the conditions; wherein, the pair information is used to characterize the entities on the nodes connected by the edge, N is an integer greater than 0, and M is an integer less than or equal to N.
[0017] In one possible implementation, the device further includes a marking module;
[0018] The labeling module is used to label nodes that are target entities with a first label and the remaining entities with a second label in the M target point combination information.
[0019] The query module is specifically used for:
[0020] If the query rule specifies the second tag, then the node where the remaining entities are located is taken as the target node; or if the query rule specifies the first tag, then the node where the target entity is located is taken as the target node; or if the query rule does not specify the first tag or the second tag, then the node where each entity is located is taken as the target node.
[0021] In one possible implementation, the combining module is specifically used for:
[0022] Based on the target entity in the graph query statement, compare it with the entities in the N candidate point combination information; filter the candidate point combination information that does not contain the target entity.
[0023] In one possible implementation, the combining module is specifically used for:
[0024] Based on the first identifier of the first selected edge, determine the first node and the second node connected to the first selected edge; wherein the first selected edge is any one of the candidate edges; combine the first entity on the first node and the second entity on the second node into a pair.
[0025] Thirdly, an electronic device is provided, comprising:
[0026] Memory, used to store computer programs;
[0027] A processor, when executing a computer program stored in the memory, implements the method steps as described in any one of the first aspects.
[0028] Fourthly, a computer-readable storage medium is provided, wherein a computer program is stored therein, and when executed by a processor, the computer program implements the method steps as described in any one of the first aspects.
[0029] In this embodiment, the graph query statement is parsed. If the first query rule is to start from the edge in the graph database, at least one candidate edge associated with the edge index is determined from the graph database based on the edge index in the graph query statement. If the second query rule is to ignore the edge direction, the corresponding pair information of each candidate edge is obtained, and the pair information is combined in pairs to obtain N candidate pair combination information. Therefore, when the edge direction is ignored during graph query, the connection between the pairs of the same edge can be highlighted by pair combination, narrowing the subsequent query range and improving the query accuracy. Furthermore, since the N candidate pair combination information is filtered to obtain M target pair combination information that meet the conditions, the subsequent query range is further narrowed, improving the query efficiency. Moreover, since the target node is determined based on the M target pair combination information, and the query is performed in the graph database starting from the target node to obtain the query result of the graph query statement, after filtering, the specific target node can be accurately identified, the query can start from the target node, and the query result can be obtained, thereby improving the accuracy of the result.
[0030] For the various aspects of the second to fourth aspects mentioned above, and the technical effects that each aspect may achieve, please refer to the above description of the technical effects that can be achieved for the first aspect or the various possible solutions in the first aspect, which will not be repeated here. Attached Figure Description
[0031] Figure 1 This is a schematic diagram of the query results for existing queries that ignore edge directions;
[0032] Figure 2 This is a schematic diagram illustrating the application scenarios applicable to the embodiments of this application;
[0033] Figure 3 A flowchart illustrating a graph database query method provided in this application embodiment;
[0034] Figure 4 A schematic diagram illustrating the relationship between an edge and a pair of points provided in an embodiment of this application;
[0035] Figure 5 This is a schematic diagram of the structure of a graph database query device provided in an embodiment of this application;
[0036] Figure 6 This is a schematic diagram of another graph database query device provided in an embodiment of this application;
[0037] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0038] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The specific operational methods in the method embodiments can also be applied to the device embodiments or system embodiments. It should be noted that in the description of this application, "multiple" is understood as "at least two". "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. A connected to B can represent: A and B directly connected, and A and B connected through C. Furthermore, in the description of this application, terms such as "first" and "second" are used only for distinguishing the purpose of description and should not be construed as indicating or implying relative importance or order.
[0039] To better understand the embodiments of this application, some terms used in the embodiments of this application will be explained below so that those skilled in the art can understand them.
[0040] (1) A graph database is a database used to store graph structures. A graph structure may include nodes, edges and attributes, and may be called an attribute graph.
[0041] (2) Attribute graphs define a graph model. An attribute graph is a directed graph consisting of vertices, edges, labels, and properties. Vertices are also called nodes, and edges are also called relationships.
[0042] (3) A directed graph is a graph with directionality, consisting of a vertex and a set of directed edges, with each directed edge connecting to an ordered pair of vertices.
[0043] (4) A graph consists of two elements: nodes and relationships. Each node represents an entity (such as a person, place, thing, category or other data), and each relationship represents the way two nodes are associated.
[0044] (5) JanusGraph is a graph database engine. It focuses on compact graph serialization, rich graph data modeling, and efficient query execution. The graphs created by JanusGraph are based on the attribute graph model. JanusGraph uses HBase as its storage backend (i.e., the graph data is actually stored in HBase). In HBase, a row of data is a node, and a row of records contains all the attributes of that node and the edges connected to it. Each attribute and each edge is an independent storage unit (cell).
[0045] (6) HBase is a NoSQL database, a distributed, column-oriented open-source database. In HBase, a table is a collection of rows, a row is a collection of column families, a column family is a collection of columns, and a column is a collection of key-value pairs. A storage unit in HBase is called a cell, which is determined by rows and columns.
[0046] (7) TinkerPop is an open-source graph computing framework for real-time transaction processing (OLAP) and batch analytical processing (OLTP). Gremlin is the graph traversal language of TinkerPop, which enables users to perform complex graph traversal with simple code. Gremlin (graph query statement) can be used to add, delete, modify and query janusGraph.
[0047] Currently, when querying graph databases, there are two query methods: one starting from a vertex and the other starting from an edge. When a business request needs to ignore edge directions during graph queries, querying from the edges may cause certain problems.
[0048] Taking the query statement "the father of an object in City A that is in the same industry as Target Object 1" as an example, the query statement is parsed to determine the query rules as follows: First, identify the same-industry relationships that match the location of City A. Then, find the objects that contain Target Object 1 among the two connected points of the same-industry relationships. Next, find their respective fathers based on the parent-child relationship. Finally, return the query results. Figure 1As shown, the results include: peer 1, target object 1, parent of target object 1; peer 1, object 2, parent of object 2; peer 2, object 3, parent of object 3; peer 2, target object 1, parent of target object 1. This is not the query result the user needs.
[0049] If the query method is changed to start from the node where target object 1 is located, it will seriously affect performance in some cases. For example, if there are 10,000 people with the same name as target object 1, and there are 5 peer relationships in city A, if the query starts from the node where target object 1 is located, it may be necessary to iterate through all 10,000 people with the same name as target object 1 before finding the 5 peer relationships in city A, which increases the query volume of the graph database and reduces processing efficiency.
[0050] In view of this, this application provides a graph database query method to improve query efficiency and accuracy.
[0051] The embodiments of this application will now be described in detail with reference to the accompanying drawings.
[0052] The following is a brief introduction to the application scenarios to which the technical solutions of the embodiments of this application are applicable. It should be noted that the application scenarios described below are only for illustrating the embodiments of this application and are not intended to limit the scope. In specific implementation, the technical solutions provided by the embodiments of this application can be flexibly applied according to actual needs.
[0053] Figure 2 This is a schematic diagram illustrating an application scenario applicable to the embodiments of this application. As shown in the figure, the scenario mainly includes: terminal 20 and server 21. Figure 2 This is a schematic diagram illustrating an application scenario applicable to the embodiments of this application. As shown in the figure, the application scenario mainly includes: terminal 20 and server 21. Terminal 20 and server 21 can interact via a communication network, which can employ communication methods including wireless communication and wired communication.
[0054] For example, terminal 20 can access the network and communicate with server 21 through cellular mobile communication technology, which may include 5th generation mobile network (5G) technology.
[0055] For example, terminal 20 can access the network and communicate with server 21 via short-range wireless communication, which may include Wireless Fidelity (Wi-Fi) technology.
[0056] This application embodiment does not impose any limitation on the number of the above-mentioned devices, such as Figure 1As shown, only terminal 20 and server 21 are described as examples. The following is a brief introduction to each of the above devices and their respective functions.
[0057] Terminal 20 is a device that can provide users with voice and / or data connectivity, including: handheld terminal devices with wireless connectivity, vehicle-mounted terminal devices, etc.
[0058] For example, terminal 20 includes, but is not limited to: mobile phones, tablets, laptops, handheld computers, mobile internet devices (MID), wearable devices, virtual reality (VR) devices, augmented reality (AR) devices, wireless terminal devices in industrial control, wireless terminal devices in autonomous driving, wireless terminal devices in smart grids, wireless terminal devices in transportation safety, wireless terminal devices in smart cities, or wireless terminal devices in smart homes, etc.
[0059] In addition, a client related to graph database query can be installed on terminal 20. This client can be software (e.g., APP, browser, etc.), or web page, mini program, etc.
[0060] In this embodiment, terminal 20 can use the aforementioned graph database to query related clients and can interact with server 21 to exchange information related to intelligent question-and-answer scenarios. For example, terminal 20 can send a query request to server 21. After receiving the graph query statement sent by terminal 20, server 21 can further parse, process, and query the graph query statement, and then output the query result of the graph query statement.
[0061] Furthermore, server 21 can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms.
[0062] Furthermore, in this embodiment of the application, the server 21 may be equipped with a graph database query system corresponding to the client. The graph database query system is used to respond to user operations that input graph query statements, analyze and process the input graph query statements, and output the accurate results of the graph query statements.
[0063] Of course, the methods provided in the embodiments of this application are not limited to... Figure 2The application scenarios shown can also be used in other possible application scenarios, and the embodiments of this application do not impose limitations. Figure 2 The functions that each device in the application scenario shown can achieve will be described in subsequent method embodiments, and will not be elaborated on here.
[0064] To further illustrate the technical solutions provided in the embodiments of this application, a detailed description is provided below in conjunction with the accompanying drawings and specific implementation methods. Although the embodiments of this application provide method operation steps as shown in the following embodiments or drawings, the method may include more or fewer operation steps based on conventional or non-inventive methods. In steps where there is no logically necessary causal relationship, the execution order of these steps is not limited to the execution order provided in the embodiments of this application. In actual processing or when the device executes the method, it may be executed in the order shown in the embodiments or drawings, or in combination.
[0065] Figure 3 This is a flowchart illustrating a graph database query method provided in an embodiment of this application. The process can be executed by a graph database query device, which can be implemented in software, hardware, or a combination of both. As shown in the figure, the process includes the following steps:
[0066] 301: The graph query statement is parsed to obtain the query rules.
[0067] Optionally, the interaction process in this step can specifically be a terminal (such as...) Figure 2 Terminal 20 in the middle sends a message to the server (such as...) Figure 2 The server 21) sends a query request, which carries a graph query statement. When the server receives the graph query statement, it parses it and determines a series of query rules to facilitate subsequent processing and querying in the graph database.
[0068] 302: Determine if any of the above query rules start from an edge in the graph database. If yes, proceed to 303; otherwise, follow other query strategies for subsequent queries.
[0069] In this step, taking the example of querying the father of an object in City A who is in the same industry as target object 1, it can be analyzed that the optimal graph database query method in this scenario should start from the edge of the same industry relationship.
[0070] 303: Based on the edge index in the graph query statement, determine at least one candidate edge associated with the edge index from the graph database.
[0071] Taking the above query for the parent of an object in City A that is in the same row as target object 1 as the above query, the edge index is City A and the target entity is target object 1. Based on City A, multiple candidate edges (row edges) associated with City A are determined from the graph database.
[0072] In some embodiments, the information of the multiple candidate edges (e.g., edge identifier, edge relationship type, edge direction, edge pair information, etc.) can also be stored for subsequent querying. As shown in Table 1, an example table of information of edges in the same row is shown.
[0073] Table 1: Example of information for parallel edges
[0074] Side marker Side direction Point identifiers on nodes connected by edges e1 out person1 (target person 1) e1 in Person2(object2) e2 out Person3 (object 3) e2 in person1 (target person 1) e3 out Person2(object2) e3 in Person3 (object 3)
[0075] Since the graph database is partitioned based on edges, an edge is stored on two connected vertices. Therefore, as shown in Table 1, when an edge is stored on person2, the direction of the edge is out, and the corresponding vertex is person1; when an edge with the same ID is stored on person1, the direction of the edge is in, and the corresponding vertex is person2.
[0076] 304: Determine if there is an option to ignore edge direction in the query rule. If yes, proceed to 305; otherwise, follow the original query rule for subsequent queries.
[0077] Optionally, the query rules can be checked based on the Gremlin syntax used in the graph query statement to determine if edge directions are ignored. Specifically, if the Gremlin syntax used in the graph query statement includes bothV(), it indicates that the query ignores edge directions and returns a 305 error.
[0078] In some embodiments, if the Gremlin syntax used in the parsed graph query statement is outV(), it indicates that the edge direction has not been ignored, and subsequent queries need to be performed according to other query strategies. For example, when the syntax is outV(), the counterpart of the edge in the out direction is obtained, and it is determined whether the entity (counterpoint identifier) on each node is the target object 1. According to Table 1 above, it is determined that only the out direction of e1 is the target object 1, so the point person2 in the other direction of the edge e1 is taken to continue the graph query, and the query result is the parent of person2.
[0079] In other embodiments, if the Gremlin syntax used in the parsed graph query statement is inV(), it indicates that the edge direction has not been ignored, and subsequent queries need to be performed according to other query strategies. For example, when the syntax is inV(), the points in the in direction of the edge are obtained, and it is determined whether the entity on each point (node) is the target object 1 (person1). According to Table 1 above, it is determined that only the out direction of e1 is the target object 1, so the point person3 in the other direction of the e1 edge is taken to continue the graph query, and the query result is the parent of person3.
[0080] 305: Obtain the information of each candidate edge corresponding to its corresponding pair of points, and combine the information of each pair of points into pairs to obtain N candidate pair of point combination information.
[0081] This point information is used to characterize the entities on the nodes connected by the edge, where N is an integer greater than 0.
[0082] When it is determined that there are ignored edge directions in the query rules, the point information of the edges including the in direction and the out direction is obtained, as shown in Table 1 above: person1, person2, person3, person1, person2, person3.
[0083] Optionally, the information of each pair of points can be combined in pairs to obtain N candidate pair of point combination information. This can be done in the following way: based on the first identifier of the first selected edge, determine the first node and the second node connected to the first selected edge, where the first selected edge is any edge of each candidate edge; combine the first entity on the first node and the second entity on the second node into a pair.
[0084] For example, taking e1 in Table 1 above as an example, based on e1, we can determine that the first node connected to e1 is the node corresponding to person1, and the second node is the node corresponding to person2. Thus, person1 and person2 are paired up, and so on, we can obtain: Pair1<person1,person2> Pair2<person3,person1> Pair3<person2,person3> This allows for graph queries that ignore edge directions, highlighting the connections between pairs of vertices along the same edge through pairwise combinations, thus narrowing the subsequent query range and improving query efficiency. For example... Figure 4 As shown, an exemplary diagram illustrates the relationship between edges and pairs of points. Person1 and Person2 are paired based on e1, Person1 and Person3 are paired based on e2, and Person2 and Person3 are paired based on e3.
[0085] 306: Perform a filtering operation on the above N candidate point combination information to obtain M target point combination information that meet the requirements. M is an integer less than or equal to N.
[0086] Optionally, filtering can be performed on the N candidate point combinations as follows:
[0087] Based on the target entity in the graph query statement, compare it with the entities in the N candidate point combination information; filter the candidate point combination information that does not contain the target entity.
[0088] For example, the target entity is person1 (target object 1), which is related to the above Pair1.<person1,person2> Pair2<person3,person1> Pair3<person2,person3> Entity comparison in the middle determines Pair1<person1,person2> Pair2<person3,person1> This includes person1, who meets the requirements; and Pair3.<person2,person3> Excluding person1, the Pair3 can be...<person2,person3> Relevant information can be filtered, for example, deleting row information for e3 in Table 1, thereby further narrowing the scope of subsequent queries or processing and improving query efficiency.
[0089] Optionally, after performing a filtering operation on the N candidate point-to-point combinations to obtain the M target point-to-point combinations that meet the requirements, each entity can be labeled to facilitate the distinction between target objects and other objects. Specifically, in the M target point-to-point combinations, nodes that are target entities are labeled with the first label (e.g., labeled src), and the remaining entities are labeled with the second label (e.g., labeled target). For example, taking the groups (air1 and pair2) corresponding to the above-mentioned conditions e1 and e2 as an example, labeling person1 in both groups with src and person2 and person3 with target, the result is: Pair1<src:person1,target:person2> Pair2<target:person3,src:person1> This distinguishes target object 1 from objects in the same row, making it easier to further narrow down the search scope based on the tags.
[0090] 307: Based on the above M target point combination information, determine the target node, and starting from the target node, query the graph database to obtain the query results of the graph query statement.
[0091] Optionally, determining the target node can be done by checking whether a tag is specified in the above query rules. Specifically, this can include the following three cases:
[0092] Scenario 1: If the query rule specifies a first tag, then the node containing the target entity will be used as the target node. For example, if the query rule specifies src, then the node containing person1 in Pair1 and Pair2 after the above tag will be used as the target node, and subsequent query operations will be performed.
[0093] For scenario 1, the query trajectory could be: e1->person1->hasfateher->person1Fahter, e2->person1->hasfateher->person1Fahter.
[0094] Scenario 2: If a second tag is specified in the query rule, the node containing the remaining entities will be used as the target node. For example, if the query rule specifies "target", the nodes containing "person2" in Pair1 and "person3" in Pair2 will be used as target nodes for subsequent query operations.
[0095] For scenario 2, the query trajectory could be: e1->person2->hasfateher->person2Fahter, e2->person3->hasfateher->person3Fahter.
[0096] Scenario 3: If the query rule does not specify a first or second tag, the node containing each entity will be used as the target node. For example, if the query rule does not specify a tag, the nodes containing person1 and person2 in Pair1 and person1 and person3 in Pair2, as described above, will be used as the target nodes for subsequent query operations.
[0097] For scenario 3, the query trajectory could be: e1->person1->hasfateher->person1Fahter, e1->person2->hasfateher->person2Fahter, e2->person3->hasfateher->person3Fahter, e2->person1->hasfateher->person1Fahter.
[0098] In this embodiment, the newly added query rule (combining point information into pairs and labeling points for differentiation) uses a new Gremlin statement that is easy to write. Based on this new query rule, the target node can be accurately located, the query can start from the target node, and the query results can be obtained, improving the accuracy of the results and meeting different user query needs, thus improving the user experience. For example, taking the query statement "the father of the object who is traveling with the target object 1 in City A" as an example, the parsed query statement is as follows: First, obtain the relationships of people traveling with the target object 1 in City A (corresponding to...) Figure 2 (303 in the middle); then find the pairs of objects with target object 1 in the two connected points of the same line relationship. This can be understood as combining the two connected points of the same line relationship into pairs, filtering out the pairs with target object 1, and specifying a label (tagert). Then, find the parent of the pair of target object 1 according to the parent relationship. Finally, return the query results, including: same line 1, object 2, object 2 parent, and same line 2, object 3, object 3 parent.
[0099] In this embodiment, the graph query statement is parsed. If the first query rule is to start from the edge in the graph database, at least one candidate edge associated with the edge index is determined from the graph database based on the edge index in the graph query statement. If the second query rule is to ignore the edge direction, the corresponding pair information of each candidate edge is obtained, and the pair information is combined in pairs to obtain N candidate pair combination information. Therefore, when the edge direction is ignored during graph query, the connection between the pairs of the same edge can be highlighted by pair combination, narrowing the subsequent query range and improving the query accuracy. Furthermore, since the N candidate pair combination information is filtered to obtain M target pair combination information that meet the conditions, the subsequent query range is further narrowed, improving the query efficiency. Moreover, since the target node is determined based on the M target pair combination information, and the query is performed in the graph database starting from the target node to obtain the query result of the graph query statement, after filtering, the specific target node can be accurately identified, the query can start from the target node, and the query result can be obtained, thereby improving the accuracy of the result.
[0100] It should be noted that the above Figure 3 The graph database query methods shown include, but are not limited to, applications on the devices or platforms exemplified below.
[0101] Social platforms, such as product recommendations, video recommendations, content recommendations, and friend recommendations, can all make recommendations based on existing edge relationships.
[0102] Medical devices, such as intelligent diagnostics and electronic medical records, can perform intelligent diagnosis by constructing a graph database based on multidimensional data such as the patient's pathological characteristics, past medical history, and historical medications, forming a decision tree or knowledge graph.
[0103] Financial platforms, for example, can establish a graph database of customer relationships and decide whether to authorize lending based on customers' social relationships, recent transaction records, and other factors.
[0104] Based on the same technical concept, this application also provides a graph database query device, which can implement the graph database query method described above in this application.
[0105] Figure 5 This is a schematic diagram of a graph database query device provided in an embodiment of this application. As shown in the figure, the device includes: a query module 501, a determination module 502, and a combination module 503.
[0106] The query module 501 is used to parse the graph query statement to obtain query rules; if the query rules contain edges starting from the graph database, it instructs the determining module to determine at least one candidate edge associated with the edge index in the graph database according to the edge index in the graph query statement; and if the query rules contain edge direction ignoring, it instructs the combining module to obtain the corresponding pair information of each candidate edge and combine the pair information into pairs to obtain N candidate pair information; and instructs the combining module to perform a filtering operation on the N candidate pair information to obtain M target pair information that meet the conditions; and, based on the M target pair information, it determines the target node and, starting from the target node, queries the graph database to obtain the query result of the graph query statement.
[0107] The determining module 502 is configured to determine at least one candidate edge associated with the edge index from the graph database according to the instructions of the query module and the edge index in the graph query statement.
[0108] The combination module 503 is used to obtain the corresponding pair information of each candidate edge according to the instruction of the query processing module, and combine the pair information into pairs to obtain N candidate pair combination information; and to perform a filtering operation on the N candidate pair combination information to obtain M target pair combination information that meet the conditions; wherein, the pair information is used to represent the entities on the nodes connected by the edge, N is an integer greater than 0, and M is an integer less than or equal to N.
[0109] Optionally, the combination module 503 is specifically used for:
[0110] Based on the target entity in the graph query statement, compare it with the entities in the N candidate point combination information; filter the candidate point combination information that does not contain the target entity.
[0111] Optional, module 503, specifically used for:
[0112] Based on the first identifier of the first selected edge, determine the first node and the second node connected to the first selected edge; wherein the first selected edge is any one of the candidate edges; combine the first entity on the first node and the second entity on the second node into a pair.
[0113] In other embodiments, in addition to the above... Figure 5 In addition to the modules shown, a marker module may also be included. Figure 6 This is a schematic diagram of another graph database query device provided in an embodiment of this application. As shown in the figure, the device includes: a query module 501, a determination module 502, a combination module 503, and a tagging module 601. The relevant descriptions of the query module 501, the determination module 502, and the combination module 503 are as follows... Figure 5 As shown, it will not be described again here.
[0114] The tagging module 601 is used to assign a first label to nodes that are target entities and a second label to the remaining entities in the M target point combination information; so that the query module 501 is specifically used for:
[0115] If the query rule specifies the second tag, then the node where the remaining entities are located is taken as the target node; or if the query rule specifies the first tag, then the node where the target entity is located is taken as the target node; or if the query rule does not specify the first tag or the second tag, then the node where each entity is located is taken as the target node.
[0116] It should be noted that the apparatus provided in this application embodiment can implement all the method steps in the above graph database query method embodiment and can achieve the same technical effect. Here, the parts and beneficial effects that are the same as those in the method embodiment will not be described in detail.
[0117] Based on the same technical concept, this application also provides an electronic device that can realize the function of the aforementioned graph database query device.
[0118] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0119] At least one processor 701 and a memory 702 connected to at least one processor 701. In this embodiment, the specific connection medium between the processor 701 and the memory 702 is not limited. Figure 7 The example shown is the connection between processor 701 and memory 702 via bus 700. Bus 700 is... Figure 7 The connections between other components are indicated by thick lines and are for illustrative purposes only, not as limiting information. The 700 bus can be divided into address bus, data bus, control bus, etc., for ease of representation. Figure 7 The term is represented by a single thick line, but this does not imply that there is only one bus or one type of bus. Alternatively, the processor 701 can also be called a controller; there is no restriction on the name.
[0120] In this embodiment, memory 702 stores instructions executable by at least one processor 701. By executing the instructions stored in memory 702, at least one processor 701 can perform a graph database query method as described above. Processor 701 can implement... Figure 5 or Figure 6 The functions of each module in the device shown.
[0121] The processor 701 is the control center of the device. It can connect to various parts of the control device through various interfaces and lines. By running or executing instructions stored in memory 702 and calling data stored in memory 702, the processor can perform various functions and process data, thereby monitoring the device as a whole.
[0122] In one possible design, processor 701 may include one or more processing units. Processor 701 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, driver interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may also not be integrated into processor 701. In some embodiments, processor 701 and memory 702 may be implemented on the same chip; in some embodiments, they may also be implemented on separate chips.
[0123] The processor 701 can be a general-purpose processor, such as a central processing unit (CPU), digital signal processor, application-specific integrated circuit, field-programmable gate array or other programmable logic device, discrete gate or transistor logic device, or discrete hardware component, capable of implementing or executing the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the graph database query method disclosed in the embodiments of this application can be directly manifested as execution by a hardware processor, or execution by a combination of hardware and software modules within the processor.
[0124] Memory 702, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. Memory 702 may include at least one type of storage medium, such as flash memory, hard disk, multimedia card, card-type memory, random access memory (RAM), static random access memory (SRAM), programmable read-only memory (PROM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), magnetic storage, magnetic disk, optical disk, etc. Memory 702 can be any other medium capable of carrying or storing desired program code in the form of instructions or data structures that can be accessed by a computer, but is not limited thereto. In the embodiments of this application, memory 702 can also be a circuit or any other device capable of implementing storage functions for storing program instructions and / or data.
[0125] By designing and programming the processor 701, the code corresponding to the graph database query method described in the foregoing embodiments can be embedded into the chip, enabling the chip to execute it during runtime. Figure 3 The illustrated embodiment presents a graph database query method. How to design and program the processor 701 is a technique well-known to those skilled in the art and will not be described further here.
[0126] It should be noted that the electronic device provided in this application embodiment can implement all the method steps implemented in the above method embodiment and can achieve the same technical effect. Here, the parts that are the same as those in the method embodiment and the beneficial effects will not be described in detail.
[0127] This application also provides a computer-readable storage medium storing computer-executable instructions for causing a computer to execute a graph database query method described in the above embodiments.
[0128] This application also provides a computer program product, which, when invoked by a computer, causes the computer to execute a graph database query method described in the above embodiments.
[0129] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0130] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable computer to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable computer, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0131] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable graph database query device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0132] These computer program instructions can also be loaded onto a computer or other programmable graph database query device, causing a series of operational steps to be performed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable device for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
Claims
1. A graph database query method, characterized in that, The method comprises the following steps: parsing a graph query statement to obtain a query rule; if the query rule starts from an edge of a graph database, determining at least one candidate edge associated with an edge index in the graph query statement from the graph database according to the edge index; if the query rule ignores the direction of the edge, obtaining pair point information corresponding to each candidate edge, and combining each pair of pair point information to obtain N candidate pair point combination information; wherein the pair point information represents entities on the nodes connected by the edge, and N is an integer greater than 0; comparing the target entity in the graph query statement with the entities in the N candidate pair point combination information; filtering the candidate pair point combination information that does not include the target entity in the N candidate pair point combination information to obtain M target pair point combination information that meets the condition requirement, and M is an integer less than or equal to N; determining a target node according to the M target pair point combination information, and querying the graph database from the target node to obtain the query result of the graph query statement.
2. The method of claim 1, wherein, After performing the filtering operation on the N candidate pair point combination information to obtain the M target pair point combination information that meets the condition requirement, the method further comprises the following steps: in the M target pair point combination information, marking the target entity on the node with a first label, and marking the remaining entities with a second label; the method of determining a target node according to the M target pair point combination information comprises the following steps: if the query rule specifies the first label, the node where the target entity is located is taken as the target node; or if the query rule specifies the second label, the node where the remaining entity is located is taken as the target node; or if the query rule does not specify the first label or the second label, the nodes where each entity is located are taken as the target node.
3. The method of claim 1, wherein, the method of obtaining pair point information corresponding to each candidate edge and combining each pair of pair point information comprises the following steps: determining a first node and a second node connected to the first selected edge according to a first identifier of the first selected edge; wherein the first selected edge is any one of the candidate edges; combining a first entity on the first node and a second entity on the second node into a pair.
4. A graph database query apparatus, characterized by, The method comprises the following steps: query module, determination module, combination module; the query module is used for parsing a graph query statement to obtain a query rule; if the query rule starts from an edge of a graph database, the determination module is instructed to determine at least one candidate edge associated with an edge index in the graph query statement from the graph database according to the edge index; and, if the query rule ignores the direction of the edge, the combination module is instructed to obtain pair point information corresponding to each candidate edge, and combine each pair of pair point information to obtain N candidate pair point combination information. and instructing the combination module to perform a filtering operation on the N candidate pair point combination information to obtain M target pair point combination information meeting a condition requirement; and instructing the query module to determine a target node according to the M target pair point combination information, and query the graph database starting from the target node to obtain a query result of the graph query statement; The determination module is configured to determine at least one candidate edge associated with the edge index in the graph database according to the edge index in the graph query statement according to an instruction of the query module. The combination module is configured to acquire pair point information corresponding to each candidate edge according to an instruction of the query module, and combine each pair point information to obtain N candidate pair point combination information. and compare the target entity in the graph query statement with entities in the N candidate pair point combination information respectively; filter the candidate pair point combination information that does not include the target entity in the N candidate pair point combination information to obtain M target pair point combination information meeting a condition requirement; wherein the pair point information is used to represent entities on nodes connected by edges, N is an integer greater than 0, and M is an integer less than or equal to N.
5. The apparatus of claim 4, wherein, The apparatus further includes a marking module. The marking module is configured to mark a node on which the target entity is located with a first label and mark a remaining entity with a second label in the M target pair point combination information. The query module is specifically configured to: if the second label is specified in the query rule, take a node on which the remaining entity is located as the target node; or if the first label is specified in the query rule, take a node on which the target entity is located as the target node; or if neither the first label nor the second label is specified in the query rule, take a node on which each entity is located as the target node. The combination module is specifically configured to:
6. The apparatus of claim 4, wherein, determine a first node and a second node connected to a first selected edge according to a first identifier of the first selected edge, wherein the first selected edge is any one of the candidate edges; and combine a first entity on the first node and a second entity on the second node into a pair. The apparatus further includes a memory and a processor.
7. An electronic device, comprising: The memory is configured to store a computer program. The processor is configured to execute the computer program stored in the memory to implement the method steps in any one of claims 1-3. The computer readable storage medium stores a computer program, and the computer program is executed by the processor to implement the method steps in any one of claims 1-3.
8. A computer-readable storage medium, characterized in that,
Citation Information
Patent Citations
A network graph index method based on adjacent node trees
CN102662974A
A method and a system for searching a relationship network based on a graph database
CN109271458A