Imagine you want to query a massive relational database, but your data is structured around complex domain knowledge that the database schema doesn't explicitly capture. Ontology-Based Data Access (OBDA)—also known as Ontology-Mediated Query Answering (OMQA)—bridges this gap by placing a logical ontology over the database. When a user issues a query, the system automatically rewrites it to incorporate the ontology's rules, allowing a standard SQL engine to execute the query and return complete answers.
As Meghyn Bienvenu explains in an overview of the field, Ontology-Mediated Query Answering: Harnessing Knowledge to Get More from Data, this paradigm allows organizations to leverage rich semantic knowledge without altering their underlying data storage systems. However, a major bottleneck threatens this approach: the size explosion problem.
The Problem: The Size Explosion of Flat Queries
The traditional way to rewrite an ontology-mediated query is to unfold every logical rule into a massive Union of Conjunctive Queries (UCQs) or a Positive Existential (PE) formula. If the ontology states that a Professor, Researcher, or Lecturer all imply the concept Academic, a query for Academic expands into a disjunction of those three terms.
When an ontology contains deep hierarchies and interconnected rules, this unfolding process cascades. Stanislav Kikot et al. demonstrated in Query Rewriting over Shallow Ontologies that even moving from an ontology of depth 1 to depth 2 triggers a worst-case exponential explosion in the size of PE rewritings. The resulting SQL queries become so massive that standard database query optimizers choke on them, rendering the theoretical elegance of OBDA practically useless.
The Solution: Structure Sharing
Why do positive existential formulas explode in size? Because they are fundamentally tree-like structures that cannot reuse intermediate computations. If a complex concept or pattern is triggered multiple times across different branches of a query expansion, a PE formula must duplicate the entire definition every single time.
Nonrecursive Datalog (NDL) solves this by introducing intermediate predicates—the logical equivalent of creating temporary views or defining variables in code. Instead of flattening the query into a single, massive, repetitive expression, an NDL rewriting creates a set of rules where intermediate concepts are computed once and referenced multiple times.
By utilizing NDL as the target language, the rewriting process shifts from expanding a tree to constructing a directed acyclic graph (DAG). As Carsten Lutz et al. show in Query Rewriting under EL TBoxes: Efficient Algorithms, this capacity for structure sharing acts as a powerful compression mechanism, preventing the exponential size explosion and keeping the rewritten query manageable for relational database systems.
The Circuit Complexity Connection
To understand why NDL achieves such dramatic compression over PE formulas, researchers turned to computational complexity theory. In Exponential Lower Bounds and Separation for Query Rewriting, Stanislav Kikot et al. established a formal bridge between query rewriting and Boolean circuit complexity.
In this analogy:
- A Positive Existential (PE) query corresponds to a Boolean formula (composed of AND/OR gates organized as a tree).
- A Nonrecursive Datalog (NDL) program corresponds to a Boolean circuit (a DAG where gate outputs can be reused as inputs elsewhere).
Just as Boolean circuits can represent certain functions exponentially more compactly than formulas, NDL can represent query rewritings exponentially or superpolynomially more succinctly than PE logic. In Ontology-Mediated Queries: Combined Complexity and Succinctness of Rewritings via Circuit Complexity, the authors mapped this succinctness landscape completely using hypergraph programs, proving that NDL rewritings can be efficiently generated in polynomial size for a much broader range of ontology depths and query structures where PE queries inevitably blow up.
Structural Sweet Spots for Succinctness
While NDL offers a more powerful toolkit for compression, the field has focused heavily on identifying the exact structural boundaries where polynomial-sized rewritings are guaranteed.
Tree-like Queries and Bounded Treewidth
The shape of the user's query matters immensely. In Succinctness of Query Rewriting in OWL 2 QL: The Case of Tree-like Queries and Tree-like Queries in OWL 2 QL: Succinctness and Complexity Results, the authors proved that for specific tree-shaped queries, NDL allows for polynomial-sized translations even when PE rewritings face superpolynomial growth.
Expanding on this, Stanislav Kikot et al. looked at queries with bounded treewidth combined with bounded-depth ontologies in The Complexity of Ontology-Based Data Access with OWL 2 QL and Bounded Treewidth Queries. They developed a novel Datalog rewriting technique that scales linearly, avoiding the performance collapse seen in traditional tools.
Optimal Combined Complexity
Beyond merely keeping the query small, NDL rewritings also exhibit excellent evaluation properties. In Theoretically Optimal Datalog Rewritings for OWL 2 QL Ontology-Mediated Queries, the authors demonstrated that NDL rewritings can be evaluated within highly efficient, parallelizable complexity classes like NL and LOGCFL, matching the theoretical lower bounds for the problem.
From Theory to Practice
The transition from theoretical circuit analogies to practical database engines requires concrete algorithms that can generate these shared structures on the fly.
Monadic Datalog and Decomposed Algorithms
For the description logic $\mathcal{E}\mathcal{L}$ (frequently used in massive biomedical ontologies like SNOMED CT), Lutz et al. introduced a "decomposed algorithm." Instead of generating flat SQL, it transforms ontology-based queries into nonrecursive monadic Datalog programs.
By breaking down query structures into reusable "node pairs," the algorithm generates a compact set of temporary views. Database optimizers can process these as a small sequence of efficient sub-queries rather than trying to parse a massive, flat logical expression.
Graph-Based Separation
The benefits of NDL rewriting extend beyond description logics to more general existential rules. In Practical Datalog Rewriting for Existential Rules, Peng Xiao et al. implemented a prototype system called Drewer. By utilizing a graph-based separation technique to identify opportunities for structure sharing, Drewer reduces the number of atoms in a rewriting by an order of magnitude compared to traditional methods.
| Rewriting Target | Structural Form | Size Scaling (Worst Case) | Database Optimizer Impact |
|---|---|---|---|
| Positive Existential (PE) / UCQ | Tree (No variable reuse) | Exponential ($2^n$) | High risk of optimizer failure due to query size |
| Nonrecursive Datalog (NDL) | DAG (Structure sharing) | Polynomial ($n^k$) for bounded structures | Highly efficient; processed as clean, modular sub-queries |
By treating query rewriting as a program-compression problem, nonrecursive Datalog rewriting changes the economics of ontology-mediated query answering. It bridges the gap between rich semantic knowledge bases and high-performance relational databases, proving that we do not have to sacrifice computational feasibility to achieve logical completeness.
Key Foundational Work
Query Rewriting over Shallow Ontologies (2013) — contributed 2 concept elements to this direction.
Exponential Lower Bounds and Separation for Query Rewriting (2012) — contributed 2 concept elements to this direction.