Compiling Linear Datalog to SQL for Program Analysis
Abstract
Datalog is a declarative query language that has proven highly effective for expressing static program analyses. Although Datalog has deep roots in database theory, most recent advances have largely emerged from the programming languages and compiler communities, with systems such as Soufflé. In contrast, modern relational engines have made significant progress in optimizing recursive SQL. This paper revisits the connection between Datalog and relational databases, advocating recursive SQL as a backend for Datalog evaluation. We present a compilation framework that translates Datalog programs, particularly those in the Linear Datalog fragment, into equivalent recursive SQL queries. To bridge the gap between Datalog and SQL, the compiler routes every program through an intermediate language called Midlog. The compiler additionally recovers functional dependencies from the program and exposes them as schema keys, unlocking the engine's standard query optimizations. This approach enables existing database engines to execute a broad class of program analyses, outperforming the Soufflé engine by up to an order of magnitude on the Umbra backend. Umbra achieves a geometric-mean speedup of 5.46 at 8 threads, whereas DuckDB is competitive with Soufflé single-threaded and is slower at 8 threads (geometric-mean speedup of 0.68). Furthermore, the generated SQL is portable; it runs on seven database systems without any engine modification. Our results highlight what the relational engines require to fully support Datalog for large-scale program analysis.
Create a lesson
Metadata
- Categories
- cs.DB, cs.PL
Related papers
Answering Conjunctive Queries over Linear Existential Rules with Transitivity
Shared title terminologycs.DBCristina Feier, Tomasz Gogacz, Filip Murlak
Causal Resolution of Undefined Answers in Datalog with Negation
Shared title terminologycs.DBRatan Bahadur Thapa
Samyama-SDG: A Declarative GraphQL @count and Regex/Ontology Synthetic Data Compiler with O(1)-Memory Referential Integrity and Causal Ground Truth
Shared title terminologycs.DBMadhulatha Mandarapu, Sandeep Kunkunuru
Distributed Datalog at Scale with Worst-Case Optimal Joins
Shared title terminologycs.DBKunting Qi, Yihao Sun, Kristopher Micinski et al.
Automated Prefetching for Object Spatial Programming Using Temporal Trace Graphs
Shared title terminologycs.DBBaichuan Li, Jayanaka Dantanarayana, Savini Kashmira et al.
Numerical Stability of Linear Algebra Operations over Relational Databases
Shared title terminologycs.DBAndrei Draghici, Yuchen He, Dan Olteanu