A graph database query method and device, electronic equipment and storage medium
By constructing an adjacency list for graph database queries, the problem of inaccurate query results in deep queries of graph databases is solved, improving query accuracy and performance, reducing resource consumption, and is suitable for terminals and application servers such as smartphones, tablets, computers, and personal digital assistants.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANGHAI SHIZHUANG INFORMATION TECHNOLOGY CO LTD
- Filing Date
- 2023-05-09
- Publication Date
- 2026-04-24
AI Technical Summary
Existing graph database query solutions suffer from inaccurate query results when performing deep queries and relationship mining, especially queries with three or more hops, leading to decreased query performance and failure of edge attribute filtering.
By constructing an adjacency list of the starting vertex and querying based on the path relationships in the adjacency list, direct operations on the graph database are reduced. The in-memory adjacency list is used for path filtering and attribute filtering, and logical expressions are generated for path querying, thus realizing edge attribute filtering and path querying.
It improves the accuracy of graph database queries, reduces the consumption of graph database resources, enhances query performance and stability, and meets the needs of high-concurrency writing and querying.
Smart Images

Figure CN116521956B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing, and more specifically, to a graph database query method, apparatus, electronic device, and storage medium. Background Technology
[0002] With the rapid development of computer science, networking, and storage, graph databases are being used more and more widely. Graph databases support efficient analysis of complex relationships, and their efficiency in processing complex, interconnected network data is far superior to that of traditional relational databases. However, due to the characteristics of graph databases, some existing query and relationship mining solutions may fail, leading to inaccurate query results. Summary of the Invention
[0003] The purpose of this invention is to provide a graph database query method, apparatus, electronic device, and storage medium. By constructing an adjacency list of starting vertices and based on the path relationships in the adjacency list, it enables path queries in a graph database. This improves the accuracy of query results by addressing the issue of edge attribute filtering failing when querying a graph database, thus enhancing the accuracy of the query results.
[0004] In a first aspect, embodiments of this application provide a graph database query method, including: querying the target edge and attribute information of the target edge corresponding to the starting vertex in the graph database according to query conditions; generating an adjacency list of the starting vertex according to the target edge and attribute information; and querying the path in the graph database based on the adjacency list.
[0005] In the above implementation process, an adjacency list is constructed based on the target edges corresponding to the starting vertices in the graph database and the target edges and attribute information. The adjacency list includes the path relationships between vertices. Based on the adjacency list, paths in the graph database are queried to find paths that meet the requirements, thus improving the accuracy of query results and mitigating the problem of query failures when directly querying the graph database.
[0006] Optionally, in this embodiment, the attribute information includes edge vertices; generating an adjacency list of the starting vertex based on the target edge and the attribute information includes: generating an adjacency list of the starting vertex in memory based on the relationship between the starting vertex, the target edge, and the edge vertices.
[0007] In the above implementation, by building an adjacency table in the application's memory, subsequent query operations are also performed based on this in-memory adjacency table. This eliminates the need for direct manipulation of the graph database, avoiding filtering failures and the inability to obtain accurate query results. Furthermore, since it doesn't directly manipulate the graph database, it reduces the consumption of CPU and memory resources, improving graph database stability and reducing its workload.
[0008] Optionally, in this embodiment of the application, querying the path in the graph database based on the adjacency list includes: obtaining the path between any two vertices, including the starting vertex and the edge vertex, according to the adjacency list; and performing attribute filtering query on the path in the graph database based on preset filtering configuration rules to obtain the valid path between any two vertices.
[0009] In the above implementation, based on the adjacency list in memory, attribute filtering queries are performed on the paths between vertices according to preset filtering configuration rules, thus achieving attribute filtering queries on edges and obtaining valid paths between two vertices. This improves upon the situation where direct operations on the graph database cause filtering failure and result in inaccurate query results.
[0010] Optionally, in this embodiment, the filtering configuration rules include attribute filtering rules and / or external storage filtering rules; based on the preset filtering configuration rules, attribute filtering queries are performed on the paths in the graph database to obtain a valid path between any two vertices, including generating a logical expression according to the attribute filtering rules and / or external storage filtering rules; and performing attribute filtering queries on the paths in the graph database based on the logical expression to obtain a valid path between any two vertices.
[0011] In the above implementation process, logical expressions are generated according to the filtering configuration rules; based on the logical expressions, the path attributes of the adjacency list in memory are filtered and queried to effectively filter the edge attributes and obtain valid paths that meet the rules.
[0012] Optionally, in this embodiment of the application, querying the path in the graph database based on the adjacency list includes: grouping the edge vertices according to a preset grouping method to obtain grouped vertex data; and concurrently executing path queries for each group of vertex data based on the adjacency list.
[0013] In the above implementation process, edge vertices are grouped to obtain group vertex data, and path queries for each group of vertex data are executed concurrently. This allows for synchronous waiting of vertex data across different groups, improving the efficiency of path filtering queries.
[0014] Optionally, in this embodiment of the application, querying the target edge and the attribute information of the target edge corresponding to the starting vertex in the graph database according to the query conditions includes: obtaining a query statement pre-written according to the query conditions; the query conditions include at least one of edge type, preset hop count and edge direction; and querying the target edge and the attribute information of the target edge corresponding to the starting vertex through the query statement.
[0015] In the above implementation process, by setting the query statement type and query conditions according to the requirements, more flexible and accurate query results can be obtained.
[0016] Optionally, in this embodiment of the application, the method further includes: separating the server cluster corresponding to the graph database into query server nodes and storage server nodes; the query server nodes are used to provide query services to the graph database; the storage server nodes are used to provide storage services to the graph database; the query server nodes are divided into query nodes and write nodes; the query nodes are associated through a first network load balancing server; and the write nodes are associated through a second network load balancing server.
[0017] In the above implementation process, the query server node and the storage server node are separated, and the query server node is divided into query node and write node. Different network load balancers are set up for the query node and the write node respectively to realize the read and write separation of the query node, meet the requirements of high write and high query at the same time, and improve the performance of the graph database.
[0018] Secondly, embodiments of this application also provide a graph database query device, comprising: a query module, used to query the target edge and attribute information of the target edge corresponding to the starting vertex in the graph database according to query conditions; an adjacency list module, used to generate an adjacency list of the starting vertex according to the target edge and attribute information; and a path query module, used to query the path in the graph database based on the adjacency list.
[0019] Thirdly, embodiments of this application also provide an electronic device, including: a processor and a memory, the memory storing machine-readable instructions executable by the processor, which, when executed by the processor, perform the method described above.
[0020] Fourthly, embodiments of this application also provide a computer-readable storage medium storing a computer program that, when executed by a processor, performs the methods described above.
[0021] The graph database query method, apparatus, electronic device, and storage medium provided in this application query the target edges corresponding to starting vertices in the graph database. Based on the target edges and attribute information, an adjacency list is constructed. The adjacency list includes path relationships between vertices. Paths in the graph database are queried based on the adjacency list to find paths that meet the requirements, improving the accuracy of query results by mitigating the problem of query failures when directly querying the graph database. Storing additional edge information provides extra flexibility for subsequent attribute filtering queries. Attached Figure Description
[0022] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0023] Figure 1 A flowchart illustrating a graph database query method provided in an embodiment of this application;
[0024] Figure 2 A schematic diagram of an adjacency list provided in an embodiment of this application;
[0025] Figure 3 This is a schematic diagram of the structure of the graph database query device provided in the embodiments of this application;
[0026] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0027] The embodiments of the technical solution of this application will now be described in detail with reference to the accompanying drawings. These embodiments are only used to more clearly illustrate the technical solution of this application and are therefore merely examples, and should not be used to limit the scope of protection of this application.
[0028] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs; the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit this application.
[0029] In the description of the embodiments of this application, technical terms such as "first" and "second" are used only to distinguish different objects and should not be construed as indicating or implying relative importance or implicitly specifying the number, specific order, or primary and secondary relationship of the indicated technical features. In the description of the embodiments of this application, "multiple" means two or more, unless otherwise explicitly defined.
[0030] Existing methods for querying data or relationships in graph databases typically involve directly manipulating the graph database by writing query statements. Current graph databases, such as Neo4j and Nebula, support edge filtering queries for one- and two-hop relationships between graph vertices. However, performance degrades significantly for three- and higher-hop queries, resulting in longer execution times, and edge attribute filtering fails for queries with more than two hops. Furthermore, deep queries and relationship mining schemes for graph databases may require mining relationships with four or more hops. Therefore, current technologies cannot provide accurate query results to support business requirements.
[0031] This application provides a graph database query method that constructs an adjacency list of starting vertices and uses the path relationships in the adjacency list to perform path queries in the graph database. This improves graph database querying at the application level, mitigating the issue of query failures when directly querying the graph database and increasing the accuracy of query results.
[0032] Please see Figure 1 The illustration shows a flowchart of a graph database query method provided in an embodiment of this application. The graph database query method provided in this application can be applied to electronic devices, which may include a terminal and a server; wherein the terminal may specifically be a smartphone, tablet computer, computer, personal digital assistant (PDA), etc.; the server may specifically be an application server or a web server. The graph database query method may include the following steps:
[0033] Step S110: Based on the query conditions, query the target edge and its attribute information corresponding to the starting vertex in the graph database.
[0034] Step S120: Generate an adjacency list of the starting vertex based on the target edge and attribute information.
[0035] Step S130: Query the paths in the graph database based on the adjacency list.
[0036] In step S110, the graph database is a data management system designed for efficient storage and retrieval of graph data, using vertices and edges as basic storage units. A graph database is a type of NoSQL database that applies graph theory to store information about relationships between entities. Here, "vertices" can represent entities, and "edges" can represent relationships between entities; that is, in a graph database, relationships between data are also stored as part of the data.
[0037] Before querying the database, you can first obtain the starting vertex for the deep query or relationship mining in the graph data. The starting vertex can be any point in the graph database; and obtain the pre-set query conditions. The query conditions can include condition settings for the target points found in the query, and can also include condition settings for the target edges found in the query.
[0038] After obtaining the query conditions, the graph database is searched for the target edges and their attribute information corresponding to the starting vertices that meet the query conditions. The attribute information of the target edges can be stored in the graph database, such as the vertex of the target edge, the relationship between the two vertices corresponding to the target edge, and the time when the relationship between the two vertices corresponding to the target edge was established, etc.
[0039] In step S120, an adjacency list of the starting vertices is generated based on the target edges retrieved from the graph database and the attribute information corresponding to each target edge. For example, each target edge has vertex information, including a start point and an end point. The vertices and their paths can be constructed using an adjacency list based on the start and end points of the target edges.
[0040] In step S130, the path between any two vertices in the adjacency list can be obtained, namely the path from the starting vertex to an edge vertex and the path from one edge vertex to another. This path is an unfiltered list of all reachable paths between the two vertices. The path is a list of edges consisting of all intermediate points traversed by the starting vertex to the target vertex. Then, a path query is performed on all reachable paths between the two vertices to filter out paths that meet the conditions.
[0041] In the above implementation process, an adjacency list is constructed based on the target edges corresponding to the starting vertices in the graph database and the target edges and attribute information. The adjacency list includes the path relationships between vertices. Based on the adjacency list, paths in the graph database are queried to find paths that meet the requirements, thus improving the accuracy of query results and mitigating the problem of query failures when directly querying the graph database.
[0042] As an optional implementation, a unique identifier can be added to the adjacency list and stored. If the query conditions of the path query are consistent with the starting vertex, the corresponding adjacency list can be obtained based on the unique identifier of the adjacency list. The path query can then be performed based on the obtained adjacency list, eliminating the need to generate the adjacency list multiple times, thus achieving adjacency list reuse and reducing resource consumption.
[0043] Please see Figure 2 The diagram shown illustrates an adjacency list provided in an embodiment of this application.
[0044] Optionally, in this embodiment, the attribute information includes edge vertices; generating an adjacency list of the starting vertex based on the target edge and the attribute information includes: generating an adjacency list of the starting vertex in memory based on the relationship between the starting vertex, the target edge, and the edge vertices.
[0045] In the specific implementation process: the edge vertices include the start and end points of the target edge. The target edge may or may not have a direction. If the target edge has a direction, then one of the edge vertices is the start point and the other is the end point; if the target edge does not have a direction, then either of the two edge vertices corresponding to the target edge can be the start point or the end point.
[0046] Based on the starting vertex, the target edge, and the relationships between edges and vertices, an adjacency list of the starting vertex is generated in memory. This memory can be application memory; the adjacency list storage method is similar to the child chain representation of a tree, a storage structure combining sequential allocation and linked allocation. The adjacency list representation of a graph associates each vertex with its set of adjacent vertices or edges.
[0047] An adjacency list can be implemented using a hash table, which associates each vertex in the graph with an array of adjacent vertices. In this representation, a vertex can be represented by any hashable object. Vertices include originating vertices and edge vertices.
[0048] Another way to implement an adjacency list is to represent vertices using index numbers. This involves using an array indexed by the number of vertices, where each vertex's array cell points to a singly linked list of its neighboring vertices.
[0049] Adjacency lists can also be used in an object-oriented representation. Each vertex object has an instance variable that points to a set object that lists neighboring edge objects. In turn, each edge object points to the two vertex objects at its endpoints. This approach allows the target edge to store additional information about the edge, providing extra flexibility for subsequent attribute filtering queries.
[0050] like Figure 2 As shown, in the directed graph of this adjacency list, the vertex labeled 1 can be used as the starting vertex, and the vertices labeled 2, 3, and 4 can be used as edge vertices. Vertex 1 is adjacent to vertex 2, vertex 3, and vertex 4; vertex 2 is adjacent to vertex 1 and vertex 3; vertex 3 is adjacent to vertex 1, vertex 2, and vertex 4; and vertex 4 is adjacent to vertex 1 and vertex 3. An adjacency list is generated by associating each vertex in the graph with its set of adjacent vertices or edges.
[0051] It should be noted that adjacency lists include directed adjacency lists and / or undirected adjacency lists; if the target edge has a direction, a directed adjacency list can be generated; if the target edge does not have a direction, an undirected adjacency list can be generated.
[0052] In the above implementation, by building an adjacency table in the application's memory, subsequent query operations are also performed based on this in-memory adjacency table. This eliminates the need for direct manipulation of the graph database, avoiding filtering failures and the inability to obtain accurate query results. Furthermore, since it doesn't directly manipulate the graph database, it reduces the consumption of CPU and memory resources, improving graph database stability and reducing its workload.
[0053] Optionally, in this embodiment of the application, querying the path in the graph database based on the adjacency list includes: obtaining the path between any two vertices, including the starting vertex and the edge vertex, according to the adjacency list; and performing attribute filtering query on the path in the graph database based on preset filtering configuration rules to obtain the valid path between any two vertices.
[0054] In the specific implementation process: a path between any two vertices refers to a path from the starting vertex to any edge vertex, and / or, from any edge vertex to other edge vertices. Filtering configuration rules can conditionally filter edge attribute information, that is, filter the attributes stored within the edge itself, which can be stored in a graph database or an external database. For example, if there are multiple paths from the starting vertex to the first edge vertex, according to the filtering configuration rules, the path that meets the configuration rules is selected as the valid path from the starting vertex to the first edge vertex.
[0055] Understandably, the above steps can be performed to filter the paths between vertices that require path lookup, depending on business needs; alternatively, the paths between every two vertices can be filtered.
[0056] In the above implementation, based on the adjacency list in memory, attribute filtering queries are performed on the paths between vertices according to preset filtering configuration rules, thus achieving attribute filtering queries on edges and obtaining valid paths between two vertices. This improves upon the situation where direct operations on the graph database cause filtering failure and result in inaccurate query results.
[0057] Optionally, in this embodiment, the filtering configuration rules include attribute filtering rules and / or external storage filtering rules; based on the preset filtering configuration rules, attribute filtering queries are performed on the paths in the graph database to obtain a valid path between any two vertices, including generating a logical expression according to the attribute filtering rules and / or external storage filtering rules; and performing attribute filtering queries on the paths in the graph database based on the logical expression to obtain a valid path between any two vertices.
[0058] In the specific implementation process: Before performing path queries, filtering configuration rules can be obtained first. Attribute filtering rules are configured based on the attribute information of the target edges stored in the graph database; external storage filtering rules are pre-stored in an external database, such as Redis or HBase. External storage filtering rules can be configured based on the external storage label attributes and external storage metrics corresponding to the edges. Since these attributes or metrics cannot be written to the graph database in real time, or do not need to be written to the graph database, storing them in an external database allows for multi-dimensional and multi-metric queries of the path.
[0059] The filtering configuration rules can include one or more. After obtaining the filtering configuration rules, logical expressions are generated based on these rules. The path attributes of the adjacency list in memory are then filtered and queried based on the logical expressions to obtain the valid path between any two vertices.
[0060] For example, if it is necessary to filter data that meets multiple filtering configuration rules, the logical expression can be: A&B&C; where A, B, and C are three filtering configuration rules; this logical expression indicates that only paths that meet the three conditions A, B, and C are selected as valid paths.
[0061] If you need to filter data that does not meet multiple filtering configuration rules, the logical expression can be: ! (A|B); This logical expression indicates that paths that do not meet rule A and do not meet rule B are considered valid paths. This logical expression can exclude data under specific conditions.
[0062] If you need to filter data that meets at least one of the multiple filtering configuration rules, the logical expression can be: A|B; this logical expression indicates that the path that meets rule A or any rule B is considered a valid path.
[0063] If you need to filter data that does not fully meet all of the multiple filtering configuration rules, the logical expression can be: ! (A&B)&(A|B); This logical expression represents the paths that do not fully meet rules A and B, and are considered valid paths.
[0064] Understandably, the above logical expression can also be customized according to actual business needs.
[0065] In the above implementation process, logical expressions are generated according to the filtering configuration rules; based on the logical expressions, the path attributes of the adjacency list in memory are filtered and queried to effectively filter the edge attributes and obtain valid paths that meet the rules.
[0066] Optionally, in this embodiment of the application, querying the path in the graph database based on the adjacency list includes: grouping the edge vertices according to a preset grouping method to obtain grouped vertex data; and concurrently executing path queries for each group of vertex data based on the adjacency list.
[0067] In the specific implementation process: after querying the target edge corresponding to the starting vertex in the graph database according to the query conditions, and obtaining the edge vertex corresponding to the target edge, all edge vertices are grouped according to a preset grouping method. This grouping method can be based on edge vertex labels or on a grouping threshold. Grouping by edge vertex labels means grouping edge vertices with the same attribute label into one group; grouping based on a grouping threshold means grouping a fixed number of edge vertices into one group.
[0068] Taking grouping based on a grouping threshold as an example, if 100 edge vertices are obtained, in order to reduce the time consumption of matching queries, the edge vertices can be divided into 5 groups of edge vertex data, with 20 edge vertices per group. Multiple processes or threads of the same program can run concurrently to perform path queries on each group of edge vertices.
[0069] In the above implementation process, the edge vertices are grouped to obtain group vertex data, and path queries for each group of vertex data are executed concurrently. This allows for synchronous waiting of vertex data across different groups, improving the efficiency of path queries.
[0070] Optionally, in this embodiment of the application, querying the target edge and the attribute information of the target edge corresponding to the starting vertex in the graph database according to the query conditions includes: obtaining a query statement pre-written according to the query conditions; the query conditions include at least one of edge type, preset hop count and edge direction; and querying the target edge and the attribute information of the target edge corresponding to the starting vertex through the query statement.
[0071] In the specific implementation process: the query statements can be written using either the MATCH statement or the LOOKUP statement. As an optional implementation, the query statement can also use the GO statement. GO statements offer relatively good query performance, but in existing technologies, using GO statements to query the database results in the edge attribute filtering failing as the number of query hops increases. The graph database query method provided in this application, however, can improve query performance by using GO statements while simultaneously implementing multi-hop edge attribute filtering queries in the in-memory adjacency list, thereby improving query efficiency and accuracy.
[0072] The query criteria include at least one of edge type, preset hop count, and edge direction. In other words, you can specify the edge type, preset hop count, and edge direction in the query criteria to ensure that the target edges retrieved meet the query conditions.
[0073] In the above implementation process, by setting the query statement type and query conditions according to the requirements, more flexible and accurate query results can be obtained.
[0074] Optionally, in this embodiment of the application, the method further includes: separating the server cluster corresponding to the graph database into query server nodes and storage server nodes; the query server nodes are used to provide query services to the graph database; the storage server nodes are used to provide storage services to the graph database; the query server nodes are divided into query nodes and write nodes; the query nodes are associated through a first network load balancing server; and the write nodes are associated through a second network load balancing server.
[0075] In the specific implementation process: Before performing path queries, to support queries with higher hop counts and improve query performance, optimizations can be performed at the graph database level. This involves separating the servers in the graph database server cluster into query server nodes and storage server nodes. That is, different servers provide query services and storage services respectively, reducing the pressure on the graph database.
[0076] In practical applications, graph databases may perform high-concurrency write operations and high-concurrency query operations simultaneously, such as in mixed query scenarios similar to OLAP and OLTP. OLAP is the main application of data warehouse systems, supporting complex analytical operations, focusing on decision support, and providing intuitive and easy-to-understand query results. OLTP (on-line transaction processing) is the main application of traditional relational databases, primarily handling basic, routine transaction processing, such as banking transactions.
[0077] Even with separate query server nodes and storage server nodes, high-concurrency writes still put CPU and memory pressure on both. To reduce CPU and memory contention during writes and queries, we further divided the query server nodes into query nodes and write nodes, even with the separate query and storage server nodes. Query nodes and write nodes write to a first load balancer and a second network load balancer, respectively. The first network load balancer connects the query nodes, and the second network load balancer connects the write nodes, thus achieving read / write separation for the query nodes.
[0078] A network load balancer (SLB) is the system's control server. User requests first arrive at this server, which then distributes the requests to specific associated processing servers based on the status of each actual processing server.
[0079] In the above implementation process, the query server node and the storage server node are separated, and the query server node is divided into query node and write node. Different network load balancers are set up for the query node and the write node respectively to realize the read and write separation of the query node, meet the requirements of high write and high query at the same time, improve the performance of the graph database, and enhance the stability of the database.
[0080] In an optional embodiment, based on query conditions such as edge type, preset hop count, and edge direction, the graph database is queried for the target edge and its vertex information corresponding to the starting vertex that meets the query conditions. An adjacency list is constructed in memory based on the starting vertex, target edge, and its vertex. All paths between the starting vertex and the edge vertices are recursively retrieved from the adjacency list. These paths are then judged according to edge filtering configuration rules and logical expressions, eliminating paths that do not meet the conditions and retaining the vertices of reachable paths.
[0081] Please see Figure 3 The diagram shown is a schematic representation of the graph database query device provided in an embodiment of this application; this embodiment of the application provides a graph database query device 200, including:
[0082] The query module 210 is used to query the target edge and the attribute information of the target edge corresponding to the starting vertex in the graph database according to the query conditions.
[0083] The adjacency list module 220 is used to generate an adjacency list of the starting vertex based on the target edge and attribute information.
[0084] The path query module 230 is used to query paths in the graph database based on the adjacency list.
[0085] Optionally, in this embodiment of the application, the attribute information includes edge vertices; the graph database query device, adjacency list module 220, is specifically used to generate an adjacency list of the starting vertex in memory based on the starting vertex, the target edge, and the association relationship between the edge vertices.
[0086] Optionally, in this embodiment of the application, the graph database query device, the query path module 230, is specifically used to obtain the path between any two vertices among the starting vertex and the edge vertex according to the adjacency list; and to perform attribute filtering query on the path in the graph database based on preset filtering configuration rules to obtain a valid path between any two vertices.
[0087] Optionally, in this embodiment of the application, the graph database query device includes attribute filtering rules and / or external storage filtering rules; the query path module 230 is further configured to generate a logical expression based on the attribute filtering rules and / or the external storage filtering rules; and perform attribute filtering query on the path in the graph database based on the logical expression to obtain a valid path between any two vertices.
[0088] Optionally, in this embodiment of the application, the graph database query device, the query path module 230, is further configured to group the edge vertices according to a preset grouping method to obtain grouped vertex data; and to concurrently execute path queries for each grouped vertex data based on the adjacency list.
[0089] Optionally, in this embodiment of the application, the graph database query device, query module 210, is specifically used to obtain a query statement pre-written according to the query conditions; the query conditions include at least one of edge type, preset number of jumps and edge direction; through the query statement, the target edge corresponding to the starting vertex and the attribute information of the target edge are queried.
[0090] Optionally, in this embodiment of the application, the graph database query device further includes a separation module, used to separate the server cluster corresponding to the graph database into query server nodes and storage server nodes; the query server nodes are used to provide query services to the graph database; the storage server nodes are used to provide storage services to the graph database; the query server nodes are divided into query nodes and write nodes; the query nodes are associated through a first network load balancing server; and the write nodes are associated through a second network load balancing server.
[0091] It should be understood that this device corresponds to the above-described graph database query method embodiment and is capable of performing the various steps involved in the above method embodiment. The specific functions of this device can be found in the description above, and detailed descriptions are omitted here to avoid repetition. The device includes at least one software functional module that can be stored in memory or embedded in the device's operating system (OS) in the form of software or firmware.
[0092] Please see Figure 4 The diagram shows a structural schematic of an electronic device provided in an embodiment of this application. An electronic device 300 provided in this application includes a processor 310 and a memory 320. The memory 320 stores machine-readable instructions executable by the processor 310. When the machine-readable instructions are executed by the processor 310, the method described above is performed.
[0093] This application also provides a storage medium storing a computer program, which is executed by a processor to perform the above-described method.
[0094] The storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read Only Memory (EPROM), Programmable Red-Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0095] It should be understood that the disclosed apparatus and methods can also be implemented in other ways, given the several embodiments provided in this application. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, or they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0096] In addition, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0097] The above description is only an optional implementation of the embodiments of this application, but the protection scope of the embodiments of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the embodiments of this application should be covered within the protection scope of the embodiments of this application.
Claims
1. A graph database query method, characterized in that, include: Based on the query criteria, retrieve the target edge corresponding to the starting vertex and the attribute information of the target edge from the graph database; Based on the target edge and the attribute information, generate the adjacency list of the starting vertex; The path in the graph database is queried based on the adjacency list; The attribute information includes edge vertices; Querying paths in the graph database based on the adjacency list includes: obtaining the path between any two vertices, including the starting vertex and the edge vertex, according to the adjacency list; generating a logical expression based on attribute filtering rules and external storage filtering rules; and performing attribute filtering queries on the paths in the graph database based on the logical expression to obtain valid paths between any two vertices; wherein the attribute filtering rules are configured based on attribute information of the target edge stored in the graph database; and the external storage filtering rules are configured based on the external storage label attribute and the external storage index corresponding to the edge. Based on the target edge and the attribute information, an adjacency list for the starting vertex is generated, including: Based on the starting vertex, the target edge, and the relationship between the edge vertices, an adjacency list of the starting vertex is generated in memory; Querying paths in the graph database based on the adjacency list includes: The edge vertices are grouped according to a preset grouping method to obtain grouped vertex data; Based on the adjacency list, path queries for each group of vertex data are executed concurrently; Based on the query criteria, retrieve the target edge corresponding to the starting vertex and the attribute information of the target edge from the graph database, including: Obtain a pre-written query statement based on the query conditions; the query conditions include at least one of edge type, preset number of hops, and edge direction; The query statement retrieves the target edge corresponding to the starting vertex and the attribute information of the target edge.
2. The method according to any one of claims 1, characterized in that, The method further includes: The server cluster corresponding to the graph database is separated into query server nodes and storage server nodes; the query server nodes are used to provide query services for the graph database; the storage server nodes are used to provide storage services for the graph database. The query server node is divided into query nodes and write nodes; the query nodes are associated through a first network load balancer; and the write nodes are associated through a second network load balancer.
3. A graph database query device, characterized in that, include: The query module is used to query the target edge corresponding to the starting vertex and the attribute information of the target edge in the graph database according to the query conditions. The adjacency list module is used to generate the adjacency list of the starting vertex based on the target edge and the attribute information. The path query module is used to query the paths in the graph database based on the adjacency list; The attribute information includes edge vertices; the path query module queries the path in the graph database based on the adjacency list, and is used to obtain the path between any two vertices among the starting vertex and the edge vertices according to the adjacency list; a logical expression is generated according to attribute filtering rules and external storage filtering rules; the path in the graph database is queried for attribute filtering based on the logical expression to obtain a valid path between any two vertices; wherein, the attribute filtering rules are configured based on the attribute information of the target edge stored in the graph database; the external storage filtering rules are configured based on the external storage label attribute and the external storage index corresponding to the edge; The adjacency list module is used to generate an adjacency list of the starting vertex in memory based on the starting vertex, the target edge, and the association relationship between the edge vertices. The query path module is used to group the edge vertices according to a preset grouping method to obtain grouped vertex data; and to concurrently perform path queries for each grouped vertex data based on the adjacency list. The query module is used to obtain a query statement pre-written according to the query conditions; the query conditions include at least one of edge type, preset number of jumps and edge direction; through the query statement, the target edge corresponding to the starting vertex and the attribute information of the target edge are queried.
4. An electronic device, characterized in that, include: A processor and a memory, the memory storing machine-readable instructions executable by the processor, which, when executed by the processor, perform the method as described in any one of claims 1 to 2.
5. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, performs the method as described in any one of claims 1 to 2.