Answer Counting under Guarded TGDs

Cristina Feier, Carsten Lutz, Marcin Przybyłko · DOI

TL;DR

This paper maps out the parameterized complexity of counting query answers when databases are governed by ontologies or integrity constraints (specifically, guarded tuple-generating dependencies). By analyzing the graph-theoretic properties of a carefully rewritten version of the query, the authors provide a complete classification that dictates exactly when exact answer counting is efficient or computationally intractable.

What Problem Does This Paper Address?

In data analytics and decision support, knowing how many items match a query is often more important than listing the items themselves. However, counting answers to complex database queries—specifically Unions of Conjunctive Queries (UCQs)—is notoriously hard. This difficulty compounds when queries interact with database constraints or ontologies, which can implicitly add missing data or restrict valid database states.

While finding answers (query evaluation) has been heavily studied in these settings, answer counting has been largely neglected. Prior work established a fine-grained complexity landscape for counting answers to queries in isolation, using structural graph properties of the query (like treewidth). However, adding an ontology changes the game: the rules can interact with the query, sometimes simplifying a seemingly complex query or making a simple query intractable.

This paper addresses this gap by analyzing how guarded tuple-generating dependencies (TGDs)—a robust formalism used to model both ontologies (to deduce facts from incomplete data) and integrity constraints (promises about data shape)—affect the complexity of exact and approximate answer counting.

For instance, consider the example database instance shown below:

Example database instance from the paper illustrating facts about books, authors, and publishers.

An ontology can use rules like Publication(x) → ∃y hasAuthor(x, y) to infer hidden relationships, which fundamentally alters how we must count valid query matches across the data.

Methods

The core challenge is that you cannot determine counting complexity simply by looking at the original query's graph structure; you must account for its interaction with the ontology. To solve this, the authors develop a sophisticated rewriting pipeline to construct a modified set of queries, denoted as $Q^*$:

  1. $\exists$-Rewriting: Eliminating existential quantifiers from the heads of the TGD rules by adjusting the query.
  2. Chen-Mengel Closure: Utilizing the algebraic inclusion-exclusion principle to break down unions of queries into combinations of simpler conjunctive queries, isolating how different parts of a query overlap.
  3. The Chase: Chasing the queries with the ontology rules. Because of the first step, this process is guaranteed to be finite.
  4. Homomorphism Core Reduction: Simplifying the resulting queries to their minimal equivalent forms.

Once $Q^*$ is constructed, the authors analyze its graph structure using four standard structural graph measures: Treewidth (TW), Contract Treewidth (CTW), Starsize (SS), and Linked Matching Number (LMN).

Additionally, the authors prove a mutual reduction between counting under an open-world assumption (ontologies) and a closed-world assumption (integrity constraints), showing that their underlying complexities are mathematically isomorphic.

Datasets

Not discussed in the paper. As a purely theoretical paper in computational complexity topology, it does not utilize empirical datasets or benchmarks.

Key Insights and Ideas

  • The Ontology Twist: An ontology can act as a double-edged sword. It can make an otherwise complex query easy to count (by structurally bounding it via rule rewritings) or make a simple query hard. Complexity is therefore a property of the interaction ($Q^*$), not the query alone.
  • Bypassing Complexity via Approximation: For exact counting, the boundary between tractability and intractability relies on the intricate $Q^*$ construction. However, for approximate counting (finding a randomized approximation within an error bound $\epsilon$), the complexity collapses beautifully: an efficient approximation scheme exists if and only if the query has bounded semantic treewidth, completely bypassing the complex $Q^*$ machinery.
  • Unified Framework: Despite ontologies (generating new data) and integrity constraints (validating existing data) serving opposite operational roles in databases, their counting complexities align perfectly under the same graph-theoretic boundaries.

Key Results

The paper delivers a complete five-way classification of exact answer counting complexity under guarded TGDs (assuming a bounded relation arity and a full data schema):

  1. Fixed-Parameter Tractable (FPT): If both Treewidth and Contract Treewidth of $Q^*$ are bounded by a constant. Exact counting can be done efficiently relative to the database size.
  2. W[1]-equivalent: If Treewidth is unbounded but Contract Treewidth is bounded.
  3. #W[1]-equivalent: If Contract Treewidth is unbounded but Starsize is bounded.
  4. #W[2]-hard: If Starsize is unbounded.
  5. #A[2]-equivalent: If the Linked Matching Number is unbounded.

The paper also resolves several "meta-problems," proving that it is algorithmically decidable to check whether a given query specification is equivalent to one with a small contract treewidth or starsize.

Limitations and Future Work

  • Bounded Arity Assumption: The classification relies on the assumption that the maximum arity (number of arguments) of the relation symbols in the database schema is bounded by a constant.
  • Full Data Schema Restriction: For the ontology setting, the authors assume a "full data schema," meaning any relation symbol used in the ontology or query can also appear in the underlying database. Extending this to unrestricted schemas remains an open challenge.
  • The Treewidth Meta-Problem: While the meta-problems for contract treewidth and starsize were proven decidable, deciding whether a query can be rewritten into an equivalent one with bounded treewidth when the ontology can be modified remains an open, highly non-trivial problem.

Summary updated

BibTeX
@inproceedings{feier2021answer,
  author = {Cristina Feier and Carsten Lutz and Marcin Przybyłko},
  title = {{Answer Counting under Guarded TGDs}},
  booktitle = {Log. Methods Comput. Sci},
  year = {2021},
}
Figure