Abstract 1 Introduction 2 Preliminaries 3 Problem definition 4 Identifying 𝑪𝑸𝑯𝑻¬: the intuitions 5 Formalizing 𝑪𝑸𝑯𝑻¬ 6 Complexity for deciding 𝑪𝑸𝑯𝑻¬ and 𝑪𝑸𝑯𝑻𝟏¬ membership 7 Related Work 8 Conclusions References Appendix A Proofs for Theorems

Conjunctive Query Containment with Safe Negation and TGD One-Boundedness

Xavier Oriol ORCID Universitat Politècnica de Catalunya, Barcelona, Spain
Abstract

Query containment is a fundamental database problem which has been extensively studied for conjunctive queries (CQs). The most famous result is arguably the Homomorphism Theorem: a CQ q1 is contained in a CQ q2 iff there is a homomorphism from q2 to q1. However, when extending conjunctive queries with safe base negation (CQ¬), this test becomes incomplete, hence, requiring significantly more expensive procedures due to its inherently harder complexity (Π2P-hard).

In this paper, we define and study the classes CQHT1¬ and CQHT¬: the classes of conjunctive queries extended with one or several safe negated atoms that satisfy the Homomorphism Theorem, and hence, whose containment check is in NP. To characterise them, we define what we call the dependency-version of a query, which is a dependency that, intuitively, models the databases in which the query is false. It turns out that, when the query q contains one (several) negated atom(s), the query satisfies the Homomorphism Theorem iff its tgd(ded)-version is uniformly one-bounded. We also show that CQHT¬ membership is EXPTIME-hard, but its complexity reduces to Π2P in the CQHT1¬ case, and to NP when bounding the number of positive atoms that can unify with the negated one.

Keywords and phrases:
conjunctive queries, query containment, safe negation, tgd, one-boundedness
Copyright and License:
[Uncaptioned image] © Xavier Oriol; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Logic and databases
; Theory of computation Database query processing and optimization (theory)
Funding:
Supported by PID2021-127181OB-I00 (MCIN/AEI), and 2021-SGR-01252.
Supplementary Material:
Text  (Technical Propositions): https://doi.org/10.5281/zenodo.18010617
Editors:
Balder ten Cate and Maurice Funk

1 Introduction

Query containment stands as one of the most fundamental problems in databases. Given two queries, q1 and q2, the query containment problem seeks to determine whether all the tuples retrieved by q1 are also retrieved by q2, irrespective of the underlying data. This question finds applications across various domains, from information integration and query optimisation to materialised view maintenance and constraint checking [3]. Thus, extensive study has been devoted to this problem, particularly for conjunctive queries (CQ) under set semantics, which corresponds to the select-project-join subset of relational algebra. Indeed, in today’s database (DB) usage, CQs are the most prevalent kind of queries [17].

Given its significance, substantial algorithmic and theoretical research has tackled CQ containment. The most famous results, possibly, are that the problem is NP-complete and that it can be solved through a homomorphism test (aka Homomorphism Theorem) [5]. I.e., given two CQs q1 and q2, we can check whether q1 is contained in q2, noted as q1q2, by creating the canonical DB of q1 (i.e. creating a DB by replacing every variable from q1 with a new fresh constant), and querying q2 over this canonical DB. From here, several refinements are possible. E.g., the problem becomes PTIME when the queries do not contain more than two atoms with the same predicate [19], or when we can bound its hypertree-width [10].

Yet, these results lose applicability when dealing with CQ extended with safe base negation (from now on CQ¬), i.e., queries containing negated atoms whose variables appear in positive atoms.

Example 1.

Consider the following boolean queries, which include safe negated atoms. qa retrieves whether there is some place p that, despite having train connections to cities, is connected to some city by aeroplane but not by train. qb retrieves whether there is some place which, despite having some city connections, is not connected by train to some city:

qa() :-  Connects(p,c1,Train), City(c1),
  Connects(p,c2,Aeroplane), City(c2), Connects(p,c2,Train).
qb() :- Connects(p,c1,t), City(c1), City(c2), Connects(p,c2,Train).

Clearly, qaqb since there is a homomorphism from qb to qa (i.e., {tTrain}). Indeed, the homomorphism test is always sound to check containment, even in CQ¬ [16]. From now on, we will write q2q1 to indicate that there is a homomorphism from q2 to q1.

However, the lack of homomorphism from qa to qb is not sufficient to assess that qbqa. Indeed, the homomorphism test is sound, but incomplete, in CQ¬. Hence, a far more sophisticated technique is required. Indeed, under the presence of negated atoms, the problem is known to be Π2P-hard [7, 20]. Consequently, such techniques encompass generating and analysing an exponential number of different canonical versions of qa [8, 20].

To address this situation, in this paper we study the conjunctive queries extended with at most one negation (CQ1¬), and those extended with several negated atoms (CQ¬), and characterise the classes CQHT1¬ and CQHT¬, i.e., their respective subclasses that satisfy the Homomorphism Theorem. That is, those boolean conjunctive queries with negation q2 s.t., in essence, given any other boolean conjunctive query with negation q1, q1q2 iff q2q1. This not only permits reducing the complexity to NP, but also exploiting the techniques given for checking homomorphisms faster [19, 10]. E.g., as we will see, both queries presented previously belong to CQHT1¬. Thus, we can check containment via the homomorphism test, and, furthermore, since no predicate appears more than twice, we can do it in PTIME [19].

To identify whether a query belongs to CQHT1¬ or CQHT¬, we realise that it is equivalent to answering whether a full-dependency (a full-tgd in the CQ1¬ case, and full-ded in the CQ¬), is uniformly one-bounded, or not, which is a property already studied in the context of logic programming [18, 13] and the chase algorithm [2]. A full-dependency is a rule of the form x¯.ϕ(x¯)i=1..nPi(xi¯), where ϕ is a conjunction of atoms and Pi(xi¯) is an atom s.t. xi¯x. A full-dependency is a full-tgd when n=1, and a full-ded when n>1. Given a full-dependency t, and a database D, chasing D with t means, roughly speaking, creating the minimal necessary atoms Pi(xi¯) to satisfy t in D. Do note that, if the predicate Pi appears in ϕ, we might need to recursively chase D. In essence, a full-dependency is said to be uniformly one-bounded if and only if, for any database D, any fact P(x¯) obtained by the chase can be obtained in a single chase step (i.e., without recursion). Bounded (full-)tgds have been well-studied since they permit avoiding recursion, and allowing first-order rewritings [1]. In this paper, we naturally extend this notion to full-deds.

Our main result is that a CQ with safe base negation satisfies the Homomorphism Theorem iff its dependency-version is uniformly one-bounded, where the dependency-version of a query is the dependency obtained by placing the negated atoms of the query in the right-hand side of the dependency (resulting in a tgd, in the CQ1¬ case, and in a ded, in the CQ¬ case).

Example 2.

The dependency-version of the queries from Example 1 are:

ta: Connects(p,c1,Train), City(c1),
      Connects(p,c2,Aeroplane), City(c2) -> Connects(p,c2,Train)
tb: Connects(p,c1,t), City(c1), City(c2) -> Connects(p,c2,Train)

Both dependencies are uniformly one-bounded tgds (i.e., we can see that, when unfolding the first Connects predicate from the tgd ti, with the very same tgd ti, we obtain a new tgd ti s.t. titi). Hence, qa and qb belong to CQHT1¬.

We show this tight connection between the Homomorphism Theorem and dependency uniform one-boundedness by reducing containment over CQ¬ into an Ontology-Based Data Access (OBDA) consistency problem. In essence, given two boolean queries q1 and q2, we build an ontology, using dependencies, that captures the DB counterexamples of q1q2; thus, its unsatisfiability proves containment. It is worth mentioning that this idea of reducing query-containment into ontology consistency has already been explored in [4, 8] to deal with query containment under constraints.

In summary, our contributions are:

  • We define the classes CQHT1¬ and CQHT¬ of boolean conjunctive queries extended with one or several negated atoms, that satisfy the Homomorphism Theorem.

  • We show that identifying whether a query qCQ1¬ belongs to CQHT1¬ is, in essence, the very same problem as identifying whether a full-tgd is uniformly one-bounded.

  • We extend the notion of uniform one-boundedness to full-deds, and show that identifying whether a query qCQ¬ belongs to CQHT¬ is, in essence, the very same problem as identifying whether a full-ded is uniformly one-bounded.

  • We demonstrate that deciding whether a query qCQ¬ belongs to CQHT¬ is EXPTIME-hard, but, in the CQHT1¬ case, its complexity lies between NP and Π2P, mirroring the currently observed complexity for the chase-firing problem [12], and it is in NP when bounding the number of positive atoms that can unify with the negated atom.

As subsidiary contributions, we also show how to build a datalog (disjunctive-datalog) program that checks whether there is a containment between two conjunctive queries with one (several) negated safe atoms.

2 Preliminaries

In the following, we introduce the basic logic notions we will use throughout the paper:

A term is either a variable, a constant, or a labelled null. We denote variables with lower case alphabetic characters (e.g., x, y, z), labelled nulls with strings starting with “#” (e.g., #x, #y, #z), and constants with strings starting with upper case characters (e.g., Train, John). A vector of terms is denoted by t¯.

A predicate is composed of a name and some arity (e.g. Connects is a 3-ary predicate). An atom is an n-ary predicate with n terms (e.g. Connects(x,y,Train)). A ground atom is an atom whose terms are labelled nulls or constants (e.g., Connects(#x,#y,Train)).

A substitution σ is a mapping from variables and labelled nulls to terms. Variables can be mapped to any term, whereas labelled nulls can only be mapped to other labelled nulls or constants. Applying a substitution σ to an atom (or conjunction of atoms) a, denoted by a[σ], consists in simultaneously replacing each variable (labelled null) v with σ(v) in a (in case σ(v) is defined). We denote a substitution with {v1t1,v2t2,} where vi are different variables and labelled-nulls and ti are terms. If all the variables are mapped to labelled nulls or constants, we call the substitution ground.

A database D is a finite set of ground atoms. Given a ground atom a, a is true in D, denoted by Da, iff aD.

Next, we review the notions of conjunctive queries and query containment.

A boolean CQ is a formula composed of a 0-ary atom, called the head, and a conjunction of atoms, called the body. E.g., q() :- A(x)B(x,y) is a CQ, where q() is the head and A(x)B(x,y) is the body. Given a boolean CQ q, and a database D, we say that the query is true in D, denoted by Dq, iff there exists a ground substitution σ that makes all the atoms of the body of q true w.r.t. D. A boolean CQ q1 is contained in another boolean CQ q2, denoted by q1q2, iff, for any database D s.t. Dq1, we have Dq2.

Given two boolean queries q1 and q2, a homomorphism from q2 to q1, denoted by q2q1, is a substitution σ that makes the body of q2 contained in the body of q1. Similarly, given a conjunction of positive atoms a, a database D, and a substitution σ s.t. Da[σ], we say that σ is a homomorphism from a to D (shortly, D satisfies a) and write, abusing notation, Da. We naturally extend the notion of homomorphism to databases as follows. Given two databases D1 and D2, a homomorphism from D1 to D2 is a substitution σ s.t. D1[σ]D2.

Given a set of (possibly non-ground) atoms, its freeze is the DB obtained after applying a substitution that replaces each variable with a fresh labelled null. Given a boolean CQ q, we define freeze(q) as the freeze of its body. E.g., the freeze of q() :- A(y)B(y,#z,John) is the DB {A(#y),B(#y,#z,John)}. Given two boolean CQ q1 and q2, we can check whether q2q1 by querying q2 over freeze(q1).

Next, we summarise the notions of tgds, deds, and OBDA techniques we require:

A (full-)dependency is a formula x¯.ϕ(x¯)i=1..nPi(xi¯), where ϕ is a conjunction of atoms, called the left-hand side (LHS), and i=1..nPi(xi¯) is a disjunction of atoms, called the right-hand side (RHS), with xi¯x¯. We denote the LHS and RHS of a dependency t by LHS(t) and RHS(t), respectively. Do note that we do not consider existential variables (i.e. all the variables appearing in the RHS also appear in the LHS). Given a dependency t and a database D, we say that D satisfies t, noted as Dt, iff for any homomorphism σ from LHS(t) to D, we have DPi(xi¯)[σ] for some Pi(xi¯)RHS(t). Otherwise, we say that D violates t. When the dependency only contains one atom in its RHS, we call it a tgd (tuple-generating dependency); when it contains several, we call it a ded (disjunctive-embedded dependency); and when it has none, we call it a denial. For brevity, we use the terms tgd/ded to refer to full-tgd/ded, and we omit the logic quantifiers.

An ontology O is a pair T,D, where T is a set of dependencies, and D is a database. A model of an ontology O is a set of ground atoms M s.t. 1) there is a homomorphism from D to M, and 2) every dependency tT is satisfied by M. We might use models(O) to refer to all the models of an ontology O. Given a boolean conjunctive query q, we use the certain answer semantics. That is, querying q over O consists in answering whether q is true in every possible model of O, which we note as T,Dq. Since we only work with full-dependencies, all models are finite.

Given an ontology O=T,D, where T is only composed of full-tgds, its universal model is a finite model Mmodels(O) s.t., for any other model Mmodels(O), MM. Given an ontology O and a (union of) conjunctive query(ies) q, we can obtain the certain-answers of q over O by querying q over its universal model M [6]. More in general, if the ontology is composed of full-tgds, full-deds, and denials, its universal model set is a finite set of models M1, …, Mnmodels(O), s.t., 1) for any possible model M, there is some Mi s.t. MiM, and 2) the set is minimal, i.e., there are no two models in the universal model set Mi,Mj s.t. MiMj [6]. In this case, we can check Oq by querying q over all the models Mi of the universal model set.

Given an ontology T,D, s.t., there is a full-tgd tT that is violated in D for some substitution σ, applying a chase step means adding RHS(t)[σ] into D. In case t is a ded violated in D for some substitution σ, applying a chase step means adding some P(x¯)[σ] into D, where PRHS(t). In case t is a denial, the chase is considered to fail, and no solution exists. The chase algorithm consists in iteratively applying any possible chase step until reaching a new database D where all dependencies are satisfied. If the ontology is composed solely of full-tgds, the result is unique and is the universal model of O. If the ontology contains full-dependencies, and we use the chase to explore every possible solution, we can obtain its universal model set.

Given a tgd t, we say that it is uniformly one-bounded (or one-bounded, for short) iff, given any database D and ground atom A(c¯), if t,DA(c¯) we can obtain A(c¯) in, at most, one single chase step. That is, either A(c¯)D, or there exists a substitution σ s.t. DLHS(t)[σ], and A(c¯)=RHS(t)[σ].

3 Problem definition

In this paper, we refer to the boolean CQ extended with base negated atoms as CQ¬. As expected, a CQ with negation q is true in a database D, denoted as Dq, iff there exists a ground substitution σ such that, for every positive atom a in the body of q, a[σ]D, and for every negated atom ¬b in the body of q, b[σ]D. We only consider safe negation, i.e., queries where all variables appearing in a negated atom also appear in at least one positive atom of the same query.

We extend also the notion of homomorphism q2q1 to queries with negation by requiring that the substitution σ maps every positive atom a of q2 to a positive atom a[σ] in the body of q1, and every negated atom ¬b of q2 to a negated atom ¬b[σ] in the body of q1.

To study which queries from CQ¬ satisfy the Homomorphism Theorem, we must first formalise this notion. In particular, to bring a meaningful definition, we must be careful with those queries containing a contradiction. E.g., q() :- A(x¯)P(x¯)¬P(x¯) is trivially contained in any other query, independently of having/not-having any homomorphism. Do note that such contradictions can be found by checking another homomorphism. I.e., we can find a contradiction by checking the existence of a homomorphism from P(x¯)¬P(x¯) (for every predicate P) to the body of our query.

Thus, we consider that a query q2 satisfies the Homomorphism Theorem, in essence, if the containment w.r.t. another query q1 can be determined by checking a homomorphism from q2 to q1, and checking whether q1 contains or not a contradiction:

Definition 3.

Given a boolean query q2CQ¬, we say that q2 satisfies the Homomorphism Theorem if and only if, q1CQ¬, we have: q1q2 iff (q2q1 or qPq1 for some qP of the form qP() :- P(x¯)¬P(x¯)). We refer to the subset of queries from CQ¬ that satisfy the Homomorphism Theorem as CQHT¬.

The main purpose of this paper is to characterise the set CQHT¬. That is, bringing a way to identify whether a query qCQ¬ belongs to CQHT¬. For our purposes, we will also study a slightly simplified case. That is, we will study the boolean conjunctive queries with at most one negated atom (from now on CQ1¬), and study when they satisfy the Homomorphism Theorem. Formally:

Definition 4.

Given a boolean query q2CQ1¬, we say that q2 satisfies the Homomorphism Theorem if and only if, for any other query q1CQ1¬, we have: q1q2 iff (q2q1 or qpq1 for some qp of the form qP() :- P(x¯)¬P(x¯)). We refer to the subset of queries from CQ1¬ that satisfy the Homomorphism Theorem as CQHT1¬

4 Identifying 𝑪𝑸𝑯𝑻¬: the intuitions

In this section, we bring the intuitions about how to check whether a query from CQ¬ satisfies the Homomorphism Theorem, and thus, belongs to CQHT¬. As we are going to see, such a query belongs to CQHT¬ iff its dependency-version is one-bounded. The formal theorems are left for the next section.

In particular, we reach such intuitions by reducing the problem of query containment of CQ¬ boolean queries to an OBDA consistency problem. That is, we build an ontology whose models represent the databases that witness the non-containment of the queries. As a result, if the ontology admits one (finite) model, there is a database counterexample for such containment. This reduction is already present in some other works, such as [4, 8].

In the following, we first discuss the reduction to an ontology finite satisfiability problem, then, we discuss why the queries whose dependency-version is one-bounded satisfy the Homomorphism Theorem, and finally, we discuss why the queries that satisfy the Homomorphism Theorem have one-bounded dependency-versions. From now on, abusing the language, we will call a query whose dependency-version is one-bounded a one-bounded query. In addition, we will only work with boolean queries with at most one negation (i.e., CQ1¬) to explain the intuitions with the easiest case.

4.1 Checking query containment with ontology satisfiability

To illustrate how to check boolean query containment via ontology finite satisfiability, consider again the queries qa and qb from Example 1, and assume that we want to check qaqb.

The idea is to build an ontology whose models represent those databases that satisfy qa but falsify qb. With this ontology at hand, we can check query containment by means of checking whether the ontology is finitely satisfiable, which can be done by computing the universal model of the ontology through the chase algorithm.

Creating an ontology whose models falsify qb can be done by adding a simple dependency in the ontology. In particular, consider the tgd tb, from Example 2 obtained by placing, in its LHS, all the positive atoms of qb, and placing, in its RHS, the unique negated atom of qb. Clearly, any model that satisfies such tgd falsifies the query qb because, whenever there is a substitution of variables that makes the positive atoms of qb true in the model, the very same substitution must also make true the negated atom of qb, thus, falsifying the query.

Making the models of the ontology represent those databases that satisfy qa is more complicated due to its negated atom. In fact, if there were no negated atoms, this would be as easy as using, as the initial database for our ontology, the freeze of qa. The problem is that the notion of query freeze for queries including negated atoms is not defined.

To deal with negated atoms, our idea is to modify the query to transform negated atoms into new positive ones, and modify the ontology to add the semantics that such new atoms represent negated atoms. This idea already appears in [6]. Basically, in our example we have to 1) change the negated atom ¬Connects(p,c2,Train) for a positive atom with a new fresh predicate notConnects(p,c2,Train), and 2) add, in the ontology, the denial Connects(x,y,z)notConnects(x,y,z).

In the following example, we show the ontology we would build to check whether qaqb.

Example 5.

Consider the ontology composed of the tgd tb (the dependency-version of qb), together the freeze of qa after replacing its negated atom for a new notConnects atom, and a denial stating the semantics of notConnects:

database: Connects(#p,#c1,Train), City(#c1), Connects(#p,#c2,Airplane), City(c2), notConnects(#p,#c2,Train).dependencies: Connects(p,c1,t), City(c1), City(c2) -> Connects(p,c2,Train). Connects(x,y,z), notConnects(x,y,z) -> .

Now, we can check if this ontology is finitely satisfiable. We can do so by chasing our database with the tgd dependency, and check whether its result violates the denial dependency. In this case, the chase generates the new tuple Connects(#p,#c2,Train). Thus, do note that we are violating the denial since, in the initial database, we already have notConnects(#p,#c2,Train). Hence, the ontology is unsatisfiable, which means that there is no database counterexample of the containment qaqb, and therefore, qaqb.

For brevity, from now on, given two boolean queries q1 and q2, we refer to an ontology that captures the database counterexamples for q1q2 as nonContainOnt(q1, q2). We will later formally define such an ontology in Section 5.1.

4.2 One-bounded queries satisfy the Homomorphism Theorem

In the following, we illustrate, with an example, why queries whose dependency-version is one-bounded satisfy the Homomorphism Theorem. That is, given two boolean conjunctive queries with at most one negated atom q1 and q2, where q2 is one-bounded, we show that if q2↝̸q1 and q1 does not contain any contradiction, then q1q2.

We show this by exploiting the ontology we have defined in the previous section. That is, when q2 is one-bounded, given any query q1, we show that if nonContainOnt(q1,q2) is unsatisfiable, then, q2q1 (or q1 contains a contradiction).

The first basic intuition is that, given the ontology nonContainOnt(q1,q2), the chase generates, roughly speaking, the negated atoms of q2 to falsify q2, and the negated atom of q1 forbids generating some of such atoms. We illustrate this with the following example:

Example 6.

Consider the following query that checks if some place p connects a city BCN through t, but does not connect to a city LIS through t.

qc :- Connects(p, BCN, t), City(BCN), City(LIS), not(Connects(p, LIS, t))

In addition, assume that we want to check whether qcqb, where qb is the query defined in Example 1. To do so, we can build the nonContainOnt(qc,qb) ontology:

database: Connects(#p, BCN, #t), City(BCN), City(LIS), notConnects(#p, LIS, #t).dependencies: Connects(p,c1,t), City(c1), City(c2) -> Connects(p,c2,Train). Connects(x,y,z), notConnects(x,y,z) -> .

Roughly speaking, when chasing the previous ontology, we will generate the necessary atoms of Connects(p,c2,Train) (the negated atom from qb) to make the query qb false, and the denial forbids the generation of Connects(#p,LIS,#t) (the negated atom of qc) to keep qc true. In other words, if the chase generates the atom Connects(#p,LIS,#t), the ontology is unsatisfiable and therefore, there is a query containment.

Then, since the tgd is one-bounded, all the atoms that can be generated by the chase can be directly identified by the different homomorphisms from the LHS of the tgd to the database. Indeed, roughly speaking, since the tgd is one-bounded, the new atoms generated by the chase cannot generate new homomorphisms that trigger the chase recursively. Continuing the previous example, we can identify the following homomorphisms from the LHS of the tgd to the database: σ1={p#p,c1BCN,t#t,c2BAR} and σ2={p#p,c1BCN,t#t,c2LIS}.

Do note that σ1 generates the new atom Connects(#p,BAR,Train), and σ2 generates the atom Connects(#p,LIS,Train). Furthermore, do note that, since the tgd is one-bounded, such new atoms do not generate new atoms in the chase recursively.

Now, if the ontology turns out to be unsatisfiable (i.e., if there is a containment), we must have violated the denial. There are two options: either the denial is violated in the very initial database (which would point to a contradiction in the query being frozen, which is not the case in our example), or it has been violated due to some atom generated during the chase. In our example, roughly speaking, the homomorphism σ2 creates an atom Connects(#p,LIS,Train), which causes the violation of the denial.

The key observation here is that the very same homomorphism that generates the atom that causes the denial violation is also a homomorphism from one query to the other.

In our example, σ2 generates the (forbidden) atom Connects(#p,LIS,Train), and σ2 is also an homomorphism from qbqc. Why is that? In essence, σ2 maps each positive atom from qb to qc by construction (since we have obtained σ2 by looking for a homomorphism from the LHS of the dependency-version of qb to the freeze of qc), and if it causes the denial violation, it also maps the negated atom from qb (the atom generated by the chase), to the negated atom of qc (the forbidden atom).

In summary, given two boolean queries q1 and q2, when the query q2 is one-bounded, testing whether there is a homomorphism from q2 to q1 checks whether any generated atom from chasing nonContainOnt(q1, q2) violates its denial. In other words, checking the homomorphism permits checking the nonContainOnt(q1, q2) satisfiability. This intuition will be later extended to the case of several negated atoms.

4.3 Queries satisfying the Homomorphism Theorem are one-bounded

In the following, we illustrate, with an example, why queries that satisfy the Homomorphism Theorem are, precisely, one-bounded queries. That is, given a boolean conjunctive query q2, we show that if q2 is not one-bounded then we can build a new query q1 s.t. q1q2 but q2↝̸q1 (where q1 does not contain any contradiction).

To do so, let’s consider a non-bounded query such as the following:

Example 7.

Consider the following query, which, in essence, checks whether the Connects relationship is not transitive.

qd() :- Connects(p1, p2, t), Connects(p2, p3, t), not(Connects(p1, p3, t))

Do note that qd is not one-bounded. Indeed, we can build an ontology that proves so:

database:       Connects(A, B, T), Connects(B, C, T), Connects(C,D,T)
dependencies:   Connects(p1, p2, t), Connects(p2, p3) -> Connects(p1, p3, t)

In essence, this ontology is formed by the dependency-version of qd, and several direct connections between AB, BC, and CD. It is easy to realise that chasing this ontology generates the atom Connects(A,D,T), but this atom cannot be generated within a single chase step, which proves that the dependency is not one-bounded.

Now, our main observation is the following: given the database D that proves that the query qd is not one-bounded, we can build a new query qe that is contained in qd, avoiding any homomorphism qdqe. The trick consists in creating a query qe whose positive atoms generate, when frozen, the database D; and adding in qe, as a negated atom, some atom that is obtained through several chase steps. That is, consider the new query qe:

qe() :- Connects(A,B,T),Connects(B,C,T),Connects(C,D,T),not(Connects(A,C,T))

This query is contained in qd, but it has no homomorphism with it. Why is that? The key idea lies in thinking again in terms of the ontology nonContainOnt(qe,qd).

The ontology is, by construction, unsatisfiable (indeed, the chase will generate the forbidden atom Connects(A,C,T) at some point), and since Connects(A,C,T) cannot be obtained in a single chase step, there is no homomorphism between the queries. Indeed, if there was an homomorphism from qe to qd, then, such homomorphism would also show the triggering of the depdendency-version of qe, with the freeze of qd, to generate Connects(A,C,T), which would mean that Connects(A,C,T) is obtained in a single chase step (contradiction!)

In summary, if some query q2 is not one-bounded, we can build another query q1 with some negated atom a s.t. nonContainOnt(q1,q2), when chased, generates a after several chase steps, and such atom a causes the violation of its denial (and therefore, ensures the containment q1q2). Furthermore, since a can only be generated after several chase steps, a makes the existence of any homomorphism from q2 to q1 impossible. Roughly speaking, the homomorphism test only checks the inconsistencies that can occur in nonContainOnt(q1,q2) within a single chase step, and if q2 is not one-bounded, we can create a query q1 where the inconsistency is found after several chase steps.

5 Formalizing 𝑪𝑸𝑯𝑻¬

Now we formalise the previous intuitions and generalise them to deal with boolean queries with several negated atoms.

In the following, we first define the notions relative to our ontology construction. In essence, we define the notions of dependency-version of a query, and its freeze, and formally prove that the ontology we build models the database counterexamples of the containment.

Then, we define, for our purposes, the notion of uniform one-boundedness for deds. Indeed, the notion of uniform one-boundedness is well defined for tgds, but, as far as we know, it has never been extended to deds. In our proposal, we define a ded as uniformly one-bounded if any atom from its universal model set can be obtained in at most one chase step, regardless of the original database.

Finally, we show that a query from CQ¬ belongs to CQHT¬ iff its dependency-version is uniformly one-bounded using the previous reduction to ontology finite satisfiability.

5.1 Building the nonContainOnt ontology

Assume two boolean conjunctive queries q1 and q2 with an arbitrary number of safe negated atoms (which might be 0). Our goal now is to formally define the construction of the nonContainOnt(q1, q2), that is, the ontology that models the counterexamples of the containment of q1q2. Recall that, in our intuitions, we have seen that the idea is to create a dependency-version of q2, and a freeze for q1, where the difficulty is that q1 might have a negated atom. We continue by 1) defining the notion of dependency-version of a query, 2) the notion of query freeze, where the query might contain several negated atoms, and 3) proving that, using such definitions, we can build the ontology nonContainOnt(q1, q2) which is (finitey) satisfiable iff q1q2.

Definition 8.

Given a boolean query q of the form q() :- p1pm¬n1¬nk, we define its ded-version as the disjunctive-embedded dependency: p1pmn1nk. Fixed a query q, we may refer to its ded-version as ded(q).

Example 9.

Given a query qf() :- P(x,y)Q(y,z)¬P(x,z)¬P(y,z), its dependency-version is P(x,y)Q(y,z)P(x,z)P(y,z).

Do note that, by construction, the dependency-version of a query with several negated atoms gives rise to a ded, whereas the dependency-version of a query with one negated atom gives rise to a tgd, and a query with no negation gives rise to a denial.

The freeze of a given query is a set of atoms where variables have been replaced with new fresh labelled nulls, and negated atoms have been replaced with new fresh predicates. Formally:

Definition 10.

Given an atom P(x¯), we define negate(P(x¯)) as the atom obtained by replacing the predicate P with a new fresh predicate notP. I.e., negate(P(x¯))=notP(x¯).

Then, given a query q() :- p1pm¬n1nk we define removeNegation(q) as the query q() :- p1pmnegate(n1).

Finally, given a boolean query qCQ¬, we define its freeze, noted as freeze(q), as the freeze of its removeNegation, i.e., freeze(q)=freeze(removeNegation(q)).

Example 11.

Given a query qg() :- P(x,y)¬P(x,x)¬P(y,y)¬R(x,y), its freeze is {P(#x,#y),notP(#x,#x),notP(#y,#y),notR(#x,#y)}.

Do note that the previous definition is an extension of the traditional notion of freeze for a conjunctive query (without negation) since it brings the very same result when the query does not contain any negated atom.

Now, we lack defining the semantics of the newly generated notP predicates. In essence, we need to create a denial stating that we cannot have P(t¯) and notP(t¯) at the same time.

Definition 12.

Given a query qCQ¬, let P1,,Pn be the predicates that appear in its negated atoms. We define the nonContradictionAxioms of q, noted as nonContradictionAxioms(q), to be the set of denials Pi(xi¯)negate(Pi(xi¯)), where xi¯ is a vector of different variables, and i=1..n.

Example 13.

The nonContradictionAxioms of the query qg from Example 11 are: P(x,y)notP(x,y) and R(x,y),notR(x,y).

Do note that the nonContradictionAxioms brings an empty-set when the query has no negation.

With all these, we can now define the nonContainOnt ontology of a couple of boolean queries q1 and q2 from CQ¬.

Definition 14.

Given a couple of boolean queries q1,q2CQ¬, we define nonContainOnt to be the ontology {ded(q2)}nonContradictionAxioms(q1),freeze(q1).

Example 15.

Given qf and qg from Examples 9 and 11, nonContainOnt(qg, qf) is

database: P(#x, #y), notP(#x,#x), notP(#y, #y), notR(#x, #y).dependencies: P(x, y), Q(y, z) -> P(x, z) v P(y, z). P(x, y), notP(x, y) -> . R(x, y), notR(x, y) -> .

With all this machinery, we can state our first main result. In essence, we can check query containment between a couple of boolean conjunctive queries with safe base negation via ontology (finite) satisfiability.

Theorem 16.

Given two boolean queries q1,q2CQ¬, we have that q1q2 if and only if nonContainOnt(q1,q2) is not finitely satisfiable.

Given two boolean conjunctive queries with safe negation q1 and q2, this result tells how to use a chase algorithm dealing with deds (such as [6]) to check query containment with negation. In essence, we have to compute the universal model set and check whether there is some model in the universal model set that does not violate any denial present in the ontology. Furthermore, if q2 only contains one negated atom, we can do so with a standard chase dealing with tgds (instead of deds).

Equivalently, we can check whether q1q2 by checking whether nonContainOnt(q1,q2), excluding its denials, entails the denials. To do so, consider the following definitions:

Definition 17.

Given two boolean queries q1,q2CQ¬, and its corresponding ontology nonContainOnt(q1,q2), we define:

  • nonContainOnt+(q1,q2) to be the ontology obtained after removing any denial from nonContainOnt(q1,q2).

  • inconsistencyQuery(q1,q2) to be the query formed by the disjunction of all the bodies of all the denials from nonContainOnt(q1,q2).

Example 18.

Consider the nonContainOnt(qg, qf) ontology of Example 15. In this case, nonContainOnt+(qg,qf) is the ontology:

database: P(#x, #y), notP(#x,#x), notP(#y, #y), notR(#x, #y).dependencies: P(x, y), Q(y, z) -> P(x, z) v P(y, z)and the inconsistencyQuery(qg,qf) is the query:

q() :- P(x,y), notP(x,y) V R(x,y), notR(x,y)

Exploiting current knowledge from the literature, given two boolean queries q1, q2 from CQ¬, we can check whether nonContainOnt(q1,q2) is finitely satisfiable by checking whether nonContainOnt+(q1,q2)⊧̸inconsistencyQuery(q1,q2).

Moreover, exploiting the fact that we work with full-dependencies (i.e, there are no existential variables in the RHS of any dependency), we could use a disjunctive-datalog engine to check if nonContainOnt+(q1,q2)⊧̸inconsistencyQuery(q1,q2) In addition, if q2 contains only one negated atom, the ontology nonContainOnt+(q1,q2) would only contain one full-tgd, and thus, we could use a pure datalog engine to solve the query containment problem of q1q2. We summarise the previous observations in the following corollary:

Corollary 19.

Given two boolean queries q1,q2 with possibly some negated atoms.

  • If q2CQ¬, we can check q1q2 via disjunctive-datalog query answering.

  • If q2CQ1¬, we can check q1q2 via datalog query answering.

Interestingly, in the special case where the queries q1 and q2 are pure conjunctive queries, we end up with an ontology with a single denial (stating, roughly speaking, that q2 must be false), and with a database that is, precisely, the freeze of q1. Thus, checking the satisfiability of the ontology consists in checking that the denial is not violated in the database, which, in essence, is a homomorphism test from q2 to q1.

5.2 Uniform one-boundedness of deds

For the case of full-deds, to the best of our knowledge, there is no similar notion of uniform one-boundedness as we have for full-tgds. For our purposes, we define that a full-ded is uniformly one bounded iff any atom that appears in its universal model set can be obtained in a single chase step. More formally:

Definition 20.

Given a full-ded t, we say that t is uniformly one-bounded iff for any database D, and any M from the universal model set of t,D, we have that, for any atom aM, there is a substitution σ s.t. DLHS(t)[σ] and aRHS(t)[σ].

Do realise that such a definition is a natural extension of the notion of uniform one-boundedness for full-tgds. Indeed, when applying the previous definition to the tgd case, we only have one universal model M where each atom in M must be obtained in a single chase step (which coincides with the classical definition of uniform one-boundedness for full-tgds).

5.3 Satisfying the Homomorphism Theorem

We now move to our main result, that is, a conjunctive query with negated atoms satisfies the Homomorphism Theorem iff its ded-version is uniformly one-bounded.

To achieve this result, we first show that, given two queries q1 and q2, where q2 is one-bounded, if there is a containment, we have that there is a homomorphism from q2q1 (or q1 is inconsistent). Then we show the opposite.

5.3.1 One-boundedness implies the Homomorphism Theorem

Assume a couple of queries q1,q2CQ¬ where q2 is one-bounded. We will now study whether q1q2 via the nonContainOnt(q1, q2), and we will conclude that there is a containment only if q2q1 (or q1 contains a contradiction). Equivalently, we will see that nonContainOnt+(q1, q2) inconsistencyQuery(q1, q2) only if q2q1 (or q1 contains a contradiction).

To study whether nonContainOnt+(q1, q2) inconsistencyQuery(q1, q2), we can compute its universal-model set, and check whether every model from the universal-model set satisfies inconsistencyQuery(q1, q2). If we find some model that does not satisfy inconsistencyQuery(q1, q2), this means that inconsistencyQuery(q1, q2) is not entailed, and hence, nonContainOnt(q1, q2) models a database counterexample for the containment q1q2.

If ded(q2) is uniformly one-bounded, that means that all the models of the universal model set can be obtained, loosely speaking, by first computing all the homomorphisms σ from LHS(ded(q2)) to freeze(q1). Indeed, once we have all such homomorphisms, obtaining their universal models is a matter of selecting, for each σ, some atom in RHS(ded(q2))[σ].

Taking a look on the freeze(q1), we should realize that, if we we want to avoid entailing inconsistencyQuery(q1, q2), we should find some model in the universal model set that does not contain any P(X¯) if we have notP(X¯) in freeze(q1).

Now, the intuitive idea is that when checking if q2q1, we are checking if all the homomorphisms σ from LHS(q2) to freeze(q1) that triggers the execution of the ded, permits the chase find some model that does not satisfy the inconsistencyQuery(q1, q2), or on the contrary, all the possibilities (all the atom ins RHS(ded(q2))[σ]) leads to an inconsistency since all atoms in RHS(ded(q2))[σ] appear in freeze(q1) (in the form of notP atoms). To illustrate this, consider the following example:

Example 21.

Consider the following queries:

ql  :- P(x,y,z), not(P(y,z,x)), not(P(z,x,y))
qm  :- P(a,b,c), not(P(b,c,a)), not(P(a,a,a))
qm’ :- P(a,a,b), not(P(a,b,a)), not(P(b,a,a))

To check whether qmql, we can build the following ontology and inconsistency query:

database:           P(#a,#b,#c), notP(#b,#c,#a), notP(#a,#a,#a)
dependencies:       P(x,y,z) -> P(y,z,x) v P(z,x,y)
inconsistencyQuery: P(x,y,z), notP(x,y,z)

The inconsistencyQuery is not entailed, which can be proved by the model {P(#a,#b,#c), notP(#b,#c,#a), notP(#a,#a,#a), P(#c,#a,#b)}. In essence, the absence of a homomorphism from ql to qm permits instantiating the atom P(#c,#a,#b) to satisfy the dependency without satisfying the inconsistencyQuery.

However, if we check whether qmql we can build the following different ontology:

database:           P(#a,#a,#b), notP(#a,#b,#a), notP(#b,#a,#a)
dependencies:       P(x,y,z) -> P(y,z,x) v P(z,x,y)
inconsistencyQuery: P(x,y,z), notP(x,y,z)

The inconsistencyQuery is now entailed. Indeed, the current database violates the dependency through the homomorphism {x#a,y#a,z#b}, and the chase forces to instantiate either P(#a,#b,#a) or P(#b,#a,#a), but since σ is also an homomorphim from ql to qm, both options leads to satisfying the inconsistencyQuery.

5.3.2 Main result

Now we go to the main result, that is, we show that being one-bounded is not only a sufficient condition, but also a necessary one to satisfy the Homomorphism Theorem. In essence, if the ded-version of a query q is not uniformly one-bounded, we can build a second query q1 that is contained in q, but without having any homomorphism qq1.

To do so, we depart from the database D that shows that q is not one-bounded. In particular, since q is not one-bounded, we have a database D that, when chased using ded(q), generates a universal model set {M1,,Mn} s.t., in some Mi, there is some atom a that cannot be obtained through a single chase step.

Now, create a new query q1 by taking all the positive atoms of D (so that, when chasing freeze(q1) with ded(q2) we basically obtain the previous models {M1,,Mn}. Now, for each Mj, we pick some atom ajMjD and include its negation in q1 (so that, freeze(q1) will include notAj, making such model Mj satisfy a contradiction ajnotAj). The crucial point is that, for the case Mi (the model that contained an atom a that could not be obtained in a single chase step), we will include the atom notA (so that there is no homomorphism from q to q1). To illustrate this, consider the following example:

Example 22.

Suppose that we have the query:

qn() :- P(A, y), P(y, z), not(P(A, z)), not(P(A, A))

Do note that this query is not one-bounded. Its dependency-version P(A,y)P(y,z)P(A,z)notP(A,A) is not one-bounded since the database {P(A,B),P(B,C),P(C,D)} makes this ded generate a universal-model set with two models:

model1: P(A, B), P(B, C), P(C, D), P(A, C), P(A, D)
model2: P(A, B), P(B, C), P(C, D), P(A, A)

where, in the first model, the atom P(A,D) is obtained, necessarily, through two chase steps. Thanks to this database and models, we can build the following query that shows that qn does not satisfy the Homomorphism Theorem:

qo() :- P(A, B), P(B, C), P(C,D), not(P(A,D)), not(P(A,A))

In essence, the query is built by picking the atoms from the database counterexample and writing them as positive atoms in our query; picking the atom that was derived through two chase steps, and writing its negation in the query; and picking another atom from the other model, and writing its negation in the query. Do note that qoqn. Indeed, chasing ded(qn) with freeze(qo) creates the two models we have previously seen, accompanied by the atoms notP(A,D) and notP(A,A) from the freeeze(qo), so, each of this models entails a contradiction P(x,y)notP(x,y). Furthermore, there is no homomorphism qnqo since the negated atom P(A,D) is obtained through two chase steps.

Using the previous observation, we reach our main result (Theorem 23). In addition, by limiting our main result to the CQ1¬, we see that a query qCQ1¬ satisfies the Homomorphism Theorem iff the tgd corresponding to q is one-bounded.

Theorem 23.

A boolean query qCQ¬ is in CQHT¬ iff ded(q) is uniformly one-bounded.

Corollary 24.

A boolean query qCQ1¬ is in CQHT¬ iff ded(q) is a one-bounded tgd.

6 Complexity for deciding 𝑪𝑸𝑯𝑻¬ and 𝑪𝑸𝑯𝑻𝟏¬ membership

We now study the complexity of deciding whether qCQ¬ belongs to CQHT¬. As we are going to see, the problem is EXPTIME-hard due to a reduction from full-tgd fact entailment [11]. To lower this result, we study the complexity of CQHT1¬, and see that its complexity lies between NP and Π2P, which virtually mirrors the known complexity of the chase triggering problem [12], whose similarity with our problem is also discussed.

6.1 Complexity for deciding 𝑪𝑸𝑯𝑻¬ membership

We show that deciding whether qCQ¬ belongs to CQHT¬ is EXPTIME-hard. We do so through a reduction from full-tgd combined complexity fact entailment (aka sirup combined complexity) [11]. In particular, the problem of full-tgd combined complexity consists in deciding whether, given a full-tgd t of the form p1pnn, a database D with contents {d1,,d|D|}, and some ground atom a, we have t,Da.

To grasp the intuition of the reduction, suppose that tgd t is not uniformly one-bounded, and the very same database D generates a universal model set U that proves so. Bearing this in mind, we build a new full-ded t2 of the form d1d|D|p1pnna. The idea is that, if t,Da, for any given database D, the universal model set of t2,D is: D when DD; and D{a} when DD (and thus, the ded t2 is uniformly one-bounded). On the contrary, if t,D⊧̸a, the universal model set of t2,D is U{Da}, and thus, it is not uniformly one-bounded.

Theorem 25.

Deciding whether a full-ded t is uniformly one-bounded is EXPTIME-hard.

Corollary 26.

Deciding CQHT¬ membership is EXPTIME-hard.

6.2 Complexity for deciding 𝑪𝑸𝑯𝑻𝟏¬ membership

We now show that CQHT1¬ membership complexity lies between NP and Π2P. The NP lower bound is clear due to previous literature results. Certainly, it is known that checking uniform one-boundedness for the case of linear full-tgds (full-tgds where the LHS only contains one atom whose predicate matches the predicate of the RHS atom) is NP-hard [13].

Theorem 27.

Deciding CQHT1¬ membership is NP-hard.

The Π2P upper bound comes from the fact that checking full-tgd not one-boundedness can be done in Σ2P. The proof is based on applying unfoldings over full-tgds [8]. In essence, given a tgd with some atom P(x¯) in its RHS, unfolding the tgd consists in replacing some atom P(y¯) with the way it can be derived through the tgd itself. To illustrate this, consider the following example:

Example 28.

Consider the tgd P(x,y)P(y,z)P(x,z). By unfolding the first atom we obtain P(x,y)P(y,y)P(y,z)P(x,z); by unfolding the second atom we obtain P(x,y)P(y,y)P(y,z)P(x,z); and by unfolding simultanously both atoms we obtain: P(x,y)P(y,y)P(y,y′′)P(y′′,z)P(x,z).

Intuitively, an unfolded tgd shows the atoms it can generate by applying two chase steps. So, if all the unfolded tgds generate the same as the original tgd, we conclude that all the atoms that can be generated through two-chase steps can be generated within a single chase step, showing that the tgd is one-bounded.

To check whether some unfolded tgd generates the same atoms as the original tgd, it suffices to check if there is a homomorphism between the two (indeed, we can interpret the tgds as non-boolean conjunctive queries where the RHS is the head of the query).

Thus, given some tgd t, if we can nondeterministically find an unfolded tgd t s.t., there is no homomorphism from tt, we can conclude that t is not one-bounded, placing this problem in Σ2P. Consequently, the one-boundedness problem lies in Π2P. Furthermore, if we bound the number of predicates in the LHS of t that can be unfolded (i.e., if we bound the number of atoms whose predicate matches the predicate of the tgd’s RHS), the total amount of possible unfolded tgds is polynomial, making the problem NP-complete.

Theorem 29.

Deciding CQHT1¬ membership is in Π2P.

Theorem 30.

Given a boolean query qCQ1¬, s.t. the number of positive atoms that can unify with the negated atoms is bounded by some k, deciding whether qCQHT1¬ is NP-complete.

This result (NP lower bound and Π2P upper bound) is quite similar to the chase triggering problem complexity. The chase triggering problem consists in deciding whether, given two (general) tgds, firing one tgd can trigger another tgd. That is, given two (general) tgds, deciding whether there is a database D such that D violates the first tgd, and when applying the chase to repair this violation, we end up violating the second tgd (which was satisfied in D). This problem is known to be NP-hard with an upper-bound to Π2P (in fact, the result is even tightened to PNP) [12]. Do note that our problem is quite similar to it, with small tricky differences. Roughly speaking, we are checking whether a (full)-tgd can trigger itself (do note that we do not have existential variables in the tgd, as they do, which makes our problem more restricted in this sense). Second, we are interested in checking whether the obtained tuple from the second triggered tgd could be obtained from the original tgd in a single chase step (which is not taken into account in the chase-triggering problem).

7 Related Work

Conjunctive query containment was shown to be NP-complete in [5], who also proposed the homomorphism test as a solution. To reduce the complexity, some researchers found some cases where the problem was in PTIME. For instance, Sarayian [19] showed that, if the queries do not contain more than two atoms with the same predicate, containment can be checked in PTIME. Gottlob et al [10] defined the notion of bounded hypertree width, which made conjunctive query containment checking in PTIME too.

Considering that we can reduce a homomorphism test from queries including negated atoms to a homomorphism test between queries with only positive atoms (e.g., replace any not(p) atom by a fresh predicate notP), this paper enlarges the application of the previous work to the CQHT¬ case.

To check containment in CQ¬, Levy and Sagiv [15] proposed building an exponential number of canonical databases and applying a homomorphism test for each one of them. Later on, while reviewing this method, Ullman stated that the query containment problem in CQ¬ was Π2P-complete [20]. It turns out, however, that the upper-bound seems only valid when the arity of the predicates is bounded since Geck et al. [9] showed that it is coNEXPTIME-complete when arities are unbounded.

The work of Wei and Lausen [22, 21] is an optimised version of the work of [15, 20]. In essence, it uses the different homomorphisms between the queries to create several simpler containment tests. However, in the worst case, their approach might create the same exponential number of canonical databases. Similarly, the work of Farré et al [8] is based on building such canonical databases at runtime. Hence, they also face the problem of searching for a counterexample over an exponential search space.

The most similar result to our work is one from Mugnier et al [14], where a sufficient condition to assess that a query belongs to CQHT¬ is given. Basically, Mugnier et al state that if a query q2 does not contain two unifiable atoms with opposite polarity, q2CQHT¬. Indeed, this is a case in which q2CQHT¬ since, roughly speaking, the RHS of the ded(q2) cannot unify with the LHS of ded(q2), which makes ded(q2) trivially uniformly one-bounded. Do note that this property is sufficient, but not necessary, as the queries provided in Example 1 can show. It is also worth mentioning that, in a different paper, Mugnier et al studied conditions that, when satisfied by q1,q2CQ¬, the query-containment complexity of q1q2 can drop down to NP-complete [16]. Do note, however, that such conditions refer to both queries, whereas we have studied conditions over q2 alone.

8 Conclusions

We have defined the classes CQHT1¬ and CQHT¬ of CQs that satisfy the Homomorphism Theorem, having one or several safe negated atoms. We have seen that deciding CQHT1¬ (CQHT¬) membership is, in essence, the same problem as deciding whether a full-tgd (full-ded) is uniformly one-bounded. We have also seen that the problem is EXPTIME-hard for the CQHT¬ case, but Π2P in the CQHT1¬ case, and can be lowered down to NP when bounding the number of positive atoms that can unify with the negated atom. We have also shown how to solve query containment using datalog queries, when the query qCQ1¬, and disjunctive datalog queries, when qCQ¬. Numerous interesting further work problems can be addressed, such as:

  • Extending this approach to non-boolean queries. Indeed, it is not immediately clear how to define the dependency-version of a non-boolean query.

  • Extending this approach for non-safe negation. In this case, do note that the dependency-version of a query might be a ded with existential variables in the RHS. Is the characterisation based on one-boundedness still sound and complete?

  • Regarding complexity, what is the upper bound of identifying CQHT¬ membership? Can we provide tighter complexity bounds for the problem of identifying CQHT1¬ membership?

References

  • [1] Miklós Ajtai and Yuri Gurevich. Datalog vs first-order logic. J. Comput. Syst. Sci., 1994. doi:10.1016/S0022-0000(05)80071-6.
  • [2] Pierre Bourhis, Michel Leclère, Marie-Laure Mugnier, Sophie Tison, Federico Ulliana, and Lily Gallois. Oblivious and semi-oblivious boundedness for existential rules. In Proc. of the 28th IJCAI, 2019. doi:10.24963/IJCAI.2019/219.
  • [3] Diego Calvanese, Giuseppe De Giacomo, and Maurizio Lenzerini. On the decidability of query containment under constraints. In Proc. of the 7th ACM PODS, 1998. doi:10.1145/275487.275504.
  • [4] Diego Calvanese, Giuseppe De Giacomo, and Maurizio Lenzerini. Conjunctive query containment and answering under description logic constraints. ACM TOCL, 9(3), 2008. doi:10.1145/1352582.1352590.
  • [5] Ashok K Chandra and Philip M Merlin. Optimal implementation of conjunctive queries in relational databases. In Proc. of the 9th ACM STOC, 1977. doi:10.1145/800105.803397.
  • [6] Alin Deutsch, Alan Nash, and Jeff Remmel. The chase revisited. In Proc. of the 27th ACM PODS, 2008.
  • [7] Carles Farré, Werner Nutt, Ernest Teniente, and Toni Urpí. Containment of conjunctive queries over databases with null values. In ICDT. Springer, 2007. doi:10.1007/11965893_27.
  • [8] Carles Farré, Ernest Teniente, and Toni Urpí. Checking query containment with the cqc method. Data & Knowledge Engineering, 53(2), 2005. doi:10.1016/J.DATAK.2004.08.002.
  • [9] Gaetano Geck, Bas Ketsman, Frank Neven, and Thomas Schwentick. Parallel-correctness and containment for conjunctive queries with union and negation. ACM TOCL, 20(3), 2019. doi:10.1145/3329120.
  • [10] Georg Gottlob, Nicola Leone, and Francesco Scarcello. Hypertree decompositions and tractable queries. In Proc. of the 8th PODS, 1999. doi:10.1145/303976.303979.
  • [11] Georg Gottlob and Christos Papadimitriou. On the complexity of single-rule datalog queries. Information and Computation, 183(1), 2003. doi:10.1016/S0890-5401(03)00012-9.
  • [12] Gösta Grahne and Adrian Onet. Anatomy of the chase. Fundam. Inform., 157(3), 2018. doi:10.3233/FI-2018-1627.
  • [13] Paris C Kanellakis. Logic programming and parallel complexity. In Foundations of Deductive Databases and Logic Programming. Elsevier, 1988. doi:10.1016/B978-0-934613-40-8.50018-X.
  • [14] Michel Leclere and Marie-Laure Mugnier. Some algorithmic improvements for the containment problem of conjunctive queries with negation. In ICDT. Springer, 2007.
  • [15] Alon Y Levy and Yehoshua Sagiv. Queries independent of updates. In VLDB, volume 93, 1993. URL: http://www.vldb.org/conf/1993/P171.PDF.
  • [16] Marie-Laure Mugnier, Geneviève Simonet, and Michaël Thomazo. On the complexity of entailment in existential conjunctive first-order logic with atomic negation. Information and Computation, 215, 2012. doi:10.1016/J.IC.2012.03.001.
  • [17] François Picalausa and Stijn Vansummeren. What are real sparql queries like? In Proc. of the Int. Workshop on Semantic Web Information Management, 2011.
  • [18] Yatin P Saraiya. Polynomial-time program transformations in deductive databases. In Proc. of the 9th ACM PODS, 1990. doi:10.1145/298514.298551.
  • [19] Yatin P Saraiya. Subtree-elimination algorithms in deductive databases. Stanford Univ., 1991.
  • [20] Jeffrey D Ullman. Information integration using logical views. In ICDT. Springer, 1997. doi:10.1007/3-540-62222-5_34.
  • [21] Fang Wei and Georg Lausen. Containment of conjunctive queries with safe negation. In ICDT. Springer, 2003.
  • [22] Fang Wei and Georg Lausen. A unified apriori-like algorithm for conjunctive query containment. In Proc. of the Int. Symp. on Database engineering & applications, 2008. doi:10.1145/1451940.1451957.

Appendix A Proofs for Theorems

 Remark.

The proof of Theorem 25 requires the following (technical) proposition whose proof, for space limitation, is published at https://doi.org/10.5281/zenodo.18010617.

Proposition 31.

Given a tgd t, a database D, and a ground atom a, we can reduce, in polynomial time, the problem of deciding whether t,Da to deciding whether t,Da, where t is a tgd, and D shows that t is not uniformly one-bounded.

Theorem 16. [Restated, see original statement.]

Given two boolean queries q1,q2CQ¬, we have that q1q2 if and only if nonContainOnt(q1,q2) is not finitely satisfiable.

Proof.

We first prove that if q1q2 then nonContainOnt(q1,q2) is finitely satisfiable. Then, we prove the other direction.

Assume that q1q2. Hence, there is a database D s.t. Dq1 but D⊧̸q2. We are now going to build a model M of nonContainOnt(q1,q2) from D. In particular, lets add all the atoms from D into M and, additionally, for each atom P(C¯) that can be built using the constants and labelled nulls from D s.t. P(C¯)D, lets include negate(P(C¯)) into M. We are now going to prove that such M satisfies all the dependencies of nonContainOnt(q1,q2), and hence, it is a model.

M satisfies ded(q2), otherwise, the very same substitution σ that proves the violation of ded(q2) in M would also prove Dq2. M satisfies nonContradictionAxiom(q1) since, by construction, we avoid adding an atom and its negation at the same time. M satisfies freeze(q1) since the very same substitution σ that proves Dq1, also proves Mfreeze(q1).

We continue proving the other direction. That is, we now show that the finite satisfiability of nonContainOnt(q1,q2) implies q1q2. Assume that nonContainOnt(q1,q2) is finitely satisfiable, and hence, we have a finite model M for it. We are now going to build a database D that proves q1q2.

In particular, we are going to build D by means of simply removing any notP atom from M. We now prove Dq1 and D⊧̸q2.

Dq1 because the very same homomorphism σ that proves Mfreeze(q1) also proves Dq1. Indeed, we have that freeze(q1)[σ]M. To realise so, consider any positive atom p1i[σ] from the query q1. Dp1i[σ], because by construction of D, for any atom (in exception of those of the form notP) pMpD. Pick now any negated atom n1j[σ]. D⊧̸n1j[σ], because, if n1j[σ]D, then, by construction, n1j[σ]M, and thus, we would have that σ proves the violation of the non-contradiction axiom nnegate(n).

D⊧̸q2 because, if there was a homomorphism σ s.t. Dq2[σ], then, M would violate ded(q2) for σ.

Theorem 23. [Restated, see original statement.]

A boolean query qCQ¬ is in CQHT¬ iff ded(q) is uniformly one-bounded.

Proof (Soundness).

Given two boolean queries q1 and q2, we prove that, if ded(q2) is uniformly one-bounded, then, q2↝̸q1 implies q1q2.

Assume that q2 contains at least one negated atom, and thus, nonContainOnt+(q1, q2) contains one tgd or ded. Do note that, in case q2 has no negated atom, ded(q2) is a denial, nonContainOnt+(q1, q2) is an ontology solely composed of the freeze of q1, and the inconsistencyQuery(q1, q2) has the form i=1..k(P(xi¯)notP(xi¯))LHS(q2). Thus, do observe that, in such case, checking whether nonContainOnt+(q1, q2) inconsistencyQuery(q1, q2) is the same as checking whether there is a homomorphism q2q1 (and whether q1 contains some contradiction), thus, satisfying our intended result.

We now chase ded(q2) with freeze(q1) to obtain the universal model-set. To do so, we compute all the homomorphisms σ from the LHS of ded(q2) to freeze(q1). Then, for each one of these homomorphisms, we need to add, in the model, some atom a[σ] where a is an atom from the RHS of ded(q2). Do note that, since ded(q2) is one-bounded, we do not need to look for new homomorphisms triggering the ded. Technically speaking, this procedure might yield a superset of the universal model set, but this is not a problem at all. Indeed, we can check whether nonContainOnt+(q1, q2) inconsistencyQuery(q1, q2) by checking whether inconsistencyQuery(q1, q2) is satisfied in all the models of (a superset of) the universal model set of nonContainOnt+(q1, q2). From now on, we refer to this set as U.

We now check whether all the models from U satisfy the inconsistencyQuery(q1, q2). To do so, we first study the form of inconsistencyQuery(q1, q2). Since we have assumed that q2 contains, at least, one negated atom, the inconsistencyQuery(q1, q2) is of the form i=1..kPi(xi¯)notPi(xi¯), where each Pi is a predicate that appears negated in q1. We continue assuming w.l.o.g. that q1 contains at least some negated atom. In case q1 has no negated atom, do note that nonContainOnt(q1, q2) is trivially satisfiable since it does not contain any denial, and thus, q1q2.

We continue checking whether all the models from U satisfy i=1..kPi(xi¯)notPi(xi¯), where each Pi is a predicate that appears negated in q1. We show that if q2↝̸q1 (and q1 does not contain a contradiction), there is some model in U not satisfying any query of the form Pi(xi¯)notPi(xi¯). Assume now that q2↝̸q1, and q1 does not contain a contradiction.

We show that, when we were building the set of models U, at each step, there was always some (partial) model Mj that was not satisfying any Pi(xi¯)notPi(xi¯). Indeed, recall that we have built U by picking, for every homomorphism σ from the LHS(ded(q2)) to freeze(q1), some atom a in RHS(ded(q2))[σ]. Consider the list {σ1,,σn} containing all of such homomorphisms. We now denote by Ui the set of partial models obtained by picking, for each j=1..i, some atom aj[σj] in RHS(ded(q2))[σj]. The proof continues by induction.

In the base case, we have a set of partial models U0 which is composed solely of the initial database. Clearly, since q1 does not contain a contradiction, this initial database does not satisfy any query of the form Pi(xi¯)notPi(xi¯).

In the inductive case, we have a set of partial models Uj which, by induction hypothesis, contains some partial model Mj that does not satisfy any query of the form Pi(xi¯)notPi(xi¯). Pick now the next homomorphism σj+1. We show that there is some atom aRHS(ded(q2))[σj+1] that can be added in Mj without violating any query of the form Pi(xi¯)notPi(xi¯). We continue the proof by contradiction. Thus, assume that, for any aRHS(ded(q2))[σj+1], Mj{a} satisfies some Pi(xi¯)notPi(xi¯). If this is the case, σj+1 is, precisely, a homomorphism from q2q1 (contradiction).

Proof (Completeness).

We prove that if the ded(q) is not uniformly one-bounded, then qCQHT¬. To do so, we build a counterexample query q1 s.t. q↝̸q1 but where q1q.

Assume that ded(q) is not uniformly one-bounded. Hence, there is some finite database D that proves so. I.e., there is some finite database D, s.t. the universal model set of ded(q),D is U, where U contains at least one model M that contains at least one atom a that cannot be obtained, from D, through a unique chase step.

The idea is to use D to build the positive atoms of the query q1. That is, assuming D={d1,,d|D|} we start building q1 as q1() :- d1d|D|. Do note that the query q1 will be composed only of constants. We lack inserting some negated atoms in q1. To do so, assume, w.l.o.g., that the universal model set of ded(q),D is U={M1,,Mn} and that M1 contains the atom a that cannot be obtained in a single chase step. We add in q1 the atom ¬a, and for each Mi, i2, we add some atom ¬bi where biMi, and biM1.

We now prove that q↝̸q1, but q1q. We start proving that q↝̸q1 by contradiction. Assume that σ is the substitution that proves qq1. There are two cases: either σ maps some negated atom from q to ¬a, or not. In the first case, a can be obtained in a single chase step (contradiction). In the second case, σ maps every negated atom from q to atoms ¬bi (possibly a subset of them). In terms of deds, this means that σ is a violation of ded(q) w.r.t. freeze(q1), and thus, every model of ded(q),freeze(q1) should contain some of such bi atoms to avoid this violation, but M1 does not contain any (contradiction).

We conclude by proving q1q. By construction, every model of ded(q),freeze(q1) entails a non-contradiction axiom. Thus, by Theorem 16, we know that q1q.

Theorem 25. [Restated, see original statement.]

Deciding whether a full-ded t is uniformly one-bounded is EXPTIME-hard.

Proof.

We apply a polynomial reduction from full-tgd combined complexity, which is EXPTIME-hard, to our problem. In particular, given a full-tgd t with the form p1pnn, a database D with contents {d1,,d|D|}, and some ground atom a, we reduce the problem of identifying whether t,Da to decide whether some ded t2 is one-bounded. In virtue of Proposition 31, w.l.o.g., we assume that t,D has a universal model U that contains an atom b that cannot be obtained in a single chase step from t,D.

Now, we build the full-ded t2 = d1d|D|p1pnna and prove that t2 is one-bounded iff t,Da. We start proving that t,Da implies t2 is one-bounded. To see so, do realize that, for any database D, t2,D has a universal model set composed of only one model which is either D itself (when DD), or D{a} (when DD). Do note that, in both cases, all atoms can be obtained through at most 1 chase step.

We continue proving that t,D⊧̸a implies t2 is not one-bounded. In particular, do note that the universal model set for t2,D is U{D{a}}, where U is the universal model of t,D. Indeed, similarly as before, we see that every potential minimal model of t2,D is D{a} and the model D{n[σ1],n[σ2],,n[σm]}, where σ1,,σm are, precisely, the violations that occur when chasing D with t. Thus, D{n[σ1],n[σ2],,n[σm]}=U. Since t,D⊧̸a, we see that aU, which makes U a true minimal model of t2,D. Furthermore, by assumption, we have that U contains some atom b that cannot be obtained in a single chase step from t,D, and thus, neither from t2,D. Thus, t2 is not one-bounded.

Theorem 27. [Restated, see original statement.]

Deciding CQHT1¬ membership is NP-hard.

Proof.

Immediately from the NP-hardness of checking one-boundedness for linear full-tgds [13], and the possibility to check whether a linear full-tgd t is one-bounded by checking whether its corresponding query q2 (i.e., q2 s.t. ded(q2)=t) belongs to CQHT1¬.

Theorem 29. [Restated, see original statement.]

Deciding CQHT1¬ membership is in Π2P.

Proof.

We prove that CQHT1¬ not membership is in Σ2P. Recall that a query q2 is not in CQHT1¬ iff ded(q2) is not uniformly one-bounded (Theorem 23). Let rewriting(t,t) represent the set of all the tgds that can be obtained after unfolding one or several atoms of the body of t with t. We can check that a full-tgd t is not uniformly one-bounded by non-deterministically guessing a new tgd trewriting1(t,t), s.t. t↝̸t. Since t is of polynomial size, and checking tt is in NP, we can see that checking whether a full-tgd is not one-bounded is in Σ2P.

Theorem 30. [Restated, see original statement.]

Given a boolean query qCQ1¬, s.t. the number of positive atoms that can unify with the negated atoms is bounded by some k, deciding whether qCQHT1¬ is NP-complete.

Proof.

The problem is NP-hard since it is a generalisation of uniform one-boundedness of linear (full-)tgds, which is NP-complete [13]. The problem is in NP slightly modifying our proof for Theorem 29. In particular, our problem can be solved by first computing all the unfolded tgds trewriting(t,t). Do note that the number of tgds is 2k, so, if k is bounded, the number of obtained tgds is constant. Then we only need to check that tt, for each trewriting(t,t). In essence, we need to find a polynomial number of polynomial homomorphisms, making the problem in NP.