Graph analysis engine
AnalyticDB for PostgreSQL integrates a graph analysis engine as an extension that lets you query and manipulate graph data by using the Cypher query language. The engine excels at processing highly interconnected datasets in scenarios such as social networks, fraud detection, recommendation engines, knowledge graphs, and network/IT O&M.
What is a graph?
The basic components of a graph are nodes and edges. Nodes represent objects or entities, and edges describe the relationships between nodes.
In the preceding figure, the nodes represent entities such as Product A, Company A, Employee A, Employee E, and Employee E's Friend A. Edges represent relationships between these nodes, such as employment, friendship, and R&D relationships. You can attach properties to nodes and edges to enrich the data. For example, you can add employee numbers to nodes or record employment start times on edges. A graph with properties is called a property graph.
Graphs describe entities and their relationships in an intuitive manner. Graph models support various node types, edge types, and properties, making them well suited for highly interconnected data scenarios.
Graph analysis engine elements
|
Element |
Description |
|
Graph |
A graph is a data structure composed of nodes and edges that represent entities and their relationships. A typical example is a social network, where each person is a node and relationships such as friends, family members, and colleagues are edges. |
|
Node |
Nodes are the core elements of a graph that represent entities. Each node can carry labels to store entity information. For example, nodes in a social network represent users, companies, or organizations, and labels can include a user's age, a company's name, or an organization's address. |
|
Edge |
Edges connect nodes and describe relationship characteristics such as weight and direction. For example, edges in a social network represent relationships such as following, friendship, or fan connections. Weight reflects the strength of a relationship, such as interaction frequency. Direction indicates the directionality of a relationship, such as the "following" direction from one user to another. |
|
Label |
Labels categorize and identify nodes or edges, adding semantic information to improve query efficiency. For example, node labels in a social network distinguish entity types such as Person or Company, and edge labels describe relationship types such as Knows or Works In. |
|
Property graph |
If the nodes or edges in a graph contain labels, this type of graph structure is called a property graph. |
|
Pattern |
In Cypher, queries revolve around patterns that match specific graph structures. When matching structures are found or created, the results can be used for further data processing or analysis. |
Advantages
Compared with the table schema of traditional relational databases, the graph structure of AnalyticDB for PostgreSQL offers more flexible data modeling. It organizes data as nodes and edges, with node-centric access, and supports create, read, update, and delete (CRUD) operations on graph data.
For example, a node can quickly traverse its outgoing edges to reach adjacent nodes. This node-and-edge traversal intuitively expresses complex entity relationships and efficiently handles highly interconnected data.
|
Difference |
Graph analysis engine |
Relational database |
|
Focus |
Focuses on data entities and their relationships. |
Focuses on the data storage classification. Tables must be predefined with schemas. |
|
Flexibility |
Highly flexible. When data changes significantly, you only need to add new nodes, edges, and properties with the corresponding types. |
Less flexible. When data changes significantly, you must adjust table schemas or create additional tables, which incurs high costs for schema modifications. |
|
Intuitiveness and complexity |
Graphs express real-world relationships directly and naturally. You can query data based on node-and-edge topologies and quickly locate results through intuitive connections, simplifying complex relationship processing. |
Requires separate entity tables and relationship tables with complex mappings, demanding a higher level of abstract thinking. |