Abstract
Graph database engines play a pivotal role in efficiently storing and managing graph data across various domains, including bioinformatics, knowledge graphs, and recommender systems. Ensuring data accuracy within graph database engines is paramount, as inaccuracies can yield unreliable analytical outcomes. Current bug-detection approaches are confined to specific graph query languages, limiting their applicabilities when handling graph database engines that use various graph query languages across various domains. Moreover, they require extensive prior knowledge to generate queries for detecting bugs. To address these challenges, we introduce DGDB, a novel paradigm harnessing large language models (LLM), such as ChatGPT, for comprehensive bug detection in graph database engines. DGDB leverages ChatGPT to generate high-quality queries for different graph query languages. It subsequently employs differential testing to identify bugs in graph database engines. We applied this paradigm to graph database engines using the Gremlin query language and those using the Cypher query language, generating approximately 4,000 queries each. In the latest versions of Neo4j, Agensgraph, and JanusGraph databases, we detected 2, 5, and 3 wrong-result bugs, respectively.
Introduction
Graph databases like Neo4j and JanusGraph are the backbone of modern recommendation engines, fraud detection systems, and knowledge graphs. But as these systems grow in complexity, so does the risk of "wrong-result" bugs—silent errors where a database returns incorrect data without crashing. Detecting these is notoriously difficult because it requires generating complex, syntactically correct queries that actually return data to test.
Existing methods usually fall into two traps: language silos (tools hard-coded for one language) and the "empty result" problem, where randomly generated queries often return nothing. To overcome these, developers previously had to write complex, expert-level algorithms. DGDB asks: Can we just teach an LLM the graph schema and let it write the tests for us?
The DGDB Framework
The researchers introduced DGDB (Differential Graph Database Bug-detection), which operates in three main stages as shown in the architecture below:
- Graph Data Generation: The system randomly generates a property graph schema (labels, properties, and relationships) and populates it with synthetic data. This typically involves property graphs with 100 nodes, 200 edges, and various property types (Integer, Float, String, etc.).
- LLM-Based Query Generation: This is the core innovation. Instead of hard-coding query logic, the graph schema and data are fed into ChatGPT (GPT-3.5-turbo) using a specialized prompt template. The prompt instructs the LLM to understand specific nodes and edges and use a variety of operators (e.g.,
MATCH,UNWIND,shortestPath). Crucially, it follows constraints to ensure queries are likely to return non-empty results and remain read-only. - Differential Testing & Validation: The generated queries are executed on different engines (e.g., Neo4j vs. AgensGraph for Cypher). If the engines return different results for the same query, a potential bug is flagged. The team uses regular expressions to normalize results for fair comparison across different output formats.
Key Results and Insights
The DGDB approach proved highly effective compared to state-of-the-art baselines like Grand and GDSmith. By explicitly telling the LLM to "ensure the queried data is the node or link mentioned earlier," they bypassed the "empty result" problem that plagues random fuzzers.
- Efficiency: DGDB achieved a non-empty-result query ratio of ~80%, significantly higher than the random-based Grand (~40%).
- Bug Discovery: In just 4,200 seconds of testing per language, DGDB detected 10 new, unfixed bugs across Neo4j (2), AgensGraph (5), and JanusGraph (3). These included issues with exceptional values, boolean priority, and type persistence.
- Versatility: Unlike previous tools limited to one language, DGDB supports "all" major graph query languages with only minor adjustments to the prompt.
Conclusion
DGDB demonstrates that LLMs can serve as effective "zero-shot" query generators for database testing. By providing a few examples of graph data, the LLM can generate complex, syntactically valid queries without needing a custom-built expression generator. While limitations like API costs and potential hallucinations exist, the paradigm offers a scalable, language-agnostic way to find critical bugs in the systems that power modern data analysis.
Summary updated