Abstract: Graph databases are getting more and more attention in the highly interconnected data domain, and the demand for efficient querying of big data is increasing. We noticed that there are duplicate patterns in graph database queries, and the results of these patterns can be stored as materialized views first, which can speed up the query rate. So we propose materialized views on property graphs, including three parts: view creation, view maintenance, and query optimization using views, and we propose for the first time an efficient templated view maintenance method for containing variable-length edges, which can be applied to multiple graph databases. In order to verify the effect of materialized views, we prototype on TuGraph and experiment on both TuGraph and Neo4j. The experiment results show that our query optimization on read statements is much higher than the additional view maintenance cost brought by write statements. The speedup ratio of the whole workload reaches up to 28.71x, and the speedup ratio of a single query reaches up to nearly 100x.
Introduction
In the era of big data, graph databases such as Neo4j and TuGraph have become essential for uncovering deep relationships in social networks, financial transactions, and recommendation engines. However, as graphs grow to billions of edges, complex queries—especially those involving "variable-length" paths (e.g., finding a friend of a friend of a friend)—can become significantly slower.
To address this, the MV4PG framework adapts the classic concept of materialized views from relational databases to the property graph domain. By pre-computing and storing the results of frequent query patterns as "shortcut" edges, MV4PG trades a small amount of storage and maintenance overhead for massive gains in query execution speed.
The Challenge of Variable-Length Paths
In relational databases, materialized views are well-understood: a complex join is calculated once and stored in a table. In graph databases, the challenge is more nuanced. Graph queries often involve variable-length edges (e.g., (n)-[:links*..]->(m)), which represent paths of unknown length. While these can be materialized as shortcut edges, keeping those shortcuts accurate when the underlying graph changes is difficult. If a single node in the middle of a 10-hop path is deleted, the system must efficiently update the materialized shortcut without re-scanning the entire graph.
System Architecture
MV4PG is structured into three core components that manage the lifecycle of a materialized view: creation, maintenance, and optimization.
1. View Creation
The framework extends the standard Cypher query language with GQL-compliant syntax to define views. This allows developers to specify complex patterns that should be materialized. For example, a multi-hop path between a Comment and a Post can be defined as a new, single edge type called ROOT_POST.
2. Templated View Maintenance
This is the primary innovation of MV4PG. Instead of recomputing views from scratch or using complex algebraic triggers, the system generates maintenance templates at the time of view creation. When data is modified (added or deleted), the system "plugs in" the changed information into these pre-defined templates to perform surgical, incremental updates to the materialized edges. This ensures that maintenance remains efficient even for variable-length paths.
3. View-Based Optimization
When a user submits a query, the MV4PG optimizer uses a subgraph matching algorithm (based on VF2) to determine if any part of the query matches an existing materialized view. If a match is found, the optimizer rewrites the query to use the shortcut edges, bypassing expensive path traversals and reducing the number of storage accesses (DBHits).
Experimental Evaluation
The researchers evaluated MV4PG using industry-standard benchmarks: the LDBC Social Network Benchmark (SNB) and the LDBC Financial Benchmark (Finbench). These tests were conducted on both TuGraph and Neo4j to demonstrate the framework's versatility.
Key Results
- Query Speedup: On the SNB dataset using TuGraph, the system achieved a maximum speedup of 96.9x for a single complex query.
- Workload Efficiency: For mixed workloads of reads and writes, the overall speedup ratio reached 28.71x on TuGraph and 1.64x on Neo4j.
- Storage Impact: Profiling revealed that for certain queries, storage accesses dropped from 292 million to just 2.4 million after optimization.
- Maintenance Overhead: While maintaining views adds overhead to write operations (making them 10-70% slower), the absolute time cost is measured in milliseconds, which is negligible compared to the seconds or minutes saved on read queries.
Conclusion and Future Work
MV4PG demonstrates that materialized views are a powerful tool for optimizing property graph queries. By utilizing templated maintenance, the system handles the complexity of variable-length edges efficiently. Future research will focus on automating view selection through workload analysis and developing a cost-based optimizer (CBO) to better manage scenarios where multiple views could satisfy a single query.
Summary updated